2bfe15b3e9
* Update upstream Code to 1.70 * Update CSP hashes * Update comment on remote authority Also remove it from script-src since it is invalid anyway. * Use absolute path for disable download patch Just to keep it consistent with the other imports. We initially added the patch like this so it was not part of the upgrade but might as well fix it now. * Fix inability to change language while code-server is running Co-authored-by: Asher <ash@coder.com>
68 lines
2.6 KiB
Diff
68 lines
2.6 KiB
Diff
Add a service worker
|
|
|
|
To test try installing code-server as a PWA.
|
|
|
|
Index: code-server/lib/vscode/src/vs/base/common/product.ts
|
|
===================================================================
|
|
--- code-server.orig/lib/vscode/src/vs/base/common/product.ts
|
|
+++ code-server/lib/vscode/src/vs/base/common/product.ts
|
|
@@ -36,6 +36,10 @@ export interface IProductConfiguration {
|
|
readonly updateEndpoint?: string
|
|
readonly logoutEndpoint?: string
|
|
readonly proxyEndpointTemplate?: string
|
|
+ readonly serviceWorker?: {
|
|
+ readonly path: string;
|
|
+ readonly scope: string;
|
|
+ }
|
|
|
|
readonly version: string;
|
|
readonly date?: string;
|
|
Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
|
|
===================================================================
|
|
--- code-server.orig/lib/vscode/src/vs/server/node/webClientServer.ts
|
|
+++ code-server/lib/vscode/src/vs/server/node/webClientServer.ts
|
|
@@ -319,6 +319,10 @@ export class WebClientServer {
|
|
updateEndpoint: !this._environmentService.args['disable-update-check'] ? base + '/update/check' : undefined,
|
|
logoutEndpoint: this._environmentService.args['auth'] && this._environmentService.args['auth'] !== "none" ? base + '/logout' : undefined,
|
|
proxyEndpointTemplate: base + '/proxy/{{port}}',
|
|
+ serviceWorker: {
|
|
+ scope: vscodeBase + '/',
|
|
+ path: base + '/_static/out/browser/serviceWorker.js',
|
|
+ },
|
|
embedderIdentifier: 'server-distro',
|
|
extensionsGallery: this._productService.extensionsGallery,
|
|
},
|
|
Index: code-server/lib/vscode/src/vs/workbench/browser/client.ts
|
|
===================================================================
|
|
--- code-server.orig/lib/vscode/src/vs/workbench/browser/client.ts
|
|
+++ code-server/lib/vscode/src/vs/workbench/browser/client.ts
|
|
@@ -90,6 +90,10 @@ export class CodeServerClient extends Di
|
|
if (this.productService.logoutEndpoint) {
|
|
this.addLogoutCommand(this.productService.logoutEndpoint);
|
|
}
|
|
+
|
|
+ if (this.productService.serviceWorker) {
|
|
+ await this.registerServiceWorker(this.productService.serviceWorker);
|
|
+ }
|
|
}
|
|
|
|
private checkUpdates(updateEndpoint: string) {
|
|
@@ -162,4 +166,17 @@ export class CodeServerClient extends Di
|
|
});
|
|
}
|
|
}
|
|
+
|
|
+ private async registerServiceWorker(serviceWorker: { path: string; scope: string }) {
|
|
+ if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) {
|
|
+ try {
|
|
+ await navigator.serviceWorker.register(serviceWorker.path, {
|
|
+ scope: serviceWorker.scope,
|
|
+ });
|
|
+ this.logService.info('[Service Worker] registered');
|
|
+ } catch (error: any) {
|
|
+ this.logService.error('[Service Worker] registration', error as Error);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
}
|