Skip to content

Commit 83c3524

Browse files
committed
vscode: Show a notification when out of date with a link to the release notes
1 parent 96170de commit 83c3524

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

ci/dev/vscode.patch

+51-3
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,10 @@ index 096b9e23493539c9937940a56e555d95bbae38d9..ef37e614004f550f7b64eacd362f6894
744744
remove(key: string, scope: StorageScope): void {
745745
diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts
746746
new file mode 100644
747-
index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee93765d71601
747+
index 0000000000000000000000000000000000000000..667ca961830feaf6fc5e5bb7ef2df3b8be97b176
748748
--- /dev/null
749749
+++ b/src/vs/server/browser/client.ts
750-
@@ -0,0 +1,189 @@
750+
@@ -0,0 +1,237 @@
751751
+import { Emitter } from 'vs/base/common/event';
752752
+import { URI } from 'vs/base/common/uri';
753753
+import { localize } from 'vs/nls';
@@ -766,6 +766,7 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
766766
+import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
767767
+import { Options } from 'vs/server/ipc.d';
768768
+import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
769+
+import { ILogService } from 'vs/platform/log/common/log';
769770
+
770771
+class TelemetryService extends TelemetryChannelClient {
771772
+ public constructor(
@@ -897,8 +898,55 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
897898
+ });
898899
+ }
899900
+
901+
+ const logService = (services.get(ILogService) as ILogService);
902+
+ const storageService = (services.get(IStorageService) as IStorageService)
903+
+ const getUpdate = async (): Promise<void> => {
904+
+ logService.debug("Checking for update...");
905+
+
906+
+ const response = await fetch("update/check", {
907+
+ headers: { "Accept": "application/json" },
908+
+ });
909+
+ if (!response.ok) {
910+
+ throw new Error(response.statusText);
911+
+ }
912+
+ const json = await response.json();
913+
+ if (json.error) {
914+
+ throw new Error(json.error);
915+
+ }
916+
+ if (json.isLatest) {
917+
+ return;
918+
+ }
919+
+
920+
+ const lastNoti = storageService.getNumber("csLastUpdateNotification", StorageScope.GLOBAL);
921+
+ if (lastNoti) {
922+
+ // Only remind them again after two days.
923+
+ const timeout = 1000*60*24*2
924+
+ const threshold = lastNoti + timeout;
925+
+ if (Date.now() < threshold) {
926+
+ return;
927+
+ }
928+
+ }
929+
+
930+
+ storageService.store("csLastUpdateNotification", Date.now(), StorageScope.GLOBAL);
931+
+ (services.get(INotificationService) as INotificationService).notify({
932+
+ severity: Severity.Info,
933+
+ message: `[code-server v${json.latest}](https://github.com/cdr/code-server/releases/tag/v${json.latest}) has been released!`,
934+
+ });
935+
+ };
936+
+
937+
+ const updateLoop = (): void => {
938+
+ getUpdate().catch((error) => {
939+
+ logService.debug(`failed to check for update: ${error}`);
940+
+ }).finally(() => {
941+
+ // Check again every 6 hours.
942+
+ setTimeout(updateLoop, 1000*60*6);
943+
+ });
944+
+ };
945+
+
946+
+ updateLoop();
947+
+
900948
+ // This will be used to set the background color while VS Code loads.
901-
+ const theme = (services.get(IStorageService) as IStorageService).get("colorThemeData", StorageScope.GLOBAL);
949+
+ const theme = storageService.get("colorThemeData", StorageScope.GLOBAL);
902950
+ if (theme) {
903951
+ localStorage.setItem("colorThemeData", theme);
904952
+ }

src/node/routes/update.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const router = Router()
77

88
const provider = new UpdateProvider()
99

10-
router.get("/", ensureAuthenticated, async (req, res) => {
10+
router.get("/check", ensureAuthenticated, async (req, res) => {
1111
const update = await provider.getUpdate(req.query.force === "true")
1212
res.json({
1313
checked: update.checked,

0 commit comments

Comments
 (0)