hardware-example 1.0.0-alpha.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/electron-builder.config.js +23 -5
- package/package.json +6 -4
- package/src/config.ts +10 -0
- package/src/index.ts +47 -3
- package/src/preload.ts +18 -2
- package/forge.config.js +0 -65
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/* eslint-disable no-template-curly-in-string */
|
|
2
|
+
// eslint-disable-next-line import/no-import-module-exports, @typescript-eslint/no-var-requires
|
|
3
|
+
const { version } = require('./package.json');
|
|
4
|
+
|
|
2
5
|
module.exports = {
|
|
3
6
|
extraMetadata: {
|
|
4
7
|
main: 'dist/index.js',
|
|
5
|
-
version
|
|
8
|
+
version,
|
|
6
9
|
},
|
|
7
10
|
appId: 'so.onekey.example.hardware-desktop',
|
|
8
11
|
productName: 'HardwareExample',
|
|
9
12
|
copyright: 'Copyright © OeKey 2024',
|
|
10
13
|
asar: true,
|
|
11
|
-
buildVersion:
|
|
14
|
+
buildVersion: version,
|
|
12
15
|
directories: {
|
|
13
16
|
output: 'out',
|
|
14
17
|
},
|
|
@@ -20,6 +23,7 @@ module.exports = {
|
|
|
20
23
|
'dist/**/*.js',
|
|
21
24
|
'!dist/__**',
|
|
22
25
|
'package.json',
|
|
26
|
+
'!scripts/**',
|
|
23
27
|
],
|
|
24
28
|
extraResources: [
|
|
25
29
|
{
|
|
@@ -64,8 +68,8 @@ module.exports = {
|
|
|
64
68
|
darkModeSupport: false,
|
|
65
69
|
category: 'productivity',
|
|
66
70
|
target: [
|
|
67
|
-
|
|
68
|
-
{ target: 'zip', arch: ['x64', 'arm64'] },
|
|
71
|
+
{ target: 'dmg', arch: ['x64', 'arm64'] },
|
|
72
|
+
// { target: 'zip', arch: ['x64', 'arm64'] },
|
|
69
73
|
],
|
|
70
74
|
entitlements: 'entitlements.mac.plist',
|
|
71
75
|
extendInfo: {
|
|
@@ -82,7 +86,12 @@ module.exports = {
|
|
|
82
86
|
icon: 'public/icons/512x512.png',
|
|
83
87
|
artifactName: 'Hardware-Example-win-${arch}.${ext}',
|
|
84
88
|
verifyUpdateCodeSignature: false,
|
|
85
|
-
target: [
|
|
89
|
+
target: [
|
|
90
|
+
{
|
|
91
|
+
target: 'nsis',
|
|
92
|
+
arch: ['x64'],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
86
95
|
},
|
|
87
96
|
linux: {
|
|
88
97
|
extraResources: [
|
|
@@ -97,4 +106,13 @@ module.exports = {
|
|
|
97
106
|
category: 'Utility',
|
|
98
107
|
target: ['AppImage'],
|
|
99
108
|
},
|
|
109
|
+
publish: [
|
|
110
|
+
{
|
|
111
|
+
provider: 'github',
|
|
112
|
+
owner: 'OneKeyHQ',
|
|
113
|
+
repo: 'hardware-js-sdk',
|
|
114
|
+
private: false,
|
|
115
|
+
vPrefixedTagName: true,
|
|
116
|
+
},
|
|
117
|
+
],
|
|
100
118
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "hardware-example",
|
|
3
3
|
"productName": "HardwareExample",
|
|
4
4
|
"executableName": "onekey-hardware-example",
|
|
5
|
-
"version": "1.0.0
|
|
5
|
+
"version": "1.0.0",
|
|
6
6
|
"author": "OneKey",
|
|
7
7
|
"description": "End-to-end encrypted workspaces for teams",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -14,15 +14,17 @@
|
|
|
14
14
|
"build-electron-web": "yarn copy:inject && yarn build:main && cd ../expo-example && yarn build:electron-web",
|
|
15
15
|
"dev": "npx concurrently \"yarn dev:electron\" \"cross-env TRANSFORM_REGENERATOR_DISABLED=true BROWSER=none yarn dev-electron-web\"",
|
|
16
16
|
"dev:electron": "electron --inspect=5858 dist/index.js",
|
|
17
|
-
"build:package": "yarn build-electron-web && electron-forge package",
|
|
18
17
|
"build:main": "webpack --config webpack.config.ts",
|
|
19
|
-
"make": "yarn clean:build && yarn build-electron-web && electron-builder build -mw --config electron-builder.config.js --publish
|
|
18
|
+
"make": "yarn clean:build && yarn build-electron-web && electron-builder build -mw --config electron-builder.config.js --publish always",
|
|
20
19
|
"lint": "eslint --ext .tsx --ext .ts ./",
|
|
21
20
|
"ts:check": "yarn tsc --noEmit"
|
|
22
21
|
},
|
|
23
22
|
"dependencies": {
|
|
24
23
|
"debug": "4.3.4",
|
|
25
24
|
"electron-is-dev": "^3.0.1",
|
|
25
|
+
"electron-log": "^5.1.5",
|
|
26
|
+
"electron-updater": "^6.2.1",
|
|
27
|
+
"fs-extra": "^11.2.0",
|
|
26
28
|
"node-fetch": "^2.6.7"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
@@ -35,5 +37,5 @@
|
|
|
35
37
|
"webpack": "^5.90.2",
|
|
36
38
|
"webpack-node-externals": "^3.0.0"
|
|
37
39
|
},
|
|
38
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "95900f4bc9cb2a286b154e2e742cfe97c5c31b1e"
|
|
39
41
|
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const ipcMessageKeys = {
|
|
2
|
+
// Updater
|
|
3
|
+
UPDATE_AVAILABLE: 'update/available',
|
|
4
|
+
UPDATE_DOWNLOADED: 'update/downloaded',
|
|
5
|
+
UPDATE_RESTART: 'update/restartApp',
|
|
6
|
+
|
|
7
|
+
APP_RELOAD_BRIDGE_PROCESS: 'app/reloadBridgeProcess',
|
|
8
|
+
|
|
9
|
+
INJECT_ONEKEY_DESKTOP_GLOBALS: 'inject/onekeyDesktop',
|
|
10
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { screen, app, BrowserWindow, session } from 'electron';
|
|
1
|
+
import { screen, app, BrowserWindow, session, ipcMain } from 'electron';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import isDevelopment from 'electron-is-dev';
|
|
4
4
|
import { format as formatUrl } from 'url';
|
|
5
|
-
import
|
|
5
|
+
import log from 'electron-log';
|
|
6
|
+
import { autoUpdater } from 'electron-updater';
|
|
7
|
+
import initProcess, { restartBridge } from './process';
|
|
8
|
+
import { ipcMessageKeys } from './config';
|
|
9
|
+
|
|
10
|
+
// Set log level
|
|
11
|
+
log.transports.file.level = 'info';
|
|
12
|
+
log.transports.console.level = 'info';
|
|
13
|
+
autoUpdater.logger = log;
|
|
6
14
|
|
|
7
15
|
const isMac = process.platform === 'darwin';
|
|
8
16
|
const isWin = process.platform === 'win32';
|
|
@@ -86,7 +94,7 @@ function createMainWindow() {
|
|
|
86
94
|
|
|
87
95
|
browserWindow.webContents.on('did-finish-load', () => {
|
|
88
96
|
console.log('browserWindow >>>> did-finish-load');
|
|
89
|
-
browserWindow.webContents.send(
|
|
97
|
+
browserWindow.webContents.send(ipcMessageKeys.INJECT_ONEKEY_DESKTOP_GLOBALS, {
|
|
90
98
|
resourcesPath: (global as any).resourcesPath,
|
|
91
99
|
staticPath: `file://${staticPath}`,
|
|
92
100
|
sdkConnectSrc,
|
|
@@ -210,6 +218,42 @@ if (!singleInstance && !process.mas) {
|
|
|
210
218
|
});
|
|
211
219
|
}
|
|
212
220
|
|
|
221
|
+
ipcMain.on(ipcMessageKeys.UPDATE_RESTART, () => {
|
|
222
|
+
log.info('App Quit And Install');
|
|
223
|
+
autoUpdater.quitAndInstall();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
ipcMain.on(ipcMessageKeys.APP_RELOAD_BRIDGE_PROCESS, () => {
|
|
227
|
+
restartBridge();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// 配置 GitHub 发布提供者
|
|
231
|
+
autoUpdater.setFeedURL({
|
|
232
|
+
provider: 'github',
|
|
233
|
+
owner: 'OneKeyHQ',
|
|
234
|
+
repo: 'hardware-js-sdk',
|
|
235
|
+
private: false,
|
|
236
|
+
releaseType: 'release',
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// 检查更新
|
|
240
|
+
app.on('ready', () => {
|
|
241
|
+
autoUpdater.on('update-available', () => {
|
|
242
|
+
log.info('Update available.');
|
|
243
|
+
mainWindow?.webContents?.send(ipcMessageKeys.UPDATE_AVAILABLE);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
autoUpdater.on('update-downloaded', () => {
|
|
247
|
+
log.info('Update downloaded.');
|
|
248
|
+
mainWindow?.webContents?.send(ipcMessageKeys.UPDATE_DOWNLOADED);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
setTimeout(() => {
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
253
|
+
autoUpdater.checkForUpdatesAndNotify();
|
|
254
|
+
}, 5000);
|
|
255
|
+
});
|
|
256
|
+
|
|
213
257
|
// wuit when all windows are closed, except on macOS. There, it's common
|
|
214
258
|
// for applications and their menu bar to stay active until the user quits
|
|
215
259
|
// explicitly with Cmd + Q
|
package/src/preload.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/require-await */
|
|
3
3
|
import { ipcRenderer, contextBridge } from 'electron';
|
|
4
|
+
import { off } from 'process';
|
|
5
|
+
import { ipcMessageKeys } from './config';
|
|
4
6
|
|
|
5
7
|
export type DesktopAPI = {
|
|
6
8
|
reloadBridgeProcess: () => void;
|
|
@@ -12,15 +14,29 @@ declare global {
|
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
const validChannels = [
|
|
18
|
+
// Update events
|
|
19
|
+
ipcMessageKeys.UPDATE_AVAILABLE,
|
|
20
|
+
ipcMessageKeys.UPDATE_DOWNLOADED,
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
ipcRenderer.on(ipcMessageKeys.INJECT_ONEKEY_DESKTOP_GLOBALS, (_, globals) => {
|
|
16
24
|
// @ts-expect-error
|
|
17
25
|
window.ONEKEY_DESKTOP_GLOBALS = globals;
|
|
18
26
|
// contextBridge.exposeInMainWorld('ONEKEY_DESKTOP_GLOBALS', globals);
|
|
19
27
|
});
|
|
20
28
|
|
|
21
29
|
const desktopApi = {
|
|
30
|
+
on: (channel: string, func: (...args: any[]) => any) => {
|
|
31
|
+
if (validChannels.includes(channel)) {
|
|
32
|
+
ipcRenderer.on(channel, (_, ...args) => func(...args));
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
updateReload: () => {
|
|
36
|
+
ipcRenderer.send(ipcMessageKeys.UPDATE_RESTART);
|
|
37
|
+
},
|
|
22
38
|
reloadBridgeProcess: () => {
|
|
23
|
-
ipcRenderer.send(
|
|
39
|
+
ipcRenderer.send(ipcMessageKeys.APP_RELOAD_BRIDGE_PROCESS);
|
|
24
40
|
},
|
|
25
41
|
};
|
|
26
42
|
|
package/forge.config.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const fs = require('fs-extra');
|
|
4
|
-
const d = require('debug');
|
|
5
|
-
|
|
6
|
-
const debug = d('forge config');
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
packagerConfig: {
|
|
10
|
-
name: 'HardwareExample',
|
|
11
|
-
appBundleId: 'so.onekey.example.hardware-desktop',
|
|
12
|
-
executableName: process.platform === 'linux' ? 'onekey-hardware-example' : 'HardwareExample',
|
|
13
|
-
appCategoryType: 'public.app-category.developer-tools',
|
|
14
|
-
appCopyright: 'Copyright 2024 OneKey Ltd',
|
|
15
|
-
asar: true,
|
|
16
|
-
icon: path.resolve(__dirname, 'public', 'icons', 'icon'),
|
|
17
|
-
},
|
|
18
|
-
rebuildConfig: {},
|
|
19
|
-
hooks: {
|
|
20
|
-
packageAfterCopy: async (forgeConfig, buildPath, electronVersion, platform, arch) => {
|
|
21
|
-
let originDir;
|
|
22
|
-
let binName;
|
|
23
|
-
const destDir = path.resolve(buildPath, '../', 'bin', 'bridge');
|
|
24
|
-
|
|
25
|
-
switch (platform) {
|
|
26
|
-
case 'darwin':
|
|
27
|
-
originDir = path.resolve(buildPath, 'public', 'bin', 'bridge', `mac-${arch}`);
|
|
28
|
-
binName = 'onekeyd';
|
|
29
|
-
break;
|
|
30
|
-
case 'win32':
|
|
31
|
-
originDir = path.resolve(buildPath, 'public', 'bin', 'bridge', 'win-x64');
|
|
32
|
-
binName = 'onekeyd.exe';
|
|
33
|
-
break;
|
|
34
|
-
case 'linux':
|
|
35
|
-
originDir = path.resolve(buildPath, 'public', 'bin', 'bridge', `linux-${arch}`);
|
|
36
|
-
binName = 'onekeyd';
|
|
37
|
-
break;
|
|
38
|
-
default:
|
|
39
|
-
originDir = '';
|
|
40
|
-
binName = 'onekeyd';
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
debug(`Copy bridge bin: originDir:${originDir}, platform:${platform}, arch:${arch}`);
|
|
45
|
-
await fs.ensureDir(destDir);
|
|
46
|
-
await fs.copy(path.resolve(originDir, binName), path.resolve(destDir, binName));
|
|
47
|
-
},
|
|
48
|
-
packageAfterPrune: async (forgeConfig, buildPath, electronVersion, platform, arch) => {
|
|
49
|
-
const bridgeDir = path.resolve(buildPath, 'public', 'bin');
|
|
50
|
-
const scrDir = path.resolve(buildPath, 'src');
|
|
51
|
-
const buildScriptDir = path.resolve(buildPath, 'scripts');
|
|
52
|
-
|
|
53
|
-
await fs.remove(bridgeDir);
|
|
54
|
-
await fs.remove(scrDir);
|
|
55
|
-
await fs.remove(buildScriptDir);
|
|
56
|
-
return null;
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
makers: [
|
|
60
|
-
{
|
|
61
|
-
name: '@electron-forge/maker-zip',
|
|
62
|
-
platforms: ['darwin', 'win32'],
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
};
|