From 737a9e33df528ba2d9fc114ebbb17f81cf3da525 Mon Sep 17 00:00:00 2001 From: raa0121 Date: Tue, 8 Feb 2022 14:05:39 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=82=92=20savingSettings=20?= =?UTF-8?q?=E3=81=8B=E3=82=89=E6=8A=9C=E3=81=8F=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=20enableAutoUpdateCheck=20=E3=81=8B=E3=82=89=20isAutoUpdateChe?= =?UTF-8?q?ck=20=E3=81=AB=20=E3=82=A2=E3=83=83=E3=83=97=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=83=88=E7=A2=BA=E8=AA=8D=E5=BE=8C=E3=80=81=E3=83=80=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=83=AD=E3=83=BC=E3=83=89=E3=81=A7=E3=81=AF=E3=81=AA?= =?UTF-8?q?=E3=81=8F=E3=80=81=E5=85=AC=E5=BC=8F=E3=82=B5=E3=82=A4=E3=83=88?= =?UTF-8?q?=E3=81=AB=E9=81=B7=E7=A7=BB=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/background.ts | 49 +++++++++++++------------------- src/components/SettingDialog.vue | 17 +++++++---- src/electron/preload.ts | 4 +-- src/store/setting.ts | 1 - src/store/type.ts | 6 ++++ src/store/ui.ts | 26 +++++++++++++---- src/type/ipc.d.ts | 2 +- src/type/preload.d.ts | 3 +- tests/unit/store/Vuex.spec.ts | 3 +- 9 files changed, 64 insertions(+), 47 deletions(-) diff --git a/src/background.ts b/src/background.ts index 418b701539..265138d040 100644 --- a/src/background.ts +++ b/src/background.ts @@ -150,6 +150,7 @@ const store = new Store<{ hotkeySettings: HotkeySetting[]; defaultStyleIds: DefaultStyleId[]; currentTheme: string; + isAutoUpdateCheck: boolean; }>({ schema: { useGpu: { @@ -176,7 +177,6 @@ const store = new Store<{ outputStereo: { type: "boolean", default: false }, outputSamplingRate: { type: "number", default: 24000 }, audioOutputDevice: { type: "string", default: "default" }, - enableAutoUpdateCheck: { type: "boolean", default: false }, }, default: { fileEncoding: "UTF-8", @@ -188,7 +188,6 @@ const store = new Store<{ outputStereo: false, outputSamplingRate: 24000, audioOutputDevice: "default", - enableAutoUpdateCheck: false, }, }, // To future developers: if you are to modify the store schema with array type, @@ -221,6 +220,10 @@ const store = new Store<{ type: "string", default: "Default", }, + isAutoUpdateCheck: { + type: "boolean", + default: false, + }, }, migrations: { ">=0.7.3": (store) => { @@ -571,16 +574,20 @@ ipcMainHandle("INHERIT_AUDIOINFO", (_, { newValue }) => { return store.get("inheritAudioInfo", false); }); -ipcMainHandle("ENABLE_AUTO_UPDATE_CHECK", (_, { newValue }) => { +ipcMainHandle("IS_AUTO_UPDATE_CHECK", (_, { newValue }) => { if (newValue !== undefined) { - store.set("enableAutoUpdateCheck", newValue); + store.set("isAutoUpdateCheck", newValue); } - return store.get("enableAutoUpdateCheck", false); + return store.get("isAutoUpdateCheck", false); }); -ipcMainHandle("UPDATE_CHECK", () => { - autoUpdater.checkForUpdatesAndNotify(); +ipcMainHandle("UPDATE_CHECK", async () => { + try { + await autoUpdater.checkForUpdatesAndNotify(); + } catch (err: unknown) { + return; + } }); ipcMainHandle("IS_AVAILABLE_GPU_MODE", () => { @@ -815,9 +822,9 @@ app.on("ready", async () => { } createWindow().then(() => runEngine()); - const savingSetting = store.get("savingSetting"); - if (savingSetting.enableAutoUpdateCheck) { - autoUpdater.checkForUpdatesAndNotify(); + const isAutoUpdateCheck = store.get("isAutoUpdateCheck"); + if (isAutoUpdateCheck) { + await autoUpdater.checkForUpdatesAndNotify(); } }); @@ -856,12 +863,13 @@ autoUpdater.on("update-available", () => { type: "info", buttons: ["はい", "いいえ"], message: "アップデート", - detail: "新しいバージョンをがありました。更新をダウンロードしますか?", + detail: "新しいバージョンをがありました。公式サイトを開きますか?", }; // ダイアログを表示しすぐに再起動するか確認 dialog.showMessageBox(win, dialogOpts).then((returnValue) => { if (returnValue.response === 0) { - autoUpdater.downloadUpdate(); + shell.openExternal("https://voicevox.hiroshiba.jp/"); + log.info(process.pid, "Open Official Site."); } }); }); @@ -869,23 +877,6 @@ autoUpdater.on("update-available", () => { autoUpdater.on("update-not-available", () => { log.info(process.pid, "Update not available."); }); -// アップデートのダウンロードが完了 -autoUpdater.on("update-downloaded", () => { - const dialogOpts = { - type: "info", - buttons: ["更新して再起動", "あとで"], - message: "アップデート", - detail: - "新しいバージョンをダウンロードしました。再起動して更新を適用しますか?", - }; - - // ダイアログを表示しすぐに再起動するか確認 - dialog.showMessageBox(win, dialogOpts).then((returnValue) => { - if (returnValue.response === 0) { - autoUpdater.quitAndInstall(); - } - }); -}); // エラーが発生 autoUpdater.on("error", (err) => { log.error(process.pid, err); diff --git a/src/components/SettingDialog.vue b/src/components/SettingDialog.vue index d45d3f61da..cd5eba46be 100644 --- a/src/components/SettingDialog.vue +++ b/src/components/SettingDialog.vue @@ -309,12 +309,8 @@
自動アップデートチェック
store.state.inheritAudioInfo); + const isAutoUpdateCheck = computed(() => store.state.isAutoUpdateCheck); + const currentThemeNameComputed = computed({ get: () => store.state.themeSetting.currentTheme, set: (currentTheme: string) => { @@ -520,6 +518,11 @@ export default defineComponent({ store.dispatch("SET_INHERIT_AUDIOINFO", { inheritAudioInfo }); }; + const changeIsAutoUpdateCheck = async (isAutoUpdateCheck: boolean) => { + if (store.state.isAutoUpdateCheck === isAutoUpdateCheck) return; + store.dispatch("SET_IS_AUTO_UPDATE_CHECK", { isAutoUpdateCheck }); + }; + const restartEngineProcess = () => { store.dispatch("RESTART_ENGINE"); }; @@ -576,6 +579,8 @@ export default defineComponent({ currentAudioOutputDeviceComputed, availableAudioOutputDevices, changeinheritAudioInfo, + isAutoUpdateCheck, + changeIsAutoUpdateCheck, restartEngineProcess, savingSetting, handleSavingSettingChange, diff --git a/src/electron/preload.ts b/src/electron/preload.ts index 72183fb07a..0b7e8451db 100644 --- a/src/electron/preload.ts +++ b/src/electron/preload.ts @@ -136,8 +136,8 @@ const api: Sandbox = { return ipcRendererInvoke("INHERIT_AUDIOINFO", { newValue }); }, - enableAutoUpdateCheck: (newValue) => { - return ipcRendererInvoke("ENABLE_AUTO_UPDATE_CHECK", { newValue }); + isAutoUpdateCheck: (newValue) => { + return ipcRendererInvoke("IS_AUTO_UPDATE_CHECK", { newValue }); }, updateCheck: () => { diff --git a/src/store/setting.ts b/src/store/setting.ts index 74620e3b74..12ab68e89d 100644 --- a/src/store/setting.ts +++ b/src/store/setting.ts @@ -30,7 +30,6 @@ export const settingStoreState: SettingStoreState = { outputStereo: false, outputSamplingRate: 24000, audioOutputDevice: "default", - enableAutoUpdateCheck: false, }, hotkeySettings: [], engineHost: process.env.VUE_APP_ENGINE_URL as unknown as string, diff --git a/src/store/type.ts b/src/store/type.ts index 1d15c09155..3bf97af009 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -666,6 +666,7 @@ export type UiStoreState = { isHotkeySettingDialogOpen: boolean; isMaximized: boolean; isPinned: boolean; + isAutoUpdateCheck: boolean; }; type UiStoreTypes = { @@ -752,6 +753,11 @@ type UiStoreTypes = { action(payload: { inheritAudioInfo: boolean }): void; }; + SET_IS_AUTO_UPDATE_CHECK: { + mutation: { isAutoUpdateCheck: boolean }; + action(payload: { isAutoUpdateCheck: boolean }): void; + }; + DETECT_UNMAXIMIZED: { mutation: undefined; action(): void; diff --git a/src/store/ui.ts b/src/store/ui.ts index 8d6613de5b..25b2b5a640 100644 --- a/src/store/ui.ts +++ b/src/store/ui.ts @@ -38,6 +38,7 @@ export const uiStoreState: UiStoreState = { isDefaultStyleSelectDialogOpen: false, isMaximized: false, isPinned: false, + isAutoUpdateCheck: false, }; export const uiStore: VoiceVoxStoreOptions = @@ -105,6 +106,12 @@ export const uiStore: VoiceVoxStoreOptions = ) { state.inheritAudioInfo = inheritAudioInfo; }, + SET_IS_AUTO_UPDATE_CHECK( + state, + { isAutoUpdateCheck }: { isAutoUpdateCheck: boolean } + ) { + state.isAutoUpdateCheck = isAutoUpdateCheck; + }, DETECT_UNMAXIMIZED(state) { state.isMaximized = false; }, @@ -180,17 +187,16 @@ export const uiStore: VoiceVoxStoreOptions = commit("LOCK_MENUBAR"); const result: number = await window.electron.showInfoDialog({ - title: "自動アップデートチェック", - message: "自動アップデートチェックを行います。\nよろしいですか?", + title: "アップデートチェック", + message: "アップデートチェックを行います。\nよろしいですか?", buttons: ["はい", "いいえ"], }); + commit("UNLOCK_UI"); + commit("UNLOCK_MENUBAR"); if (result == 1) { return; } window.electron.updateCheck(); - } else { - commit("UNLOCK_UI"); - commit("UNLOCK_MENUBAR"); } }, IS_HOTKEY_SETTING_DIALOG_OPEN( @@ -260,6 +266,16 @@ export const uiStore: VoiceVoxStoreOptions = ), }); }, + async SET_IS_AUTO_UPDATE_CHECK( + { commit }, + { isAutoUpdateCheck }: { isAutoUpdateCheck: boolean } + ) { + commit("SET_IS_AUTO_UPDATE_CHECK", { + isAutoUpdateCheck: await window.electron.isAutoUpdateCheck( + isAutoUpdateCheck + ), + }); + }, async DETECT_UNMAXIMIZED({ commit }) { commit("DETECT_UNMAXIMIZED"); }, diff --git a/src/type/ipc.d.ts b/src/type/ipc.d.ts index 34a16828ee..42a6417395 100644 --- a/src/type/ipc.d.ts +++ b/src/type/ipc.d.ts @@ -97,7 +97,7 @@ type IpcIHData = { return: boolean; }; - ENABLE_AUTO_UPDATE_CHECK: { + IS_AUTO_UPDATE_CHECK: { args: [obj: { newValue?: boolean }]; return: boolean; }; diff --git a/src/type/preload.d.ts b/src/type/preload.d.ts index 4ae4a52982..989affb152 100644 --- a/src/type/preload.d.ts +++ b/src/type/preload.d.ts @@ -37,7 +37,7 @@ export interface Sandbox { openTextEditContextMenu(): Promise; useGpu(newValue?: boolean): Promise; inheritAudioInfo(newValue?: boolean): Promise; - enableAutoUpdateCheck(newValue?: boolean): Promise; + isAutoUpdateCheck(newValue?: boolean): Promise; updateCheck(): void; isAvailableGPUMode(): Promise; onReceivedIPCMsg( @@ -110,7 +110,6 @@ export type SavingSetting = { outputStereo: boolean; outputSamplingRate: number; audioOutputDevice: string; - enableAutoUpdateCheck: boolean; }; export type DefaultStyleId = { diff --git a/tests/unit/store/Vuex.spec.ts b/tests/unit/store/Vuex.spec.ts index ee2cab4b2b..a5be9a8d83 100644 --- a/tests/unit/store/Vuex.spec.ts +++ b/tests/unit/store/Vuex.spec.ts @@ -35,6 +35,7 @@ describe("store/vuex.js test", () => { isDefaultStyleSelectDialogOpen: false, isMaximized: false, savedLastCommandUnixMillisec: null, + isAutoUpdateCheck: false, savingSetting: { fileEncoding: "UTF-8", fixedExportEnabled: false, @@ -45,7 +46,6 @@ describe("store/vuex.js test", () => { outputStereo: false, outputSamplingRate: 24000, audioOutputDevice: "default", - enableAutoUpdateCheck: false, }, themeSetting: { currentTheme: "Default", @@ -107,6 +107,7 @@ describe("store/vuex.js test", () => { assert.isEmpty(store.state.redoCommands); assert.equal(store.state.useGpu, false); assert.equal(store.state.inheritAudioInfo, true); + assert.equal(store.state.isAutoUpdateCheck, false); assert.equal(store.state.isHelpDialogOpen, false); assert.equal(store.state.isSettingDialogOpen, false); assert.equal(store.state.isUpdateCheckDialogOpen, false);