Skip to content

Commit

Permalink
Merge branch 'v2.17' of github.com:opensumi/core into v2.18
Browse files Browse the repository at this point in the history
  • Loading branch information
erha19 committed Jun 2, 2022
2 parents 77e7fe0 + 0f2e164 commit 1dc4809
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
9 changes: 8 additions & 1 deletion packages/core-common/src/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ export interface IElectronMainUIServiceShape {

showSaveDialog(windowId: number, options: Electron.SaveDialogOptions): Promise<string | undefined>;

setZoomFactor(webContentsId: number, options: { value?: number; delta?: number }): void;
/**
* 默认:最小缩放因子为 0.25,最大缩放因子为 5.0
*/
setZoomFactor(
webContentsId: number,
options: { value?: number; delta?: number; minValue?: number | undefined; maxValue?: number | undefined },
): Promise<void>;
getZoomFactor(webContentsId: number): Promise<number | undefined>;

/**
* 在资源管理器里打开文件
Expand Down
27 changes: 24 additions & 3 deletions packages/core-electron-main/src/bootstrap/services/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,40 @@ export class ElectronMainUIService
openInTerminal(targetPath);
}

getZoomFactor(webContentsId: number): number | undefined {
async getZoomFactor(webContentsId: number): Promise<number | undefined> {
const contents = webContents.fromId(webContentsId);
return contents?.getZoomFactor();
}

setZoomFactor(webContentsId: number, options: { value?: number; delta?: number } = {}) {
async setZoomFactor(
webContentsId: number,
options: { value?: number; delta?: number; minValue?: number; maxValue?: number } = {},
) {
if (options.minValue === undefined) {
options.minValue = 0.25;
}
if (options.maxValue === undefined) {
options.maxValue = 5;
}

const contents = webContents.fromId(webContentsId);
if (contents) {
let factor: number | undefined;
if (options.value) {
factor = options.value;
contents.setZoomFactor(options.value);
}
if (options.delta) {
contents.setZoomFactor(contents.getZoomFactor() + options.delta);
factor = contents.getZoomFactor() + options.delta;
}
if (factor) {
if (options.minValue && factor < options.minValue) {
factor = options.minValue;
}
if (options.maxValue && factor > options.maxValue) {
factor = options.maxValue;
}
contents.setZoomFactor(factor);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/electron-basic/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ export class ElectronBasicContribution
command: 'electron.zoomOut',
keybinding: isWindows ? 'alt+-' : 'ctrlcmd+-',
});
keybindings.registerKeybinding({
command: 'electron.zoomReset',
keybinding: isWindows ? 'alt+numpad0' : 'ctrlcmd+numpad0',
});
}

onStart() {
Expand Down

0 comments on commit 1dc4809

Please sign in to comment.