From 2a7433da164e4d1ec58bf80be2bf39d7953906d2 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Sun, 8 May 2022 00:12:23 +0200 Subject: [PATCH] refactor: removed pinia ipc plugins --- src/renderer/index.js | 57 +++++++++++++++++++- src/renderer/stores/index.js | 13 ----- src/renderer/stores/plugins/ipcExceptions.js | 7 --- src/renderer/stores/plugins/ipcShortcuts.js | 12 ----- src/renderer/stores/plugins/ipcUpdates.js | 36 ------------- 5 files changed, 55 insertions(+), 70 deletions(-) delete mode 100644 src/renderer/stores/index.js delete mode 100644 src/renderer/stores/plugins/ipcExceptions.js delete mode 100644 src/renderer/stores/plugins/ipcShortcuts.js delete mode 100644 src/renderer/stores/plugins/ipcUpdates.js diff --git a/src/renderer/index.js b/src/renderer/index.js index 6d5539ad..cb67257c 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -1,13 +1,17 @@ 'use strict'; +import { ipcRenderer } from 'electron'; import { createApp } from 'vue'; +import { createPinia } from 'pinia'; import '@mdi/font/css/materialdesignicons.css'; import 'leaflet/dist/leaflet.css'; import '@/scss/main.scss'; import { VueMaskDirective } from 'v-mask'; + +import { useApplicationStore } from '@/stores/application'; import { useSettingsStore } from '@/stores/settings'; +import { useNotificationsStore } from '@/stores/notifications'; import App from '@/App.vue'; -import { pinia } from '@/stores'; import i18n from '@/i18n'; // https://github.com/probil/v-mask/issues/498#issuecomment-827027834 @@ -20,9 +24,58 @@ const vMaskV3 = { createApp(App) .directive('mask', vMaskV3) - .use(pinia) + .use(createPinia()) .use(i18n) .mount('#app'); const { locale } = useSettingsStore(); i18n.global.locale = locale; + +// IPC exceptions +ipcRenderer.on('unhandled-exception', (event, error) => { + useNotificationsStore().addNotification({ status: 'error', message: error.message }); +}); + +// IPC app updates +ipcRenderer.on('checking-for-update', () => { + useApplicationStore().updateStatus = 'checking'; +}); + +ipcRenderer.on('update-available', () => { + useApplicationStore().updateStatus = 'available'; +}); + +ipcRenderer.on('update-not-available', () => { + useApplicationStore().updateStatus = 'noupdate'; +}); + +ipcRenderer.on('check-failed', () => { + useApplicationStore().updateStatus = 'nocheck'; +}); + +ipcRenderer.on('no-auto-update', () => { + useApplicationStore().updateStatus = 'disabled'; +}); + +ipcRenderer.on('download-progress', (event, data) => { + useApplicationStore().updateStatus = 'downloading'; + useApplicationStore().downloadprogress = data.percent; +}); + +ipcRenderer.on('update-downloaded', () => { + useApplicationStore().updateStatus = 'downloaded'; +}); + +ipcRenderer.on('link-to-download', () => { + useApplicationStore().updateStatus = 'link'; +}); + +// IPC shortcuts +ipcRenderer.on('toggle-preferences', () => { + useApplicationStore().showSettingModal('general'); +}); + +ipcRenderer.on('open-updates-preferences', () => { + useApplicationStore().showSettingModal('update'); + ipcRenderer.send('check-for-updates'); +}); diff --git a/src/renderer/stores/index.js b/src/renderer/stores/index.js deleted file mode 100644 index 27c2d4a9..00000000 --- a/src/renderer/stores/index.js +++ /dev/null @@ -1,13 +0,0 @@ -// @ts-check -import { createPinia } from 'pinia'; -import { ipcUpdates } from './plugins/ipcUpdates'; -import { ipcShortcuts } from './plugins/ipcShortcuts'; -import { ipcExceptions } from './plugins/ipcExceptions'; - -const pinia = createPinia(); -pinia - .use(ipcUpdates) - .use(ipcShortcuts) - .use(ipcExceptions); - -export { pinia }; diff --git a/src/renderer/stores/plugins/ipcExceptions.js b/src/renderer/stores/plugins/ipcExceptions.js deleted file mode 100644 index 45c4fd69..00000000 --- a/src/renderer/stores/plugins/ipcExceptions.js +++ /dev/null @@ -1,7 +0,0 @@ -import { ipcRenderer } from 'electron'; - -export function ipcExceptions ({ store }) { - ipcRenderer.on('unhandled-exception', (event, error) => { - store.notifications.addNotification({ status: 'error', message: error.message }); - }); -} diff --git a/src/renderer/stores/plugins/ipcShortcuts.js b/src/renderer/stores/plugins/ipcShortcuts.js deleted file mode 100644 index df8526e1..00000000 --- a/src/renderer/stores/plugins/ipcShortcuts.js +++ /dev/null @@ -1,12 +0,0 @@ -import { ipcRenderer } from 'electron'; - -export function ipcShortcuts ({ store }) { - ipcRenderer.on('toggle-preferences', () => { - store.application.showSettingModal('general'); - }); - - ipcRenderer.on('open-updates-preferences', () => { - store.application.showSettingModal('update'); - ipcRenderer.send('check-for-updates'); - }); -} diff --git a/src/renderer/stores/plugins/ipcUpdates.js b/src/renderer/stores/plugins/ipcUpdates.js deleted file mode 100644 index 71a06d62..00000000 --- a/src/renderer/stores/plugins/ipcUpdates.js +++ /dev/null @@ -1,36 +0,0 @@ -import { ipcRenderer } from 'electron'; - -export function ipcUpdates ({ store }) { - ipcRenderer.on('checking-for-update', () => { - store.application.updateStatus = 'checking'; - }); - - ipcRenderer.on('update-available', () => { - store.application.updateStatus = 'available'; - }); - - ipcRenderer.on('update-not-available', () => { - store.application.updateStatus = 'noupdate'; - }); - - ipcRenderer.on('check-failed', () => { - store.application.updateStatus = 'nocheck'; - }); - - ipcRenderer.on('no-auto-update', () => { - store.application.updateStatus = 'disabled'; - }); - - ipcRenderer.on('download-progress', (event, data) => { - store.application.updateStatus = 'downloading'; - store.application.downloadprogress = data.percent; - }); - - ipcRenderer.on('update-downloaded', () => { - store.application.updateStatus = 'downloaded'; - }); - - ipcRenderer.on('link-to-download', () => { - store.application.updateStatus = 'link'; - }); -}