2022-03-23 04:07:14 +08:00
|
|
|
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
|
2022-04-01 05:14:03 +08:00
|
|
|
@@ -298,6 +298,10 @@ export class WebClientServer {
|
2022-03-23 04:07:14 +08:00
|
|
|
proxyEndpointTemplate: base + '/proxy/{{port}}',
|
2022-04-01 05:14:03 +08:00
|
|
|
codeServerVersion: this._productService.codeServerVersion,
|
2022-03-31 07:33:58 +08:00
|
|
|
embedderIdentifier: 'server-distro',
|
2022-03-23 04:07:14 +08:00
|
|
|
+ serviceWorker: {
|
|
|
|
+ scope: vscodeBase + '/',
|
|
|
|
+ path: base + '/_static/out/browser/serviceWorker.js',
|
|
|
|
+ },
|
|
|
|
extensionsGallery: {
|
|
|
|
...this._productService.extensionsGallery,
|
|
|
|
'resourceUrlTemplate': this._webExtensionResourceUrlTemplate ? this._webExtensionResourceUrlTemplate.with({
|
|
|
|
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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
}
|