| 
 | 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 | +@@ -30,6 +30,11 @@ export interface IBrowserWorkbenchEnviro  | 
 | 32 | + 	 * Options used to configure the workbench.  | 
 | 33 | + 	 */  | 
 | 34 | + 	readonly options?: IWorkbenchConstructionOptions;  | 
 | 35 | ++  | 
 | 36 | ++	/**  | 
 | 37 | ++	 * Enable downloading files via menu actions.  | 
 | 38 | ++	 */  | 
 | 39 | ++	readonly isEnabledFileDownloads?: boolean;  | 
 | 40 | + }  | 
 | 41 | +   | 
 | 42 | + export class BrowserWorkbenchEnvironmentService implements IBrowserWorkbenchEnvironmentService {  | 
 | 43 | +@@ -61,6 +66,13 @@ export class BrowserWorkbenchEnvironment  | 
 | 44 | + 		return this.options.userDataPath;  | 
 | 45 | + 	}  | 
 | 46 | +   | 
 | 47 | ++	get isEnabledFileDownloads(): boolean {  | 
 | 48 | ++		if (typeof this.options.isEnabledFileDownloads === "undefined") {  | 
 | 49 | ++			throw new Error('isEnabledFileDownloads was not provided to the browser');  | 
 | 50 | ++		}  | 
 | 51 | ++		return this.options.isEnabledFileDownloads;  | 
 | 52 | ++	}  | 
 | 53 | ++  | 
 | 54 | + 	@memoize  | 
 | 55 | + 	get settingsResource(): URI { return joinPath(this.userRoamingDataHome, 'settings.json'); }  | 
 | 56 | +   | 
 | 57 | +Index: code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts  | 
 | 58 | +===================================================================  | 
 | 59 | +--- code-server.orig/lib/vscode/src/vs/server/node/serverEnvironmentService.ts  | 
 | 60 | ++++ code-server/lib/vscode/src/vs/server/node/serverEnvironmentService.ts  | 
 | 61 | +@@ -15,6 +15,7 @@ export const serverOptions: OptionDescri  | 
 | 62 | + 	'disable-update-check': { type: 'boolean' },  | 
 | 63 | + 	'auth': { type: 'string' },  | 
 | 64 | + 	'locale': { type: 'string' },  | 
 | 65 | ++	'disable-file-downloads': { type: 'boolean' },  | 
 | 66 | +   | 
 | 67 | + 	/* ----- server setup ----- */  | 
 | 68 | +   | 
 | 69 | +@@ -92,6 +93,7 @@ export interface ServerParsedArgs {  | 
 | 70 | + 	'disable-update-check'?: boolean;  | 
 | 71 | + 	'auth'?: string  | 
 | 72 | + 	'locale'?: string  | 
 | 73 | ++	'disable-file-downloads'?: boolean;  | 
 | 74 | +   | 
 | 75 | + 	/* ----- server setup ----- */  | 
 | 76 | +   | 
 | 77 | +Index: code-server/lib/vscode/src/vs/server/node/webClientServer.ts  | 
 | 78 | +===================================================================  | 
 | 79 | +--- code-server.orig/lib/vscode/src/vs/server/node/webClientServer.ts  | 
 | 80 | ++++ code-server/lib/vscode/src/vs/server/node/webClientServer.ts  | 
 | 81 | +@@ -290,6 +290,7 @@ export class WebClientServer {  | 
 | 82 | + 					logLevel: this._logService.getLevel(),  | 
 | 83 | + 				},  | 
 | 84 | + 				userDataPath: this._environmentService.userDataPath,  | 
 | 85 | ++				isEnabledFileDownloads: !this._environmentService.args['disable-file-downloads'],  | 
 | 86 | + 				settingsSyncOptions: !this._environmentService.isBuilt && this._environmentService.args['enable-sync'] ? { enabled: true } : undefined,  | 
 | 87 | + 				productConfiguration: <Partial<IProductConfiguration>>{  | 
 | 88 | + 					rootEndpoint: base,  | 
 | 89 | +Index: code-server/lib/vscode/src/vs/workbench/browser/contextkeys.ts  | 
 | 90 | +===================================================================  | 
 | 91 | +--- code-server.orig/lib/vscode/src/vs/workbench/browser/contextkeys.ts  | 
 | 92 | ++++ code-server/lib/vscode/src/vs/workbench/browser/contextkeys.ts  | 
 | 93 | +@@ -7,12 +7,11 @@ import { Event } from 'vs/base/common/ev  | 
 | 94 | + import { Disposable } from 'vs/base/common/lifecycle';  | 
 | 95 | + import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';  | 
 | 96 | + import { InputFocusedContext, IsMacContext, IsLinuxContext, IsWindowsContext, IsWebContext, IsMacNativeContext, IsDevelopmentContext, IsIOSContext } from 'vs/platform/contextkey/common/contextkeys';  | 
 | 97 | +-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';  | 
 | 98 | ++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';  | 
 | 99 | + import { TEXT_DIFF_EDITOR_ID, EditorInputCapabilities, SIDE_BY_SIDE_EDITOR_ID, DEFAULT_EDITOR_ASSOCIATION } from 'vs/workbench/common/editor';  | 
 | 100 | + import { trackFocus, addDisposableListener, EventType } from 'vs/base/browser/dom';  | 
 | 101 | + import { preferredSideBySideGroupDirection, GroupDirection, IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';  | 
 | 102 | + import { IConfigurationService } from 'vs/platform/configuration/common/configuration';  | 
 | 103 | +-import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';  | 
 | 104 | + import { IEditorService } from 'vs/workbench/services/editor/common/editorService';  | 
 | 105 | + import { WorkbenchState, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';  | 
 | 106 | + import { IWorkbenchLayoutService, Parts, positionToString } from 'vs/workbench/services/layout/browser/layoutService';  | 
 | 107 | +@@ -24,6 +23,7 @@ import { IEditorResolverService } from '  | 
 | 108 | + import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';  | 
 | 109 | + import { Schemas } from 'vs/base/common/network';  | 
 | 110 | + import { WebFileSystemAccess } from 'vs/platform/files/browser/webFileSystemAccess';  | 
 | 111 | ++import { IBrowserWorkbenchEnvironmentService } from '../services/environment/browser/environmentService';  | 
 | 112 | +   | 
 | 113 | + export class WorkbenchContextKeysHandler extends Disposable {  | 
 | 114 | + 	private inputFocusedContext: IContextKey<boolean>;  | 
 | 115 | +@@ -75,7 +75,7 @@ export class WorkbenchContextKeysHandler  | 
 | 116 | + 		@IContextKeyService private readonly contextKeyService: IContextKeyService,  | 
 | 117 | + 		@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,  | 
 | 118 | + 		@IConfigurationService private readonly configurationService: IConfigurationService,  | 
 | 119 | +-		@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,  | 
 | 120 | ++		@IBrowserWorkbenchEnvironmentService private readonly environmentService: IBrowserWorkbenchEnvironmentService,  | 
 | 121 | + 		@IEditorService private readonly editorService: IEditorService,  | 
 | 122 | + 		@IEditorResolverService private readonly editorResolverService: IEditorResolverService,  | 
 | 123 | + 		@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,  | 
 | 124 | +@@ -194,6 +194,9 @@ export class WorkbenchContextKeysHandler  | 
 | 125 | + 		this.auxiliaryBarVisibleContext = AuxiliaryBarVisibleContext.bindTo(this.contextKeyService);  | 
 | 126 | + 		this.auxiliaryBarVisibleContext.set(this.layoutService.isVisible(Parts.AUXILIARYBAR_PART));  | 
 | 127 | +   | 
 | 128 | ++		// code-server  | 
 | 129 | ++		IsEnabledFileDownloads.bindTo(this.contextKeyService).set(this.environmentService.isEnabledFileDownloads ?? true)  | 
 | 130 | ++  | 
 | 131 | + 		this.registerListeners();  | 
 | 132 | + 	}  | 
 | 133 | +   | 
 | 134 | +Index: code-server/lib/vscode/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts  | 
 | 135 | +===================================================================  | 
 | 136 | +--- code-server.orig/lib/vscode/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts  | 
 | 137 | ++++ code-server/lib/vscode/src/vs/workbench/contrib/files/browser/fileActions.contribution.ts  | 
 | 138 | +@@ -21,7 +21,7 @@ import { CLOSE_SAVED_EDITORS_COMMAND_ID,  | 
 | 139 | + import { AutoSaveAfterShortDelayContext } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';  | 
 | 140 | + import { WorkbenchListDoubleSelection } from 'vs/platform/list/browser/listService';  | 
 | 141 | + import { Schemas } from 'vs/base/common/network';  | 
 | 142 | +-import { DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, WorkbenchStateContext, WorkspaceFolderCountContext, SidebarFocusContext, ActiveEditorCanRevertContext, ActiveEditorContext, ResourceContextKey } from 'vs/workbench/common/contextkeys';  | 
 | 143 | ++import { DirtyWorkingCopiesContext, EmptyWorkspaceSupportContext, EnterMultiRootWorkspaceSupportContext, HasWebFileSystemAccess, WorkbenchStateContext, WorkspaceFolderCountContext, SidebarFocusContext, ActiveEditorCanRevertContext, ActiveEditorContext, ResourceContextKey, IsEnabledFileDownloads } from 'vs/workbench/common/contextkeys';  | 
 | 144 | + import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';  | 
 | 145 | + import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';  | 
 | 146 | + import { ThemeIcon } from 'vs/platform/theme/common/themeService';  | 
 | 147 | +@@ -475,13 +475,16 @@ MenuRegistry.appendMenuItem(MenuId.Explo  | 
 | 148 | + 		id: DOWNLOAD_COMMAND_ID,  | 
 | 149 | + 		title: DOWNLOAD_LABEL  | 
 | 150 | + 	},  | 
 | 151 | +-	when: ContextKeyExpr.or(  | 
 | 152 | +-		// native: for any remote resource  | 
 | 153 | +-		ContextKeyExpr.and(IsWebContext.toNegated(), ResourceContextKey.Scheme.notEqualsTo(Schemas.file)),  | 
 | 154 | +-		// web: for any files  | 
 | 155 | +-		ContextKeyExpr.and(IsWebContext, ExplorerFolderContext.toNegated(), ExplorerRootContext.toNegated()),  | 
 | 156 | +-		// web: for any folders if file system API support is provided  | 
 | 157 | +-		ContextKeyExpr.and(IsWebContext, HasWebFileSystemAccess)  | 
 | 158 | ++	when: ContextKeyExpr.and(  | 
 | 159 | ++		IsEnabledFileDownloads,  | 
 | 160 | ++		ContextKeyExpr.or(  | 
 | 161 | ++			// native: for any remote resource  | 
 | 162 | ++			ContextKeyExpr.and(IsWebContext.toNegated(), ResourceContextKey.Scheme.notEqualsTo(Schemas.file)),  | 
 | 163 | ++			// web: for any files  | 
 | 164 | ++			ContextKeyExpr.and(IsWebContext, ExplorerFolderContext.toNegated(), ExplorerRootContext.toNegated()),  | 
 | 165 | ++			// web: for any folders if file system API support is provided  | 
 | 166 | ++			ContextKeyExpr.and(IsWebContext, HasWebFileSystemAccess)  | 
 | 167 | ++		)  | 
 | 168 | + 	)  | 
 | 169 | + }));  | 
 | 170 | +   | 
 | 171 | +Index: code-server/lib/vscode/src/vs/workbench/common/contextkeys.ts  | 
 | 172 | +===================================================================  | 
 | 173 | +--- code-server.orig/lib/vscode/src/vs/workbench/common/contextkeys.ts  | 
 | 174 | ++++ code-server/lib/vscode/src/vs/workbench/common/contextkeys.ts  | 
 | 175 | +@@ -30,6 +30,8 @@ export const IsFullscreenContext = new R  | 
 | 176 | +   | 
 | 177 | + export const HasWebFileSystemAccess = new RawContextKey<boolean>('hasWebFileSystemAccess', false, true); // Support for FileSystemAccess web APIs (https://wicg.github.io/file-system-access)  | 
 | 178 | +   | 
 | 179 | ++export const IsEnabledFileDownloads = new RawContextKey<boolean>('isEnabledFileDownloads', true, true);  | 
 | 180 | ++  | 
 | 181 | + //#endregion  | 
 | 182 | +   | 
 | 183 | +   | 
0 commit comments