added foreground service for timer
This commit is contained in:
parent
f92e43e216
commit
525d0740f8
3 changed files with 341 additions and 208 deletions
|
@ -1,15 +1,14 @@
|
||||||
import { TimerNotif } from './shared/utils'
|
import { TimerNotif } from './shared/utils'
|
||||||
const superProto = android.app.Service.prototype
|
const superProto = android.app.Service.prototype
|
||||||
|
|
||||||
android.app.Service.extend('com.tns.ForegroundService', {
|
android.app.Service.extend('com.tns.ForegroundService', {
|
||||||
onStartCommand: function(intent, flags, startId) {
|
onStartCommand: function(intent, flags, startId) {
|
||||||
console.log('onStartCommand')
|
|
||||||
superProto.onStartCommand.call(this, intent, flags, startId)
|
superProto.onStartCommand.call(this, intent, flags, startId)
|
||||||
return android.app.Service.START_STICKY
|
return android.app.Service.START_STICKY
|
||||||
},
|
},
|
||||||
onCreate: function() {
|
onCreate: function() {
|
||||||
console.log('onCreate')
|
|
||||||
superProto.onCreate.call(this)
|
superProto.onCreate.call(this)
|
||||||
this.startForeground(777, this.getNotification())
|
this.startForeground(6, this.getNotification())
|
||||||
},
|
},
|
||||||
onBind: function(intent) {
|
onBind: function(intent) {
|
||||||
return superProto.onBind.call(this, intent)
|
return superProto.onBind.call(this, intent)
|
||||||
|
@ -18,17 +17,16 @@ android.app.Service.extend('com.tns.ForegroundService', {
|
||||||
return superProto.onUnbind.call(this, intent)
|
return superProto.onUnbind.call(this, intent)
|
||||||
},
|
},
|
||||||
onDestroy: function() {
|
onDestroy: function() {
|
||||||
console.log('onDestroy')
|
|
||||||
this.stopForeground(true)
|
this.stopForeground(true)
|
||||||
},
|
},
|
||||||
getNotification: function() {
|
getNotification: function() {
|
||||||
return TimerNotif.getNotification(
|
return TimerNotif.getNotification(
|
||||||
{
|
{
|
||||||
bID: 'bringToFront',
|
bID: 'info',
|
||||||
cID: 'cti',
|
cID: 'cti',
|
||||||
cName: 'Cooking Timer info',
|
cName: 'Cooking Timer info',
|
||||||
description: `0 ongoing, 0 paused`,
|
description: `0 ongoing, 0 paused`,
|
||||||
nID: 777,
|
nID: 6,
|
||||||
priority: -2,
|
priority: -2,
|
||||||
sound: null,
|
sound: null,
|
||||||
title: 'EnRecipes is running',
|
title: 'EnRecipes is running',
|
||||||
|
|
196
app/main.ts
196
app/main.ts
|
@ -1,15 +1,98 @@
|
||||||
|
import {
|
||||||
|
Application,
|
||||||
|
AndroidApplication,
|
||||||
|
ApplicationSettings,
|
||||||
|
Utils,
|
||||||
|
Device,
|
||||||
|
Color,
|
||||||
|
Frame,
|
||||||
|
} from '@nativescript/core'
|
||||||
import {
|
import {
|
||||||
localize,
|
localize,
|
||||||
androidLaunchEventLocalizationHandler,
|
androidLaunchEventLocalizationHandler,
|
||||||
} from '@nativescript/localize'
|
} from '@nativescript/localize'
|
||||||
import { Application, AndroidApplication, Utils } from '@nativescript/core'
|
import Vue from 'nativescript-vue'
|
||||||
|
import EnRecipes from './components/EnRecipes.vue'
|
||||||
|
import EditRecipe from './components/EditRecipe.vue'
|
||||||
|
import MealPlanner from './components/MealPlanner.vue'
|
||||||
|
import CookingTimer from './components/CookingTimer.vue'
|
||||||
|
import GroceryList from './components/GroceryList.vue'
|
||||||
|
import store from './store'
|
||||||
|
import * as utils from '~/shared/utils'
|
||||||
|
|
||||||
const keepScreenOn = () => {
|
export const EventBus = new Vue()
|
||||||
|
|
||||||
|
let renderView: any = EnRecipes
|
||||||
|
|
||||||
|
import CollectionView from '@nativescript-community/ui-collectionview/vue'
|
||||||
|
Vue.use(CollectionView)
|
||||||
|
import { StackLayout, GridLayout, DockLayout } from '@nativescript-rtl/ui'
|
||||||
|
Vue.registerElement('RStackLayout', () => StackLayout)
|
||||||
|
Vue.registerElement('RGridLayout', () => GridLayout)
|
||||||
|
Vue.registerElement('RDockLayout', () => DockLayout)
|
||||||
|
|
||||||
|
import { myMixin } from './shared/mixins'
|
||||||
|
Vue.mixin(myMixin)
|
||||||
|
|
||||||
|
const initFrame = () => {
|
||||||
|
const vm = store
|
||||||
|
|
||||||
|
//MAIN INIT
|
||||||
|
vm.commit('setTheme', ApplicationSettings.getString('appTheme', 'sysDef'))
|
||||||
|
if (!vm.state.recipes.length) vm.commit('initRecipes')
|
||||||
|
vm.commit('initMealPlans')
|
||||||
|
vm.commit('initListItems')
|
||||||
|
vm.commit('initTimerPresets')
|
||||||
|
if (!Object.keys(vm.state.timerSound).length) {
|
||||||
|
let hasTimerSound = ApplicationSettings.getString('timerSound', null)
|
||||||
|
vm.commit(
|
||||||
|
'setTimerSound',
|
||||||
|
hasTimerSound ? JSON.parse(hasTimerSound) : utils.getTones().defaultTone
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// INIT FRAME
|
||||||
|
const View = android.view.View as any
|
||||||
|
const window = Application.android.startActivity.getWindow()
|
||||||
|
const decorView = window.getDecorView()
|
||||||
|
let sdkv = parseInt(Device.sdkVersion)
|
||||||
|
function setColors(color) {
|
||||||
|
window.setStatusBarColor(new Color(color).android)
|
||||||
|
sdkv >= 27 && window.setNavigationBarColor(new Color(color).android)
|
||||||
|
}
|
||||||
|
switch (vm.state.appTheme) {
|
||||||
|
case 'Light':
|
||||||
|
setColors('#f1f3f5')
|
||||||
|
break
|
||||||
|
case 'Dark':
|
||||||
|
setColors('#212529')
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
setColors('#000000')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (sdkv >= 27)
|
||||||
|
decorView.setSystemUiVisibility(
|
||||||
|
vm.state.appTheme == 'Light'
|
||||||
|
? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR |
|
||||||
|
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||||
|
: View.SYSTEM_UI_FLAG_DARK_STATUS_BAR |
|
||||||
|
View.SYSTEM_UI_FLAG_DARK_NAVIGATION_BAR
|
||||||
|
)
|
||||||
|
else
|
||||||
|
decorView.setSystemUiVisibility(
|
||||||
|
vm.state.appTheme == 'Light'
|
||||||
|
? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||||
|
: View.SYSTEM_UI_FLAG_DARK_STATUS_BAR
|
||||||
|
)
|
||||||
|
Frame.topmost().className = store.state.appTheme
|
||||||
|
}
|
||||||
|
const showOverLockscreen = () => {
|
||||||
let ctx = Utils.ad.getApplicationContext()
|
let ctx = Utils.ad.getApplicationContext()
|
||||||
const pm = ctx.getSystemService(android.content.Context.POWER_SERVICE)
|
const pm = ctx.getSystemService(android.content.Context.POWER_SERVICE)
|
||||||
let isScreenOff = !pm.isInteractive()
|
let isScreenOff = !pm.isInteractive()
|
||||||
if (isScreenOff) {
|
if (isScreenOff) {
|
||||||
console.log('keepScreenOn')
|
console.log('showOverLockscreen')
|
||||||
const window = Application.android.startActivity.getWindow()
|
const window = Application.android.startActivity.getWindow()
|
||||||
const windowMgr = android.view.WindowManager
|
const windowMgr = android.view.WindowManager
|
||||||
const flags =
|
const flags =
|
||||||
|
@ -17,42 +100,63 @@ const keepScreenOn = () => {
|
||||||
windowMgr.LayoutParams.FLAG_TURN_SCREEN_ON |
|
windowMgr.LayoutParams.FLAG_TURN_SCREEN_ON |
|
||||||
windowMgr.LayoutParams.FLAG_KEEP_SCREEN_ON
|
windowMgr.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||||
window.addFlags(flags)
|
window.addFlags(flags)
|
||||||
function clearFlags(args) {
|
|
||||||
args.cancel = true
|
|
||||||
window.clearFlags(flags)
|
|
||||||
Application.android.off(
|
|
||||||
AndroidApplication.activityBackPressedEvent,
|
|
||||||
clearFlags
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Application.android.on(
|
|
||||||
AndroidApplication.activityBackPressedEvent,
|
|
||||||
clearFlags
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Application.on(Application.resumeEvent, keepScreenOn)
|
const intentListener = ({ intent, android }: any) => {
|
||||||
|
console.log(intent, android)
|
||||||
|
let action = ((intent || android).getStringExtra('action') ||
|
||||||
|
(android && android.getAction())) as string
|
||||||
|
|
||||||
|
if (action) {
|
||||||
|
console.log(action)
|
||||||
|
switch (action) {
|
||||||
|
case 'new_recipe':
|
||||||
|
renderView = EditRecipe
|
||||||
|
break
|
||||||
|
case 'planner':
|
||||||
|
renderView = MealPlanner
|
||||||
|
break
|
||||||
|
case 'timer':
|
||||||
|
renderView = CookingTimer
|
||||||
|
Vue.navigateTo(CookingTimer as any, {
|
||||||
|
animated: false,
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case 'grocery':
|
||||||
|
renderView = GroceryList
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Application.on(Application.resumeEvent, (args) => {
|
||||||
|
console.log('App Resume')
|
||||||
|
showOverLockscreen()
|
||||||
|
})
|
||||||
|
|
||||||
Application.on(Application.launchEvent, (args) => {
|
Application.on(Application.launchEvent, (args) => {
|
||||||
console.log('launching')
|
console.log('App Launch')
|
||||||
|
console.log('RTL', store.state.RTL)
|
||||||
|
store.commit('setRTL')
|
||||||
if (args.android) {
|
if (args.android) {
|
||||||
androidLaunchEventLocalizationHandler()
|
androidLaunchEventLocalizationHandler()
|
||||||
intentListener(args)
|
intentListener(args)
|
||||||
}
|
}
|
||||||
|
Application.android.on(
|
||||||
|
AndroidApplication.activityNewIntentEvent,
|
||||||
|
intentListener
|
||||||
|
)
|
||||||
|
Frame.on(Frame.loadedEvent, initFrame)
|
||||||
})
|
})
|
||||||
|
|
||||||
import Vue from 'nativescript-vue'
|
Application.on(Application.exitEvent, () => {
|
||||||
import EnRecipes from './components/EnRecipes.vue'
|
console.log('App Exit')
|
||||||
import CookingTimer from './components/CookingTimer.vue'
|
renderView = EnRecipes
|
||||||
import store from './store'
|
Application.android.off(
|
||||||
|
AndroidApplication.activityNewIntentEvent,
|
||||||
export const EventBus = new Vue()
|
intentListener
|
||||||
|
)
|
||||||
import CollectionView from '@nativescript-community/ui-collectionview/vue'
|
})
|
||||||
Vue.use(CollectionView)
|
|
||||||
|
|
||||||
import { lvMixin } from './shared/mixins'
|
|
||||||
Vue.mixin(lvMixin)
|
|
||||||
|
|
||||||
Vue.config.silent = false
|
Vue.config.silent = false
|
||||||
|
|
||||||
|
@ -60,37 +164,5 @@ Vue.filter('L', localize)
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
store,
|
store,
|
||||||
render: (h) => h(EnRecipes),
|
render: (h) => h('Frame', [h(renderView)]),
|
||||||
}).$start()
|
}).$start()
|
||||||
|
|
||||||
const intentListener = ({ intent, android }: any) => {
|
|
||||||
let ct = 'CookingTimer'
|
|
||||||
let action = (intent || android).getStringExtra('action')
|
|
||||||
console.log('calling: ', action)
|
|
||||||
if (action == 'open_timer' && store.state.currentComponent != ct) {
|
|
||||||
let openTimer = setInterval(() => {
|
|
||||||
let comp = store.state.currentComponent
|
|
||||||
if (comp == ct) clearInterval(openTimer)
|
|
||||||
else {
|
|
||||||
if (comp == 'CTSettings') Vue.navigateBack()
|
|
||||||
else {
|
|
||||||
Vue.navigateTo(CookingTimer)
|
|
||||||
store.commit('setComponent', 'CookingTimer')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 250)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Application.on(Application.launchEvent, () => {
|
|
||||||
Application.android.on(
|
|
||||||
AndroidApplication.activityNewIntentEvent,
|
|
||||||
intentListener
|
|
||||||
)
|
|
||||||
})
|
|
||||||
Application.on(Application.exitEvent, () => {
|
|
||||||
store.commit('setComponent', 'EnRecipes')
|
|
||||||
Application.android.off(
|
|
||||||
AndroidApplication.activityNewIntentEvent,
|
|
||||||
intentListener
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
323
app/store.ts
323
app/store.ts
|
@ -5,11 +5,17 @@ import { openOrCreate } from '@akylas/nativescript-sqlite'
|
||||||
import {
|
import {
|
||||||
getFileAccess,
|
getFileAccess,
|
||||||
File,
|
File,
|
||||||
ApplicationSettings,
|
|
||||||
Application,
|
Application,
|
||||||
knownFolders,
|
knownFolders,
|
||||||
path,
|
path,
|
||||||
} from '@nativescript/core'
|
} from '@nativescript/core'
|
||||||
|
import {
|
||||||
|
getNumber,
|
||||||
|
setNumber,
|
||||||
|
getString,
|
||||||
|
setString,
|
||||||
|
} from '@nativescript/core/application-settings'
|
||||||
|
import * as utils from '~/shared/utils'
|
||||||
|
|
||||||
// OPEN DATABASE FILE
|
// OPEN DATABASE FILE
|
||||||
const db = openOrCreate(
|
const db = openOrCreate(
|
||||||
|
@ -31,6 +37,11 @@ db.execute(
|
||||||
'CREATE TABLE IF NOT EXISTS mealPlans (date INT, type TEXT, title TEXT)'
|
'CREATE TABLE IF NOT EXISTS mealPlans (date INT, type TEXT, title TEXT)'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CREATE timerPresets TABLE
|
||||||
|
db.execute(
|
||||||
|
'CREATE TABLE IF NOT EXISTS timerPresets (id INT PRIMARY KEY, label TEXT, time TEXT)'
|
||||||
|
)
|
||||||
|
|
||||||
const defaultCuisines = [
|
const defaultCuisines = [
|
||||||
'American',
|
'American',
|
||||||
'Brazilian',
|
'Brazilian',
|
||||||
|
@ -136,21 +147,22 @@ const defaultUnits = [
|
||||||
'medium',
|
'medium',
|
||||||
'large',
|
'large',
|
||||||
]
|
]
|
||||||
|
|
||||||
const listItems = {
|
const listItems = {
|
||||||
cuisines: {
|
cuisines: {
|
||||||
sort: true,
|
sort: 1,
|
||||||
defaultItems: defaultCuisines,
|
defaultItems: defaultCuisines,
|
||||||
},
|
},
|
||||||
categories: {
|
categories: {
|
||||||
sort: true,
|
sort: 1,
|
||||||
defaultItems: defaultCategories,
|
defaultItems: defaultCategories,
|
||||||
},
|
},
|
||||||
yieldUnits: {
|
yieldUnits: {
|
||||||
sort: false,
|
sort: 0,
|
||||||
defaultItems: defaultYieldUnits,
|
defaultItems: defaultYieldUnits,
|
||||||
},
|
},
|
||||||
units: {
|
units: {
|
||||||
sort: false,
|
sort: 0,
|
||||||
defaultItems: defaultUnits,
|
defaultItems: defaultUnits,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -227,10 +239,15 @@ export default new Vuex.Store({
|
||||||
trans: '\ue93c',
|
trans: '\ue93c',
|
||||||
delay: '\ue93d',
|
delay: '\ue93d',
|
||||||
ring: '\ue93e',
|
ring: '\ue93e',
|
||||||
|
print: '\ue93f',
|
||||||
},
|
},
|
||||||
currentComponent: 'EnRecipes',
|
currentComponent: 'EnRecipes',
|
||||||
sortType: 'Oldest first',
|
sortType: 'random',
|
||||||
language: [
|
language: [
|
||||||
|
{
|
||||||
|
locale: 'ar',
|
||||||
|
title: 'العربية',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
locale: 'da',
|
locale: 'da',
|
||||||
title: 'Dansk',
|
title: 'Dansk',
|
||||||
|
@ -239,10 +256,18 @@ export default new Vuex.Store({
|
||||||
locale: 'de',
|
locale: 'de',
|
||||||
title: 'Deutsch',
|
title: 'Deutsch',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
locale: 'en-IN',
|
||||||
|
title: 'English (IN)',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
locale: 'en-GB',
|
locale: 'en-GB',
|
||||||
title: 'English (UK)',
|
title: 'English (UK)',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
locale: 'en-US',
|
||||||
|
title: 'English (US)',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
locale: 'es',
|
locale: 'es',
|
||||||
title: 'Español',
|
title: 'Español',
|
||||||
|
@ -267,10 +292,6 @@ export default new Vuex.Store({
|
||||||
locale: 'hi',
|
locale: 'hi',
|
||||||
title: 'हिंदी',
|
title: 'हिंदी',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
locale: 'ml',
|
|
||||||
title: 'മലയാളം',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
locale: 'id',
|
locale: 'id',
|
||||||
title: 'Indonesia',
|
title: 'Indonesia',
|
||||||
|
@ -279,6 +300,14 @@ export default new Vuex.Store({
|
||||||
locale: 'it',
|
locale: 'it',
|
||||||
title: 'Italiano',
|
title: 'Italiano',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
locale: 'ja',
|
||||||
|
title: '日本語',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
locale: 'ml',
|
||||||
|
title: 'മലയാളം',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
locale: 'nb-NO',
|
locale: 'nb-NO',
|
||||||
title: 'Norsk bokmål',
|
title: 'Norsk bokmål',
|
||||||
|
@ -287,10 +316,10 @@ export default new Vuex.Store({
|
||||||
locale: 'nl',
|
locale: 'nl',
|
||||||
title: 'Nederlands',
|
title: 'Nederlands',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// locale: 'pt',
|
locale: 'pt',
|
||||||
// title: 'Português',
|
title: 'Português',
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
locale: 'pt-BR',
|
locale: 'pt-BR',
|
||||||
title: 'Português (BR)',
|
title: 'Português (BR)',
|
||||||
|
@ -308,97 +337,114 @@ export default new Vuex.Store({
|
||||||
title: 'తెలుగు',
|
title: 'తెలుగు',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
shakeEnabled: ApplicationSettings.getBoolean('shakeEnabled', true),
|
shakeEnabled: getNumber('shakeEnabled', 1),
|
||||||
importSummary: {
|
importSummary: {
|
||||||
found: 0,
|
found: 0,
|
||||||
imported: 0,
|
imported: 0,
|
||||||
updated: 0,
|
updated: 0,
|
||||||
},
|
},
|
||||||
layout: ApplicationSettings.getString('layout', 'detailed'),
|
layout: getString('layout', 'detailed'),
|
||||||
selectedCuisine: null,
|
selectedCuisine: null,
|
||||||
selectedCategory: null,
|
selectedCategory: null,
|
||||||
selectedTag: null,
|
selectedTag: null,
|
||||||
appTheme: 'sysDef',
|
appTheme: 'sysDef',
|
||||||
mondayFirst: ApplicationSettings.getBoolean('mondayFirst', false),
|
mondayFirst: getNumber('mondayFirst', 0),
|
||||||
timerDelay: ApplicationSettings.getString('timerDelay', '1 minute'),
|
timerDelay: getString('timerDelay', '1 minute'),
|
||||||
timerSound: {},
|
timerSound: {},
|
||||||
timerVibrate: ApplicationSettings.getBoolean('timerVibrate', false),
|
timerVibrate: getNumber('timerVibrate', 0),
|
||||||
timerPresets: [
|
timerPresets: [],
|
||||||
{
|
|
||||||
id: 534534563,
|
|
||||||
label: 'Soft Eggs',
|
|
||||||
recipeID: null,
|
|
||||||
time: '00:06:00',
|
|
||||||
timerInterval: null,
|
|
||||||
isPaused: false,
|
|
||||||
preset: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 564646,
|
|
||||||
label: 'Medium Eggs',
|
|
||||||
recipeID: null,
|
|
||||||
time: '00:08:00',
|
|
||||||
timerInterval: null,
|
|
||||||
isPaused: false,
|
|
||||||
preset: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 43276767,
|
|
||||||
label: 'Hard Eggs',
|
|
||||||
recipeID: null,
|
|
||||||
time: '00:10:00',
|
|
||||||
timerInterval: null,
|
|
||||||
isPaused: false,
|
|
||||||
preset: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
activeTimers: [],
|
activeTimers: [],
|
||||||
timerIntervals: [],
|
FGService: 0,
|
||||||
|
RTL: 0,
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
addTimerPreset(state, timer) {
|
setRTL(state) {
|
||||||
state.timerPresets.push(timer)
|
state.RTL = utils.RTL() as any | 0
|
||||||
},
|
},
|
||||||
removeTimerPreset(state, index) {
|
setFGService(state, val) {
|
||||||
state.timerPresets.splice(index, 1)
|
state.FGService = val
|
||||||
|
},
|
||||||
|
addTimerPreset(state, timer) {
|
||||||
|
let i = state.timerPresets.findIndex((e) => e.id == timer.id)
|
||||||
|
if (state.timerPresets.some((e) => e.id == timer.id)) {
|
||||||
|
state.timerPresets.splice(i, 1, timer)
|
||||||
|
} else state.timerPresets.push(timer)
|
||||||
|
db.execute(
|
||||||
|
`REPLACE INTO timerPresets (id, label, time) VALUES (?, ?, ?)`,
|
||||||
|
[timer.id, timer.label, timer.time]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
deleteTimerPreset(state, i) {
|
||||||
|
let id = state.timerPresets[i]
|
||||||
|
state.timerPresets.splice(i, 1)
|
||||||
|
db.execute(`DELETE FROM timerPresets WHERE id = ${id}`)
|
||||||
|
},
|
||||||
|
initTimerPresets(state) {
|
||||||
|
if (!state.timerPresets.length)
|
||||||
|
db.select(`SELECT * FROM timerPresets`).then((res) => {
|
||||||
|
res.forEach((t) => {
|
||||||
|
t.recipeID = 0
|
||||||
|
t.timerInt = 0
|
||||||
|
t.isPaused = 0
|
||||||
|
t.preset = 1
|
||||||
|
t.done = 0
|
||||||
|
state.timerPresets.push(t)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
importTimerPresets(state, timers) {
|
||||||
|
let newPresets = timers.filter(
|
||||||
|
(e) => !state.timerPresets.some((f) => f.id === e.id)
|
||||||
|
)
|
||||||
|
newPresets.forEach((t) => {
|
||||||
|
db.execute(
|
||||||
|
`INSERT INTO timerPresets (id, label, time) VALUES (?, ?, ?)`,
|
||||||
|
[t.id, t.label, t.time]
|
||||||
|
)
|
||||||
|
state.timerPresets.push(t)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
clearTimerInterval(state) {
|
clearTimerInterval(state) {
|
||||||
state.activeTimers.forEach((e) => {
|
state.activeTimers.forEach((e) => {
|
||||||
clearInterval(e.timerInterval)
|
clearInterval(e.timerInt)
|
||||||
e.timerInterval = null
|
e.timerInt = 0
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addActiveTimer(state, { timer, index }) {
|
addActiveTimer(state, { timer, i }) {
|
||||||
state.activeTimers.splice(index, 0, timer)
|
state.activeTimers.splice(i, 0, timer)
|
||||||
|
},
|
||||||
|
sortActiveTimers(state) {
|
||||||
|
let a = state.activeTimers.reduce((acc, e) => {
|
||||||
|
;(acc[e.recipeID] = acc[e.recipeID] || []).push(e)
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
state.activeTimers = [...(<any>Object).values(a).flat(2)]
|
||||||
},
|
},
|
||||||
updateActiveTimer(state, timer) {
|
updateActiveTimer(state, timer) {
|
||||||
let index = state.activeTimers.findIndex((e) => e.id == timer.id)
|
let i = state.activeTimers.findIndex((e) => e.id == timer.id)
|
||||||
state.activeTimers.splice(index, 1, timer)
|
state.activeTimers.splice(i, 1, timer)
|
||||||
},
|
},
|
||||||
removeActiveTimer(state, index) {
|
removeActiveTimer(state, i) {
|
||||||
state.activeTimers.splice(index, 1)
|
state.activeTimers.splice(i, 1)
|
||||||
},
|
},
|
||||||
setTimerDelay(state, delay) {
|
setTimerDelay(state, delay) {
|
||||||
state.timerDelay = delay
|
state.timerDelay = delay
|
||||||
ApplicationSettings.setString('timerDelay', delay)
|
setString('timerDelay', delay)
|
||||||
},
|
},
|
||||||
setTimerSound(state, sound) {
|
setTimerSound(state, sound) {
|
||||||
state.timerSound = {
|
state.timerSound = sound
|
||||||
title: sound.title,
|
setString('timerSound', JSON.stringify(sound))
|
||||||
uri: sound.uri,
|
|
||||||
}
|
|
||||||
ApplicationSettings.setString('timerSound', JSON.stringify(sound))
|
|
||||||
},
|
},
|
||||||
setTimerVibrate(state, bool) {
|
setTimerVibrate(state, n) {
|
||||||
state.timerVibrate = bool
|
state.timerVibrate = n
|
||||||
ApplicationSettings.setBoolean('timerVibrate', bool)
|
setNumber('timerVibrate', n)
|
||||||
},
|
},
|
||||||
clearImportSummary(state) {
|
clearImportSummary(state) {
|
||||||
for (const key in state.importSummary) state.importSummary[key] = 0
|
for (const key in state.importSummary) state.importSummary[key] = 0
|
||||||
},
|
},
|
||||||
setFirstDay(state, bool) {
|
setFirstDay(state, n) {
|
||||||
state.mondayFirst = bool
|
state.mondayFirst = n | 0
|
||||||
ApplicationSettings.setBoolean('mondayFirst', bool)
|
setNumber('mondayFirst', n | 0)
|
||||||
},
|
},
|
||||||
setTheme(state, theme) {
|
setTheme(state, theme) {
|
||||||
switch (theme) {
|
switch (theme) {
|
||||||
|
@ -414,7 +460,7 @@ export default new Vuex.Store({
|
||||||
state.appTheme = theme
|
state.appTheme = theme
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
ApplicationSettings.setString('appTheme', theme)
|
setString('appTheme', theme)
|
||||||
},
|
},
|
||||||
clearFilter(state) {
|
clearFilter(state) {
|
||||||
state.selectedCuisine = state.selectedCategory = state.selectedTag = null
|
state.selectedCuisine = state.selectedCategory = state.selectedTag = null
|
||||||
|
@ -436,8 +482,8 @@ export default new Vuex.Store({
|
||||||
state.recipes.push(e)
|
state.recipes.push(e)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
state.shakeEnabled = ApplicationSettings.getBoolean('shakeEnabled', true)
|
state.shakeEnabled = getNumber('shakeEnabled', 1)
|
||||||
state.sortType = ApplicationSettings.getString('sortType', 'Oldest first')
|
state.sortType = getString('sortType', 'random')
|
||||||
},
|
},
|
||||||
importRecipesFromJSON(state, recipes) {
|
importRecipesFromJSON(state, recipes) {
|
||||||
let localRecipesIDs, partition
|
let localRecipesIDs, partition
|
||||||
|
@ -463,6 +509,12 @@ export default new Vuex.Store({
|
||||||
r.yieldQuantity = r.yield.quantity
|
r.yieldQuantity = r.yield.quantity
|
||||||
r.yieldUnit = r.yield.unit
|
r.yieldUnit = r.yield.unit
|
||||||
delete r.yield
|
delete r.yield
|
||||||
|
function getTime(d) {
|
||||||
|
return new Date(d).getTime()
|
||||||
|
}
|
||||||
|
r.lastTried = getTime(r.lastTried)
|
||||||
|
r.lastModified = getTime(r.lastModified)
|
||||||
|
r.created = getTime(r.created)
|
||||||
return r
|
return r
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -492,9 +544,9 @@ export default new Vuex.Store({
|
||||||
JSON.stringify(r.notes),
|
JSON.stringify(r.notes),
|
||||||
r.favorite ? 1 : 0,
|
r.favorite ? 1 : 0,
|
||||||
r.tried ? 1 : 0,
|
r.tried ? 1 : 0,
|
||||||
r.lastTried ? new Date(r.lastTried).getTime() : null,
|
r.lastTried,
|
||||||
r.lastModified ? new Date(r.lastModified).getTime() : null,
|
r.lastModified,
|
||||||
r.created ? new Date(r.created).getTime() : null,
|
r.created,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -533,9 +585,9 @@ export default new Vuex.Store({
|
||||||
JSON.stringify(r.notes),
|
JSON.stringify(r.notes),
|
||||||
r.favorite ? 1 : 0,
|
r.favorite ? 1 : 0,
|
||||||
r.tried ? 1 : 0,
|
r.tried ? 1 : 0,
|
||||||
r.lastTried ? new Date(r.lastTried).getTime() : null,
|
r.lastTried,
|
||||||
r.lastModified ? new Date(r.lastModified).getTime() : null,
|
r.lastModified,
|
||||||
r.created ? new Date(r.created).getTime() : null,
|
r.created,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -649,9 +701,9 @@ export default new Vuex.Store({
|
||||||
function exist({ id }, index: number) {
|
function exist({ id }, index: number) {
|
||||||
if (id === recipe.id) {
|
if (id === recipe.id) {
|
||||||
i = index
|
i = index
|
||||||
return true
|
return 1
|
||||||
}
|
}
|
||||||
return false
|
return 0
|
||||||
}
|
}
|
||||||
state.recipes.some(exist)
|
state.recipes.some(exist)
|
||||||
? Object.assign(state.recipes[i], recipe)
|
? Object.assign(state.recipes[i], recipe)
|
||||||
|
@ -659,9 +711,9 @@ export default new Vuex.Store({
|
||||||
},
|
},
|
||||||
deleteRecipes(state, ids) {
|
deleteRecipes(state, ids) {
|
||||||
ids.forEach((id: string) => {
|
ids.forEach((id: string) => {
|
||||||
let index = state.recipes.findIndex((e) => e.id === id)
|
let i = state.recipes.findIndex((e) => e.id === id)
|
||||||
getFileAccess().deleteFile(state.recipes[index].image)
|
getFileAccess().deleteFile(state.recipes[i].image)
|
||||||
state.recipes.splice(index, 1)
|
state.recipes.splice(i, 1)
|
||||||
db.execute(`DELETE FROM recipes WHERE id = '${id}'`)
|
db.execute(`DELETE FROM recipes WHERE id = '${id}'`)
|
||||||
state.recipes.forEach((e, i) => {
|
state.recipes.forEach((e, i) => {
|
||||||
if (e.combinations.includes(id)) {
|
if (e.combinations.includes(id)) {
|
||||||
|
@ -774,11 +826,11 @@ export default new Vuex.Store({
|
||||||
type = 'snacks'
|
type = 'snacks'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return f.title === e.title && f.date === date && f.type === type
|
return f.title == e.title && f.date == date && f.type == type
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return !state.mealPlans.some(
|
return !state.mealPlans.some(
|
||||||
(f) => f.title === e.title && f.date === e.date && f.type === e.type
|
(f) => f.title == e.title && f.date == e.date && f.type == e.type
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -835,13 +887,13 @@ export default new Vuex.Store({
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addMealPlan(state, { date, type, title }) {
|
addMealPlan(state, { date, type, title, index, inDB }) {
|
||||||
let mealPlan = {
|
let mealPlan = {
|
||||||
date,
|
date,
|
||||||
type,
|
type,
|
||||||
title,
|
title,
|
||||||
}
|
}
|
||||||
state.mealPlans.push(mealPlan)
|
if (inDB) {
|
||||||
const cols = Object.keys(mealPlan).join(', ')
|
const cols = Object.keys(mealPlan).join(', ')
|
||||||
const placeholder = Object.keys(mealPlan)
|
const placeholder = Object.keys(mealPlan)
|
||||||
.fill('?')
|
.fill('?')
|
||||||
|
@ -850,32 +902,33 @@ export default new Vuex.Store({
|
||||||
`INSERT INTO mealPlans (${cols}) VALUES (${placeholder})`,
|
`INSERT INTO mealPlans (${cols}) VALUES (${placeholder})`,
|
||||||
Object.values(mealPlan)
|
Object.values(mealPlan)
|
||||||
)
|
)
|
||||||
|
if (index === null) state.mealPlans.push(mealPlan)
|
||||||
|
} else {
|
||||||
|
state.mealPlans.splice(index, 0, mealPlan)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
deleteMealPlan(state, { date, type, title }) {
|
deleteMealPlan(state, { date, type, title, index, inDB }) {
|
||||||
let index = state.mealPlans.findIndex(
|
if (inDB) {
|
||||||
(e) => e.title === title && e.type === type && e.date === date
|
|
||||||
)
|
|
||||||
state.mealPlans.splice(index, 1)
|
|
||||||
state.mealPlans = [...state.mealPlans]
|
|
||||||
db.execute(
|
db.execute(
|
||||||
`DELETE FROM mealPlans WHERE date = ${date} AND type = '${type}' AND title = '${title}'`
|
`DELETE FROM mealPlans WHERE date = ${date} AND type = '${type}' AND title = '${title}'`
|
||||||
)
|
)
|
||||||
},
|
} else {
|
||||||
toggleState(state, { id, key, setDate }) {
|
state.mealPlans.splice(index, 1)
|
||||||
let index = state.recipes.findIndex((e) => e.id == id)
|
state.mealPlans = [...state.mealPlans]
|
||||||
state.recipes[index][key] = state.recipes[index][key] ? 0 : 1
|
|
||||||
db.execute(
|
|
||||||
`UPDATE recipes SET ${key} = ${state.recipes[index][key]} WHERE id = '${id}'`
|
|
||||||
)
|
|
||||||
if (setDate) {
|
|
||||||
state.recipes[index].lastTried = new Date().getTime()
|
|
||||||
db.execute(
|
|
||||||
`UPDATE recipes SET lastTried = ${state.recipes[index].lastTried} WHERE id = '${id}'`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setComponent(state, comp) {
|
toggleState(state, { id, key, setDate }) {
|
||||||
state.currentComponent = comp
|
let i = state.recipes.findIndex((e) => e.id == id)
|
||||||
|
state.recipes[i][key] = state.recipes[i][key] ? 0 : 1
|
||||||
|
db.execute(
|
||||||
|
`UPDATE recipes SET ${key} = ${state.recipes[i][key]} WHERE id = '${id}'`
|
||||||
|
)
|
||||||
|
if (setDate) {
|
||||||
|
state.recipes[i].lastTried = new Date().getTime()
|
||||||
|
db.execute(
|
||||||
|
`UPDATE recipes SET lastTried = ${state.recipes[i].lastTried} WHERE id = '${id}'`
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
unSyncCombinations(state, { id, combinations }) {
|
unSyncCombinations(state, { id, combinations }) {
|
||||||
state.recipes.forEach((e, i) => {
|
state.recipes.forEach((e, i) => {
|
||||||
|
@ -890,19 +943,17 @@ export default new Vuex.Store({
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
setShake(state, shake) {
|
setShake(state, shake) {
|
||||||
state.shakeEnabled = shake
|
state.shakeEnabled = shake | 0
|
||||||
ApplicationSettings.setBoolean('shakeEnabled', shake)
|
setNumber('shakeEnabled', shake | 0)
|
||||||
},
|
},
|
||||||
setRating(state, { id, rating }) {
|
setRating(state, { id, rating }) {
|
||||||
let index = state.recipes.findIndex((e) => e.id == id)
|
let i = state.recipes.findIndex((e) => e.id == id)
|
||||||
state.recipes[index].rating = rating
|
state.recipes[i].rating = rating
|
||||||
db.execute(`UPDATE recipes SET rating = ${rating} WHERE id = '${id}'`)
|
db.execute(`UPDATE recipes SET rating = ${rating} WHERE id = '${id}'`)
|
||||||
},
|
},
|
||||||
toggleCart(state, { id }) {
|
toggleCart(state, { id }) {
|
||||||
let index = state.recipes.indexOf(
|
let i = state.recipes.indexOf(state.recipes.filter((e) => e.id === id)[0])
|
||||||
state.recipes.filter((e) => e.id === id)[0]
|
state.recipes[i].inBag = !state.recipes[i].inBag
|
||||||
)
|
|
||||||
state.recipes[index].inBag = !state.recipes[index].inBag
|
|
||||||
},
|
},
|
||||||
unlinkBrokenImages(state) {
|
unlinkBrokenImages(state) {
|
||||||
state.recipes.forEach((r, i) => {
|
state.recipes.forEach((r, i) => {
|
||||||
|
@ -924,11 +975,26 @@ export default new Vuex.Store({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
setRTL({ commit }) {
|
||||||
|
commit('setRTL')
|
||||||
|
},
|
||||||
|
sortActiveTimers({ commit }) {
|
||||||
|
commit('sortActiveTimers')
|
||||||
|
},
|
||||||
|
setFGService({ commit }, val) {
|
||||||
|
commit('setFGService', val)
|
||||||
|
},
|
||||||
addTimerPreset({ commit }, timer) {
|
addTimerPreset({ commit }, timer) {
|
||||||
commit('addTimerPreset', timer)
|
commit('addTimerPreset', timer)
|
||||||
},
|
},
|
||||||
removeTimerPreset({ commit }, timer) {
|
deleteTimerPreset({ commit }, timer) {
|
||||||
commit('removeTimerPreset', timer)
|
commit('deleteTimerPreset', timer)
|
||||||
|
},
|
||||||
|
initTimerPresets({ commit }) {
|
||||||
|
commit('initTimerPresets')
|
||||||
|
},
|
||||||
|
importTimerPresets({ commit }, timers) {
|
||||||
|
commit('importTimerPresets', timers)
|
||||||
},
|
},
|
||||||
clearTimerInterval({ commit }) {
|
clearTimerInterval({ commit }) {
|
||||||
commit('clearTimerInterval')
|
commit('clearTimerInterval')
|
||||||
|
@ -939,8 +1005,8 @@ export default new Vuex.Store({
|
||||||
updateActiveTimer({ commit }, timer) {
|
updateActiveTimer({ commit }, timer) {
|
||||||
commit('updateActiveTimer', timer)
|
commit('updateActiveTimer', timer)
|
||||||
},
|
},
|
||||||
removeActiveTimer({ commit }, index) {
|
removeActiveTimer({ commit }, i) {
|
||||||
commit('removeActiveTimer', index)
|
commit('removeActiveTimer', i)
|
||||||
},
|
},
|
||||||
setTimerDelay({ commit }, delay) {
|
setTimerDelay({ commit }, delay) {
|
||||||
commit('setTimerDelay', delay)
|
commit('setTimerDelay', delay)
|
||||||
|
@ -948,14 +1014,14 @@ export default new Vuex.Store({
|
||||||
setTimerSound({ commit }, sound) {
|
setTimerSound({ commit }, sound) {
|
||||||
commit('setTimerSound', sound)
|
commit('setTimerSound', sound)
|
||||||
},
|
},
|
||||||
setTimerVibrate({ commit }, bool) {
|
setTimerVibrate({ commit }, n) {
|
||||||
commit('setTimerVibrate', bool)
|
commit('setTimerVibrate', n)
|
||||||
},
|
},
|
||||||
clearImportSummary({ commit }) {
|
clearImportSummary({ commit }) {
|
||||||
commit('clearImportSummary')
|
commit('clearImportSummary')
|
||||||
},
|
},
|
||||||
setFirstDay({ commit }, bool) {
|
setFirstDay({ commit }, n) {
|
||||||
commit('setFirstDay', bool)
|
commit('setFirstDay', n)
|
||||||
},
|
},
|
||||||
setTheme({ commit }, theme) {
|
setTheme({ commit }, theme) {
|
||||||
commit('setTheme', theme)
|
commit('setTheme', theme)
|
||||||
|
@ -1017,9 +1083,6 @@ export default new Vuex.Store({
|
||||||
toggleStateAction({ commit }, toggledRecipe) {
|
toggleStateAction({ commit }, toggledRecipe) {
|
||||||
commit('toggleState', toggledRecipe)
|
commit('toggleState', toggledRecipe)
|
||||||
},
|
},
|
||||||
setComponent({ commit }, comp) {
|
|
||||||
commit('setComponent', comp)
|
|
||||||
},
|
|
||||||
unSyncCombinationsAction({ commit }, combinations) {
|
unSyncCombinationsAction({ commit }, combinations) {
|
||||||
commit('unSyncCombinations', combinations)
|
commit('unSyncCombinations', combinations)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue