2026-07-28 02:12:46 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 预加载:桌面能力 + 用户目录(对标 Codex ~/.codex → ~/.aps)
|
|
|
|
|
|
*/
|
|
|
|
|
|
const { contextBridge, ipcRenderer } = require('electron');
|
2026-08-20 11:39:21 +08:00
|
|
|
|
|
|
|
|
|
|
function argumentValue(name) {
|
|
|
|
|
|
const prefix = `--${name}=`;
|
|
|
|
|
|
const value = process.argv.find((argument) => argument.startsWith(prefix));
|
|
|
|
|
|
return value ? decodeURIComponent(value.slice(prefix.length)) : '';
|
|
|
|
|
|
}
|
2026-07-28 02:12:46 +08:00
|
|
|
|
|
|
|
|
|
|
/** 安装态 / 桌面态:固定用户主目录下的 .aps */
|
2026-08-20 11:39:21 +08:00
|
|
|
|
const home = argumentValue('aps-home');
|
2026-07-28 02:12:46 +08:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
contextBridge.exposeInMainWorld('apsDesktop', {
|
|
|
|
|
|
mode: 'desktop',
|
2026-08-20 11:39:21 +08:00
|
|
|
|
apiUrl: argumentValue('aps-api-url'),
|
2026-07-28 02:12:46 +08:00
|
|
|
|
home,
|
2026-08-20 11:39:21 +08:00
|
|
|
|
skillsDir: argumentValue('aps-skills-dir'),
|
|
|
|
|
|
sessionsDir: argumentValue('aps-sessions-dir'),
|
2026-07-28 02:12:46 +08:00
|
|
|
|
async getDeviceId() {
|
|
|
|
|
|
return ipcRenderer.invoke('aps:get-device-id');
|
|
|
|
|
|
},
|
|
|
|
|
|
openHome() {
|
|
|
|
|
|
ipcRenderer.send('aps:open-path', 'home');
|
|
|
|
|
|
},
|
|
|
|
|
|
openSkills() {
|
|
|
|
|
|
ipcRenderer.send('aps:open-path', 'skills');
|
|
|
|
|
|
},
|
|
|
|
|
|
openSessions() {
|
|
|
|
|
|
ipcRenderer.send('aps:open-path', 'sessions');
|
|
|
|
|
|
},
|
|
|
|
|
|
async pickDirectory() {
|
|
|
|
|
|
return ipcRenderer.invoke('aps:pick-directory');
|
|
|
|
|
|
},
|
2026-08-20 11:39:21 +08:00
|
|
|
|
|
|
|
|
|
|
/** 离线升级入口(updater.cjs):检查更新 / 应用升级(失败自动回滚)/ 手动回滚 */
|
|
|
|
|
|
checkForUpdate(options) {
|
|
|
|
|
|
return ipcRenderer.invoke('aps:check-for-update', options);
|
|
|
|
|
|
},
|
|
|
|
|
|
applyUpdate(options) {
|
|
|
|
|
|
return ipcRenderer.invoke('aps:apply-update', options);
|
|
|
|
|
|
},
|
|
|
|
|
|
rollback(options) {
|
|
|
|
|
|
return ipcRenderer.invoke('aps:rollback', options);
|
|
|
|
|
|
},
|
2026-07-28 02:12:46 +08:00
|
|
|
|
toggleDevTools() {
|
|
|
|
|
|
ipcRenderer.send('aps:toggle-devtools');
|
|
|
|
|
|
},
|
|
|
|
|
|
toggleFullScreen() {
|
|
|
|
|
|
ipcRenderer.send('aps:toggle-fullscreen');
|
|
|
|
|
|
},
|
|
|
|
|
|
leaveFullScreen() {
|
|
|
|
|
|
ipcRenderer.send('aps:leave-fullscreen');
|
|
|
|
|
|
},
|
|
|
|
|
|
windowMinimize() {
|
|
|
|
|
|
ipcRenderer.send('aps:window-minimize');
|
|
|
|
|
|
},
|
|
|
|
|
|
windowMaximize() {
|
|
|
|
|
|
ipcRenderer.send('aps:window-maximize');
|
|
|
|
|
|
},
|
|
|
|
|
|
windowClose() {
|
|
|
|
|
|
ipcRenderer.send('aps:window-close');
|
|
|
|
|
|
},
|
|
|
|
|
|
onWindowState(callback) {
|
|
|
|
|
|
if (typeof callback !== 'function') return () => {};
|
|
|
|
|
|
const handler = (_event, state) => callback(state);
|
|
|
|
|
|
ipcRenderer.on('aps:window-state', handler);
|
|
|
|
|
|
ipcRenderer.send('aps:window-state-request');
|
|
|
|
|
|
return () => ipcRenderer.removeListener('aps:window-state', handler);
|
|
|
|
|
|
},
|
|
|
|
|
|
onMenuAction(callback) {
|
|
|
|
|
|
if (typeof callback !== 'function') return () => {};
|
|
|
|
|
|
const handler = (_event, action) => callback(action);
|
|
|
|
|
|
ipcRenderer.on('menu:action', handler);
|
|
|
|
|
|
return () => ipcRenderer.removeListener('menu:action', handler);
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
console.error('[aps-desktop] preload expose failed', err);
|
|
|
|
|
|
}
|