Skip to content

Commit

Permalink
設定を savingSettings から抜くように
Browse files Browse the repository at this point in the history
enableAutoUpdateCheck から isAutoUpdateCheck に
アップデート確認後、ダウンロードではなく、公式サイトに遷移するように
  • Loading branch information
raa0121 committed Feb 8, 2022
1 parent 60b5879 commit 737a9e3
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 47 deletions.
49 changes: 20 additions & 29 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const store = new Store<{
hotkeySettings: HotkeySetting[];
defaultStyleIds: DefaultStyleId[];
currentTheme: string;
isAutoUpdateCheck: boolean;
}>({
schema: {
useGpu: {
Expand All @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -221,6 +220,10 @@ const store = new Store<{
type: "string",
default: "Default",
},
isAutoUpdateCheck: {
type: "boolean",
default: false,
},
},
migrations: {
">=0.7.3": (store) => {
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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();
}
});

Expand Down Expand Up @@ -856,36 +863,20 @@ 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.");
}
});
});
// アップデートがなかった(最新版だった)
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);
Expand Down
17 changes: 11 additions & 6 deletions src/components/SettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,8 @@
<div>自動アップデートチェック</div>
<q-space />
<q-toggle
name="enabled"
align="left"
:model-value="savingSetting.enableAutoUpdateCheck"
@update:model-value="
handleSavingSettingChange('enableAutoUpdateCheck', $event)
"
:model-value="isAutoUpdateCheck"
@update:model-value="changeIsAutoUpdateCheck($event)"
>
<q-tooltip
:delay="500"
Expand Down Expand Up @@ -399,6 +395,8 @@ export default defineComponent({
});
const inheritAudioInfoMode = computed(() => store.state.inheritAudioInfo);
const isAutoUpdateCheck = computed(() => store.state.isAutoUpdateCheck);
const currentThemeNameComputed = computed({
get: () => store.state.themeSetting.currentTheme,
set: (currentTheme: string) => {
Expand Down Expand Up @@ -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");
};
Expand Down Expand Up @@ -576,6 +579,8 @@ export default defineComponent({
currentAudioOutputDeviceComputed,
availableAudioOutputDevices,
changeinheritAudioInfo,
isAutoUpdateCheck,
changeIsAutoUpdateCheck,
restartEngineProcess,
savingSetting,
handleSavingSettingChange,
Expand Down
4 changes: 2 additions & 2 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand Down
1 change: 0 additions & 1 deletion src/store/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ export type UiStoreState = {
isHotkeySettingDialogOpen: boolean;
isMaximized: boolean;
isPinned: boolean;
isAutoUpdateCheck: boolean;
};

type UiStoreTypes = {
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 21 additions & 5 deletions src/store/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const uiStoreState: UiStoreState = {
isDefaultStyleSelectDialogOpen: false,
isMaximized: false,
isPinned: false,
isAutoUpdateCheck: false,
};

export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =
Expand Down Expand Up @@ -105,6 +106,12 @@ export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =
) {
state.inheritAudioInfo = inheritAudioInfo;
},
SET_IS_AUTO_UPDATE_CHECK(
state,
{ isAutoUpdateCheck }: { isAutoUpdateCheck: boolean }
) {
state.isAutoUpdateCheck = isAutoUpdateCheck;
},
DETECT_UNMAXIMIZED(state) {
state.isMaximized = false;
},
Expand Down Expand Up @@ -180,17 +187,16 @@ export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =
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(
Expand Down Expand Up @@ -260,6 +266,16 @@ export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =
),
});
},
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");
},
Expand Down
2 changes: 1 addition & 1 deletion src/type/ipc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type IpcIHData = {
return: boolean;
};

ENABLE_AUTO_UPDATE_CHECK: {
IS_AUTO_UPDATE_CHECK: {
args: [obj: { newValue?: boolean }];
return: boolean;
};
Expand Down
3 changes: 1 addition & 2 deletions src/type/preload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface Sandbox {
openTextEditContextMenu(): Promise<void>;
useGpu(newValue?: boolean): Promise<boolean>;
inheritAudioInfo(newValue?: boolean): Promise<boolean>;
enableAutoUpdateCheck(newValue?: boolean): Promise<boolean>;
isAutoUpdateCheck(newValue?: boolean): Promise<boolean>;
updateCheck(): void;
isAvailableGPUMode(): Promise<boolean>;
onReceivedIPCMsg<T extends keyof IpcSOData>(
Expand Down Expand Up @@ -110,7 +110,6 @@ export type SavingSetting = {
outputStereo: boolean;
outputSamplingRate: number;
audioOutputDevice: string;
enableAutoUpdateCheck: boolean;
};

export type DefaultStyleId = {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/store/Vuex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("store/vuex.js test", () => {
isDefaultStyleSelectDialogOpen: false,
isMaximized: false,
savedLastCommandUnixMillisec: null,
isAutoUpdateCheck: false,
savingSetting: {
fileEncoding: "UTF-8",
fixedExportEnabled: false,
Expand All @@ -45,7 +46,6 @@ describe("store/vuex.js test", () => {
outputStereo: false,
outputSamplingRate: 24000,
audioOutputDevice: "default",
enableAutoUpdateCheck: false,
},
themeSetting: {
currentTheme: "Default",
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 737a9e3

Please sign in to comment.