Skip to content

Commit

Permalink
feat: add auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 committed Jun 13, 2024
1 parent 1cbb0a9 commit 8af292e
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-example-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
yarn build
- name: Build Desktop Application
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: yarn build:example:desktop

- name: Upload Mac x64 Artifacts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/* eslint-disable no-template-curly-in-string */
// eslint-disable-next-line import/no-import-module-exports, @typescript-eslint/no-var-requires
const { version } = require('./package.json');

module.exports = {
extraMetadata: {
main: 'dist/index.js',
version: '1',
version,
},
appId: 'so.onekey.example.hardware-desktop',
productName: 'HardwareExample',
copyright: 'Copyright © OeKey 2024',
asar: true,
buildVersion: '1',
buildVersion: version,
directories: {
output: 'out',
},
Expand Down Expand Up @@ -97,4 +100,13 @@ module.exports = {
category: 'Utility',
target: ['AppImage'],
},
publish: [
{
provider: 'github',
owner: 'OneKeyHQ',
repo: 'hardware-js-sdk',
private: false,
vPrefixedTagName: true,
},
],
};
4 changes: 3 additions & 1 deletion packages/connect-examples/electron-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"dev:electron": "electron --inspect=5858 dist/index.js",
"build:package": "yarn build-electron-web && electron-forge package",
"build:main": "webpack --config webpack.config.ts",
"make": "yarn clean:build && yarn build-electron-web && electron-builder build -mw --config electron-builder.config.js --publish never",
"make": "yarn clean:build && yarn build-electron-web && electron-builder build -mw --config electron-builder.config.js --publish always",
"lint": "eslint --ext .tsx --ext .ts ./",
"ts:check": "yarn tsc --noEmit"
},
"dependencies": {
"debug": "4.3.4",
"electron-is-dev": "^3.0.1",
"electron-log": "^5.1.5",
"electron-updater": "^6.3.0-alpha.4",
"node-fetch": "^2.6.7"
},
"devDependencies": {
Expand Down
43 changes: 42 additions & 1 deletion packages/connect-examples/electron-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { screen, app, BrowserWindow, session } from 'electron';
import { screen, app, BrowserWindow, session, ipcMain } from 'electron';
import path from 'path';
import isDevelopment from 'electron-is-dev';
import { format as formatUrl } from 'url';
import log from 'electron-log';
import { autoUpdater } from 'electron-updater';
import initProcess from './process';

// Set log level
log.transports.file.level = 'info';
autoUpdater.logger = log;

const isMac = process.platform === 'darwin';
const isWin = process.platform === 'win32';

Expand Down Expand Up @@ -185,6 +191,16 @@ function createMainWindow() {
}
});

autoUpdater.on('update-available', () => {
log.info('Update available.');
mainWindow?.webContents?.send('update/available');
});

autoUpdater.on('update-downloaded', () => {
log.info('Update downloaded.');
mainWindow?.webContents?.send('update/downloaded');
});

return browserWindow;
}

Expand All @@ -210,6 +226,31 @@ if (!singleInstance && !process.mas) {
});
}

ipcMain.on('update/restartApp', () => {
autoUpdater.quitAndInstall();
});

const token = process.env.GT_READ_RELEASE;
log.info('GitHub token:', token);
if (!token) {
console.error('GitHub token is not set');
app.quit();
}

// 配置 GitHub 发布提供者
autoUpdater.setFeedURL({
provider: 'github',
owner: 'OneKeyHQ',
repo: 'hardware-js-sdk',
private: false,
});

// 检查更新
app.on('ready', () => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
autoUpdater.checkForUpdatesAndNotify();
});

// wuit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q
Expand Down
42 changes: 42 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7094,6 +7094,14 @@ [email protected]:
debug "^4.3.4"
sax "^1.2.4"

