fix: try to fix updater not working (#2294)

Co-authored-by: Himself65 <himself65@outlook.com>
This commit is contained in:
Peng Xiao
2023-05-10 13:40:22 +08:00
committed by GitHub
parent 752d0545ca
commit e4f13ddae4
6 changed files with 37 additions and 19 deletions

View File

@@ -61,6 +61,9 @@ const ipcMain = {
handlers.push(callback); handlers.push(callback);
registeredHandlers.set(key, handlers); registeredHandlers.set(key, handlers);
}, },
setMaxListeners: (_n: number) => {
// noop
},
}; };
const nativeTheme = { const nativeTheme = {

View File

@@ -1,4 +1,5 @@
import { watch } from 'chokidar'; import { watch } from 'chokidar';
import { app } from 'electron';
import { appContext } from '../../context'; import { appContext } from '../../context';
import { subjects } from '../../events'; import { subjects } from '../../events';
@@ -87,3 +88,7 @@ export async function cleanupSQLiteDBs() {
dbMapping.clear(); dbMapping.clear();
dbWatchers.clear(); dbWatchers.clear();
} }
app?.on('before-quit', async () => {
await cleanupSQLiteDBs();
});

View File

@@ -15,7 +15,7 @@ import { listWorkspaces } from '../workspace/workspace';
export async function revealDBFile(workspaceId: string) { export async function revealDBFile(workspaceId: string) {
const workspaceDB = await ensureSQLiteDB(workspaceId); const workspaceDB = await ensureSQLiteDB(workspaceId);
shell.showItemInFolder(workspaceDB.path); shell.showItemInFolder(await fs.realpath(workspaceDB.path));
} }
// provide a backdoor to set dialog path for testing in playwright // provide a backdoor to set dialog path for testing in playwright

View File

@@ -36,6 +36,8 @@ export const allHandlers = {
} satisfies Record<string, NamespaceHandlers>; } satisfies Record<string, NamespaceHandlers>;
export const registerHandlers = () => { export const registerHandlers = () => {
// TODO: listen to namespace instead of individual event types
ipcMain.setMaxListeners(100);
for (const [namespace, namespaceHandlers] of Object.entries(allHandlers)) { for (const [namespace, namespaceHandlers] of Object.entries(allHandlers)) {
for (const [key, handler] of Object.entries(namespaceHandlers)) { for (const [key, handler] of Object.entries(namespaceHandlers)) {
const chan = `${namespace}:${key}`; const chan = `${namespace}:${key}`;

View File

@@ -18,15 +18,19 @@ export const registerUpdater = async () => {
// require it will cause some side effects and will break generate-main-exposed-meta, // require it will cause some side effects and will break generate-main-exposed-meta,
// so we wrap it in a function // so we wrap it in a function
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const { autoUpdater } = await import('electron-updater'); const { autoUpdater } = require('electron-updater');
_autoUpdater = autoUpdater; _autoUpdater = autoUpdater;
autoUpdater.autoDownload = false; if (!_autoUpdater) {
autoUpdater.allowPrerelease = buildType !== 'stable'; return;
autoUpdater.autoInstallOnAppQuit = false; }
autoUpdater.autoRunAppAfterInstall = true;
autoUpdater.setFeedURL({ _autoUpdater.autoDownload = false;
_autoUpdater.allowPrerelease = buildType !== 'stable';
_autoUpdater.autoInstallOnAppQuit = false;
_autoUpdater.autoRunAppAfterInstall = true;
_autoUpdater.setFeedURL({
channel: buildType, channel: buildType,
provider: 'github', provider: 'github',
repo: 'AFFiNE', repo: 'AFFiNE',
@@ -34,11 +38,11 @@ export const registerUpdater = async () => {
releaseType: buildType === 'stable' ? 'release' : 'prerelease', releaseType: buildType === 'stable' ? 'release' : 'prerelease',
}); });
autoUpdater.autoDownload = false; _autoUpdater.autoDownload = false;
autoUpdater.allowPrerelease = buildType !== 'stable'; _autoUpdater.allowPrerelease = buildType !== 'stable';
autoUpdater.autoInstallOnAppQuit = false; _autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.autoRunAppAfterInstall = true; _autoUpdater.autoRunAppAfterInstall = true;
autoUpdater.setFeedURL({ _autoUpdater.setFeedURL({
channel: buildType, channel: buildType,
provider: 'github', provider: 'github',
repo: 'AFFiNE', repo: 'AFFiNE',
@@ -47,23 +51,23 @@ export const registerUpdater = async () => {
}); });
if (isMacOS()) { if (isMacOS()) {
autoUpdater.on('update-available', () => { _autoUpdater.on('update-available', () => {
autoUpdater.downloadUpdate(); _autoUpdater!.downloadUpdate();
logger.info('Update available, downloading...'); logger.info('Update available, downloading...');
}); });
autoUpdater.on('download-progress', e => { _autoUpdater.on('download-progress', e => {
logger.info(`Download progress: ${e.percent}`); logger.info(`Download progress: ${e.percent}`);
}); });
autoUpdater.on('update-downloaded', e => { _autoUpdater.on('update-downloaded', e => {
updaterSubjects.clientUpdateReady.next({ updaterSubjects.clientUpdateReady.next({
version: e.version, version: e.version,
}); });
logger.info('Update downloaded, ready to install'); logger.info('Update downloaded, ready to install');
}); });
autoUpdater.on('error', e => { _autoUpdater.on('error', e => {
logger.error('Error while updating client', e); logger.error('Error while updating client', e);
}); });
autoUpdater.forceDevUpdateConfig = isDev; _autoUpdater.forceDevUpdateConfig = isDev;
await autoUpdater.checkForUpdatesAndNotify(); await _autoUpdater.checkForUpdatesAndNotify();
} }
}; };

View File

@@ -57,6 +57,10 @@ const events: MainIPCEventMap = (() => {
const { const {
events: eventsMeta, events: eventsMeta,
}: MainExposedMeta = require('../main/exposed-meta'); }: MainExposedMeta = require('../main/exposed-meta');
// NOTE: ui may try to listen to a lot of the same events, so we increase the limit...
ipcRenderer.setMaxListeners(100);
const all = eventsMeta.map(([namespace, eventNames]) => { const all = eventsMeta.map(([namespace, eventNames]) => {
const namespaceEvents = eventNames.map(name => { const namespaceEvents = eventNames.map(name => {
const channel = `${namespace}:${name}`; const channel = `${namespace}:${name}`;