mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
feat: implement latest version updater for macos (#2214)
Co-authored-by: himself65 <himself65@outlook.com>
This commit is contained in:
@@ -2,4 +2,5 @@
|
||||
// It will guide preload and main process on the correct event types and payloads
|
||||
export interface MainEventMap {
|
||||
'main:on-db-update': (workspaceId: string) => void;
|
||||
'main:client-update-available': (version: string) => void;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { openWorkspaceDatabase } from './data/sqlite';
|
||||
import { deleteWorkspace, listWorkspaces } from './data/workspace';
|
||||
import { getExchangeTokenParams, oauthEndpoint } from './google-auth';
|
||||
import { sendMainEvent } from './send-main-event';
|
||||
import { updateClient } from './updater';
|
||||
|
||||
let currentWorkspaceId = '';
|
||||
|
||||
@@ -144,6 +145,10 @@ function registerUIHandlers() {
|
||||
ipcMain.handle('main:env-update', async (_, env, value) => {
|
||||
process.env[env] = value;
|
||||
});
|
||||
|
||||
ipcMain.handle('ui:client-update-install', async () => {
|
||||
await updateClient();
|
||||
});
|
||||
}
|
||||
|
||||
function registerDBHandlers() {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { logger } from '../../logger';
|
||||
import { registerHandlers } from './handlers';
|
||||
import { restoreOrCreateWindow } from './main-window';
|
||||
import { registerProtocol } from './protocol';
|
||||
import { registerUpdater } from './updater';
|
||||
|
||||
if (require('electron-squirrel-startup')) app.exit();
|
||||
if (process.defaultApp) {
|
||||
@@ -58,6 +59,7 @@ app
|
||||
.then(registerProtocol)
|
||||
.then(registerHandlers)
|
||||
.then(restoreOrCreateWindow)
|
||||
.then(registerUpdater)
|
||||
.catch(e => console.error('Failed create window:', e));
|
||||
/**
|
||||
* Check new app version in production mode only
|
||||
|
||||
43
apps/electron/layers/main/src/updater.ts
Normal file
43
apps/electron/layers/main/src/updater.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { autoUpdater } from 'electron-updater';
|
||||
|
||||
import { isMacOS } from '../../utils';
|
||||
import { sendMainEvent } from './send-main-event';
|
||||
const buildType = (process.env.BUILD_TYPE || 'canary').trim().toLowerCase();
|
||||
const mode = process.env.NODE_ENV;
|
||||
const isDev = mode === 'development';
|
||||
|
||||
autoUpdater.autoDownload = false;
|
||||
autoUpdater.allowPrerelease = buildType !== 'stable';
|
||||
autoUpdater.autoInstallOnAppQuit = false;
|
||||
autoUpdater.autoRunAppAfterInstall = false;
|
||||
autoUpdater.setFeedURL({
|
||||
channel: buildType,
|
||||
provider: 'github',
|
||||
repo: 'AFFiNE',
|
||||
owner: 'toeverything',
|
||||
releaseType: buildType === 'stable' ? 'release' : 'prerelease',
|
||||
});
|
||||
|
||||
export const updateClient = async () => {
|
||||
autoUpdater.quitAndInstall();
|
||||
};
|
||||
|
||||
export const registerUpdater = async () => {
|
||||
if (isMacOS()) {
|
||||
autoUpdater.on('update-available', () => {
|
||||
autoUpdater.downloadUpdate();
|
||||
});
|
||||
autoUpdater.on('download-progress', e => {
|
||||
console.log(e.percent);
|
||||
});
|
||||
|
||||
autoUpdater.on('update-downloaded', e => {
|
||||
sendMainEvent('main:client-update-available', e.version);
|
||||
});
|
||||
autoUpdater.on('error', e => {
|
||||
console.log(e.message);
|
||||
});
|
||||
autoUpdater.forceDevUpdateConfig = isDev;
|
||||
await autoUpdater.checkForUpdatesAndNotify();
|
||||
}
|
||||
};
|
||||
@@ -72,6 +72,13 @@ const apis = {
|
||||
updateEnv: (env: string, value: string) => {
|
||||
ipcRenderer.invoke('main:env-update', env, value);
|
||||
},
|
||||
onClientUpdateInstall: () => {
|
||||
ipcRenderer.invoke('ui:client-update-install');
|
||||
},
|
||||
|
||||
onClientUpdateAvailable: (callback: (version: string) => void) => {
|
||||
return onMainEvent('main:client-update-available', callback);
|
||||
},
|
||||
};
|
||||
|
||||
const appInfo = {
|
||||
|
||||
Reference in New Issue
Block a user