[email protected]:
version "9.2.5-alpha.2"
resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-9.2.5-alpha.2.tgz#b0a1737996717d7ae0b71e5efdf0bfbd1dd2c21e"
integrity sha512-/Ln2ddejGj2HNMJ+X66mKHRcOvmRzUO/dSi8t4hSV64J7IA+DE+mqDb+zogIE2gin7p7YwcGiOkKny4nwPPPXg==
dependencies:
debug "^4.3.4"
sax "^1.2.4"

[email protected]:
version "24.9.4"
resolved "https://registry.yarnpkg.com/builder-util/-/builder-util-24.9.4.tgz#8cde880e7c719285e9cb30e6850ddd5bf475ac04"
Expand Down Expand Up @@ -8806,6 +8814,11 @@ electron-is-dev@^3.0.1:
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-3.0.1.tgz#1cbc79b1dd046787903acd357efdfab6549dc17a"
integrity sha512-8TjjAh8Ec51hUi3o4TaU0mD3GMTOESi866oRNavj9A3IQJ7pmv+MJVmdZBFGw4GFT36X7bkqnuDNYvkQgvyI8Q==

electron-log@^5.1.5:
version "5.1.5"
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-5.1.5.tgz#70d5051fc5ab7669b2592f53f72034867269c96e"
integrity sha512-vuq10faUAxRbILgQx7yHoMObKZDEfj7hMSZrJPsVrDNeCpV/HN11dU7QuY4UDUe055pzBxhSCB3m0+6D3Aktjw==

[email protected]:
version "24.9.4"
resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-24.9.4.tgz#70db542763a78e4980e4e6409c203aef320d0d05"
Expand All @@ -8824,6 +8837,20 @@ electron-to-chromium@^1.4.668:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.673.tgz#1f077d9a095761804aec7ec6346c3f4b69b56534"
integrity sha512-zjqzx4N7xGdl5468G+vcgzDhaHkaYgVcf9MqgexcTqsl2UHSCmOj/Bi3HAprg4BZCpC7HyD8a6nZl6QAZf72gw==

electron-updater@^6.3.0-alpha.4:
version "6.3.0-alpha.4"
resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-6.3.0-alpha.4.tgz#7c5a9594bc00a6ee6c6fc9f092444a1d7d2e8ede"
integrity sha512-01Pmb4K23cIos6zuvX3e0MF3KxScHFaHivCs+6LUcnUZTuGuRfwGrQU7ov2iChbV0U5o+hnVecrO/HI6UoRT1Q==
dependencies:
builder-util-runtime "9.2.5-alpha.2"
fs-extra "^10.1.0"
js-yaml "^4.1.0"
lazy-val "^1.0.5"
lodash.escaperegexp "^4.1.2"
lodash.isequal "^4.5.0"
semver "^7.3.8"
tiny-typed-emitter "^2.1.0"

electron@^28.0.0:
version "28.2.3"
resolved "https://registry.yarnpkg.com/electron/-/electron-28.2.3.tgz#d26821bcfda7ee445b4b75231da4b057a7ce6e7b"
Expand Down Expand Up @@ -12989,6 +13016,16 @@ lodash.debounce@^4.0.8:
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==

lodash.escaperegexp@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz#64762c48618082518ac3df4ccf5d5886dae20347"
integrity sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==

lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
integrity sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==

lodash.ismatch@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
Expand Down Expand Up @@ -17583,6 +17620,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/tiny-queue/-/tiny-queue-0.2.0.tgz#c49fcb5c87555be1b4a5df7eb87101d5b78bc9dc"
integrity sha512-ucfrvjzfbtc+xqmn95DEUtGcDHJHQgZ9IR0mizPOZBkY45reZDCJjafUGVJOGJassjn0MavTyWOCQcG+agpLxw==

tiny-typed-emitter@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz#b3b027fdd389ff81a152c8e847ee2f5be9fad7b5"
integrity sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==

tmp-promise@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-3.0.3.tgz#60a1a1cc98c988674fcbfd23b6e3367bdeac4ce7"
Expand Down

0 comments on commit 8af292e

Please sign in to comment.