mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* feat: native auto updater for MSIX on Windows Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * doc: added MSIX debug documentation Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: allow downgrade with json release file and emit update-available Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * test: msix auot-update tests Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * doc: API documentation Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * test: add package version validation Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: docs typo Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: don't allow auto-updating when using appinstaller manifest Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: getPackageInfo interface implementation Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: review feedback, add comment Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: missed filename commit Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: install test cert on demand Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: time stamp mismatch in tests Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: feedback - rename to MSIXPackageInfo Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: update and reference windowsStore property Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: remove getPackagInfo from public API Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: type error bcause of removed API Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> * fix: fix Windows MSIX release build errors (#49613) * fix: fix MSIX release build * fix: add C++/WinRT headers * build: modify include paths * fix: compile msix as seperate source set * build: add additional needed deps for msix --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Jan Hannemann <jan.hannemann@outlook.com> Co-authored-by: Keeley Hammond <vertedinde@electronjs.org>
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import * as squirrelUpdate from '@electron/internal/browser/api/auto-updater/squirrel-update-win';
|
|
|
|
import { app } from 'electron/main';
|
|
|
|
import { EventEmitter } from 'events';
|
|
|
|
class AutoUpdater extends EventEmitter implements Electron.AutoUpdater {
|
|
updateAvailable: boolean = false;
|
|
updateURL: string | null = null;
|
|
|
|
quitAndInstall () {
|
|
if (!this.updateAvailable) {
|
|
return this.emitError(new Error('No update available, can\'t quit and install'));
|
|
}
|
|
squirrelUpdate.processStart();
|
|
app.quit();
|
|
}
|
|
|
|
getFeedURL () {
|
|
return this.updateURL ?? '';
|
|
}
|
|
|
|
getPackageInfo () {
|
|
// Squirrel-based Windows apps don't have MSIX package information
|
|
return undefined;
|
|
}
|
|
|
|
setFeedURL (options: { url: string } | string) {
|
|
let updateURL: string;
|
|
if (typeof options === 'object') {
|
|
if (typeof options.url === 'string') {
|
|
updateURL = options.url;
|
|
} else {
|
|
throw new TypeError('Expected options object to contain a \'url\' string property in setFeedUrl call');
|
|
}
|
|
} else if (typeof options === 'string') {
|
|
updateURL = options;
|
|
} else {
|
|
throw new TypeError('Expected an options object with a \'url\' property to be provided');
|
|
}
|
|
this.updateURL = updateURL;
|
|
}
|
|
|
|
async checkForUpdates () {
|
|
const url = this.updateURL;
|
|
if (!url) {
|
|
return this.emitError(new Error('Update URL is not set'));
|
|
}
|
|
if (!squirrelUpdate.supported()) {
|
|
return this.emitError(new Error('Can not find Squirrel'));
|
|
}
|
|
this.emit('checking-for-update');
|
|
try {
|
|
const update = await squirrelUpdate.checkForUpdate(url);
|
|
if (update == null) {
|
|
return this.emit('update-not-available');
|
|
}
|
|
this.updateAvailable = true;
|
|
this.emit('update-available');
|
|
|
|
await squirrelUpdate.update(url);
|
|
const { releaseNotes, version } = update;
|
|
// Date is not available on Windows, so fake it.
|
|
const date = new Date();
|
|
this.emit('update-downloaded', {}, releaseNotes, version, date, this.updateURL, () => {
|
|
this.quitAndInstall();
|
|
});
|
|
} catch (error) {
|
|
this.emitError(error as Error);
|
|
}
|
|
}
|
|
|
|
// Private: Emit both error object and message, this is to keep compatibility
|
|
// with Old APIs.
|
|
emitError (error: Error) {
|
|
this.emit('error', error, error.message);
|
|
}
|
|
}
|
|
|
|
export default new AutoUpdater();
|