mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
fix: printPDF and download
This commit is contained in:
parent
9c4aa82c8f
commit
9b6d9a83d7
5 changed files with 200 additions and 262 deletions
15
package.json
15
package.json
|
|
@ -42,6 +42,7 @@
|
|||
"bluebird": "3.7.2",
|
||||
"default-gateway": "6.0.3",
|
||||
"dugite": "2.5.2",
|
||||
"electron-dl": "^3.5.1",
|
||||
"electron-ipc-cat": "2.0.1",
|
||||
"electron-settings": "5.0.0",
|
||||
"electron-squirrel-startup": "1.0.0",
|
||||
|
|
@ -83,6 +84,13 @@
|
|||
"zx": "7.2.3"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@electron-forge/maker-deb": "7.2.0",
|
||||
"@electron-forge/maker-flatpak": "7.2.0",
|
||||
"@electron-forge/maker-rpm": "7.2.0",
|
||||
"@electron-forge/maker-snap": "7.2.0",
|
||||
"@electron-forge/maker-squirrel": "7.2.0",
|
||||
"@electron-forge/maker-wix": "7.2.0",
|
||||
"@electron-forge/maker-zip": "7.2.0",
|
||||
"registry-js": "1.15.1",
|
||||
"sqlite-vss-darwin-arm64": "0.1.2",
|
||||
"sqlite-vss-darwin-x64": "0.1.2",
|
||||
|
|
@ -95,13 +103,6 @@
|
|||
"@dnd-kit/sortable": "5.0.0",
|
||||
"@dnd-kit/utilities": "3.0.0",
|
||||
"@electron-forge/cli": "7.2.0",
|
||||
"@electron-forge/maker-deb": "7.2.0",
|
||||
"@electron-forge/maker-flatpak": "7.2.0",
|
||||
"@electron-forge/maker-rpm": "7.2.0",
|
||||
"@electron-forge/maker-snap": "7.2.0",
|
||||
"@electron-forge/maker-squirrel": "7.2.0",
|
||||
"@electron-forge/maker-wix": "7.2.0",
|
||||
"@electron-forge/maker-zip": "7.2.0",
|
||||
"@electron-forge/plugin-auto-unpack-natives": "7.2.0",
|
||||
"@electron-forge/plugin-webpack": "7.2.0",
|
||||
"@electron/rebuild": "^3.4.1",
|
||||
|
|
|
|||
377
pnpm-lock.yaml
generated
377
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -529,8 +529,8 @@ export class View implements IViewService {
|
|||
|
||||
public async getActiveBrowserView(): Promise<BrowserView | undefined> {
|
||||
const workspace = await this.workspaceService.getActiveWorkspace();
|
||||
const isMenubarOpen = await this.windowService.isMenubarOpen();
|
||||
if (workspace !== undefined) {
|
||||
const isMenubarOpen = await this.windowService.isMenubarOpen();
|
||||
if (isMenubarOpen) {
|
||||
return this.getView(workspace.id, WindowNames.menuBar);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ export class Workspace implements IWorkspaceService {
|
|||
accelerator: `CmdOrCtrl+${index + 1}`,
|
||||
},
|
||||
{
|
||||
label: () => `${workspace.name || `Workspace ${index + 1}`} ${i18n.t('ContextMenu.DeveloperTools')}`,
|
||||
label: () => `${workspace.name || `Workspace ${index + 1}`} ${i18n.t('Menu.DeveloperToolsActiveWorkspace')}`,
|
||||
id: `${workspace.id}-devtool`,
|
||||
click: async () => {
|
||||
const view = this.viewService.getView(workspace.id, WindowNames.main);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import type { IWikiService } from '@services/wiki/interface';
|
|||
import type { IWindowService } from '@services/windows/interface';
|
||||
import { IBrowserViewMetaData, WindowNames } from '@services/windows/WindowProperties';
|
||||
import type { IWorkspace, IWorkspaceService } from '@services/workspaces/interface';
|
||||
import { CancelError as DownloadCancelError, download } from 'electron-dl';
|
||||
import path from 'path';
|
||||
import type { IInitializeWorkspaceOptions, IWorkspaceViewService } from './interface';
|
||||
|
||||
|
|
@ -252,35 +253,57 @@ export class WorkspaceView implements IWorkspaceViewService {
|
|||
}
|
||||
|
||||
private async registerMenu(): Promise<void> {
|
||||
const hasWorkspaces = async (): Promise<boolean> => (await this.workspaceService.countWorkspaces()) > 0;
|
||||
const hasActiveWorkspaces = async (): Promise<boolean> => (await this.workspaceService.getActiveWorkspace()) !== undefined;
|
||||
|
||||
await this.menuService.insertMenu('Workspaces', [
|
||||
{
|
||||
label: () => i18n.t('Menu.DeveloperToolsActiveWorkspace'),
|
||||
accelerator: 'CmdOrCtrl+Option+I',
|
||||
click: async () => (await this.viewService.getActiveBrowserView())?.webContents?.openDevTools?.({ mode: 'detach' }),
|
||||
enabled: hasWorkspaces,
|
||||
enabled: hasActiveWorkspaces,
|
||||
},
|
||||
]);
|
||||
await this.menuService.insertMenu('Wiki', [
|
||||
{
|
||||
label: () => i18n.t('Menu.PrintPage'),
|
||||
click: async () => {
|
||||
const browserViews = await this.viewService.getActiveBrowserViews();
|
||||
browserViews.forEach((browserView) => {
|
||||
browserView?.webContents?.print();
|
||||
});
|
||||
try {
|
||||
const browserView = await this.viewService.getActiveBrowserView();
|
||||
const win = this.windowService.get(WindowNames.main);
|
||||
logger.info(
|
||||
`print page, browserView printToPDF method is ${browserView?.webContents?.printToPDF === undefined ? 'undefined' : 'define'}, win is ${
|
||||
win === undefined ? 'undefined' : 'define'
|
||||
}`,
|
||||
);
|
||||
if (browserView === undefined || win === undefined) {
|
||||
return;
|
||||
}
|
||||
const pdfBuffer = await browserView?.webContents?.printToPDF({
|
||||
generateTaggedPDF: true,
|
||||
});
|
||||
// turn buffer to data uri
|
||||
const dataUri = `data:application/pdf;base64,${pdfBuffer?.toString('base64')}`;
|
||||
await download(win, dataUri, { filename: 'wiki.pdf', overwrite: false });
|
||||
logger.info(`print page done`);
|
||||
} catch (error) {
|
||||
if (error instanceof DownloadCancelError) {
|
||||
logger.debug('item.cancel() was called');
|
||||
} else {
|
||||
logger.error(`print page error: ${(error as Error).message}`, error);
|
||||
}
|
||||
}
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
},
|
||||
{
|
||||
label: () => i18n.t('Menu.PrintActiveTiddler'),
|
||||
accelerator: 'CmdOrCtrl+Alt+Shift+P',
|
||||
click: async () => {
|
||||
await this.printTiddler();
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
enabled: hasActiveWorkspaces,
|
||||
},
|
||||
// TODO: get active tiddler title
|
||||
// {
|
||||
// label: () => i18n.t('Menu.PrintActiveTiddler'),
|
||||
// accelerator: 'CmdOrCtrl+Alt+Shift+P',
|
||||
// click: async () => {
|
||||
// await this.printTiddler(title);
|
||||
// },
|
||||
// enabled: hasActiveWorkspaces,
|
||||
// },
|
||||
{
|
||||
label: () => i18n.t('Menu.ExportWholeWikiHTML'),
|
||||
click: async () => {
|
||||
|
|
@ -300,7 +323,7 @@ export class WorkspaceView implements IWorkspaceViewService {
|
|||
logger.error("Can not export whole wiki, pickDirectory's pathOfNewHTML is empty");
|
||||
}
|
||||
},
|
||||
enabled: hasWorkspaces,
|
||||
enabled: hasActiveWorkspaces,
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
|
|
@ -327,13 +350,10 @@ export class WorkspaceView implements IWorkspaceViewService {
|
|||
]);
|
||||
}
|
||||
|
||||
public async printTiddler(tiddlerName?: string): Promise<void> {
|
||||
const browserViews = await this.viewService.getActiveBrowserViews();
|
||||
browserViews.forEach((browserView) => {
|
||||
if (browserView !== undefined) {
|
||||
browserView.webContents.send(WikiChannel.printTiddler, tiddlerName);
|
||||
}
|
||||
});
|
||||
public async printTiddler(tiddlerName: string): Promise<void> {
|
||||
const browserView = await this.viewService.getActiveBrowserView();
|
||||
logger.info(`printTiddler() printing tiddler ${tiddlerName ?? 'undefined'}, browserView is ${browserView?.webContents === undefined ? 'undefined' : 'define'}`);
|
||||
browserView?.webContents?.send?.(WikiChannel.printTiddler, tiddlerName);
|
||||
}
|
||||
|
||||
public async setWorkspaceView(workspaceID: string, workspaceOptions: IWorkspace): Promise<void> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue