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 @@ -33,6 +33,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",
"markdown-it": "12.0.4",
Expand Down
41 changes: 41 additions & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
StyleInfo,
} from "./type/preload";

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

Expand All @@ -47,6 +48,8 @@ if (isDevelopment) {
);
}

autoUpdater.logger = log;

let win: BrowserWindow;

// 多重起動防止
Expand Down Expand Up @@ -797,6 +800,7 @@ app.on("ready", async () => {
}

createWindow().then(() => runEngine());
autoUpdater.checkForUpdatesAndNotify();
});

app.on("second-instance", () => {
Expand All @@ -819,3 +823,40 @@ if (isDevelopment) {
});
}
}

//-------------------------------------------
// 自動アップデート関連のイベント処理
//-------------------------------------------
// アップデートをチェック開始
autoUpdater.on("checking-for-update", () => {
log.info(process.pid, "checking-for-update...");
});
// アップデートが見つかった
autoUpdater.on("update-available", () => {
log.info(process.pid, "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);
});