|
| 1 | +Add option to disable file downloads via CLI |
| 2 | + |
| 3 | +This patch adds support for a new CLI flag called `--disable-file-downloads` |
| 4 | +which allows a user to remove the "Download..." option that shows up when you |
| 5 | +right-click files in Code. The default value for this is `false`. |
| 6 | + |
| 7 | +To test this, start code-server with `--disable-file-downloads`, open editor, |
| 8 | +right-click on a file (not a folder) and you should **not** see the |
| 9 | +"Download..." option. |
| 10 | + |
| 11 | +Index: code-server/lib/vscode/src/vs/workbench/browser/web.api.ts |
| 12 | +=================================================================== |
| 13 | +--- code-server.orig/lib/vscode/src/vs/workbench/browser/web.api.ts |
| 14 | ++++ code-server/lib/vscode/src/vs/workbench/browser/web.api.ts |
| 15 | +@@ -210,6 +210,11 @@ export interface IWorkbenchConstructionO |
| 16 | + */ |
| 17 | + readonly userDataPath?: string |
| 18 | + |
| 19 | ++ /** |
| 20 | ++ * Whether the "Download..." option is enabled for files. |
| 21 | ++ */ |
| 22 | ++ readonly isEnabledFileDownloads?: boolean |
| 23 | ++ |
| 24 | + //#endregion |
| 25 | + |
| 26 | + |
| 27 | +Index: code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts |
| 28 | +=================================================================== |
| 29 | +--- code-server.orig/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts |
| 30 | ++++ code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts |
| 31 | +@@ -61,6 +61,13 @@ export class BrowserWorkbenchEnvironment |
| 32 | + return this.options.userDataPath; |
| 33 | + } |
| 34 | + |
| 35 | ++ get isEnabledFileDownloads(): boolean { |
| 36 | ++ if (typeof this.options.isEnabledFileDownloads === "undefined") { |
| 37 | ++ throw new Error('isEnabledFileDownloads was not provided to the browser'); |
| 38 | ++ } |
| 39 | ++ return this.options.isEnabledFileDownloads; |
| 40 | ++ } |
| 41 | ++ |
| 42 | + @memoize |
| 43 | + get settingsResource(): URI { return joinPath(this.userRoamingDataHome, 'settings.json'); } |
| 44 | + |
| 45 | +Index: code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts |
| 46 | +=================================================================== |
| 47 | +--- code-server.orig/lib/vscode/src/vs/server/node/serverEnvironmentService.ts |
| 48 | ++++ code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts |
| 49 | +@@ -15,6 +15,7 @@ export const serverOptions: OptionDescri |
| 50 | + 'disable-update-check': { type: 'boolean' }, |
| 51 | + 'auth': { type: 'string' }, |
| 52 | + 'locale': { type: 'string' }, |
| 53 | ++ 'disable-file-downloads': { type: 'boolean' }, |
| 54 | + |
| 55 | + /* ----- server setup ----- */ |
| 56 | + |
| 57 | +@@ -92,6 +93,7 @@ export interface ServerParsedArgs { |
| 58 | + 'disable-update-check'?: boolean; |
| 59 | + 'auth'?: string |
| 60 | + 'locale'?: string |
| 61 | ++ 'disable-file-downloads'?: boolean; |
| 62 | + |
| 63 | + /* ----- server setup ----- */ |
| 64 | + |
| 65 | +Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts |
| 66 | +=================================================================== |
| 67 | +--- code-server.orig/lib/vscode/src/vs/server/node/webClientServer.ts |
| 68 | ++++ code-server/lib/vscode/src/vs/server/node/webClientServer.ts |
| 69 | +@@ -290,6 +290,7 @@ export class WebClientServer { |
| 70 | + logLevel: this._logService.getLevel(), |
| 71 | + }, |
| 72 | + userDataPath: this._environmentService.userDataPath, |
| 73 | ++ isEnabledFileDownloads: this._environmentService.args['disable-file-downloads'], |
| 74 | + settingsSyncOptions: !this._environmentService.isBuilt && this._environmentService.args['enable-sync'] ? { enabled: true } : undefined, |
| 75 | + productConfiguration: <Partial<IProductConfiguration>>{ |
| 76 | + rootEndpoint: base, |
| 77 | +Index: code-server/lib/vscode/src/vs/workbench/browser/contextkeys.ts |
| 78 | +=================================================================== |
| 79 | +--- code-server.orig/lib/vscode/src/vs/workbench/browser/contextkeys.ts |
| 80 | ++++ code-server/lib/vscode/src/vs/workbench/browser/contextkeys.ts |
| 81 | +@@ -7,7 +7,7 @@ import { Event } from 'vs/base/common/ev |
| 82 | + import { Disposable } from 'vs/base/common/lifecycle'; |
| 83 | + import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; |
| 84 | + import { InputFocusedContext, IsMacContext, IsLinuxContext, IsWindowsContext, IsWebContext, IsMacNativeContext, IsDevelopmentContext, IsIOSContext } from 'vs/platform/contextkey/common/contextkeys'; |
| 85 | +-import { SplitEditorsVertically, InEditorZenModeContext, ActiveEditorCanRevertContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, EditorTabsVisibleContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorReadonlyContext, EditorAreaVisibleContext, ActiveEditorAvailableEditorIdsContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext } from 'vs/workbench/common/contextkeys'; |
| 86 | ++import { SplitEditorsVertically, InEditorZenModeContext, ActiveEditorCanRevertContext, ActiveEditorGroupLockedContext, ActiveEditorCanSplitInGroupContext, SideBySideEditorActiveContext, AuxiliaryBarVisibleContext, SideBarVisibleContext, PanelAlignmentContext, PanelMaximizedContext, PanelVisibleContext, ActiveEditorContext, EditorsVisibleContext, TextCompareEditorVisibleContext, TextCompareEditorActiveContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, EditorTabsVisibleContext, IsCenteredLayoutContext, ActiveEditorGroupIndexContext, ActiveEditorGroupLastContext, ActiveEditorReadonlyContext, EditorAreaVisibleContext, ActiveEditorAvailableEditorIdsContext, DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, IsFullscreenContext, OpenFolderWorkspaceSupportContext, RemoteNameContext, VirtualWorkspaceContext, WorkbenchStateContext, WorkspaceFolderCountContext, PanelPositionContext, IsEnabledFileDownloads } from 'vs/workbench/common/contextkeys'; |
| 87 | + import { TEXT_DIFF_EDITOR_ID, EditorInputCapabilities, SIDE_BY_SIDE_EDITOR_ID, DEFAULT_EDITOR_ASSOCIATION } from 'vs/workbench/common/editor'; |
| 88 | + import { trackFocus, addDisposableListener, EventType } from 'vs/base/browser/dom'; |
| 89 | + import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; |
| 90 | +@@ -194,6 +194,9 @@ export class WorkbenchContextKeysHandler |
| 91 | + this.auxiliaryBarVisibleContext = AuxiliaryBarVisibleContext.bindTo(this.contextKeyService); |
| 92 | + this.auxiliaryBarVisibleContext.set(this.layoutService.isVisible(Parts.AUXILIARYBAR_PART)); |
| 93 | + |
| 94 | ++ // code-server |
| 95 | ++ IsEnabledFileDownloads.bindTo(this.contextKeyService).set(this.environmentService.isEnabledFileDownloads) |
| 96 | ++ |
| 97 | + this.registerListeners(); |
| 98 | + } |
| 99 | + |
| 100 | +Index: code-server/lib/vscode/src/vs/workbench/services/environment/common/environmentService.ts |
| 101 | +=================================================================== |
| 102 | +--- code-server.orig/lib/vscode/src/vs/workbench/services/environment/common/environmentService.ts |
| 103 | ++++ code-server/lib/vscode/src/vs/workbench/services/environment/common/environmentService.ts |
| 104 | +@@ -44,6 +44,9 @@ export interface IWorkbenchEnvironmentSe |
| 105 | + readonly filesToOpenOrCreate?: IPath[] | undefined; |
| 106 | + readonly filesToDiff?: IPath[] | undefined; |
| 107 | + |
| 108 | ++ // --- code-server |
| 109 | ++ readonly isEnabledFileDownloads: boolean; |
| 110 | ++ |
| 111 | + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 112 | + // NOTE: KEEP THIS INTERFACE AS SMALL AS POSSIBLE. AS SUCH: |
| 113 | + // - PUT NON-WEB PROPERTIES INTO NATIVE WB ENV SERVICE |
0 commit comments