From d8e73ef40a023518305447faa6da4cf60f0e841d Mon Sep 17 00:00:00 2001 From: phan Date: Tue, 7 May 2024 03:21:00 -0400 Subject: [PATCH] auto updater --- .github/workflows/pre-release.yml | 7 ++----- .github/workflows/release.yml | 34 ------------------------------- src/main/index.ts | 29 +++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 42 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index dfa20bc..956bbb3 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -4,10 +4,7 @@ on: workflow_dispatch: inputs: version: - description: 'Release version (e.g., alpha-v0.0.2)' - required: true - version-number: - description: 'Release version number (e.g., 1.0.0)' + description: 'Release version (e.g., 0.0.2)' required: true jobs: @@ -36,5 +33,5 @@ jobs: with: github_token: ${{ secrets.github_token }} release: true - args: -c.extraMetadata.version=${{ github.event.inputs.version-number }} -c.publish.releaseType=prerelease + args: -c.extraMetadata.version=${{ github.event.inputs.version }} -c.publish.releaseType=prerelease diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index bc48b02..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: release - -on: - workflow_dispatch: - inputs: - version: - description: 'Release version (e.g. alpha-v1.0.0)' - required: true - -jobs: - release: - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [ubuntu-latest, windows-latest] - #os: [macos-latest, ubuntu-latest, windows-latest] - - steps: - - name: Check out Git repository - uses: actions/checkout@v1 - - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: 18.x - - - name: Build/release Electron app - uses: samuelmeuli/action-electron-builder@v1 - with: - # GitHub token, automatically provided to the action - # (No need to define this secret in the repo settings) - github_token: ${{ secrets.github_token }} - release: true \ No newline at end of file diff --git a/src/main/index.ts b/src/main/index.ts index 647229b..b47085c 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,6 +1,6 @@ import { electronApp, is, optimizer } from "@electron-toolkit/utils"; import { CardData, PersonaFormData } from "@shared/types"; -import { BrowserWindow, Menu, Tray, app, ipcMain, nativeImage, net, protocol, shell } from "electron"; +import { BrowserWindow, Menu, Tray, app, dialog, ipcMain, nativeImage, net, protocol, shell } from "electron"; import { autoUpdater } from "electron-updater"; import path, { join } from "path"; import icon from "../../resources/icon.png?asset"; @@ -239,8 +239,31 @@ app.whenReady().then(async () => { }); createWindow(); - // Implement Electron auto-updater - // autoUpdater.on(); + + autoUpdater.checkForUpdates(); + + autoUpdater.on("update-downloaded", (e) => { + const { version } = e; + const dialogOpts: Electron.MessageBoxOptions = { + type: "info", + buttons: ["Restart", "Later"], + title: "Application Update", + message: `anime.gf version ${version} has been downloaded.`, + detail: "Restart the application to apply the update." + }; + + dialog.showMessageBox(dialogOpts).then((val) => { + if (val.response === 0) { + isQuiting = true; + autoUpdater.quitAndInstall(); + } + }); + }); + + autoUpdater.on("error", (error) => { + console.error("There was a problem updating the application"); + console.error(error); + }); }); function createWindow(): void {