Skip to content

Commit a1537d7

Browse files
authored
Merge pull request #2358 from cdr/update-noti-45e1
vscode: Show notification when upgrade is available
2 parents bb26d2e + def8124 commit a1537d7

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

ci/build/release-github-draft.sh

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ v$VERSION
1515
1616
VS Code v$(vscode_version)
1717
18+
Upgrading is as easy as installing the new version over the old one. code-server
19+
maintains all user data in \`~/.local/share/code-server\` so that it is preserved in between
20+
installations.
21+
1822
## New Features
1923
- ⭐ Summarize new features here with references to issues
2024

ci/dev/vscode.patch

+56-5
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..385b9da491d38a9f5d10fab6e4666c84a892f49d
773773
--- /dev/null
774774
+++ b/src/vs/server/browser/client.ts
775-
@@ -0,0 +1,189 @@
775+
@@ -0,0 +1,240 @@
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,8 @@ 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';
795+
+import * as path from 'vs/base/common/path';
794796
+
795797
+class TelemetryService extends TelemetryChannelClient {
796798
+ public constructor(
@@ -922,8 +924,57 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
922924
+ });
923925
+ }
924926
+
927+
+ const logService = (services.get(ILogService) as ILogService);
928+
+ const storageService = (services.get(IStorageService) as IStorageService);
929+
+ // We set this here first in case the path changes.
930+
+ const updateCheckEndpoint = path.join(window.location.pathname, "/update/check")
931+
+ const getUpdate = async (): Promise<void> => {
932+
+ logService.debug("Checking for update...");
933+
+
934+
+ const response = await fetch(updateCheckEndpoint, {
935+
+ headers: { "Accept": "application/json" },
936+
+ });
937+
+ if (!response.ok) {
938+
+ throw new Error(response.statusText);
939+
+ }
940+
+ const json = await response.json();
941+
+ if (json.error) {
942+
+ throw new Error(json.error);
943+
+ }
944+
+ if (json.isLatest) {
945+
+ return;
946+
+ }
947+
+
948+
+ const lastNoti = storageService.getNumber("csLastUpdateNotification", StorageScope.GLOBAL);
949+
+ if (lastNoti) {
950+
+ // Only remind them again after two days.
951+
+ const timeout = 1000*60*24*2;
952+
+ const threshold = lastNoti + timeout;
953+
+ if (Date.now() < threshold) {
954+
+ return;
955+
+ }
956+
+ }
957+
+
958+
+ storageService.store("csLastUpdateNotification", Date.now(), StorageScope.GLOBAL);
959+
+ (services.get(INotificationService) as INotificationService).notify({
960+
+ severity: Severity.Info,
961+
+ message: `[code-server v${json.latest}](https://github.com/cdr/code-server/releases/tag/v${json.latest}) has been released!`,
962+
+ });
963+
+ };
964+
+
965+
+ const updateLoop = (): void => {
966+
+ getUpdate().catch((error) => {
967+
+ logService.debug(`failed to check for update: ${error}`);
968+
+ }).finally(() => {
969+
+ // Check again every 6 hours.
970+
+ setTimeout(updateLoop, 1000*60*6);
971+
+ });
972+
+ };
973+
+
974+
+ updateLoop();
975+
+
925976
+ // 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);
977+
+ const theme = storageService.get("colorThemeData", StorageScope.GLOBAL);
927978
+ if (theme) {
928979
+ localStorage.setItem("colorThemeData", theme);
929980
+ }
@@ -3858,15 +3909,15 @@ index 738ce140c1af76ee0017c59cc883578e966f5348..80833b7023ed5795bb3de303b54ec08d
38583909

38593910
.monaco-workbench .part.editor > .content .welcomePage .splash ul {
38603911
diff --git a/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts b/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts
3861-
index 4a61a79fe447e2aa238af568791bff1e0cec4d29..791b63342f476f1baba9d31b040d3ef589e3f70a 100644
3912+
index 4a61a79fe447e2aa238af568791bff1e0cec4d29..69cc2e4331a3b04d05d79632920f5c5bbfa924e8 100644
38623913
--- a/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts
38633914
+++ b/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts
38643915
@@ -328,7 +328,7 @@ class WelcomePage extends Disposable {
38653916

38663917
const prodName = container.querySelector('.welcomePage .title .caption') as HTMLElement;
38673918
if (prodName) {
38683919
- prodName.textContent = this.productService.nameLong;
3869-
+ prodName.textContent = `code-server v${this.productService.codeServerVersion}`
3920+
+ prodName.textContent = `code-server v${this.productService.codeServerVersion}`;
38703921
}
38713922

38723923
recentlyOpened.then(({ workspaces }) => {

doc/install.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
33
# Install
44

5+
- [Upgrading](#upgrading)
56
- [install.sh](#installsh)
67
- [Flags](#flags)
78
- [Detection Reference](#detection-reference)
@@ -19,6 +20,12 @@
1920
This document demonstrates how to install `code-server` on
2021
various distros and operating systems.
2122

23+
## Upgrading
24+
25+
When upgrading you can just install the new version over the old one. code-server
26+
maintains all user data in `~/.local/share/code-server` so that it is preserved in between
27+
installations.
28+
2229
## install.sh
2330

2431
We have a [script](../install.sh) to install code-server for Linux, macOS and FreeBSD.

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,

src/node/update.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class UpdateProvider {
7575
public isLatestVersion(latest: Update): boolean {
7676
logger.debug("comparing versions", field("current", version), field("latest", latest.version))
7777
try {
78-
return latest.version === version || semver.lt(latest.version, version)
78+
return semver.lte(latest.version, version)
7979
} catch (error) {
8080
return true
8181
}

0 commit comments

Comments
 (0)