version-1-update.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. diff --git a/src/vs/platform/update/common/update.ts b/src/vs/platform/update/common/update.ts
  2. index 199f433..a6cbb10 100644
  3. --- a/src/vs/platform/update/common/update.ts
  4. +++ b/src/vs/platform/update/common/update.ts
  5. @@ -51,3 +51,4 @@ export const enum UpdateType {
  6. Archive,
  7. - Snap
  8. + Snap,
  9. + WindowsInstaller,
  10. }
  11. @@ -110 +111,38 @@ export interface IUpdateService {
  12. }
  13. +
  14. +export type Architecture =
  15. + | "arm"
  16. + | "arm64"
  17. + | "ia32"
  18. + | "loong64"
  19. + | "mips"
  20. + | "mipsel"
  21. + | "ppc"
  22. + | "ppc64"
  23. + | "riscv64"
  24. + | "s390"
  25. + | "s390x"
  26. + | "x64";
  27. +
  28. +export type Platform =
  29. + | "aix"
  30. + | "android"
  31. + | "darwin"
  32. + | "freebsd"
  33. + | "haiku"
  34. + | "linux"
  35. + | "openbsd"
  36. + | "sunos"
  37. + | "win32"
  38. + | "cygwin"
  39. + | "netbsd";
  40. +
  41. +export type Quality =
  42. + | "insider"
  43. + | "stable";
  44. +
  45. +export type Target =
  46. + | "archive"
  47. + | "msi"
  48. + | "system"
  49. + | "user";
  50. \ No newline at end of file
  51. diff --git a/src/vs/platform/update/electron-main/abstractUpdateService.ts b/src/vs/platform/update/electron-main/abstractUpdateService.ts
  52. index 48638aa..8f738e7 100644
  53. --- a/src/vs/platform/update/electron-main/abstractUpdateService.ts
  54. +++ b/src/vs/platform/update/electron-main/abstractUpdateService.ts
  55. @@ -14,6 +14,10 @@ import { IProductService } from '../../product/common/productService.js';
  56. import { IRequestService } from '../../request/common/request.js';
  57. -import { AvailableForDownload, DisablementReason, IUpdateService, State, StateType, UpdateType } from '../common/update.js';
  58. +import { Architecture, AvailableForDownload, DisablementReason, IUpdateService, Platform, State, StateType, Target, UpdateType } from '../common/update.js';
  59. -export function createUpdateURL(platform: string, quality: string, productService: IProductService): string {
  60. - return `${productService.updateUrl}/api/update/${platform}/${quality}/${productService.commit}`;
  61. +export function createUpdateURL(productService: IProductService, quality: string, platform: Platform, architecture: Architecture, target?: Target): string {
  62. + if (target) {
  63. + return `${productService.updateUrl}/${quality}/${platform}/${architecture}/${target}/latest.json`;
  64. + } else {
  65. + return `${productService.updateUrl}/${quality}/${platform}/${architecture}/latest.json`;
  66. + }
  67. }
  68. diff --git a/src/vs/platform/update/electron-main/updateService.darwin.ts b/src/vs/platform/update/electron-main/updateService.darwin.ts
  69. index d3f27d3..4622c99 100644
  70. --- a/src/vs/platform/update/electron-main/updateService.darwin.ts
  71. +++ b/src/vs/platform/update/electron-main/updateService.darwin.ts
  72. @@ -15,3 +15,3 @@ import { ILogService } from '../../log/common/log.js';
  73. import { IProductService } from '../../product/common/productService.js';
  74. -import { IRequestService } from '../../request/common/request.js';
  75. +import { IRequestService, asJson } from '../../request/common/request.js';
  76. import { ITelemetryService } from '../../telemetry/common/telemetry.js';
  77. @@ -19,2 +19,4 @@ import { IUpdate, State, StateType, UpdateType } from '../common/update.js';
  78. import { AbstractUpdateService, createUpdateURL, UpdateErrorClassification, UpdateNotAvailableClassification } from './abstractUpdateService.js';
  79. +import { CancellationToken } from '../../../base/common/cancellation.js';
  80. +import * as semver from 'semver';
  81. @@ -76,9 +78,3 @@ export class DarwinUpdateService extends AbstractUpdateService implements IRelau
  82. protected buildUpdateFeedUrl(quality: string): string | undefined {
  83. - let assetID: string;
  84. - if (!this.productService.darwinUniversalAssetId) {
  85. - assetID = process.arch === 'x64' ? 'darwin' : 'darwin-arm64';
  86. - } else {
  87. - assetID = this.productService.darwinUniversalAssetId;
  88. - }
  89. - const url = createUpdateURL(assetID, quality, this.productService);
  90. + const url = createUpdateURL(this.productService, quality, process.platform, process.arch);
  91. try {
  92. @@ -94,4 +90,23 @@ export class DarwinUpdateService extends AbstractUpdateService implements IRelau
  93. protected doCheckForUpdates(context: any): void {
  94. + if (!this.url) {
  95. + return;
  96. + }
  97. +
  98. this.setState(State.CheckingForUpdates(context));
  99. - electron.autoUpdater.checkForUpdates();
  100. +
  101. + this.requestService.request({ url: this.url }, CancellationToken.None)
  102. + .then<IUpdate | null>(asJson)
  103. + .then(update => {
  104. + if (!update || !update.url || !update.version || !update.productVersion) {
  105. + this.setState(State.Idle(UpdateType.Setup));
  106. + }
  107. + else if(semver.compareBuild(update.productVersion.replace(/(\d+\.\d+\.\d+)(?:\.(\d+))(?:\-\w+)?/, '$1+$2'), `${this.productService.version}+${this.productService.release}`) >= 0) {
  108. + this.setState(State.Idle(UpdateType.Setup));
  109. + }
  110. + else {
  111. + electron.autoUpdater.checkForUpdates();
  112. + }
  113. +
  114. + return Promise.resolve(null);
  115. + })
  116. }
  117. diff --git a/src/vs/platform/update/electron-main/updateService.linux.ts b/src/vs/platform/update/electron-main/updateService.linux.ts
  118. index 6e076c7..81556b6 100644
  119. --- a/src/vs/platform/update/electron-main/updateService.linux.ts
  120. +++ b/src/vs/platform/update/electron-main/updateService.linux.ts
  121. @@ -33,3 +33,3 @@ export class LinuxUpdateService extends AbstractUpdateService {
  122. protected buildUpdateFeedUrl(quality: string): string {
  123. - return createUpdateURL(`linux-${process.arch}`, quality, this.productService);
  124. + return createUpdateURL(this.productService, quality, process.platform, process.arch);
  125. }
  126. diff --git a/src/vs/platform/update/electron-main/updateService.win32.ts b/src/vs/platform/update/electron-main/updateService.win32.ts
  127. index 61109e5..2581f3b 100644
  128. --- a/src/vs/platform/update/electron-main/updateService.win32.ts
  129. +++ b/src/vs/platform/update/electron-main/updateService.win32.ts
  130. @@ -11,3 +11,2 @@ import { CancellationToken } from '../../../base/common/cancellation.js';
  131. import { memoize } from '../../../base/common/decorators.js';
  132. -import { hash } from '../../../base/common/hash.js';
  133. import * as path from '../../../base/common/path.js';
  134. @@ -25,4 +24,5 @@ import { asJson, IRequestService } from '../../request/common/request.js';
  135. import { ITelemetryService } from '../../telemetry/common/telemetry.js';
  136. -import { AvailableForDownload, DisablementReason, IUpdate, State, StateType, UpdateType } from '../common/update.js';
  137. -import { AbstractUpdateService, createUpdateURL, UpdateErrorClassification, UpdateNotAvailableClassification } from './abstractUpdateService.js';
  138. +import { AvailableForDownload, DisablementReason, IUpdate, State, StateType, Target, UpdateType } from '../common/update.js';
  139. +import { AbstractUpdateService, createUpdateURL} from './abstractUpdateService.js';
  140. +import * as semver from 'semver';
  141. @@ -42,5 +42,9 @@ function getUpdateType(): UpdateType {
  142. if (typeof _updateType === 'undefined') {
  143. - _updateType = fs.existsSync(path.join(path.dirname(process.execPath), 'unins000.exe'))
  144. - ? UpdateType.Setup
  145. - : UpdateType.Archive;
  146. + if (fs.existsSync(path.join(path.dirname(process.execPath), 'unins000.exe'))) {
  147. + _updateType = UpdateType.Setup;
  148. + } else if (path.basename(path.normalize(path.join(process.execPath, '..', '..'))) === 'Program Files') {
  149. + _updateType = UpdateType.WindowsInstaller;
  150. + } else {
  151. + _updateType = UpdateType.Archive;
  152. + }
  153. }
  154. @@ -63,2 +67,3 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  155. @IConfigurationService configurationService: IConfigurationService,
  156. + // @ts-expect-error
  157. @ITelemetryService private readonly telemetryService: ITelemetryService,
  158. @@ -102,11 +107,21 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  159. protected buildUpdateFeedUrl(quality: string): string | undefined {
  160. - let platform = `win32-${process.arch}`;
  161. -
  162. - if (getUpdateType() === UpdateType.Archive) {
  163. - platform += '-archive';
  164. - } else if (this.productService.target === 'user') {
  165. - platform += '-user';
  166. + let target: Target;
  167. +
  168. + switch (getUpdateType()) {
  169. + case UpdateType.Archive:
  170. + target = "archive"
  171. + break;
  172. + case UpdateType.WindowsInstaller:
  173. + target = "msi"
  174. + break;
  175. + default:
  176. + if (this.productService.target === 'user') {
  177. + target = "user"
  178. + }
  179. + else {
  180. + target = "system"
  181. + }
  182. }
  183. - return createUpdateURL(platform, quality, this.productService);
  184. + return createUpdateURL(this.productService, quality, process.platform, process.arch, target);
  185. }
  186. @@ -126,4 +141,7 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  187. if (!update || !update.url || !update.version || !update.productVersion) {
  188. - this.telemetryService.publicLog2<{ explicit: boolean }, UpdateNotAvailableClassification>('update:notAvailable', { explicit: !!context });
  189. + this.setState(State.Idle(updateType));
  190. + return Promise.resolve(null);
  191. + }
  192. + if(semver.compareBuild(update.productVersion.replace(/(\d+\.\d+\.\d+)(?:\.(\d+))(?:\-\w+)?/, '$1+$2'), `${this.productService.version}+${this.productService.release}`) >= 0) {
  193. this.setState(State.Idle(updateType));
  194. @@ -158,3 +176,3 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  195. - const fastUpdatesEnabled = this.configurationService.getValue('update.enableWindowsBackgroundUpdates');
  196. + const fastUpdatesEnabled = getUpdateType() == UpdateType.Setup && this.configurationService.getValue('update.enableWindowsBackgroundUpdates');
  197. if (fastUpdatesEnabled) {
  198. @@ -170,3 +188,2 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  199. .then(undefined, err => {
  200. - this.telemetryService.publicLog2<{ messageHash: string }, UpdateErrorClassification>('update:error', { messageHash: String(hash(String(err))) });
  201. this.logService.error(err);
  202. @@ -254,6 +271,14 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  203. } else {
  204. - spawn(this.availableUpdate.packagePath, ['/silent', '/log', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
  205. - detached: true,
  206. - stdio: ['ignore', 'ignore', 'ignore']
  207. - });
  208. + const type = getUpdateType();
  209. + if (type == UpdateType.WindowsInstaller) {
  210. + spawn('msiexec.exe', ['/i', this.availableUpdate.packagePath], {
  211. + detached: true,
  212. + stdio: ['ignore', 'ignore', 'ignore']
  213. + });
  214. + } else {
  215. + spawn(this.availableUpdate.packagePath, ['/silent', '/log', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
  216. + detached: true,
  217. + stdio: ['ignore', 'ignore', 'ignore']
  218. + });
  219. + }
  220. }