未验证 提交 a1537d71 编写于 作者: A Anmol Sethi 提交者: GitHub

Merge pull request #2358 from cdr/update-noti-45e1

vscode: Show notification when upgrade is available
...@@ -15,6 +15,10 @@ v$VERSION ...@@ -15,6 +15,10 @@ v$VERSION
VS Code v$(vscode_version) VS Code v$(vscode_version)
Upgrading is as easy as installing the new version over the old one. code-server
maintains all user data in \`~/.local/share/code-server\` so that it is preserved in between
installations.
## New Features ## New Features
- ⭐ Summarize new features here with references to issues - ⭐ Summarize new features here with references to issues
......
...@@ -769,10 +769,10 @@ index 096b9e23493539c9937940a56e555d95bbae38d9..ef37e614004f550f7b64eacd362f6894 ...@@ -769,10 +769,10 @@ index 096b9e23493539c9937940a56e555d95bbae38d9..ef37e614004f550f7b64eacd362f6894
remove(key: string, scope: StorageScope): void { remove(key: string, scope: StorageScope): void {
diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee93765d71601 index 0000000000000000000000000000000000000000..385b9da491d38a9f5d10fab6e4666c84a892f49d
--- /dev/null --- /dev/null
+++ b/src/vs/server/browser/client.ts +++ b/src/vs/server/browser/client.ts
@@ -0,0 +1,189 @@ @@ -0,0 +1,240 @@
+import { Emitter } from 'vs/base/common/event'; +import { Emitter } from 'vs/base/common/event';
+import { URI } from 'vs/base/common/uri'; +import { URI } from 'vs/base/common/uri';
+import { localize } from 'vs/nls'; +import { localize } from 'vs/nls';
...@@ -791,6 +791,8 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937 ...@@ -791,6 +791,8 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
+import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; +import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
+import { Options } from 'vs/server/ipc.d'; +import { Options } from 'vs/server/ipc.d';
+import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; +import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
+import { ILogService } from 'vs/platform/log/common/log';
+import * as path from 'vs/base/common/path';
+ +
+class TelemetryService extends TelemetryChannelClient { +class TelemetryService extends TelemetryChannelClient {
+ public constructor( + public constructor(
...@@ -922,8 +924,57 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937 ...@@ -922,8 +924,57 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
+ }); + });
+ } + }
+ +
+ const logService = (services.get(ILogService) as ILogService);
+ const storageService = (services.get(IStorageService) as IStorageService);
+ // We set this here first in case the path changes.
+ const updateCheckEndpoint = path.join(window.location.pathname, "/update/check")
+ const getUpdate = async (): Promise<void> => {
+ logService.debug("Checking for update...");
+
+ const response = await fetch(updateCheckEndpoint, {
+ 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. + // 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) { + if (theme) {
+ localStorage.setItem("colorThemeData", theme); + localStorage.setItem("colorThemeData", theme);
+ } + }
...@@ -3858,7 +3909,7 @@ index 738ce140c1af76ee0017c59cc883578e966f5348..80833b7023ed5795bb3de303b54ec08d ...@@ -3858,7 +3909,7 @@ index 738ce140c1af76ee0017c59cc883578e966f5348..80833b7023ed5795bb3de303b54ec08d
.monaco-workbench .part.editor > .content .welcomePage .splash ul { .monaco-workbench .part.editor > .content .welcomePage .splash ul {
diff --git a/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts b/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts diff --git a/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts b/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts
index 4a61a79fe447e2aa238af568791bff1e0cec4d29..791b63342f476f1baba9d31b040d3ef589e3f70a 100644 index 4a61a79fe447e2aa238af568791bff1e0cec4d29..69cc2e4331a3b04d05d79632920f5c5bbfa924e8 100644
--- a/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts --- a/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts
+++ b/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts +++ b/src/vs/workbench/contrib/welcome/page/browser/welcomePage.ts
@@ -328,7 +328,7 @@ class WelcomePage extends Disposable { @@ -328,7 +328,7 @@ class WelcomePage extends Disposable {
...@@ -3866,7 +3917,7 @@ index 4a61a79fe447e2aa238af568791bff1e0cec4d29..791b63342f476f1baba9d31b040d3ef5 ...@@ -3866,7 +3917,7 @@ index 4a61a79fe447e2aa238af568791bff1e0cec4d29..791b63342f476f1baba9d31b040d3ef5
const prodName = container.querySelector('.welcomePage .title .caption') as HTMLElement; const prodName = container.querySelector('.welcomePage .title .caption') as HTMLElement;
if (prodName) { if (prodName) {
- prodName.textContent = this.productService.nameLong; - prodName.textContent = this.productService.nameLong;
+ prodName.textContent = `code-server v${this.productService.codeServerVersion}` + prodName.textContent = `code-server v${this.productService.codeServerVersion}`;
} }
recentlyOpened.then(({ workspaces }) => { recentlyOpened.then(({ workspaces }) => {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
# Install # Install
- [Upgrading](#upgrading)
- [install.sh](#installsh) - [install.sh](#installsh)
- [Flags](#flags) - [Flags](#flags)
- [Detection Reference](#detection-reference) - [Detection Reference](#detection-reference)
...@@ -19,6 +20,12 @@ ...@@ -19,6 +20,12 @@
This document demonstrates how to install `code-server` on This document demonstrates how to install `code-server` on
various distros and operating systems. various distros and operating systems.
## Upgrading
When upgrading you can just install the new version over the old one. code-server
maintains all user data in `~/.local/share/code-server` so that it is preserved in between
installations.
## install.sh ## install.sh
We have a [script](../install.sh) to install code-server for Linux, macOS and FreeBSD. We have a [script](../install.sh) to install code-server for Linux, macOS and FreeBSD.
......
...@@ -7,7 +7,7 @@ export const router = Router() ...@@ -7,7 +7,7 @@ export const router = Router()
const provider = new UpdateProvider() 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") const update = await provider.getUpdate(req.query.force === "true")
res.json({ res.json({
checked: update.checked, checked: update.checked,
......
...@@ -75,7 +75,7 @@ export class UpdateProvider { ...@@ -75,7 +75,7 @@ export class UpdateProvider {
public isLatestVersion(latest: Update): boolean { public isLatestVersion(latest: Update): boolean {
logger.debug("comparing versions", field("current", version), field("latest", latest.version)) logger.debug("comparing versions", field("current", version), field("latest", latest.version))
try { try {
return latest.version === version || semver.lt(latest.version, version) return semver.lte(latest.version, version)
} catch (error) { } catch (error) {
return true return true
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册