diff --git a/src/App.tsx b/src/App.tsx index 2b4894b..7457902 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,6 +2,7 @@ import { Component, Vue } from 'vue-property-decorator' import Mousetrap from 'mousetrap' import { AppModule } from '@/store/app' import { PageModule } from './store/page' +import { modKey } from './utils/helper' @Component export default class MainApp extends Vue { @@ -15,8 +16,6 @@ export default class MainApp extends Vue { } initKeybinds() { - const modKey = 'ctrl' - Mousetrap.bind(`${modKey}+t`, () => { PageModule.openTab({ type: 'themes' }) PageModule.openBlock({ id: 'settings' }) @@ -69,14 +68,6 @@ export default class MainApp extends Vue { PageModule.CLOSE_ALL_ACTIVE_BLOCK() }) - Mousetrap.bind(`${modKey}+p`, () => { - console.log('power off') - }) - - Mousetrap.bind(`${modKey}+r`, () => { - console.log('restart') - }) - Mousetrap.bind(`${modKey}+R`, () => { AppModule.randomizeSettingsTheme() }) diff --git a/src/components/app/AppDialog.tsx b/src/components/app/AppDialog.tsx index d2a6233..b7a2ad1 100644 --- a/src/components/app/AppDialog.tsx +++ b/src/components/app/AppDialog.tsx @@ -2,8 +2,8 @@ import { Component, Prop, Vue } from 'vue-property-decorator' import { PageModule } from '@/store/page' import AppIcon from '@/components/app/AppIcon.vue' import AppButton from './AppButton' +import { preventDefault } from '@/utils/helper' -// let showDialog = false @Component({ components: { AppIcon } }) @@ -20,7 +20,7 @@ export default class AppDialog extends Vue { } generateDialog() { - return
+ return
{ this.$t(this.dialog?.title + '') }

{ this.$t(this.dialog?.text + '') }

diff --git a/src/components/base/ShutdownButton.tsx b/src/components/base/ShutdownButton.tsx index 3e6ab4e..d3ae654 100644 --- a/src/components/base/ShutdownButton.tsx +++ b/src/components/base/ShutdownButton.tsx @@ -3,7 +3,8 @@ import { Component, Vue } from 'vue-property-decorator' import { PageModule } from '@/store/page' import AppIcon from '@/components/app/AppIcon.vue' import ShutdownMenu from '@/components/base/ShutdownMenu' -import { appWindow } from '@/models/lightdm' +import Mousetrap from 'mousetrap' +import { modKey, systemActionsObject } from '@/utils/helper' @Component({ components: { AppIcon, ShutdownMenu } @@ -13,32 +14,19 @@ export default class ShutdownBlock extends Vue { return !!PageModule.activeBlock } - shutdown(event: MouseEvent) { - event.stopPropagation() - this.openShutdownDialog() + mounted() { + Mousetrap.bind(`${modKey}+p`, systemActionsObject.shutdown) } - openShutdownDialog() { - PageModule.openDialog({ - title: 'modals.shutdown.title', - text: 'modals.shutdown.text', - actions: [ - { - title: 'text.yes', - callback: appWindow.lightdm.shutdown - }, - { - title: 'text.no', - callback: PageModule.closeDialog - } - ] - }) + shutdown(event: MouseEvent) { + event.stopPropagation() + systemActionsObject.shutdown() } render() { const button =
-
+
diff --git a/src/components/base/ShutdownMenu.tsx b/src/components/base/ShutdownMenu.tsx index 32daee4..962b761 100644 --- a/src/components/base/ShutdownMenu.tsx +++ b/src/components/base/ShutdownMenu.tsx @@ -2,6 +2,7 @@ import { Component, Vue } from 'vue-property-decorator' import AppIcon from '@/components/app/AppIcon.vue' import { appWindow } from '@/models/lightdm' +import { systemActionsObject } from '@/utils/helper' @Component({ components: { AppIcon } @@ -12,17 +13,17 @@ export default class ShutdownMenu extends Vue { { icon: 'restart', show: appWindow.lightdm.can_restart, - callback: appWindow.lightdm.restart + callback: systemActionsObject.restart }, { icon: 'suspend', show: appWindow.lightdm.can_suspend, - callback: appWindow.lightdm.suspend + callback: systemActionsObject.suspend }, { icon: 'hibernate', show: appWindow.lightdm.can_hibernate, - callback: appWindow.lightdm.hibernate + callback: systemActionsObject.hibernate } ].filter(({ show }) => show) } diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 0285748..9f93424 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -1,7 +1,11 @@ import { AppInputThemeSlider } from '@/models/app' +import { appWindow, Lightdm } from '@/models/lightdm' import { AppModule } from '@/store/app' +import { PageModule } from '@/store/page' import { debounce, DebounceSettings } from 'lodash' +export const modKey = 'fn' + export function Debounce(time = 500, options?: DebounceSettings): MethodDecorator { const map = new Map() @@ -82,3 +86,34 @@ export const generateDesktopIcons = () => { } }) } + +const systemActions = ['hibernate', 'restart', 'shutdown', 'suspend'] as const +type systemActionsType = typeof systemActions[number] + +export const buildSystemDialog = (callbackName: systemActionsType) => { + return () => PageModule.openDialog({ + title: `modals.${callbackName}.title`, + text: `modals.${callbackName}.text`, + actions: [ + { + title: 'text.yes', + callback: appWindow.lightdm[callbackName] + }, + { + title: 'text.no', + callback: PageModule.closeDialog + } + ] + }) +} + +export const systemActionsObject = systemActions.reduce((acc, action) => { + return { + ...acc, + [action]: buildSystemDialog(action) + } +}, {} as Record void>) + +export const preventDefault = (event: Event) => { + event.preventDefault() +}