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);
registeredHandlers.set(key, handlers);
},
setMaxListeners: (_n: number) => {
// noop
},
};
const nativeTheme = {

View File

@@ -1,4 +1,5 @@
import { watch } from 'chokidar';
import { app } from 'electron';
import { appContext } from '../../context';
import { subjects } from '../../events';
@@ -87,3 +88,7 @@ export async function cleanupSQLiteDBs() {
dbMapping.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) {
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

View File

@@ -36,6 +36,8 @@ export const allHandlers = {
} satisfies Record<string, NamespaceHandlers>;
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 [key, handler] of Object.entries(namespaceHandlers)) {
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,
// so we wrap it in a function
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { autoUpdater } = await import('electron-updater');
const { autoUpdater } = require('electron-updater');
_autoUpdater = autoUpdater;
autoUpdater.autoDownload = false;
autoUpdater.allowPrerelease = buildType !== 'stable';
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.autoRunAppAfterInstall = true;
autoUpdater.setFeedURL({
if (!_autoUpdater) {
return;
}
_autoUpdater.autoDownload = false;
_autoUpdater.allowPrerelease = buildType !== 'stable';
_autoUpdater.autoInstallOnAppQuit = false;
_autoUpdater.autoRunAppAfterInstall = true;
_autoUpdater.setFeedURL({
channel: buildType,
provider: 'github',
repo: 'AFFiNE',
@@ -34,11 +38,11 @@ export const registerUpdater = async () => {
releaseType: buildType === 'stable' ? 'release' : 'prerelease',
});
autoUpdater.autoDownload = false;
autoUpdater.allowPrerelease = buildType !== 'stable';
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,
provider: 'github',
repo: 'AFFiNE',
@@ -47,23 +51,23 @@ export const registerUpdater = async () => {
});
if (isMacOS()) {
autoUpdater.on('update-available', () => {
autoUpdater.downloadUpdate();
_autoUpdater.on('update-available', () => {
_autoUpdater!.downloadUpdate();
logger.info('Update available, downloading...');
});
autoUpdater.on('download-progress', e => {
_autoUpdater.on('download-progress', e => {
logger.info(`Download progress: ${e.percent}`);
});
autoUpdater.on('update-downloaded', e => {
_autoUpdater.on('update-downloaded', e => {
updaterSubjects.clientUpdateReady.next({
version: e.version,
});
logger.info('Update downloaded, ready to install');
});
autoUpdater.on('error', e => {
_autoUpdater.on('error', e => {
logger.error('Error while updating client', e);
});
autoUpdater.forceDevUpdateConfig = isDev;
await autoUpdater.checkForUpdatesAndNotify();
_autoUpdater.forceDevUpdateConfig = isDev;
await _autoUpdater.checkForUpdatesAndNotify();
}
};

View File

@@ -57,6 +57,10 @@ const events: MainIPCEventMap = (() => {
const {
events: eventsMeta,
}: 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 namespaceEvents = eventNames.map(name => {
const channel = `${namespace}:${name}`;