mirror of https://git.tuxpa.in/a/code-server.git
vscode: Show notification when upgrade is available
And link to the release notes.
This commit is contained in:
parent
bb26d2edd3
commit
fb63c0cd22
|
@ -769,10 +769,10 @@ index 096b9e23493539c9937940a56e555d95bbae38d9..ef37e614004f550f7b64eacd362f6894
|
|||
remove(key: string, scope: StorageScope): void {
|
||||
diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee93765d71601
|
||||
index 0000000000000000000000000000000000000000..667ca961830feaf6fc5e5bb7ef2df3b8be97b176
|
||||
--- /dev/null
|
||||
+++ b/src/vs/server/browser/client.ts
|
||||
@@ -0,0 +1,189 @@
|
||||
@@ -0,0 +1,237 @@
|
||||
+import { Emitter } from 'vs/base/common/event';
|
||||
+import { URI } from 'vs/base/common/uri';
|
||||
+import { localize } from 'vs/nls';
|
||||
|
@ -791,6 +791,7 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
|
|||
+import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
|
||||
+import { Options } from 'vs/server/ipc.d';
|
||||
+import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
+import { ILogService } from 'vs/platform/log/common/log';
|
||||
+
|
||||
+class TelemetryService extends TelemetryChannelClient {
|
||||
+ public constructor(
|
||||
|
@ -922,8 +923,55 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
|
|||
+ });
|
||||
+ }
|
||||
+
|
||||
+ const logService = (services.get(ILogService) as ILogService);
|
||||
+ const storageService = (services.get(IStorageService) as IStorageService)
|
||||
+ const getUpdate = async (): Promise<void> => {
|
||||
+ logService.debug("Checking for update...");
|
||||
+
|
||||
+ const response = await fetch("update/check", {
|
||||
+ headers: { "Accept": "application/json" },
|
||||
+ });
|
||||
+ if (!response.ok) {
|
||||
+ throw new Error(response.statusText);
|
||||
+ }
|
||||
+ const json = await response.json();
|
||||
+ if (json.error) {
|
||||
+ throw new Error(json.error);
|
||||
+ }
|
||||
+ if (json.isLatest) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ const lastNoti = storageService.getNumber("csLastUpdateNotification", StorageScope.GLOBAL);
|
||||
+ if (lastNoti) {
|
||||
+ // Only remind them again after two days.
|
||||
+ const timeout = 1000*60*24*2
|
||||
+ const threshold = lastNoti + timeout;
|
||||
+ if (Date.now() < threshold) {
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ storageService.store("csLastUpdateNotification", Date.now(), StorageScope.GLOBAL);
|
||||
+ (services.get(INotificationService) as INotificationService).notify({
|
||||
+ severity: Severity.Info,
|
||||
+ message: `[code-server v${json.latest}](https://github.com/cdr/code-server/releases/tag/v${json.latest}) has been released!`,
|
||||
+ });
|
||||
+ };
|
||||
+
|
||||
+ const updateLoop = (): void => {
|
||||
+ getUpdate().catch((error) => {
|
||||
+ logService.debug(`failed to check for update: ${error}`);
|
||||
+ }).finally(() => {
|
||||
+ // Check again every 6 hours.
|
||||
+ setTimeout(updateLoop, 1000*60*6);
|
||||
+ });
|
||||
+ };
|
||||
+
|
||||
+ updateLoop();
|
||||
+
|
||||
+ // This will be used to set the background color while VS Code loads.
|
||||
+ const theme = (services.get(IStorageService) as IStorageService).get("colorThemeData", StorageScope.GLOBAL);
|
||||
+ const theme = storageService.get("colorThemeData", StorageScope.GLOBAL);
|
||||
+ if (theme) {
|
||||
+ localStorage.setItem("colorThemeData", theme);
|
||||
+ }
|
||||
|
|
|
@ -7,7 +7,7 @@ export const router = Router()
|
|||
|
||||
const provider = new UpdateProvider()
|
||||
|
||||
router.get("/", ensureAuthenticated, async (req, res) => {
|
||||
router.get("/check", ensureAuthenticated, async (req, res) => {
|
||||
const update = await provider.getUpdate(req.query.force === "true")
|
||||
res.json({
|
||||
checked: update.checked,
|
||||
|
|
Loading…
Reference in New Issue