Skip to content

Commit fc2b01b

Browse files
authored
fix(agent-tars): app updater not work (#328)
1 parent 1b9712e commit fc2b01b

File tree

7 files changed

+115
-31
lines changed

7 files changed

+115
-31
lines changed

apps/agent-tars/dev-app-update.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/agent-tars/package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@electron-toolkit/preload": "^3.0.1",
5151
"@electron-toolkit/utils": "^4.0.0",
5252
"@electron/asar": "^3.2.18",
53-
"update-electron-app": "^3.1.0",
53+
"electron-updater": "^6.3.9",
5454
"openai": "^4.86.2",
5555
"dotenv": "16.4.7",
5656
"@agent-infra/shared": "workspace:*",
@@ -94,5 +94,17 @@
9494
"vite-tsconfig-paths": "^5.1.4",
9595
"vitest": "^3.0.8",
9696
"vite-plugin-singlefile": "2.2.0"
97+
},
98+
"build": {
99+
"publish": [
100+
{
101+
"provider": "github",
102+
"owner": "bytedance",
103+
"repo": "UI-TARS-desktop"
104+
}
105+
],
106+
"electronDownload": {
107+
"mirror": "https://npmmirror.com/mirrors/electron/"
108+
}
97109
}
98110
}

apps/agent-tars/src/main/index.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
11
import { app, shell, BrowserWindow, ipcMain } from 'electron';
22
import { join } from 'path';
33
import { registerIpcMain } from '@ui-tars/electron-ipc/main';
4-
import { updateElectronApp, UpdateSourceType } from 'update-electron-app';
54
import { electronApp, optimizer, is } from '@electron-toolkit/utils';
65
import { ipcRoutes } from './ipcRoutes';
76
import icon from '../../resources/icon.png?asset';
87
import MenuBuilder from './menu';
98
import { logger } from './utils/logger';
109
import { ErrorReporter } from './utils/errorReporter';
10+
import { AppUpdater } from './utils/updateApp';
1111

12-
class AppUpdater {
13-
constructor() {
14-
// autoUpdater.logger = logger;
15-
// autoUpdater.checkForUpdatesAndNotify();
16-
if (process.env.CI !== 'e2e') {
17-
updateElectronApp({
18-
updateSource: {
19-
type: UpdateSourceType.ElectronPublicUpdateService,
20-
repo: 'bytedance/UI-TARS-desktop',
21-
host: 'https://update.electronjs.org',
22-
},
23-
updateInterval: '20 minutes',
24-
});
25-
}
26-
}
27-
}
28-
29-
function createWindow(): void {
12+
function createWindow(): BrowserWindow {
3013
// Create the browser window.
3114
const mainWindow = new BrowserWindow({
3215
width: 1200,
@@ -86,6 +69,8 @@ function createWindow(): void {
8669
// Set up the application menu
8770
const menuBuilder = new MenuBuilder(mainWindow);
8871
menuBuilder.buildMenu();
72+
73+
return mainWindow;
8974
}
9075

9176
const initializeApp = async () => {
@@ -122,8 +107,6 @@ app.whenReady().then(async () => {
122107
optimizer.watchWindowShortcuts(window);
123108
});
124109

125-
new AppUpdater();
126-
127110
await initializeApp();
128111

129112
// IPC test
@@ -133,7 +116,9 @@ app.whenReady().then(async () => {
133116
});
134117
registerIpcMain(ipcRoutes);
135118

136-
createWindow();
119+
const mainWindow = createWindow();
120+
121+
new AppUpdater(mainWindow);
137122

138123
app.on('activate', function () {
139124
// On macOS it's common to re-create a window in the app when the
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { UpdateInfo } from 'builder-util-runtime';
2+
import { app, BrowserWindow } from 'electron';
3+
import { logger } from '@main/utils/logger';
4+
import {
5+
AppUpdater as ElectronAppUpdater,
6+
autoUpdater,
7+
} from 'electron-updater';
8+
9+
export class AppUpdater {
10+
autoUpdater: ElectronAppUpdater = autoUpdater;
11+
constructor(mainWindow: BrowserWindow) {
12+
autoUpdater.logger = logger;
13+
autoUpdater.autoDownload = true;
14+
autoUpdater.forceDevUpdateConfig = !app.isPackaged;
15+
16+
autoUpdater.on('error', (error) => {
17+
logger.error('Update_Error', error);
18+
mainWindow.webContents.send('main:error', error);
19+
});
20+
21+
autoUpdater.on('update-available', (releaseInfo: UpdateInfo) => {
22+
logger.info('new version', releaseInfo);
23+
mainWindow.webContents.send('app-update-available', releaseInfo);
24+
});
25+
26+
this.autoUpdater = autoUpdater;
27+
28+
this.autoUpdater.checkForUpdatesAndNotify();
29+
}
30+
}

apps/agent-tars/src/renderer/mock/ipc.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ declare global {
136136
ipcRenderer: {
137137
invoke: (channel: string, ...args: any[]) => Promise<any>;
138138
on: (channel: string, listener: (...args: any[]) => void) => void;
139+
once: (channel: string, listener: (...args: any[]) => void) => void;
140+
off: (channel: string, listener: (...args: any[]) => void) => void;
139141
};
140142
};
141143
}
@@ -148,5 +150,11 @@ window.electron = {
148150
on: async () => {
149151
// noop
150152
},
153+
once: async () => {
154+
// noop
155+
},
156+
off: async () => {
157+
// noop
158+
},
151159
},
152160
};

packages/common/electron-build/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"registry": "https://registry.npmjs.org"
3838
},
3939
"dependencies": {
40+
"electron-updater": "6.3.9",
4041
"flora-colossus": "2.0.0",
4142
"@common/configs": "workspace:*"
4243
},

pnpm-lock.yaml

Lines changed: 56 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)