Skip to content

Commit

Permalink
起動時チェックをオプションにし、チェックでの自動ダウンロードはしないように
Browse files Browse the repository at this point in the history
  • Loading branch information
raa0121 committed Dec 16, 2021
1 parent c4958bd commit d4cca24
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ if (isDevelopment) {
}

autoUpdater.logger = log;
autoUpdater.autoDownload = false;

let win: BrowserWindow;

Expand Down Expand Up @@ -175,6 +176,7 @@ 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 @@ -186,6 +188,7 @@ 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 @@ -568,6 +571,18 @@ ipcMainHandle("INHERIT_AUDIOINFO", (_, { newValue }) => {
return store.get("inheritAudioInfo", false);
});

ipcMainHandle("ENABLE_AUTO_UPDATE_CHECK", (_, { newValue }) => {
if (newValue !== undefined) {
store.set("enableAutoUpdateCheck", newValue);
}

return store.get("enableAutoUpdateCheck", false);
});

ipcMainHandle("UPDATE_CHECK", () => {
autoUpdater.checkForUpdatesAndNotify();
});

ipcMainHandle("IS_AVAILABLE_GPU_MODE", () => {
return hasSupportedGpu();
});
Expand Down Expand Up @@ -800,7 +815,10 @@ app.on("ready", async () => {
}

createWindow().then(() => runEngine());
autoUpdater.checkForUpdatesAndNotify();
const enableAutoUpdateCheck = store.get("enableAutoUpdateCheck", false);
if (enableAutoUpdateCheck) {
autoUpdater.checkForUpdatesAndNotify();
}
});

