mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 10:41:02 -08:00
fix: type errors
This commit is contained in:
parent
d646d3c372
commit
66a1512c6c
24 changed files with 98 additions and 102 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
|
const tsEslintConfig = require('./tsconfig.eslint.json');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
ignorePatterns: tsEslintConfig.exclude,
|
||||||
parser: '@typescript-eslint/parser',
|
parser: '@typescript-eslint/parser',
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
project: './tsconfig.eslint.json',
|
project: './tsconfig.eslint.json',
|
||||||
|
|
|
||||||
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
|
@ -10,6 +10,7 @@
|
||||||
"submenu",
|
"submenu",
|
||||||
"subwiki",
|
"subwiki",
|
||||||
"subwiki's",
|
"subwiki's",
|
||||||
|
"tiddlygit",
|
||||||
"tiddlywiki's"
|
"tiddlywiki's"
|
||||||
],
|
],
|
||||||
"i18n-ally.sourceLanguage": "zh",
|
"i18n-ally.sourceLanguage": "zh",
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ const InfoContainer = styled.div`
|
||||||
padding: 0 12px;
|
padding: 0 12px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default function FindInPage(): JSX.Element | null {
|
export default function FindInPage(): JSX.Element | undefined {
|
||||||
const [open, openSetter] = useState(false);
|
const [open, openSetter] = useState(false);
|
||||||
const [text, textSetter] = useState('');
|
const [text, textSetter] = useState('');
|
||||||
const [activeMatch, activeMatchSetter] = useState(0);
|
const [activeMatch, activeMatchSetter] = useState(0);
|
||||||
|
|
@ -48,9 +48,9 @@ export default function FindInPage(): JSX.Element | null {
|
||||||
window.remote.unregisterOpenFindInPage(handleOpenFindInPage);
|
window.remote.unregisterOpenFindInPage(handleOpenFindInPage);
|
||||||
window.remote.unregisterUpdateFindInPageMatches(updateFindInPageMatches);
|
window.remote.unregisterUpdateFindInPageMatches(updateFindInPageMatches);
|
||||||
};
|
};
|
||||||
}, [handleOpenFindInPage]);
|
}, [handleOpenFindInPage, updateFindInPageMatches]);
|
||||||
if (!open) {
|
if (!open) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Root>
|
<Root>
|
||||||
|
|
@ -69,8 +69,8 @@ export default function FindInPage(): JSX.Element | null {
|
||||||
placeholder="Find"
|
placeholder="Find"
|
||||||
value={text}
|
value={text}
|
||||||
margin="dense"
|
margin="dense"
|
||||||
onChange={(e) => {
|
onChange={(event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||||
const value = e.target.value;
|
const value = event.target.value;
|
||||||
textSetter(value);
|
textSetter(value);
|
||||||
if (value.length > 0) {
|
if (value.length > 0) {
|
||||||
void window.service.window.findInPage(value, true);
|
void window.service.window.findInPage(value, true);
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,13 @@ export enum ViewChannel {
|
||||||
}
|
}
|
||||||
export enum WikiChannel {
|
export enum WikiChannel {
|
||||||
name = 'WikiChannel',
|
name = 'WikiChannel',
|
||||||
|
addTiddler = 'wiki-add-tiddler',
|
||||||
|
addTiddlerDone = 'wiki-add-tiddler-done',
|
||||||
|
getTiddlerText = 'wiki-get-tiddler-text',
|
||||||
|
getTiddlerTextDone = 'wiki-get-tiddler-text-done',
|
||||||
|
syncProgress = 'wiki-sync-progress',
|
||||||
|
openTiddler = 'wiki-open-tiddler',
|
||||||
|
sendActionMessage = 'wiki-send-action-message',
|
||||||
}
|
}
|
||||||
export enum WikiGitWorkspaceChannel {
|
export enum WikiGitWorkspaceChannel {
|
||||||
name = 'WikiGitWorkspaceChannel',
|
name = 'WikiGitWorkspaceChannel',
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { useEffect, useState, useCallback, Dispatch } from 'react';
|
import { useEffect, useState, useCallback } from 'react';
|
||||||
import { AsyncReturnType } from 'type-fest';
|
import { AsyncReturnType } from 'type-fest';
|
||||||
import { useDebouncedFn } from 'beautiful-react-hooks';
|
import { useDebouncedFn } from 'beautiful-react-hooks';
|
||||||
|
|
||||||
|
|
@ -19,6 +19,7 @@ export function usePromiseValue<T, DefaultValueType = T | undefined>(
|
||||||
void (async () => {
|
void (async () => {
|
||||||
valueSetter(await asyncValue());
|
valueSetter(await asyncValue());
|
||||||
})();
|
})();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, dependency);
|
}, dependency);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
import { ipcRenderer } from 'electron';
|
|
||||||
|
|
||||||
export function loadListeners(store: any): void {
|
|
||||||
ipcRenderer.on('log', (_event: Electron.IpcRendererEvent, message: any) => {
|
|
||||||
if (message) console.log(message); // eslint-disable-line no-console
|
|
||||||
});
|
|
||||||
|
|
||||||
// send back a request with text
|
|
||||||
ipcRenderer.on('request-back-find-in-page', (_event: Electron.IpcRendererEvent, forward: any) => {
|
|
||||||
const { open, text } = store.getState().findInPage;
|
|
||||||
if (!open) return;
|
|
||||||
void window.service.window.findInPage(text, forward);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Typography, TextField, FormHelperText, MenuItem } from '@material-ui/core';
|
import { Typography, MenuItem } from '@material-ui/core';
|
||||||
import { Folder as FolderIcon } from '@material-ui/icons';
|
import { Folder as FolderIcon } from '@material-ui/icons';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ export function SortableWorkspaceSelector({ index, workspace }: ISortableItemPro
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.remote.popContextMenu(template, { x: event.clientX, y: event.clientY, editFlags: { canCopy: false } });
|
void window.remote.popContextMenu(template, { x: event.clientX, y: event.clientY, editFlags: { canCopy: false } });
|
||||||
}}>
|
}}>
|
||||||
<WorkspaceSelector
|
<WorkspaceSelector
|
||||||
active={active}
|
active={active}
|
||||||
|
|
|
||||||
|
|
@ -613,7 +613,7 @@ export default function Preferences(): JSX.Element {
|
||||||
await window.service.preference.set('downloadPath', filePaths[0]);
|
await window.service.preference.set('downloadPath', filePaths[0]);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: Error) => {
|
||||||
console.log(error); // eslint-disable-line no-console
|
console.log(error); // eslint-disable-line no-console
|
||||||
});
|
});
|
||||||
}}>
|
}}>
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,10 @@ import { useTranslation } from 'react-i18next';
|
||||||
import BuildIcon from '@material-ui/icons/Build';
|
import BuildIcon from '@material-ui/icons/Build';
|
||||||
import CloudDownloadIcon from '@material-ui/icons/CloudDownload';
|
import CloudDownloadIcon from '@material-ui/icons/CloudDownload';
|
||||||
import CodeIcon from '@material-ui/icons/Code';
|
import CodeIcon from '@material-ui/icons/Code';
|
||||||
import ExtensionIcon from '@material-ui/icons/Extension';
|
|
||||||
import LanguageIcon from '@material-ui/icons/Language';
|
import LanguageIcon from '@material-ui/icons/Language';
|
||||||
import MoreHorizIcon from '@material-ui/icons/MoreHoriz';
|
import MoreHorizIcon from '@material-ui/icons/MoreHoriz';
|
||||||
import NotificationsIcon from '@material-ui/icons/Notifications';
|
import NotificationsIcon from '@material-ui/icons/Notifications';
|
||||||
import PowerIcon from '@material-ui/icons/Power';
|
import PowerIcon from '@material-ui/icons/Power';
|
||||||
import RotateLeftIcon from '@material-ui/icons/RotateLeft';
|
|
||||||
import RouterIcon from '@material-ui/icons/Router';
|
import RouterIcon from '@material-ui/icons/Router';
|
||||||
import SecurityIcon from '@material-ui/icons/Security';
|
import SecurityIcon from '@material-ui/icons/Security';
|
||||||
import StorefrontIcon from '@material-ui/icons/Storefront';
|
import StorefrontIcon from '@material-ui/icons/Storefront';
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,7 @@ export const remoteMethods = {
|
||||||
await service.menu.buildContextMenuAndPopup(ipcSafeMenus, parameters, windowName);
|
await service.menu.buildContextMenuAndPopup(ipcSafeMenus, parameters, windowName);
|
||||||
return unregister;
|
return unregister;
|
||||||
},
|
},
|
||||||
getCurrentWindow: async () => {
|
closeCurrentWindow: async (): Promise<() => void> => {
|
||||||
const currentWindow = await service.window.get(windowName);
|
|
||||||
if (currentWindow === undefined) {
|
|
||||||
throw new Error(`currentWindow is undefined when getCurrentWindow() in preload script with windowName: ${windowName}`);
|
|
||||||
}
|
|
||||||
return currentWindow;
|
|
||||||
},
|
|
||||||
closeCurrentWindow: async () => {
|
|
||||||
await service.window.close(windowName);
|
await service.window.close(windowName);
|
||||||
},
|
},
|
||||||
/** call NodeJS.path */
|
/** call NodeJS.path */
|
||||||
|
|
@ -36,11 +29,11 @@ export const remoteMethods = {
|
||||||
setVisualZoomLevelLimits: (minimumLevel: number, maximumLevel: number): void => {
|
setVisualZoomLevelLimits: (minimumLevel: number, maximumLevel: number): void => {
|
||||||
webFrame.setVisualZoomLevelLimits(minimumLevel, maximumLevel);
|
webFrame.setVisualZoomLevelLimits(minimumLevel, maximumLevel);
|
||||||
},
|
},
|
||||||
registerOpenFindInPage: (handleOpenFindInPage: () => void) => void ipcRenderer.on(WindowChannel.openFindInPage, handleOpenFindInPage),
|
registerOpenFindInPage: (handleOpenFindInPage: () => void): void => void ipcRenderer.on(WindowChannel.openFindInPage, handleOpenFindInPage),
|
||||||
unregisterOpenFindInPage: (handleOpenFindInPage: () => void) => void ipcRenderer.removeListener(WindowChannel.openFindInPage, handleOpenFindInPage),
|
unregisterOpenFindInPage: (handleOpenFindInPage: () => void): void => void ipcRenderer.removeListener(WindowChannel.openFindInPage, handleOpenFindInPage),
|
||||||
registerUpdateFindInPageMatches: (updateFindInPageMatches: (event: Electron.IpcRendererEvent, activeMatchOrdinal: number, matches: number) => void) =>
|
registerUpdateFindInPageMatches: (updateFindInPageMatches: (event: Electron.IpcRendererEvent, activeMatchOrdinal: number, matches: number) => void): void =>
|
||||||
void ipcRenderer.on(ViewChannel.updateFindInPageMatches, updateFindInPageMatches),
|
void ipcRenderer.on(ViewChannel.updateFindInPageMatches, updateFindInPageMatches),
|
||||||
unregisterUpdateFindInPageMatches: (updateFindInPageMatches: (event: Electron.IpcRendererEvent, activeMatchOrdinal: number, matches: number) => void) =>
|
unregisterUpdateFindInPageMatches: (updateFindInPageMatches: (event: Electron.IpcRendererEvent, activeMatchOrdinal: number, matches: number) => void): void =>
|
||||||
void ipcRenderer.removeListener(ViewChannel.updateFindInPageMatches, updateFindInPageMatches),
|
void ipcRenderer.removeListener(ViewChannel.updateFindInPageMatches, updateFindInPageMatches),
|
||||||
};
|
};
|
||||||
contextBridge.exposeInMainWorld('remote', remoteMethods);
|
contextBridge.exposeInMainWorld('remote', remoteMethods);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* eslint-disable @typescript-eslint/no-misused-promises */
|
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||||
import { webFrame } from 'electron';
|
import { webFrame } from 'electron';
|
||||||
import { WorkspaceChannel } from '@/constants/channels';
|
import { WorkspaceChannel, Channels } from '@/constants/channels';
|
||||||
import './wiki-operation';
|
import './wiki-operation';
|
||||||
import { preference, workspace, workspaceView, menu } from './common/services';
|
import { preference, workspace, workspaceView, menu } from './common/services';
|
||||||
import { IPossibleWindowMeta, WindowMeta, WindowNames } from '@services/windows/WindowProperties';
|
import { IPossibleWindowMeta, WindowMeta, WindowNames } from '@services/windows/WindowProperties';
|
||||||
|
|
@ -25,15 +25,13 @@ document.addEventListener('DOMContentLoaded', () => handleLoaded('document.on("D
|
||||||
// DOMContentLoaded might not be triggered so double check with 'onload'
|
// DOMContentLoaded might not be triggered so double check with 'onload'
|
||||||
// https://github.com/atomery/webcatalog/issues/797
|
// https://github.com/atomery/webcatalog/issues/797
|
||||||
window.addEventListener('load', () => handleLoaded('window.on("onload")'));
|
window.addEventListener('load', () => handleLoaded('window.on("onload")'));
|
||||||
window.addEventListener('message', (event) => {
|
window.addEventListener('message', async (event?: MessageEvent<{ type?: Channels; workspaceID?: string } | undefined>) => {
|
||||||
if (!event.data) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// set workspace to active when its notification is clicked
|
// set workspace to active when its notification is clicked
|
||||||
if (event.data.type === WorkspaceChannel.focusWorkspace) {
|
if (event?.data?.type === WorkspaceChannel.focusWorkspace) {
|
||||||
const id = event.data.workspaceID;
|
const id = event.data.workspaceID;
|
||||||
if (workspace.get(id) !== undefined) {
|
if (id !== undefined && (await workspace.get(id)) !== undefined) {
|
||||||
void workspaceView.setActiveWorkspaceView(id).then(async () => await menu.buildMenu());
|
await workspaceView.setActiveWorkspaceView(id);
|
||||||
|
await menu.buildMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,45 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||||
/**
|
/**
|
||||||
* Call tiddlywiki api from electron
|
* Call tiddlywiki api from electron
|
||||||
* This file should be required by view.ts preload script to work
|
* This file should be required by view.ts preload script to work
|
||||||
*/
|
*/
|
||||||
import { ipcRenderer, webFrame } from 'electron';
|
import { ipcRenderer, webFrame } from 'electron';
|
||||||
import Promise from 'bluebird';
|
import { delay } from 'bluebird';
|
||||||
|
import { WikiChannel } from '@/constants/channels';
|
||||||
|
|
||||||
// add tiddler
|
// add tiddler
|
||||||
ipcRenderer.on('wiki-add-tiddler', async (event, title, text, meta) => {
|
ipcRenderer.on(WikiChannel.addTiddler, async (event, title: string, text: string, meta: unknown) => {
|
||||||
const extraMeta = typeof meta === 'object' ? JSON.stringify(meta) : '{}';
|
const extraMeta = typeof meta === 'object' ? JSON.stringify(meta) : '{}';
|
||||||
await webFrame.executeJavaScript(`
|
await webFrame.executeJavaScript(`
|
||||||
$tw.wiki.addTiddler({ title: '${title}', text: '${text}', ...${extraMeta} });
|
$tw.wiki.addTiddler({ title: '${title}', text: '${text}', ...${extraMeta} });
|
||||||
`);
|
`);
|
||||||
// wait for fs to be settle
|
// wait for fs to be settle
|
||||||
await (Promise as any).delay(1000);
|
await delay(1000);
|
||||||
ipcRenderer.invoke('wiki-add-tiddler-done');
|
await ipcRenderer.invoke(WikiChannel.addTiddlerDone);
|
||||||
});
|
});
|
||||||
// get tiddler text
|
// get tiddler text
|
||||||
ipcRenderer.on('wiki-get-tiddler-text', async (event, title) => {
|
ipcRenderer.on(WikiChannel.getTiddlerText, async (event, title: string) => {
|
||||||
const tiddlerText = await webFrame.executeJavaScript(`
|
const tiddlerText: string = await (webFrame.executeJavaScript(`
|
||||||
$tw.wiki.getTiddlerText('${title}');
|
$tw.wiki.getTiddlerText('${title}');
|
||||||
`);
|
`) as Promise<string>);
|
||||||
ipcRenderer.invoke('wiki-get-tiddler-text-done', tiddlerText);
|
await ipcRenderer.invoke(WikiChannel.getTiddlerTextDone, tiddlerText);
|
||||||
});
|
});
|
||||||
// add snackbar to notify user
|
// add snackbar to notify user
|
||||||
ipcRenderer.on('wiki-sync-progress', (event, message) => {
|
ipcRenderer.on(WikiChannel.syncProgress, async (event, message: string) => {
|
||||||
webFrame.executeJavaScript(`
|
await webFrame.executeJavaScript(`
|
||||||
$tw.wiki.addTiddler({ title: '$:/state/notification/wiki-sync-progress', text: '${message}' });
|
$tw.wiki.addTiddler({ title: '$:/state/notification/${WikiChannel.syncProgress}', text: '${message}' });
|
||||||
$tw.notifier.display('$:/state/notification/wiki-sync-progress');
|
$tw.notifier.display('$:/state/notification/${WikiChannel.syncProgress}');
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
// open a tiddler
|
// open a tiddler
|
||||||
ipcRenderer.on('wiki-open-tiddler', (event, tiddlerName) => {
|
ipcRenderer.on(WikiChannel.openTiddler, async (event, tiddlerName: string) => {
|
||||||
webFrame.executeJavaScript(`
|
await webFrame.executeJavaScript(`
|
||||||
window.location.href = "http://localhost:5212/#${tiddlerName}";
|
window.location.href = "http://localhost:5212/#${tiddlerName}";
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
// send an action message
|
// send an action message
|
||||||
ipcRenderer.on('wiki-send-action-message', (event, actionMessage) => {
|
ipcRenderer.on(WikiChannel.sendActionMessage, async (event, actionMessage: string) => {
|
||||||
webFrame.executeJavaScript(`
|
await webFrame.executeJavaScript(`
|
||||||
$tw.rootWidget.dispatchEvent({ type: "${actionMessage}" });
|
$tw.rootWidget.dispatchEvent({ type: "${actionMessage}" });
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import i18n from '@services/libs/i18n';
|
||||||
import { getModifiedFileList, ModifiedFileList, getRemoteUrl } from './inspect';
|
import { getModifiedFileList, ModifiedFileList, getRemoteUrl } from './inspect';
|
||||||
import { IGitService, IGitUserInfos } from './interface';
|
import { IGitService, IGitUserInfos } from './interface';
|
||||||
import { defaultGitInfo } from './defaultGitInfo';
|
import { defaultGitInfo } from './defaultGitInfo';
|
||||||
|
import { WikiChannel } from '@/constants/channels';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class Git implements IGitService {
|
export class Git implements IGitService {
|
||||||
|
|
@ -47,15 +48,15 @@ export class Git implements IGitService {
|
||||||
const browserView = await this.viewService.getActiveBrowserView();
|
const browserView = await this.viewService.getActiveBrowserView();
|
||||||
if (browserView !== undefined) {
|
if (browserView !== undefined) {
|
||||||
const tiddlerText = await new Promise((resolve) => {
|
const tiddlerText = await new Promise((resolve) => {
|
||||||
browserView.webContents.send('wiki-get-tiddler-text', '$:/GitHub/Repo');
|
browserView.webContents.send(WikiChannel.getTiddlerText, '$:/GitHub/Repo');
|
||||||
ipcMain.once('wiki-get-tiddler-text-done', (_event, value) => resolve(value));
|
ipcMain.once(WikiChannel.getTiddlerTextDone, (_event, value) => resolve(value));
|
||||||
});
|
});
|
||||||
if (tiddlerText !== githubRepoName) {
|
if (tiddlerText !== githubRepoName) {
|
||||||
await new Promise<void>((resolve) => {
|
await new Promise<void>((resolve) => {
|
||||||
browserView.webContents.send('wiki-add-tiddler', '$:/GitHub/Repo', githubRepoName, {
|
browserView.webContents.send(WikiChannel.addTiddler, '$:/GitHub/Repo', githubRepoName, {
|
||||||
type: 'text/vnd.tiddlywiki',
|
type: 'text/vnd.tiddlywiki',
|
||||||
});
|
});
|
||||||
ipcMain.once('wiki-add-tiddler-done', () => resolve());
|
ipcMain.once(WikiChannel.addTiddlerDone, () => resolve());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ export function buildLanguageMenu(): void {
|
||||||
lng: language,
|
lng: language,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
windowService.sendToAllWindows(I18NChannels.changeLanguageRequest, {
|
await windowService.sendToAllWindows(I18NChannels.changeLanguageRequest, {
|
||||||
lng: language,
|
lng: language,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { ipcMain, IpcMain, IpcMainInvokeEvent } from 'electron';
|
import { ipcMain, IpcMainInvokeEvent } from 'electron';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ export function mainBindings(): void {
|
||||||
const localeFilePath = path.join(LOCALIZATION_FOLDER, readFileArguments.filename);
|
const localeFilePath = path.join(LOCALIZATION_FOLDER, readFileArguments.filename);
|
||||||
const windowService = container.get<IWindowService>(serviceIdentifier.Window);
|
const windowService = container.get<IWindowService>(serviceIdentifier.Window);
|
||||||
fs.readFile(localeFilePath, 'utf8', (error, data) => {
|
fs.readFile(localeFilePath, 'utf8', (error, data) => {
|
||||||
windowService.sendToAllWindows(I18NChannels.readFileResponse, {
|
void windowService.sendToAllWindows(I18NChannels.readFileResponse, {
|
||||||
key: readFileArguments.key,
|
key: readFileArguments.key,
|
||||||
error,
|
error,
|
||||||
data: typeof data !== 'undefined' && data !== null ? data.toString() : '',
|
data: typeof data !== 'undefined' && data !== null ? data.toString() : '',
|
||||||
|
|
@ -37,7 +37,7 @@ export function mainBindings(): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fs.writeFile(localeFilePath, JSON.stringify(writeFileArguments.data), (error: Error) => {
|
fs.writeFile(localeFilePath, JSON.stringify(writeFileArguments.data), (error: Error) => {
|
||||||
windowService.sendToAllWindows(I18NChannels.writeFileResponse, {
|
void windowService.sendToAllWindows(I18NChannels.writeFileResponse, {
|
||||||
keys: writeFileArguments.keys,
|
keys: writeFileArguments.keys,
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import type { IViewService } from '@services/view/interface';
|
||||||
import type { IWindowService } from '@services/windows/interface';
|
import type { IWindowService } from '@services/windows/interface';
|
||||||
import serviceIdentifier from '@services/serviceIdentifier';
|
import serviceIdentifier from '@services/serviceIdentifier';
|
||||||
import { WindowNames } from '@services/windows/WindowProperties';
|
import { WindowNames } from '@services/windows/WindowProperties';
|
||||||
|
import { WikiChannel } from '@/constants/channels';
|
||||||
|
|
||||||
const handlers = {
|
const handlers = {
|
||||||
createWikiProgress: (message: string) => {
|
createWikiProgress: (message: string) => {
|
||||||
|
|
@ -16,7 +17,7 @@ const handlers = {
|
||||||
wikiSyncProgress: async (message: string) => {
|
wikiSyncProgress: async (message: string) => {
|
||||||
const viewService = container.get<IViewService>(serviceIdentifier.View);
|
const viewService = container.get<IViewService>(serviceIdentifier.View);
|
||||||
const browserView = await viewService.getActiveBrowserView();
|
const browserView = await viewService.getActiveBrowserView();
|
||||||
browserView?.webContents?.send('wiki-sync-progress', message);
|
browserView?.webContents?.send(WikiChannel.syncProgress, message);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Menu, MenuItemConstructorOptions, shell, WebContents } from 'electron';
|
import { MenuItemConstructorOptions, WebContents } from 'electron';
|
||||||
|
|
||||||
import { ProxyPropertyType } from '@/helpers/electron-ipc-proxy/common';
|
import { ProxyPropertyType } from '@/helpers/electron-ipc-proxy/common';
|
||||||
import { MenuChannel } from '@/constants/channels';
|
import { MenuChannel } from '@/constants/channels';
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,12 @@ import type { INotificationService } from '@services/notifications/interface';
|
||||||
import { WindowNames } from '@services/windows/WindowProperties';
|
import { WindowNames } from '@services/windows/WindowProperties';
|
||||||
import i18n from '@services/libs/i18n';
|
import i18n from '@services/libs/i18n';
|
||||||
import { IPreferences, IPreferenceService } from './interface';
|
import { IPreferences, IPreferenceService } from './interface';
|
||||||
import { IViewService } from '@services/view/interface';
|
|
||||||
import { defaultPreferences } from './defaultPreferences';
|
import { defaultPreferences } from './defaultPreferences';
|
||||||
import { lazyInject } from '@services/container';
|
import { lazyInject } from '@services/container';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class Preference implements IPreferenceService {
|
export class Preference implements IPreferenceService {
|
||||||
@lazyInject(serviceIdentifier.Window) private readonly windowService!: IWindowService;
|
@lazyInject(serviceIdentifier.Window) private readonly windowService!: IWindowService;
|
||||||
@lazyInject(serviceIdentifier.View) private readonly viewService!: IViewService;
|
|
||||||
@lazyInject(serviceIdentifier.NotificationService) private readonly notificationService!: INotificationService;
|
@lazyInject(serviceIdentifier.NotificationService) private readonly notificationService!: INotificationService;
|
||||||
|
|
||||||
private cachedPreferences: IPreferences;
|
private cachedPreferences: IPreferences;
|
||||||
|
|
@ -82,6 +80,7 @@ export class Preference implements IPreferenceService {
|
||||||
this.cachedPreferences[key] = value;
|
this.cachedPreferences[key] = value;
|
||||||
this.cachedPreferences = { ...this.cachedPreferences, ...this.sanitizePreference(this.cachedPreferences) };
|
this.cachedPreferences = { ...this.cachedPreferences, ...this.sanitizePreference(this.cachedPreferences) };
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
await settings.set(`preferences.${key}`, this.cachedPreferences[key] as any);
|
await settings.set(`preferences.${key}`, this.cachedPreferences[key] as any);
|
||||||
|
|
||||||
this.reactWhenPreferencesChanged(key, value);
|
this.reactWhenPreferencesChanged(key, value);
|
||||||
|
|
@ -107,6 +106,7 @@ export class Preference implements IPreferenceService {
|
||||||
*/
|
*/
|
||||||
private async setPreferences(newPreferences: IPreferences): Promise<void> {
|
private async setPreferences(newPreferences: IPreferences): Promise<void> {
|
||||||
this.cachedPreferences = newPreferences;
|
this.cachedPreferences = newPreferences;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
await settings.set(`preferences`, { ...newPreferences } as any);
|
await settings.set(`preferences`, { ...newPreferences } as any);
|
||||||
this.updatePreferenceSubject();
|
this.updatePreferenceSubject();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||||
/* eslint-disable @typescript-eslint/consistent-type-assertions */
|
/* eslint-disable @typescript-eslint/consistent-type-assertions */
|
||||||
import { app, dialog, shell } from 'electron';
|
import { app, dialog, shell } from 'electron';
|
||||||
import { injectable } from 'inversify';
|
import { injectable } from 'inversify';
|
||||||
|
|
@ -162,38 +163,34 @@ export class Updater implements IUpdaterService {
|
||||||
info: progressObject,
|
info: progressObject,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
autoUpdater.on('update-downloaded', (info: UpdateInfo) => {
|
autoUpdater.on('update-downloaded', async (info: UpdateInfo) => {
|
||||||
const mainWindow = this.windowService.get(WindowNames.main);
|
const mainWindow = this.windowService.get(WindowNames.main);
|
||||||
if (mainWindow !== undefined) {
|
if (mainWindow !== undefined) {
|
||||||
this.setMetaData({
|
this.setMetaData({
|
||||||
status: 'update-downloaded',
|
status: 'update-downloaded',
|
||||||
info,
|
info,
|
||||||
});
|
});
|
||||||
dialog
|
const { response } = await dialog.showMessageBox(mainWindow, {
|
||||||
.showMessageBox(mainWindow, {
|
|
||||||
type: 'info',
|
type: 'info',
|
||||||
buttons: ['Restart', 'Later'],
|
buttons: ['Restart', 'Later'],
|
||||||
title: 'Application Update',
|
title: 'Application Update',
|
||||||
message: `A new version (${info.version}) has been downloaded. Restart the application to apply the updates.`,
|
message: `A new version (${info.version}) has been downloaded. Restart the application to apply the updates.`,
|
||||||
cancelId: 1,
|
cancelId: 1,
|
||||||
})
|
});
|
||||||
.then(({ response }) => {
|
|
||||||
if (response === 0) {
|
if (response === 0) {
|
||||||
// Fix autoUpdater.quitAndInstall() does not quit immediately
|
// Fix autoUpdater.quitAndInstall() does not quit immediately
|
||||||
// https://github.com/electron/electron/issues/3583
|
// https://github.com/electron/electron/issues/3583
|
||||||
// https://github.com/electron-userland/electron-builder/issues/1604
|
// https://github.com/electron-userland/electron-builder/issues/1604
|
||||||
setImmediate(() => {
|
setImmediate(async () => {
|
||||||
app.removeAllListeners(MainChannel.windowAllClosed);
|
app.removeAllListeners(MainChannel.windowAllClosed);
|
||||||
const mainWindow = this.windowService.get(WindowNames.main);
|
const mainWindow = this.windowService.get(WindowNames.main);
|
||||||
if (mainWindow !== undefined) {
|
if (mainWindow !== undefined) {
|
||||||
this.windowService.updateWindowMeta(WindowNames.main, { forceClose: true });
|
await this.windowService.updateWindowMeta(WindowNames.main, { forceClose: true });
|
||||||
mainWindow.close();
|
mainWindow.close();
|
||||||
}
|
}
|
||||||
autoUpdater.quitAndInstall(false);
|
autoUpdater.quitAndInstall(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.catch(console.log);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import { lazyInject } from '@services/container';
|
||||||
import { TIDDLYWIKI_TEMPLATE_FOLDER_PATH, TIDDLERS_PATH } from '@/constants/paths';
|
import { TIDDLYWIKI_TEMPLATE_FOLDER_PATH, TIDDLERS_PATH } from '@/constants/paths';
|
||||||
import { updateSubWikiPluginContent, getSubWikiPluginContent, ISubWikiPluginContent } from './update-plugin-content';
|
import { updateSubWikiPluginContent, getSubWikiPluginContent, ISubWikiPluginContent } from './update-plugin-content';
|
||||||
import { IWikiService } from './interface';
|
import { IWikiService } from './interface';
|
||||||
|
import { WikiChannel } from '@/constants/channels';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class Wiki implements IWikiService {
|
export class Wiki implements IWikiService {
|
||||||
|
|
@ -42,14 +43,14 @@ export class Wiki implements IWikiService {
|
||||||
public async requestOpenTiddlerInWiki(tiddlerName: string): Promise<void> {
|
public async requestOpenTiddlerInWiki(tiddlerName: string): Promise<void> {
|
||||||
const browserView = await this.viewService.getActiveBrowserView();
|
const browserView = await this.viewService.getActiveBrowserView();
|
||||||
if (browserView !== undefined) {
|
if (browserView !== undefined) {
|
||||||
browserView.webContents.send('wiki-open-tiddler', tiddlerName);
|
browserView.webContents.send(WikiChannel.openTiddler, tiddlerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async requestWikiSendActionMessage(actionMessage: string): Promise<void> {
|
public async requestWikiSendActionMessage(actionMessage: string): Promise<void> {
|
||||||
const browserView = await this.viewService.getActiveBrowserView();
|
const browserView = await this.viewService.getActiveBrowserView();
|
||||||
if (browserView !== undefined) {
|
if (browserView !== undefined) {
|
||||||
browserView.webContents.send('wiki-send-action-message', actionMessage);
|
browserView.webContents.send(WikiChannel.sendActionMessage, actionMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ export interface IWikiService {
|
||||||
stopAllWiki(): Promise<void>;
|
stopAllWiki(): Promise<void>;
|
||||||
copyWikiTemplate(newFolderPath: string, folderName: string): Promise<string>;
|
copyWikiTemplate(newFolderPath: string, folderName: string): Promise<string>;
|
||||||
getSubWikiPluginContent(mainWikiPath: string): Promise<ISubWikiPluginContent[]>;
|
getSubWikiPluginContent(mainWikiPath: string): Promise<ISubWikiPluginContent[]>;
|
||||||
|
/** send tiddlywiki action message to current active wiki */
|
||||||
requestWikiSendActionMessage(actionMessage: string): Promise<void>;
|
requestWikiSendActionMessage(actionMessage: string): Promise<void>;
|
||||||
requestOpenTiddlerInWiki(tiddlerName: string): Promise<void>;
|
requestOpenTiddlerInWiki(tiddlerName: string): Promise<void>;
|
||||||
linkWiki(mainWikiPath: string, folderName: string, subWikiPath: string): Promise<void>;
|
linkWiki(mainWikiPath: string, folderName: string, subWikiPath: string): Promise<void>;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||||
|
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
const { workerData, parentPort, isMainThread } = require('worker_threads');
|
const { workerData, parentPort, isMainThread } = require('worker_threads');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const $tw = require('@tiddlygit/tiddlywiki').TiddlyWiki();
|
const $tw = require('@tiddlygit/tiddlywiki').TiddlyWiki();
|
||||||
|
|
@ -29,7 +35,7 @@ module.exports = startNodeJSWiki;
|
||||||
|
|
||||||
if (!isMainThread) {
|
if (!isMainThread) {
|
||||||
startNodeJSWiki();
|
startNodeJSWiki();
|
||||||
parentPort.once('message', async (message) => {
|
parentPort.once('message', (message) => {
|
||||||
if (typeof message === 'object' && message.type === 'command' && message.message === 'exit') {
|
if (typeof message === 'object' && message.type === 'command' && message.message === 'exit') {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,5 +19,5 @@
|
||||||
"./*.json",
|
"./*.json",
|
||||||
"./*.js"
|
"./*.js"
|
||||||
],
|
],
|
||||||
"exclude": ["template/**/*.js", "src/services/libs/i18n/i18next-electron-fs-backend.ts"]
|
"exclude": ["template/**/*.js", "src/services/libs/i18n/i18next-electron-fs-backend.ts", "src/services/wiki/wiki-worker.js"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue