enrecipes/app/main.ts

97 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-02-28 15:10:26 +00:00
import {
localize,
androidLaunchEventLocalizationHandler,
} from '@nativescript/localize'
2021-05-25 14:32:53 +00:00
import { Application, AndroidApplication, Utils } from '@nativescript/core'
const keepScreenOn = () => {
let ctx = Utils.ad.getApplicationContext()
const pm = ctx.getSystemService(android.content.Context.POWER_SERVICE)
let isScreenOff = !pm.isInteractive()
if (isScreenOff) {
console.log('keepScreenOn')
const window = Application.android.startActivity.getWindow()
const windowMgr = android.view.WindowManager
const flags =
2021-05-25 14:32:53 +00:00
windowMgr.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
windowMgr.LayoutParams.FLAG_TURN_SCREEN_ON |
windowMgr.LayoutParams.FLAG_KEEP_SCREEN_ON
window.addFlags(flags)
function clearFlags(args) {
args.cancel = true
window.clearFlags(flags)
Application.android.off(
AndroidApplication.activityBackPressedEvent,
clearFlags
)
}
Application.android.on(
AndroidApplication.activityBackPressedEvent,
clearFlags
2021-05-25 14:32:53 +00:00
)
}
}
Application.on(Application.resumeEvent, keepScreenOn)
Application.on(Application.launchEvent, (args) => {
2021-05-25 14:32:53 +00:00
console.log('launching')
if (args.android) {
androidLaunchEventLocalizationHandler()
intentListener(args)
}
})
2021-05-22 08:56:31 +00:00
2021-02-28 15:10:26 +00:00
import Vue from 'nativescript-vue'
2021-04-14 13:38:22 +00:00
import EnRecipes from './components/EnRecipes.vue'
import CookingTimer from './components/CookingTimer.vue'
2021-02-28 15:10:26 +00:00
import store from './store'
2020-10-14 19:32:32 +00:00
2021-05-22 08:56:31 +00:00
export const EventBus = new Vue()
2021-04-01 10:55:35 +00:00
import CollectionView from '@nativescript-community/ui-collectionview/vue'
Vue.use(CollectionView)
2021-01-23 17:20:15 +00:00
2021-05-25 14:32:53 +00:00
import { lvMixin } from './shared/mixins'
2021-04-01 10:55:35 +00:00
Vue.mixin(lvMixin)
2020-10-22 18:36:50 +00:00
2021-04-12 18:09:48 +00:00
Vue.config.silent = false
2021-01-23 17:20:15 +00:00
Vue.filter('L', localize)
2020-09-15 11:10:16 +00:00
new Vue({
store,
2021-04-01 10:55:35 +00:00
render: (h) => h(EnRecipes),
2020-09-15 11:10:16 +00:00
}).$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
)
})