app.on("second-instance", () => {
Expand Down Expand Up @@ -834,6 +852,19 @@ autoUpdater.on("checking-for-update", () => {
// アップデートが見つかった
autoUpdater.on("update-available", () => {
log.info(process.pid, "Update available.");
const dialogOpts = {
type: "info",
buttons: ["はい", "いいえ"],
message: "アップデート",
detail:
"新しいバージョンをがありました。更新をダウンロードしますか?",
}
// ダイアログを表示しすぐに再起動するか確認
dialog.showMessageBox(win, dialogOpts).then((returnValue) => {
if (returnValue.response === 0) {
autoUpdater.downloadUpdate();
}
});
});
// アップデートがなかった(最新版だった)
autoUpdater.on("update-not-available", () => {
Expand Down
10 changes: 10 additions & 0 deletions src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ export default defineComponent({
});
},
},
{ type: "separator" },
{
type: "button",
label: "アップデート確認",
onClick() {
store.dispatch("IS_UPDATE_CHECK_DIALOG_OPEN", {
isUpdateCheckDialogOpen: true,
});
},
},
],
},
{
Expand Down
22 changes: 22 additions & 0 deletions src/components/SettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,28 @@
</q-tooltip>
</q-select>
</q-card-actions>
<q-card-actions class="q-px-md q-py-none bg-grey-3">
<div>自動アップデートチェック</div>
<q-space />
<q-toggle
name="enabled"
align="left"
:model-value="savingSetting.enableAutoUpdateCheck"
@update:model-value="
handleSavingSettingChange('enableAutoUpdateCheck', $event)
"
>
<q-tooltip
:delay="500"
anchor="center left"
self="center right"
transition-show="jump-left"
transition-hide="jump-right"
>
起動時にアップデートチェックを行います
</q-tooltip>
</q-toggle>
</q-card-actions>
</q-card>
<!-- 今後実験的機能を追加する場合はここに追加 -->
<!-- FIXME: 0.9.1に間に合わなかったのでダークモード機能を一旦省きました -->
Expand Down
8 changes: 8 additions & 0 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ const api: Sandbox = {
return ipcRendererInvoke("INHERIT_AUDIOINFO", { newValue });
},

enableAutoUpdateCheck: (newValue) => {
return ipcRendererInvoke("ENABLE_AUTO_UPDATE_CHECK", { newValue });
},

updateCheck: () => {
return ipcRendererInvoke("UPDATE_CHECK");
},

isAvailableGPUMode: () => {
return ipcRendererInvoke("IS_AVAILABLE_GPU_MODE");
},
Expand Down
6 changes: 6 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ export type UiStoreState = {
inheritAudioInfo: boolean;
isHelpDialogOpen: boolean;
isSettingDialogOpen: boolean;
isUpdateCheckDialogOpen: boolean;
isDefaultStyleSelectDialogOpen: boolean;
isHotkeySettingDialogOpen: boolean;
isMaximized: boolean;
Expand Down Expand Up @@ -714,6 +715,11 @@ type UiStoreTypes = {
action(payload: { isSettingDialogOpen: boolean }): void;
};

IS_UPDATE_CHECK_DIALOG_OPEN: {
mutation: { isUpdateCheckDialogOpen: boolean };
action(payload: { isUpdateCheckDialogOpen: boolean }): void;
};

IS_HOTKEY_SETTING_DIALOG_OPEN: {
mutation: { isHotkeySettingDialogOpen: boolean };
action(payload: { isHotkeySettingDialogOpen: boolean }): void;
Expand Down
21 changes: 21 additions & 0 deletions src/store/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const uiStoreState: UiStoreState = {
inheritAudioInfo: true,
isHelpDialogOpen: false,
isSettingDialogOpen: false,
isUpdateCheckDialogOpen: false,
isHotkeySettingDialogOpen: false,
isDefaultStyleSelectDialogOpen: false,
isMaximized: false,
Expand Down Expand Up @@ -78,6 +79,12 @@ export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =
) {
state.isSettingDialogOpen = isSettingDialogOpen;
},
IS_UPDATE_CHECK_DIALOG_OPEN(
state,
{ isUpdateCheckDialogOpen }: { isUpdateCheckDialogOpen: boolean }
) {
state.isUpdateCheckDialogOpen = isUpdateCheckDialogOpen;
},
IS_HOTKEY_SETTING_DIALOG_OPEN(state, { isHotkeySettingDialogOpen }) {
state.isHotkeySettingDialogOpen = isHotkeySettingDialogOpen;
},
Expand Down Expand Up @@ -162,6 +169,20 @@ export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =

commit("IS_SETTING_DIALOG_OPEN", { isSettingDialogOpen });
},
async IS_UPDATE_CHECK_DIALOG_OPEN(
{ state, commit },
{ isUpdateCheckDialogOpen }: { isUpdateCheckDialogOpen: boolean }
) {
const result: number = await window.electron.showInfoDialog({
title: "自動アップデートチェック",
message: "自動アップデートチェックを行います。\nよろしいですか?",
buttons: ["はい", "いいえ"],
});
if (result == 1) {
return;
}
window.electron.updateCheck();
},
IS_HOTKEY_SETTING_DIALOG_OPEN(
{ state, commit },
{ isHotkeySettingDialogOpen }
Expand Down
10 changes: 10 additions & 0 deletions src/type/ipc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ type IpcIHData = {
return: boolean;
};

ENABLE_AUTO_UPDATE_CHECK: {
args: [obj: { newValue?: boolean }];
return: boolean;
};

UPDATE_CHECK: {
args: [];
return: void;
};

IS_AVAILABLE_GPU_MODE: {
args: [];
return: boolean;
Expand Down
2 changes: 2 additions & 0 deletions src/type/preload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface Sandbox {
openTextEditContextMenu(): Promise<void>;
useGpu(newValue?: boolean): Promise<boolean>;
inheritAudioInfo(newValue?: boolean): Promise<boolean>;
enableAutoUpdateCheck(newValue?: boolean): Promise<boolean>;
updateCheck(): void;
isAvailableGPUMode(): Promise<boolean>;
onReceivedIPCMsg<T extends keyof IpcSOData>(
channel: T,
Expand Down

0 comments on commit d4cca24

Please sign in to comment.