mirror of
https://github.com/danog/code-server.git
synced 2024-11-30 04:39:46 +01:00
5bc26e90cb
* Fix code-server version not appearing in other languages It needs to be separate from the localize call since the language version of that string is used and it will not include a spot for the code-server version. I also moved the "v" so we do not get "vUnknown". * Add code-server version to product configuration Before 1.64 the entire product configuration was sent to the client but that was removed so we have to add anything we want to use on the client, like the code-server version (used in the about dialog). Fixes #5027. * Refresh patches * Change version test to look for specific version This will catch if we are not sending the actual version to the client.
68 lines
2.5 KiB
Diff
68 lines
2.5 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
|
|
@@ -298,6 +298,10 @@ export class WebClientServer {
|
|
proxyEndpointTemplate: base + '/proxy/{{port}}',
|
|
codeServerVersion: this._productService.codeServerVersion,
|
|
embedderIdentifier: 'server-distro',
|
|
+ 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);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
}
|