mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-24 18:02:47 +08:00
fix(electron): app got deleted when auto update on windows (#7820)
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
// credits: migrated from https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/providers/GitHubProvider.ts
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
import type {
|
||||
CustomPublishOptions,
|
||||
GithubOptions,
|
||||
@@ -10,7 +7,6 @@ import type {
|
||||
XElement,
|
||||
} from 'builder-util-runtime';
|
||||
import { HttpError, newError, parseXml } from 'builder-util-runtime';
|
||||
import { app } from 'electron';
|
||||
import type {
|
||||
AppUpdater,
|
||||
ResolvedUpdateFileInfo,
|
||||
@@ -24,6 +20,9 @@ import {
|
||||
resolveFiles,
|
||||
} from 'electron-updater/out/providers/Provider';
|
||||
import * as semver from 'semver';
|
||||
|
||||
import { isSquirrelBuild } from './utils';
|
||||
|
||||
interface GithubUpdateInfo extends UpdateInfo {
|
||||
tag: string;
|
||||
}
|
||||
@@ -41,13 +40,6 @@ interface GithubRelease {
|
||||
|
||||
const hrefRegExp = /\/tag\/([^/]+)$/;
|
||||
|
||||
function isSquirrelBuild() {
|
||||
// if it is squirrel build, there will be 'squirrel.exe'
|
||||
// otherwise it is in nsis web mode
|
||||
const files = fs.readdirSync(path.dirname(app.getPath('exe')));
|
||||
return files.some(it => it.includes('squirrel.exe'));
|
||||
}
|
||||
|
||||
export class CustomGitHubProvider extends BaseGitHubProvider<GithubUpdateInfo> {
|
||||
constructor(
|
||||
options: CustomPublishOptions,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { app } from 'electron';
|
||||
import { autoUpdater } from 'electron-updater';
|
||||
import { autoUpdater as defaultAutoUpdater } from 'electron-updater';
|
||||
|
||||
import { buildType } from '../config';
|
||||
import { logger } from '../logger';
|
||||
import { CustomGitHubProvider } from './custom-github-provider';
|
||||
import { updaterSubjects } from './event';
|
||||
import { WindowsUpdater } from './windows-updater';
|
||||
|
||||
const mode = process.env.NODE_ENV;
|
||||
const isDev = mode === 'development';
|
||||
@@ -12,6 +13,9 @@ const isDev = mode === 'development';
|
||||
// skip auto update in dev mode & internal
|
||||
const disabled = buildType === 'internal' || isDev;
|
||||
|
||||
export const autoUpdater =
|
||||
process.platform === 'win32' ? new WindowsUpdater() : defaultAutoUpdater;
|
||||
|
||||
export const quitAndInstall = async () => {
|
||||
autoUpdater.quitAndInstall();
|
||||
};
|
||||
|
||||
18
packages/frontend/electron/src/main/updater/utils.ts
Normal file
18
packages/frontend/electron/src/main/updater/utils.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
import { app } from 'electron';
|
||||
|
||||
let _isSquirrelBuild: boolean | null = null;
|
||||
export function isSquirrelBuild() {
|
||||
if (typeof _isSquirrelBuild === 'boolean') {
|
||||
return _isSquirrelBuild;
|
||||
}
|
||||
|
||||
// if it is squirrel build, there will be 'squirrel.exe'
|
||||
// otherwise it is in nsis web mode
|
||||
const files = fs.readdirSync(path.dirname(app.getPath('exe')));
|
||||
_isSquirrelBuild = files.some(it => it.includes('squirrel.exe'));
|
||||
|
||||
return _isSquirrelBuild;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { app } from 'electron';
|
||||
import { NsisUpdater } from 'electron-updater';
|
||||
import { DownloadedUpdateHelper } from 'electron-updater/out/DownloadedUpdateHelper';
|
||||
|
||||
export class WindowsUpdater extends NsisUpdater {
|
||||
protected override downloadedUpdateHelper: DownloadedUpdateHelper =
|
||||
new DownloadedUpdateHelper(app.getPath('sessionData'));
|
||||
}
|
||||
Reference in New Issue
Block a user