Skip to content

Commit bee0fe0

Browse files
committed
Add option to disable uploads, disable Show Local button when applicable and add trace logs for file read/write operations.
1 parent 0c98611 commit bee0fe0

File tree

8 files changed

+374
-38
lines changed

8 files changed

+374
-38
lines changed

patches/display-language.diff

+8-4
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
220220
import { CharCode } from 'vs/base/common/charCode';
221221
import { getRemoteServerRootPath } from 'vs/platform/remote/common/remoteHosts';
222222
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
223-
@@ -344,6 +345,8 @@ export class WebClientServer {
223+
@@ -345,6 +346,8 @@ export class WebClientServer {
224224
callbackRoute: this._callbackRoute
225225
};
226226

@@ -229,7 +229,7 @@ Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
229229
const nlsBaseUrl = this._productService.extensionsGallery?.nlsBaseUrl;
230230
const values: { [key: string]: string } = {
231231
WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration),
232-
@@ -352,6 +355,7 @@ export class WebClientServer {
232+
@@ -353,6 +356,7 @@ export class WebClientServer {
233233
WORKBENCH_NLS_BASE_URL: vscodeBase + (nlsBaseUrl ? `${nlsBaseUrl}${!nlsBaseUrl.endsWith('/') ? '/' : ''}${this._productService.commit}/${this._productService.version}/` : ''),
234234
BASE: base,
235235
VS_BASE: vscodeBase,
@@ -241,22 +241,26 @@ Index: code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
241241
===================================================================
242242
--- code-server.orig/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
243243
+++ code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
244-
@@ -17,6 +17,7 @@ export const serverOptions: OptionDescri
244+
@@ -17,8 +17,9 @@ export const serverOptions: OptionDescri
245245
'disable-update-check': { type: 'boolean' },
246246
'auth': { type: 'string' },
247247
'disable-file-downloads': { type: 'boolean' },
248+
'disable-file-uploads': { type: 'boolean' },
248249
+ 'locale': { type: 'string' },
249250

250251
/* ----- server setup ----- */
251252

252-
@@ -99,6 +100,7 @@ export interface ServerParsedArgs {
253+
'host': { type: 'string', cat: 'o', args: 'ip-address', description: nls.localize('host', "The host name or IP address the server should listen to. If not set, defaults to 'localhost'.") },
254+
@@ -100,8 +100,9 @@ export interface ServerParsedArgs {
253255
'disable-update-check'?: boolean;
254256
'auth'?: string
255257
'disable-file-downloads'?: boolean;
258+
'disable-file-uploads'?: boolean;
256259
+ 'locale'?: string
257260

258261
/* ----- server setup ----- */
259262

263+
host?: string;
260264
Index: code-server/lib/vscode/src/vs/workbench/workbench.web.main.ts
261265
===================================================================
262266
--- code-server.orig/lib/vscode/src/vs/workbench/workbench.web.main.ts

patches/disable-downloads.diff renamed to patches/external-file-actions.diff

+198-14
Large diffs are not rendered by default.

patches/getting-started.diff

+23-13
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ Index: code-server/lib/vscode/src/vs/workbench/browser/web.api.ts
135135
===================================================================
136136
--- code-server.orig/lib/vscode/src/vs/workbench/browser/web.api.ts
137137
+++ code-server/lib/vscode/src/vs/workbench/browser/web.api.ts
138-
@@ -286,6 +286,11 @@ export interface IWorkbenchConstructionO
138+
@@ -291,6 +291,11 @@ export interface IWorkbenchConstructionO
139139
*/
140-
readonly isEnabledFileDownloads?: boolean
140+
readonly isEnabledFileUploads?: boolean
141141

142142
+ /**
143143
+ * Whether to use Coder's custom Getting Started text.
@@ -151,8 +151,8 @@ Index: code-server/lib/vscode/src/vs/workbench/services/environment/browser/envi
151151
===================================================================
152152
--- code-server.orig/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
153153
+++ code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
154-
@@ -39,6 +39,11 @@ export interface IBrowserWorkbenchEnviro
155-
readonly isEnabledFileDownloads?: boolean;
154+
@@ -44,6 +44,11 @@ export interface IBrowserWorkbenchEnviro
155+
readonly isEnabledFileUploads?: boolean;
156156

157157
/**
158158
+ * Enable Coder's custom getting started text.
@@ -163,8 +163,8 @@ Index: code-server/lib/vscode/src/vs/workbench/services/environment/browser/envi
163163
* Gets whether a resolver extension is expected for the environment.
164164
*/
165165
readonly expectsResolverExtension: boolean;
166-
@@ -123,6 +128,13 @@ export class BrowserWorkbenchEnvironment
167-
return this.options.isEnabledFileDownloads;
166+
@@ -135,6 +140,13 @@ export class BrowserWorkbenchEnvironment
167+
return this.options.isEnabledFileUploads;
168168
}
169169

170170
+ get isEnabledCoderGettingStarted(): boolean {
@@ -181,34 +181,40 @@ Index: code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
181181
===================================================================
182182
--- code-server.orig/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
183183
+++ code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts
184-
@@ -18,6 +18,7 @@ export const serverOptions: OptionDescri
184+
@@ -18,8 +18,9 @@ export const serverOptions: OptionDescri
185185
'auth': { type: 'string' },
186186
'disable-file-downloads': { type: 'boolean' },
187+
'disable-file-uploads': { type: 'boolean' },
187188
'locale': { type: 'string' },
188189
+ 'disable-getting-started-override': { type: 'boolean' },
189190

190191
/* ----- server setup ----- */
191192

192-
@@ -101,6 +102,7 @@ export interface ServerParsedArgs {
193+
'host': { type: 'string', cat: 'o', args: 'ip-address', description: nls.localize('host', "The host name or IP address the server should listen to. If not set, defaults to 'localhost'.") },
194+
@@ -102,8 +103,9 @@ export interface ServerParsedArgs {
193195
'auth'?: string
194196
'disable-file-downloads'?: boolean;
197+
'disable-file-uploads'?: boolean;
195198
'locale'?: string
196199
+ 'disable-getting-started-override'?: boolean,
197200

198201
/* ----- server setup ----- */
199202

203+
host?: string;
200204
Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts
201205
===================================================================
202206
--- code-server.orig/lib/vscode/src/vs/server/node/webClientServer.ts
203207
+++ code-server/lib/vscode/src/vs/server/node/webClientServer.ts
204-
@@ -335,6 +335,7 @@ export class WebClientServer {
208+
@@ -335,8 +335,9 @@ export class WebClientServer {
205209
webviewEndpoint: vscodeBase + this._staticRoute + '/out/vs/workbench/contrib/webview/browser/pre',
206210
userDataPath: this._environmentService.userDataPath,
207211
isEnabledFileDownloads: !this._environmentService.args['disable-file-downloads'],
212+
isEnabledFileUploads: !this._environmentService.args['disable-file-uploads'],
208213
+ isEnabledCoderGettingStarted: !this._environmentService.args['disable-getting-started-override'],
209214
_wrapWebWorkerExtHostInIframe,
210215
developmentOptions: { enableSmokeTestDriver: this._environmentService.args['enable-smoke-test-driver'] ? true : undefined, logLevel: this._logService.getLevel() },
211216
settingsSyncOptions: !this._environmentService.isBuilt && this._environmentService.args['enable-sync'] ? { enabled: true } : undefined,
217+
enableWorkspaceTrust: !this._environmentService.args['disable-workspace-trust'],
212218
Index: code-server/lib/vscode/src/vs/workbench/browser/contextkeys.ts
213219
===================================================================
214220
--- code-server.orig/lib/vscode/src/vs/workbench/browser/contextkeys.ts
@@ -217,28 +223,32 @@ Index: code-server/lib/vscode/src/vs/workbench/browser/contextkeys.ts
217223
import { Disposable } from 'vs/base/common/lifecycle';
218224
import { IContextKeyService, IContextKey, setConstant as setConstantContextKey } from 'vs/platform/contextkey/common/contextkey';
219225
import { InputFocusedContext, IsMacContext, IsLinuxContext, IsWindowsContext, IsWebContext, IsMacNativeContext, IsDevelopmentContext, IsIOSContext, ProductQualityContext, IsMobileContext } from 'vs/platform/contextkey/common/contextkeys';
220-
-import { SplitEditorsVertically, InEditorZenModeContext, ActiveEditorCanRevertContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, EmbedderIdentifierContext, EditorTabsVisibleContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorReadonlyContext, EditorAreaVisibleContext, ActiveEditorAvailableEditorIdsContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, TemporaryWorkspaceContext, IsEnabledFileDownloads, ActiveEditorCanToggleReadonlyContext, applyAvailableEditorIds, MaximizedEditorGroupContext, TitleBarVisibleContext, TitleBarStyleContext } from 'vs/workbench/common/contextkeys';
221-
+import { SplitEditorsVertically, InEditorZenModeContext, ActiveEditorCanRevertContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, EmbedderIdentifierContext, EditorTabsVisibleContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorReadonlyContext, EditorAreaVisibleContext, ActiveEditorAvailableEditorIdsContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, TemporaryWorkspaceContext, IsEnabledFileDownloads, IsEnabledCoderGettingStarted, ActiveEditorCanToggleReadonlyContext, applyAvailableEditorIds, MaximizedEditorGroupContext, TitleBarVisibleContext, TitleBarStyleContext } from 'vs/workbench/common/contextkeys';
226+
-import { SplitEditorsVertically, InEditorZenModeContext, ActiveEditorCanRevertContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, EmbedderIdentifierContext, EditorTabsVisibleContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorReadonlyContext, EditorAreaVisibleContext, ActiveEditorAvailableEditorIdsContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, TemporaryWorkspaceContext, ActiveEditorCanToggleReadonlyContext, applyAvailableEditorIds ,MaximizedEditorGroupContext, TitleBarVisibleContext, TitleBarStyleContext, IsEnabledFileDownloads, IsEnabledFileUploads } from 'vs/workbench/common/contextkeys';
227+
+import { SplitEditorsVertically, InEditorZenModeContext, ActiveEditorCanRevertContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, EmbedderIdentifierContext, EditorTabsVisibleContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorReadonlyContext, EditorAreaVisibleContext, ActiveEditorAvailableEditorIdsContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, TemporaryWorkspaceContext, ActiveEditorCanToggleReadonlyContext, applyAvailableEditorIds, MaximizedEditorGroupContext, TitleBarVisibleContext, TitleBarStyleContext, IsEnabledFileDownloads, IsEnabledFileUploads, IsEnabledCoderGettingStarted, } from 'vs/workbench/common/contextkeys';
222228
import { TEXT_DIFF_EDITOR_ID, EditorInputCapabilities, SIDE_BY_SIDE_EDITOR_ID, EditorResourceAccessor, SideBySideEditor } from 'vs/workbench/common/editor';
223229
import { trackFocus, addDisposableListener, EventType, onDidRegisterWindow } from 'vs/base/browser/dom';
224230
import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
225-
@@ -221,6 +221,7 @@ export class WorkbenchContextKeysHandler
231+
@@ -221,8 +221,9 @@ export class WorkbenchContextKeysHandler
226232

227233
// code-server
228234
IsEnabledFileDownloads.bindTo(this.contextKeyService).set(this.environmentService.isEnabledFileDownloads ?? true)
235+
IsEnabledFileUploads.bindTo(this.contextKeyService).set(this.environmentService.isEnabledFileUploads ?? true)
229236
+ IsEnabledCoderGettingStarted.bindTo(this.contextKeyService).set(this.environmentService.isEnabledCoderGettingStarted ?? true)
230237

231238
this.registerListeners();
232239
}
240+
233241
Index: code-server/lib/vscode/src/vs/workbench/common/contextkeys.ts
234242
===================================================================
235243
--- code-server.orig/lib/vscode/src/vs/workbench/common/contextkeys.ts
236244
+++ code-server/lib/vscode/src/vs/workbench/common/contextkeys.ts
237-
@@ -40,6 +40,7 @@ export const HasWebFileSystemAccess = ne
245+
@@ -40,8 +40,9 @@ export const HasWebFileSystemAccess = ne
238246
export const EmbedderIdentifierContext = new RawContextKey<string | undefined>('embedderIdentifier', undefined, localize('embedderIdentifier', 'The identifier of the embedder according to the product service, if one is defined'));
239247

240248
export const IsEnabledFileDownloads = new RawContextKey<boolean>('isEnabledFileDownloads', true, true);
249+
export const IsEnabledFileUploads = new RawContextKey<boolean>('isEnabledFileUploads', true, true);
241250
+export const IsEnabledCoderGettingStarted = new RawContextKey<boolean>('isEnabledCoderGettingStarted', true, true);
242251

243252
//#endregion
244253

254+

patches/series

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ unique-db.diff
1313
local-storage.diff
1414
service-worker.diff
1515
sourcemaps.diff
16-
disable-downloads.diff
16+
external-file-actions.diff
1717
telemetry.diff
1818
display-language.diff
1919
cli-window-open.diff

src/node/cli.ts

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface UserProvidedCodeArgs {
4848
"github-auth"?: string
4949
"disable-update-check"?: boolean
5050
"disable-file-downloads"?: boolean
51+
"disable-file-uploads"?: boolean
5152
"disable-workspace-trust"?: boolean
5253
"disable-getting-started-override"?: boolean
5354
"disable-proxy"?: boolean
@@ -170,6 +171,11 @@ export const options: Options<Required<UserProvidedArgs>> = {
170171
description:
171172
"Disable file downloads from Code. This can also be set with CS_DISABLE_FILE_DOWNLOADS set to 'true' or '1'.",
172173
},
174+
"disable-file-uploads": {
175+
type: "boolean",
176+
description:
177+
"Disable file uploads.",
178+
},
173179
"disable-workspace-trust": {
174180
type: "boolean",
175181
description: "Disable Workspace Trust feature. This switch only affects the current session.",

test/e2e/downloads.test.ts

+70-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,43 @@ describe("Downloads (enabled)", ["--disable-workspace-trust"], {}, async () => {
2323

2424
expect(await codeServerPage.page.isVisible("text=Download...")).toBe(true)
2525
})
26+
27+
test("should see the 'Show Local' button on Save As", async ({ codeServerPage }) => {
28+
// Setup
29+
const workspaceDir = await codeServerPage.workspaceDir
30+
const fileName = "unique-file-save-as.txt"
31+
const tmpFilePath = path.join(workspaceDir, fileName)
32+
await fs.writeFile(tmpFilePath, "Hello World")
33+
34+
// Action
35+
await codeServerPage.page.waitForSelector(`text=${fileName}`)
36+
37+
await codeServerPage.openFile(fileName)
38+
await codeServerPage.page.click(".tab")
39+
await codeServerPage.navigateMenus(["File", "Auto Save"])
40+
await codeServerPage.page.keyboard.type("Making some edits.")
41+
await codeServerPage.navigateMenus(["File", "Save As..."])
42+
await codeServerPage.page.waitForSelector(".quick-input-widget")
43+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
44+
})
45+
46+
test("should see the 'Show Local' button on Save File", async ({ codeServerPage }) => {
47+
48+
// Action
49+
await codeServerPage.navigateMenus(["File", "New Text File"])
50+
await codeServerPage.waitForTab("Untitled-1")
51+
await codeServerPage.navigateMenus(["File", "Save"])
52+
await codeServerPage.page.waitForSelector(".quick-input-widget")
53+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
54+
})
55+
56+
test("should see the 'Show Local' button on Save Workspace As", async ({ codeServerPage }) => {
57+
// Action
58+
await codeServerPage.navigateMenus(["File", "Save Workspace As..."])
59+
await codeServerPage.page.waitForSelector(".quick-input-widget")
60+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(true)
61+
})
62+
2663
})
2764

2865
describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-downloads"], {}, async () => {
@@ -35,7 +72,7 @@ describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-d
3572
// Setup
3673
const workspaceDir = await codeServerPage.workspaceDir
3774
const tmpFilePath = path.join(workspaceDir, "unique-file.txt")
38-
await fs.writeFile(tmpFilePath, "hello world")
75+
await fs.writeFile(tmpFilePath, "Hello World")
3976

4077
// Action
4178
const fileInExplorer = await codeServerPage.page.waitForSelector("text=unique-file.txt")
@@ -45,4 +82,36 @@ describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-d
4582

4683
expect(await codeServerPage.page.isVisible("text=Download...")).toBe(false)
4784
})
85+
86+
test("should not see the 'Show Local' button on Save as", async ({ codeServerPage }) => {
87+
// Setup
88+
const workspaceDir = await codeServerPage.workspaceDir
89+
const fileName = "unique-file-save-as.txt"
90+
const tmpFilePath = path.join(workspaceDir, fileName)
91+
await fs.writeFile(tmpFilePath, "Hello World")
92+
93+
// Action
94+
await codeServerPage.page.waitForSelector(`text=${fileName}`)
95+
await codeServerPage.openFile(fileName)
96+
await codeServerPage.page.click(".tab")
97+
await codeServerPage.navigateMenus(["File", "Save As..."])
98+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
99+
})
100+
101+
test("should not see the 'Show Local' button on Save File", async ({ codeServerPage }) => {
102+
// Action
103+
await codeServerPage.navigateMenus(["File", "New Text File"])
104+
await codeServerPage.waitForTab("Untitled-1")
105+
await codeServerPage.navigateMenus(["File", "Save"])
106+
await codeServerPage.page.waitForSelector(".quick-input-widget")
107+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
108+
})
109+
110+
test("should not see the 'Show Local' button on Save Workspace As", async ({ codeServerPage }) => {
111+
// Action
112+
await codeServerPage.navigateMenus(["File", "Save Workspace As..."])
113+
await codeServerPage.page.waitForSelector(".quick-input-widget")
114+
expect(await codeServerPage.page.isVisible("text=Show Local")).toBe(false)
115+
})
116+
48117
})

0 commit comments

Comments
 (0)