mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-27 20:33:12 -08:00
feat: make zoom and many menu item works
fixes https://github.com/tiddly-gittly/TidGi-Desktop/issues/365
This commit is contained in:
parent
26282bc19f
commit
6833d14bb3
4 changed files with 49 additions and 66 deletions
|
|
@ -18,6 +18,6 @@ try {
|
|||
|
||||
export const browserViewMetaData = { windowName, ...extraMeta };
|
||||
contextBridge.exposeInMainWorld('meta', browserViewMetaData);
|
||||
ipcRenderer.on(MetaDataChannel.getViewMetaData, (event) => {
|
||||
event.returnValue = browserViewMetaData;
|
||||
ipcRenderer.on(MetaDataChannel.getViewMetaData, (event, payload?: { ipcToken: string }) => {
|
||||
ipcRenderer.send(`${MetaDataChannel.getViewMetaData}-${payload?.ipcToken ?? ''}`, browserViewMetaData);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -110,13 +110,12 @@ export class View implements IViewService {
|
|||
},
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{ role: 'togglefullscreen' },
|
||||
{
|
||||
label: () => i18n.t('Menu.ActualSize'),
|
||||
accelerator: 'CmdOrCtrl+0',
|
||||
click: async (_menuItem, browserWindow) => {
|
||||
// if item is called in popup window
|
||||
// open menu bar in the popup window instead
|
||||
// modify menu bar in the popup window instead
|
||||
if (browserWindow === undefined) return;
|
||||
const { isPopup } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
if (isPopup === true) {
|
||||
|
|
@ -124,12 +123,9 @@ export class View implements IViewService {
|
|||
contents.zoomFactor = 1;
|
||||
return;
|
||||
}
|
||||
// modify browser view in the main window
|
||||
const mainWindow = this.windowService.get(WindowNames.main);
|
||||
const webContent = mainWindow?.getBrowserView()?.webContents;
|
||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||
if (webContent) {
|
||||
webContent.setZoomFactor(1);
|
||||
}
|
||||
mainWindow?.getBrowserView()?.webContents?.setZoomFactor(1);
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
},
|
||||
|
|
@ -138,20 +134,19 @@ export class View implements IViewService {
|
|||
accelerator: 'CmdOrCtrl+=',
|
||||
click: async (_menuItem, browserWindow) => {
|
||||
// if item is called in popup window
|
||||
// open menu bar in the popup window instead
|
||||
// modify menu bar in the popup window instead
|
||||
if (browserWindow === undefined) return;
|
||||
const { isPopup } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
if (isPopup === true) {
|
||||
const contents = browserWindow.webContents;
|
||||
contents.zoomFactor += 0.1;
|
||||
contents.zoomFactor += 0.05;
|
||||
return;
|
||||
}
|
||||
// modify browser view in the main window
|
||||
const mainWindow = this.windowService.get(WindowNames.main);
|
||||
const webContent = mainWindow?.getBrowserView()?.webContents;
|
||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||
if (webContent) {
|
||||
webContent.setZoomFactor(webContent.getZoomFactor() + 0.1);
|
||||
}
|
||||
webContent?.setZoomFactor(webContent.getZoomFactor() + 0.05);
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
},
|
||||
|
|
@ -160,20 +155,19 @@ export class View implements IViewService {
|
|||
accelerator: 'CmdOrCtrl+-',
|
||||
click: async (_menuItem, browserWindow) => {
|
||||
// if item is called in popup window
|
||||
// open menu bar in the popup window instead
|
||||
// modify menu bar in the popup window instead
|
||||
if (browserWindow === undefined) return;
|
||||
const { isPopup } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
if (isPopup === true) {
|
||||
const contents = browserWindow.webContents;
|
||||
contents.zoomFactor -= 0.1;
|
||||
contents.zoomFactor -= 0.05;
|
||||
return;
|
||||
}
|
||||
// modify browser view in the main window
|
||||
const mainWindow = this.windowService.get(WindowNames.main);
|
||||
const webContent = mainWindow?.getBrowserView()?.webContents;
|
||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||
if (webContent) {
|
||||
webContent.setZoomFactor(webContent.getZoomFactor() - 0.1);
|
||||
}
|
||||
webContent?.setZoomFactor(webContent.getZoomFactor() - 0.05);
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
},
|
||||
|
|
@ -183,20 +177,16 @@ export class View implements IViewService {
|
|||
accelerator: 'CmdOrCtrl+R',
|
||||
click: async (_menuItem, browserWindow) => {
|
||||
// if item is called in popup window
|
||||
// open menu bar in the popup window instead
|
||||
// modify menu bar in the popup window instead
|
||||
if (browserWindow === undefined) return;
|
||||
const { isPopup } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
if (isPopup === true) {
|
||||
browserWindow.webContents.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// refresh the main window browser view's wiki content, instead of sidebar's react content
|
||||
const mainWindow = this.windowService.get(WindowNames.main);
|
||||
const webContent = mainWindow?.getBrowserView()?.webContents;
|
||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||
if (webContent) {
|
||||
webContent.reload();
|
||||
}
|
||||
mainWindow?.getBrowserView()?.webContents?.reload();
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||
/* eslint-disable @typescript-eslint/consistent-type-assertions */
|
||||
import { app, BrowserWindow, BrowserWindowConstructorOptions, clipboard, ipcMain, Menu, nativeImage, Tray } from 'electron';
|
||||
import { app, BrowserWindow, BrowserWindowConstructorOptions, ipcMain, Menu, nativeImage, Tray } from 'electron';
|
||||
import windowStateKeeper, { State as windowStateKeeperState } from 'electron-window-state';
|
||||
import { injectable } from 'inversify';
|
||||
import mergeDeep from 'lodash/merge';
|
||||
|
|
@ -375,9 +375,7 @@ export class Window implements IWindowService {
|
|||
}
|
||||
|
||||
private async registerMenu(): Promise<void> {
|
||||
await this.menuService.insertMenu('View', [
|
||||
{ role: 'reload' },
|
||||
{ role: 'forceReload' },
|
||||
await this.menuService.insertMenu('Window', [
|
||||
// `role: 'zoom'` is only supported on macOS
|
||||
isMac
|
||||
? {
|
||||
|
|
@ -462,11 +460,8 @@ export class Window implements IWindowService {
|
|||
// navigate in the popup window instead
|
||||
if (browserWindow !== undefined) {
|
||||
// TODO: test if we really can get this isPopup value
|
||||
const { isPopup } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
if (isPopup === true) {
|
||||
browserWindow.webContents.goBack();
|
||||
return;
|
||||
}
|
||||
const { isPopup = false } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
await this.goBack(isPopup ? WindowNames.menuBar : WindowNames.main);
|
||||
}
|
||||
ipcMain.emit('request-go-back');
|
||||
},
|
||||
|
|
@ -479,39 +474,13 @@ export class Window implements IWindowService {
|
|||
// if back is called in popup window
|
||||
// navigate in the popup window instead
|
||||
if (browserWindow !== undefined) {
|
||||
const { isPopup } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
if (isPopup === true) {
|
||||
browserWindow.webContents.goBack();
|
||||
return;
|
||||
}
|
||||
const { isPopup = false } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
await this.goForward(isPopup ? WindowNames.menuBar : WindowNames.main);
|
||||
}
|
||||
ipcMain.emit('request-go-forward');
|
||||
},
|
||||
enabled: async () => (await this.workspaceService.countWorkspaces()) > 0,
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: () => i18n.t('ContextMenu.CopyLink'),
|
||||
accelerator: 'CmdOrCtrl+L',
|
||||
click: async (_menuItem, browserWindow) => {
|
||||
// if back is called in popup window
|
||||
// copy the popup window URL instead
|
||||
if (browserWindow !== undefined) {
|
||||
const { isPopup } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
if (isPopup === true) {
|
||||
const url = browserWindow.webContents.getURL();
|
||||
clipboard.writeText(url);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const mainWindow = this.get(WindowNames.main);
|
||||
const url = mainWindow?.getBrowserView()?.webContents?.getURL();
|
||||
if (typeof url === 'string') {
|
||||
clipboard.writeText(url);
|
||||
}
|
||||
},
|
||||
enabled: async () => (await this.workspaceService.countWorkspaces()) > 0,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable unicorn/consistent-destructuring */
|
||||
import { delay, mapSeries } from 'bluebird';
|
||||
import { app, dialog, session } from 'electron';
|
||||
import { app, clipboard, dialog, session } from 'electron';
|
||||
import { injectable } from 'inversify';
|
||||
|
||||
import { WikiChannel } from '@/constants/channels';
|
||||
import { MetaDataChannel, WikiChannel } from '@/constants/channels';
|
||||
import { tiddlywikiLanguagesMap } from '@/constants/languages';
|
||||
import type { IAuthenticationService } from '@services/auth/interface';
|
||||
import { lazyInject } from '@services/container';
|
||||
|
|
@ -19,10 +19,11 @@ import { SupportedStorageServices } from '@services/types';
|
|||
import type { IViewService } from '@services/view/interface';
|
||||
import type { IWikiService } from '@services/wiki/interface';
|
||||
import type { IWindowService } from '@services/windows/interface';
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
import { IBrowserViewMetaData, WindowNames } from '@services/windows/WindowProperties';
|
||||
import type { IWorkspace, IWorkspaceService } from '@services/workspaces/interface';
|
||||
import { WorkspaceFailedToLoadError } from './error';
|
||||
import type { IInitializeWorkspaceOptions, IWorkspaceViewService } from './interface';
|
||||
import getFromRenderer from '@services/libs/getFromRenderer';
|
||||
|
||||
@injectable()
|
||||
export class WorkspaceView implements IWorkspaceViewService {
|
||||
|
|
@ -255,6 +256,29 @@ export class WorkspaceView implements IWorkspaceViewService {
|
|||
await this.printTiddler();
|
||||
},
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: () => i18n.t('ContextMenu.CopyLink'),
|
||||
accelerator: 'CmdOrCtrl+L',
|
||||
click: async (_menuItem, browserWindow) => {
|
||||
// if back is called in popup window
|
||||
// copy the popup window URL instead
|
||||
if (browserWindow !== undefined) {
|
||||
const { isPopup } = await getFromRenderer<IBrowserViewMetaData>(MetaDataChannel.getViewMetaData, browserWindow);
|
||||
if (isPopup === true) {
|
||||
const url = browserWindow.webContents.getURL();
|
||||
clipboard.writeText(url);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const mainWindow = this.windowService.get(WindowNames.main);
|
||||
const url = mainWindow?.getBrowserView()?.webContents?.getURL();
|
||||
if (typeof url === 'string') {
|
||||
clipboard.writeText(url);
|
||||
}
|
||||
},
|
||||
enabled: async () => (await this.workspaceService.countWorkspaces()) > 0,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue