Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron-updater を追加し、自動更新を行えるように #543

Closed
wants to merge 12 commits into from
119 changes: 111 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"dayjs": "1.10.7",
"electron-log": "4.4.1",
"electron-store": "8.0.0",
"electron-updater": "4.6.1",
"encoding-japanese": "1.0.30",
"immer": "9.0.2",
"lodash.debounce": "4.0.8",
Expand Down
62 changes: 62 additions & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
ActivePointScrollMode,
} from "./type/preload";

import { autoUpdater } from "electron-updater";
import log from "electron-log";
import dayjs from "dayjs";

Expand All @@ -58,6 +59,9 @@ if (isDevelopment) {
);
}

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

let win: BrowserWindow;

// 多重起動防止
Expand Down Expand Up @@ -184,6 +188,7 @@ const store = new Store<{
experimentalSetting: ExperimentalSetting;
acceptRetrieveTelemetry: AcceptRetrieveTelemetryStatus;
acceptTerms: AcceptTermsStatus;
isAutoUpdateCheck: boolean;
}>({
schema: {
useGpu: {
Expand Down Expand Up @@ -298,6 +303,10 @@ const store = new Store<{
type: "string",
default: "Default",
},
isAutoUpdateCheck: {
type: "boolean",
default: false,
},
experimentalSetting: {
type: "object",
properties: {
Expand Down Expand Up @@ -783,6 +792,22 @@ ipcMainHandle("ACTIVE_POINT_SCROLL_MODE", (_, { newValue }) => {
return store.get("activePointScrollMode", "OFF");
});

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

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

ipcMainHandle("UPDATE_CHECK", async () => {
try {
await autoUpdater.checkForUpdatesAndNotify();
} catch (err: unknown) {
return;
}
});

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

createWindow().then(() => runEngine());
const isAutoUpdateCheck = store.get("isAutoUpdateCheck");
if (isAutoUpdateCheck) {
await autoUpdater.checkForUpdatesAndNotify();
}
});

app.on("second-instance", () => {
Expand All @@ -1028,3 +1057,36 @@ if (isDevelopment) {
});
}
}

//-------------------------------------------
// 自動アップデート関連のイベント処理
//-------------------------------------------
// アップデートをチェック開始
autoUpdater.on("checking-for-update", () => {
log.info(process.pid, "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) {
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("error", (err) => {
log.error(process.pid, err);
});
10 changes: 10 additions & 0 deletions src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ export default defineComponent({
});
},
},
{ type: "separator" },
{
type: "button",
label: "アップデート確認",
onClick() {
store.dispatch("IS_UPDATE_CHECK_DIALOG_OPEN", {
isUpdateCheckDialogOpen: true,
});
},
},
],
},
{
Expand Down
27 changes: 27 additions & 0 deletions src/components/SettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,24 @@
</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
:model-value="isAutoUpdateCheck"
@update:model-value="changeIsAutoUpdateCheck($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>
<q-card flat class="setting-card">
<q-card-actions>
Expand Down Expand Up @@ -534,6 +552,8 @@ export default defineComponent({

const experimentalSetting = computed(() => store.state.experimentalSetting);

const isAutoUpdateCheck = computed(() => store.state.isAutoUpdateCheck);

const currentThemeNameComputed = computed({
get: () => store.state.themeSetting.currentTheme,
set: (currentTheme: string) => {
Expand Down Expand Up @@ -689,6 +709,11 @@ export default defineComponent({
});
};

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 @@ -749,6 +774,8 @@ export default defineComponent({
availableAudioOutputDevices,
changeinheritAudioInfo,
changeExperimentalSetting,
isAutoUpdateCheck,
changeIsAutoUpdateCheck,
restartEngineProcess,
savingSetting,
handleSavingSettingChange,
Expand Down
8 changes: 8 additions & 0 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ const api: Sandbox = {
return ipcRendererInvoke("ACTIVE_POINT_SCROLL_MODE", { newValue });
},

isAutoUpdateCheck: (newValue) => {
return ipcRendererInvoke("IS_AUTO_UPDATE_CHECK", { newValue });
},

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

isAvailableGPUMode: () => {
return ipcRendererInvoke("IS_AVAILABLE_GPU_MODE");
},
Expand Down
Loading