mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-02 08:15:56 +01:00
Browser: support hard reload (#298840)
This commit is contained in:
@@ -204,8 +204,9 @@ export interface IBrowserViewService {
|
||||
/**
|
||||
* Reload the current page
|
||||
* @param id The browser view identifier
|
||||
* @param hard Whether to do a hard reload (bypassing cache)
|
||||
*/
|
||||
reload(id: string): Promise<void>;
|
||||
reload(id: string, hard?: boolean): Promise<void>;
|
||||
|
||||
/**
|
||||
* Toggle developer tools for the browser view.
|
||||
|
||||
@@ -445,8 +445,12 @@ export class BrowserView extends Disposable implements ICDPTarget {
|
||||
/**
|
||||
* Reload the current page
|
||||
*/
|
||||
reload(): void {
|
||||
this._view.webContents.reload();
|
||||
reload(hard?: boolean): void {
|
||||
if (hard) {
|
||||
this._view.webContents.reloadIgnoringCache();
|
||||
} else {
|
||||
this._view.webContents.reload();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -310,8 +310,8 @@ export class BrowserViewMainService extends Disposable implements IBrowserViewMa
|
||||
return this._getBrowserView(id).goForward();
|
||||
}
|
||||
|
||||
async reload(id: string): Promise<void> {
|
||||
return this._getBrowserView(id).reload();
|
||||
async reload(id: string, hard?: boolean): Promise<void> {
|
||||
return this._getBrowserView(id).reload(hard);
|
||||
}
|
||||
|
||||
async toggleDevTools(id: string): Promise<void> {
|
||||
|
||||
@@ -138,7 +138,7 @@ export interface IBrowserViewModel extends IDisposable {
|
||||
loadURL(url: string): Promise<void>;
|
||||
goBack(): Promise<void>;
|
||||
goForward(): Promise<void>;
|
||||
reload(): Promise<void>;
|
||||
reload(hard?: boolean): Promise<void>;
|
||||
toggleDevTools(): Promise<void>;
|
||||
captureScreenshot(options?: IBrowserViewCaptureScreenshotOptions): Promise<VSBuffer>;
|
||||
dispatchKeyEvent(keyEvent: IBrowserViewKeyDownEvent): Promise<void>;
|
||||
@@ -353,9 +353,9 @@ export class BrowserViewModel extends Disposable implements IBrowserViewModel {
|
||||
return this.browserViewService.goForward(this.id);
|
||||
}
|
||||
|
||||
async reload(): Promise<void> {
|
||||
async reload(hard?: boolean): Promise<void> {
|
||||
this.logNavigationTelemetry('reload', this._url);
|
||||
return this.browserViewService.reload(this.id);
|
||||
return this.browserViewService.reload(this.id, hard);
|
||||
}
|
||||
|
||||
async toggleDevTools(): Promise<void> {
|
||||
|
||||
@@ -705,8 +705,8 @@ export class BrowserEditor extends EditorPane {
|
||||
return this._model?.goForward();
|
||||
}
|
||||
|
||||
async reload(): Promise<void> {
|
||||
return this._model?.reload();
|
||||
async reload(hard?: boolean): Promise<void> {
|
||||
return this._model?.reload(hard);
|
||||
}
|
||||
|
||||
async toggleDevTools(): Promise<void> {
|
||||
|
||||
@@ -175,6 +175,11 @@ class ReloadAction extends Action2 {
|
||||
id: MenuId.BrowserNavigationToolbar,
|
||||
group: 'navigation',
|
||||
order: 3,
|
||||
alt: {
|
||||
id: HardReloadAction.ID,
|
||||
title: localize2('browser.hardReloadAction', 'Hard Reload'),
|
||||
icon: Codicon.refresh,
|
||||
}
|
||||
},
|
||||
keybinding: {
|
||||
when: CONTEXT_BROWSER_FOCUSED,
|
||||
@@ -193,6 +198,34 @@ class ReloadAction extends Action2 {
|
||||
}
|
||||
}
|
||||
|
||||
class HardReloadAction extends Action2 {
|
||||
static readonly ID = 'workbench.action.browser.hardReload';
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
id: HardReloadAction.ID,
|
||||
title: localize2('browser.hardReloadAction', 'Hard Reload'),
|
||||
category: BrowserCategory,
|
||||
icon: Codicon.refresh,
|
||||
f1: true,
|
||||
precondition: BROWSER_EDITOR_ACTIVE,
|
||||
keybinding: {
|
||||
when: CONTEXT_BROWSER_FOCUSED,
|
||||
weight: KeybindingWeight.WorkbenchContrib + 75, // Priority over debug and reload workbench
|
||||
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyR,
|
||||
secondary: [KeyMod.CtrlCmd | KeyCode.F5],
|
||||
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyR, secondary: [] }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async run(accessor: ServicesAccessor, browserEditor = accessor.get(IEditorService).activeEditorPane): Promise<void> {
|
||||
if (browserEditor instanceof BrowserEditor) {
|
||||
await browserEditor.reload(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FocusUrlInputAction extends Action2 {
|
||||
static readonly ID = 'workbench.action.browser.focusUrlInput';
|
||||
|
||||
@@ -574,6 +607,7 @@ registerAction2(NewTabAction);
|
||||
registerAction2(GoBackAction);
|
||||
registerAction2(GoForwardAction);
|
||||
registerAction2(ReloadAction);
|
||||
registerAction2(HardReloadAction);
|
||||
registerAction2(FocusUrlInputAction);
|
||||
registerAction2(AddElementToChatAction);
|
||||
registerAction2(AddConsoleLogsToChatAction);
|
||||
|
||||
Reference in New Issue
Block a user