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
|
2023-04-11 02:28:13 +08:00
|
|
|
@@ -60,6 +60,10 @@ export interface IProductConfiguration {
|
2022-03-23 04:07:14 +08:00
|
|
|
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/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
|
2022-09-16 05:49:28 +08:00
|
|
|
@@ -89,6 +89,10 @@ export class CodeServerClient extends Di
|
2022-03-23 04:07:14 +08:00
|
|
|
if (this.productService.logoutEndpoint) {
|
|
|
|
this.addLogoutCommand(this.productService.logoutEndpoint);
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ if (this.productService.serviceWorker) {
|
|
|
|
+ await this.registerServiceWorker(this.productService.serviceWorker);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
private checkUpdates(updateEndpoint: string) {
|
2022-09-16 05:49:28 +08:00
|
|
|
@@ -161,4 +165,17 @@ export class CodeServerClient extends Di
|
2022-03-23 04:07:14 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
}
|
2022-10-15 00:08:58 +08:00
|
|
|
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
|
2023-05-16 07:44:03 +08:00
|
|
|
@@ -306,6 +306,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: process.env.VSCODE_PROXY_URI ?? base + '/proxy/{{port}}/',
|
|
|
|
+ serviceWorker: {
|
|
|
|
+ scope: vscodeBase + '/',
|
|
|
|
+ path: base + '/_static/out/browser/serviceWorker.js',
|
|
|
|
+ },
|
|
|
|
embedderIdentifier: 'server-distro',
|
|
|
|
extensionsGallery: this._productService.extensionsGallery,
|
|
|
|
};
|