1
>
/*---------------------------------------------------------------------------------------------
update.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Event } from '../../../base/common/event.js';
7
>
import { upcast } from '../../../base/common/types.js';
8
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
9
>
10
>
export interface IUpdate {
11
>
version: string; // Build commit ID
12
>
productVersion?: string; // Product version like 1.2.3
13
>
timestamp?: number;
14
>
url?: string;
15
>
sha256hash?: string;
16
>
}
17
>
18
>
/**
19
>
* Updates are run as a state machine:
20
>
*
21
>
* Uninitialized
22
>
* ↓
23
>
* Idle
24
>
* ↓ ↑
25
>
* Checking for Updates → Available for Download
26
>
* ↓ ↓
27
>
* ← Overwriting
28
>
* Downloading ↑
29
>
* → Ready
30
>
* ↓ ↑
31
>
* Downloaded → Updating
32
>
*
33
>
* Available: There is an update available for download (linux, darwin on metered connection).
34
>
* Ready: Code will be updated as soon as it restarts (win32, darwin).
35
>
* Downloaded: There is an update ready to be installed in the background (win32).
36
>
* Overwriting: A newer update is being downloaded to replace the pending update (darwin).
37
>
* Cancelling: Updates are being disabled at runtime; in-flight/pending work is being torn down before Disabled.
38
>
*/
39
>
40
>
export const enum StateType {
41
>
Uninitialized = 'uninitialized',
42
>
Idle = 'idle',
43
>
Disabled = 'disabled',
44
>
CheckingForUpdates = 'checking for updates',
45
>
AvailableForDownload = 'available for download',
46
>
Downloading = 'downloading',
47
>
Downloaded = 'downloaded',
48
>
Updating = 'updating',
49
>
Ready = 'ready',
50
>
Overwriting = 'overwriting',
51
>
Cancelling = 'cancelling',
52
>
Restarting = 'restarting',
53
>
}
54
>
55
>
export const enum UpdateType {
56
>
Setup,
57
>
Archive,
58
>
Snap
59
>
}
60
>
61
>
export const enum DisablementReason {
62
>
NotBuilt,
63
>
DisabledByEnvironment,
64
>
ManuallyDisabled,
65
>
Policy,
66
>
MissingConfiguration,
67
>
InvalidConfiguration,
68
>
RunningAsAdmin,
69
>
}
70
>
71
>
export type Uninitialized = { type: StateType.Uninitialized };
72
>
export type Disabled = { type: StateType.Disabled; reason: DisablementReason };
73
>
export type Idle = { type: StateType.Idle; updateType: UpdateType; error?: string; notAvailable?: boolean };
74
>
export type CheckingForUpdates = { type: StateType.CheckingForUpdates; explicit: boolean };
75
>
export type AvailableForDownload = { type: StateType.AvailableForDownload; update: IUpdate; canInstall?: boolean };
76
>
export type Downloading = { type: StateType.Downloading; update?: IUpdate; explicit: boolean; overwrite: boolean; downloadedBytes?: number; totalBytes?: number; startTime?: number };
77
>
export type Downloaded = { type: StateType.Downloaded; update: IUpdate; explicit: boolean; overwrite: boolean };
78
>
export type Updating = { type: StateType.Updating; update: IUpdate; currentProgress?: number; maxProgress?: number; explicit: boolean };
79
>
export type Ready = { type: StateType.Ready; update: IUpdate; explicit: boolean; overwrite: boolean };
80
>
export type Overwriting = { type: StateType.Overwriting; update: IUpdate; explicit: boolean };
81
>
export type Cancelling = { type: StateType.Cancelling };
82
>
export type Restarting = { type: StateType.Restarting; update: IUpdate };
83
>
84
>
export type State = Uninitialized | Disabled | Idle | CheckingForUpdates | AvailableForDownload | Downloading | Downloaded | Updating | Ready | Overwriting | Cancelling | Restarting;
85
>
86
>
export const State = {
87
>
Uninitialized: upcast<Uninitialized>({ type: StateType.Uninitialized }),
88
>
Disabled: (reason: DisablementReason): Disabled => ({ type: StateType.Disabled, reason }),
89
>
Idle: (updateType: UpdateType, error?: string, notAvailable?: boolean): Idle => ({ type: StateType.Idle, updateType, error, notAvailable }),
90
>
CheckingForUpdates: (explicit: boolean): CheckingForUpdates => ({ type: StateType.CheckingForUpdates, explicit }),
91
>
AvailableForDownload: (update: IUpdate, canInstall?: boolean): AvailableForDownload => ({ type: StateType.AvailableForDownload, update, canInstall }),
92
>
Downloading: (update: IUpdate | undefined, explicit: boolean, overwrite: boolean, downloadedBytes?: number, totalBytes?: number, startTime?: number): Downloading => ({ type: StateType.Downloading, update, explicit, overwrite, downloadedBytes, totalBytes, startTime }),
93
>
Downloaded: (update: IUpdate, explicit: boolean, overwrite: boolean): Downloaded => ({ type: StateType.Downloaded, update, explicit, overwrite }),
94
>
Updating: (update: IUpdate, explicit: boolean, currentProgress?: number, maxProgress?: number): Updating => ({ type: StateType.Updating, update, explicit, currentProgress, maxProgress }),
95
>
Ready: (update: IUpdate, explicit: boolean, overwrite: boolean): Ready => ({ type: StateType.Ready, update, explicit, overwrite }),
96
>
Overwriting: (update: IUpdate, explicit: boolean): Overwriting => ({ type: StateType.Overwriting, update, explicit }),
97
>
Cancelling: upcast<Cancelling>({ type: StateType.Cancelling }),
98
>
Restarting: (update: IUpdate): Restarting => ({ type: StateType.Restarting, update }),
99
>
};
100
>
101
>
export interface IAutoUpdater extends Event.NodeEventEmitter {
102
>
setFeedURL(url: string): void;
103
>
checkForUpdates(): void;
104
>
applyUpdate?(): Promise<void>;
105
>
quitAndInstall(): void;
106
>
}
107
>
108
>
export const IUpdateService = createDecorator<IUpdateService>('updateService');
109
>
110
>
export interface IUpdateService {
111
>
readonly _serviceBrand: undefined;
112
>
113
>
readonly onStateChange: Event<State>;
114
>
readonly state: State;
115
>
116
>
checkForUpdates(explicit: boolean): Promise<void>;
117
>
downloadUpdate(explicit: boolean): Promise<void>;
118
>
applyUpdate(): Promise<void>;
119
>
quitAndInstall(): Promise<void>;
120
>
121
>
/**
122
>
* @deprecated This method should not be used any more. It will be removed in a future release.
123
>
*/
124
>
isLatestVersion(): Promise<boolean | undefined>;
125
>
_applySpecificUpdate(packagePath: string): Promise<void>;
126
>
setInternalOrg(internalOrg: string | undefined): Promise<void>;
127
>
}