Skip to content

Commit fb63c0c

Browse files
committed
vscode: Show notification when upgrade is available
And link to the release notes.
1 parent bb26d2e commit fb63c0c

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
@@ -769,10 +769,10 @@ index 096b9e23493539c9937940a56e555d95bbae38d9..ef37e614004f550f7b64eacd362f6894
769769
remove(key: string, scope: StorageScope): void {
770770
diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts
771771
new file mode 100644
772-
index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee93765d71601
772+
index 0000000000000000000000000000000000000000..667ca961830feaf6fc5e5bb7ef2df3b8be97b176
773773
--- /dev/null
774774
+++ b/src/vs/server/browser/client.ts
775-
@@ -0,0 +1,189 @@
775+
@@ -0,0 +1,237 @@
776776
+import { Emitter } from 'vs/base/common/event';
777777
+import { URI } from 'vs/base/common/uri';
778778
+import { localize } from 'vs/nls';
@@ -791,6 +791,7 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
791791
+import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
792792
+import { Options } from 'vs/server/ipc.d';
793793
+import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
794+
+import { ILogService } from 'vs/platform/log/common/log';
794795
+
795796
+class TelemetryService extends TelemetryChannelClient {
796797
+ public constructor(
@@ -922,8 +923,55 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
922923
+ });
923924
+ }
924925
+
926+
+ const logService = (services.get(ILogService) as ILogService);
927+
+ const storageService = (services.get(IStorageService) as IStorageService)
928+
+ const getUpdate = async (): Promise<void> => {
929+
+ logService.debug("Checking for update...");
930+
+
931+
+ const response = await fetch("update/check", {
932+
+ headers: { "Accept": "application/json" },
933+
+ });
934+
+ if (!response.ok) {
935+
+ throw new Error(response.statusText);
936+
+ }
937+
+ const json = await response.json();
938+
+ if (json.error) {
939+
+ throw new Error(json.error);
940+
+ }
941+
+ if (json.isLatest) {
942+
+ return;
943+
+ }
944+
+
945+
+ const lastNoti = storageService.getNumber("csLastUpdateNotification", StorageScope.GLOBAL);
946+
+ if (lastNoti) {
947+
+ // Only remind them again after two days.
948+
+ const timeout = 1000*60*24*2
949+
+ const threshold = lastNoti + timeout;
950+
+ if (Date.now() < threshold) {
951+
+ return;
952+
+ }
953+
+ }
954+
+
955+
+ storageService.store("csLastUpdateNotification", Date.now(), StorageScope.GLOBAL);
956+
+ (services.get(INotificationService) as INotificationService).notify({
957+
+ severity: Severity.Info,
958+
+ message: `[code-server v${json.latest}](https://github.com/cdr/code-server/releases/tag/v${json.latest}) has been released!`,
959+
+ });
960+
+ };
961+
+
962+
+ const updateLoop = (): void => {
963+
+ getUpdate().catch((error) => {
964+
+ logService.debug(`failed to check for update: ${error}`);
965+
+ }).finally(() => {
966+
+ // Check again every 6 hours.
967+
+ setTimeout(updateLoop, 1000*60*6);
968+
+ });
969+
+ };
970+
+
971+
+ updateLoop();
972+
+
925973
+ // This will be used to set the background color while VS Code loads.
926-
+ const theme = (services.get(IStorageService) as IStorageService).get("colorThemeData", StorageScope.GLOBAL);
974+
+ const theme = storageService.get("colorThemeData", StorageScope.GLOBAL);
927975
+ if (theme) {
928976
+ localStorage.setItem("colorThemeData", theme);
929977
+ }

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)