version-1-update.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 a1ec3fe..f954720 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 57398fb..b30ef50 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 } 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,29 @@ 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. + return Promise.resolve(null);
  108. + }
  109. +
  110. + const fetchedVersion = /\d+\.\d+\.\d+\.\d+/.test(update.productVersion) ? update.productVersion.replace(/(\d+\.\d+\.\d+)\.\d+(\-\w+)?/, '$1$2') : update.productVersion.replace(/(\d+\.\d+\.)0+(\d+)(\-\w+)?/, '$1$2$3')
  111. + const currentVersion = this.productService.version.replace(/(\d+\.\d+\.)0+(\d+)(\-\w+)?/, '$1$2$3')
  112. +
  113. + if(semver.compareBuild(currentVersion, fetchedVersion) >= 0) {
  114. + this.setState(State.Idle(UpdateType.Setup));
  115. + }
  116. + else {
  117. + electron.autoUpdater.checkForUpdates();
  118. + }
  119. +
  120. + return Promise.resolve(null);
  121. + })
  122. }
  123. diff --git a/src/vs/platform/update/electron-main/updateService.linux.ts b/src/vs/platform/update/electron-main/updateService.linux.ts
  124. index dd18900..920dc10 100644
  125. --- a/src/vs/platform/update/electron-main/updateService.linux.ts
  126. +++ b/src/vs/platform/update/electron-main/updateService.linux.ts
  127. @@ -31,3 +31,3 @@ export class LinuxUpdateService extends AbstractUpdateService {
  128. protected buildUpdateFeedUrl(quality: string): string {
  129. - return createUpdateURL(`linux-${process.arch}`, quality, this.productService);
  130. + return createUpdateURL(this.productService, quality, process.platform, process.arch);
  131. }
  132. diff --git a/src/vs/platform/update/electron-main/updateService.win32.ts b/src/vs/platform/update/electron-main/updateService.win32.ts
  133. index db92de2..2bbdad9 100644
  134. --- a/src/vs/platform/update/electron-main/updateService.win32.ts
  135. +++ b/src/vs/platform/update/electron-main/updateService.win32.ts
  136. @@ -11,3 +11,2 @@ import { CancellationToken } from '../../../base/common/cancellation.js';
  137. import { memoize } from '../../../base/common/decorators.js';
  138. -import { hash } from '../../../base/common/hash.js';
  139. import * as path from '../../../base/common/path.js';
  140. @@ -25,4 +24,5 @@ import { asJson, IRequestService } from '../../request/common/request.js';
  141. import { ITelemetryService } from '../../telemetry/common/telemetry.js';
  142. -import { AvailableForDownload, DisablementReason, IUpdate, State, StateType, UpdateType } from '../common/update.js';
  143. -import { AbstractUpdateService, createUpdateURL, UpdateErrorClassification } from './abstractUpdateService.js';
  144. +import { AvailableForDownload, DisablementReason, IUpdate, State, StateType, Target, UpdateType } from '../common/update.js';
  145. +import { AbstractUpdateService, createUpdateURL} from './abstractUpdateService.js';
  146. +import * as semver from 'semver';
  147. @@ -42,5 +42,9 @@ function getUpdateType(): UpdateType {
  148. if (typeof _updateType === 'undefined') {
  149. - _updateType = fs.existsSync(path.join(path.dirname(process.execPath), 'unins000.exe'))
  150. - ? UpdateType.Setup
  151. - : UpdateType.Archive;
  152. + if (fs.existsSync(path.join(path.dirname(process.execPath), 'unins000.exe'))) {
  153. + _updateType = UpdateType.Setup;
  154. + } else if (path.basename(path.normalize(path.join(process.execPath, '..', '..'))) === 'Program Files') {
  155. + _updateType = UpdateType.WindowsInstaller;
  156. + } else {
  157. + _updateType = UpdateType.Archive;
  158. + }
  159. }
  160. @@ -63,2 +67,3 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  161. @IConfigurationService configurationService: IConfigurationService,
  162. + // @ts-expect-error
  163. @ITelemetryService private readonly telemetryService: ITelemetryService,
  164. @@ -102,11 +107,21 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  165. protected buildUpdateFeedUrl(quality: string): string | undefined {
  166. - let platform = `win32-${process.arch}`;
  167. -
  168. - if (getUpdateType() === UpdateType.Archive) {
  169. - platform += '-archive';
  170. - } else if (this.productService.target === 'user') {
  171. - platform += '-user';
  172. + let target: Target;
  173. +
  174. + switch (getUpdateType()) {
  175. + case UpdateType.Archive:
  176. + target = "archive"
  177. + break;
  178. + case UpdateType.WindowsInstaller:
  179. + target = "msi"
  180. + break;
  181. + default:
  182. + if (this.productService.target === 'user') {
  183. + target = "user"
  184. + }
  185. + else {
  186. + target = "system"
  187. + }
  188. }
  189. - return createUpdateURL(platform, quality, this.productService);
  190. + return createUpdateURL(this.productService, quality, process.platform, process.arch, target);
  191. }
  192. @@ -130,2 +145,10 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  193. + const fetchedVersion = /\d+\.\d+\.\d+\.\d+/.test(update.productVersion) ? update.productVersion.replace(/(\d+\.\d+\.\d+)\.\d+(\-\w+)?/, '$1$2') : update.productVersion.replace(/(\d+\.\d+\.)0+(\d+)(\-\w+)?/, '$1$2$3')
  194. + const currentVersion = this.productService.version.replace(/(\d+\.\d+\.)0+(\d+)(\-\w+)?/, '$1$2$3')
  195. +
  196. + if(semver.compareBuild(currentVersion, fetchedVersion) >= 0) {
  197. + this.setState(State.Idle(updateType));
  198. + return Promise.resolve(null);
  199. + }
  200. +
  201. if (updateType === UpdateType.Archive) {
  202. @@ -156,3 +179,3 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  203. - const fastUpdatesEnabled = this.configurationService.getValue('update.enableWindowsBackgroundUpdates');
  204. + const fastUpdatesEnabled = getUpdateType() == UpdateType.Setup && this.configurationService.getValue('update.enableWindowsBackgroundUpdates');
  205. if (fastUpdatesEnabled) {
  206. @@ -168,3 +191,2 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  207. .then(undefined, err => {
  208. - this.telemetryService.publicLog2<{ messageHash: string }, UpdateErrorClassification>('update:error', { messageHash: String(hash(String(err))) });
  209. this.logService.error(err);
  210. @@ -252,6 +274,14 @@ export class Win32UpdateService extends AbstractUpdateService implements IRelaun
  211. } else {
  212. - spawn(this.availableUpdate.packagePath, ['/silent', '/log', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
  213. - detached: true,
  214. - stdio: ['ignore', 'ignore', 'ignore']
  215. - });
  216. + const type = getUpdateType();
  217. + if (type == UpdateType.WindowsInstaller) {
  218. + spawn('msiexec.exe', ['/i', this.availableUpdate.packagePath], {
  219. + detached: true,
  220. + stdio: ['ignore', 'ignore', 'ignore']
  221. + });
  222. + } else {
  223. + spawn(this.availableUpdate.packagePath, ['/silent', '/log', '/mergetasks=runcode,!desktopicon,!quicklaunchicon'], {
  224. + detached: true,
  225. + stdio: ['ignore', 'ignore', 'ignore']
  226. + });
  227. + }
  228. }