diff --git a/.eslintrc.js b/.eslintrc.js index 9c5bd12a..3579d6c0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -51,10 +51,7 @@ module.exports = { '@typescript-eslint/no-misused-promises': [ 'error', { - checksVoidReturn: { - arguments: false, - attributes: false, - }, + checksVoidReturn: false, }, ], 'react/react-in-jsx-scope': 'off', diff --git a/src/constants/urls.ts b/src/constants/urls.ts index 6f7dd625..039ec1b4 100644 --- a/src/constants/urls.ts +++ b/src/constants/urls.ts @@ -4,3 +4,7 @@ export const defaultServerIP = '0.0.0.0'; export const latestStableUpdateUrl = 'https://github.com/tiddly-gittly/TidGi-Desktop/releases/latest'; export const githubDesktopUrl = 'https://desktop.github.com/'; +/** https://tiddlywiki.com/#SafeMode + * This is currently unused, because it always entering /#safe:safe , very annoying. And even entered, the url can still not containing this. So I decided not support enter/quit safe mode now. + */ +export const safeModeHash = '#:safe'; diff --git a/src/services/native/index.ts b/src/services/native/index.ts index 3f64bef1..8db02ca2 100644 --- a/src/services/native/index.ts +++ b/src/services/native/index.ts @@ -17,6 +17,7 @@ import { IZxFileInput } from '@services/wiki/wikiWorker'; import { ZxNotInitializedError } from './error'; import { lazyInject } from '@services/container'; import i18next from 'i18next'; +import { getLocalHostUrlWithActualIP } from '@services/libs/url'; @injectable() export class NativeService implements INativeService { @@ -154,4 +155,8 @@ ${message.message} public async openNewGitHubIssue(error: Error): Promise { reportErrorToGithubWithTemplates(error); } + + public async getLocalHostUrlWithActualIP(url: string): Promise { + return await getLocalHostUrlWithActualIP(url); + } } diff --git a/src/services/native/interface.ts b/src/services/native/interface.ts index 932a96ce..e9e41774 100644 --- a/src/services/native/interface.ts +++ b/src/services/native/interface.ts @@ -16,6 +16,7 @@ export interface INativeService { * @param wikiFolderLocation Each wiki has its own worker, we use wiki's folder path to determine which worker to use. If not provided, will use current active workspace's wiki's path */ executeZxScript$(zxWorkerArguments: IZxFileInput, wikiFolderLocation?: string): Observable; + getLocalHostUrlWithActualIP(url: string): Promise; log(level: string, message: string, meta?: Record): Promise; open(uri: string, isDirectory?: boolean): Promise; openInEditor(filePath: string, editorName?: string | undefined): Promise; @@ -30,6 +31,7 @@ export const NativeServiceIPCDescriptor = { channel: NativeChannel.name, properties: { executeZxScript$: ProxyPropertyType.Function$, + getLocalHostUrlWithActualIP: ProxyPropertyType.Function, log: ProxyPropertyType.Function, open: ProxyPropertyType.Function, openInEditor: ProxyPropertyType.Function, diff --git a/src/services/view/index.ts b/src/services/view/index.ts index 531cd16b..aa199de9 100644 --- a/src/services/view/index.ts +++ b/src/services/view/index.ts @@ -472,6 +472,18 @@ export class View implements IViewService { }); } + public async getViewCurrentUrl(workspaceID?: string): Promise { + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (!workspaceID) { + return; + } + const view = this.getView(workspaceID, WindowNames.main); + if (view === undefined) { + return; + } + return view.webContents.getURL(); + } + public async getActiveBrowserView(): Promise { const workspace = await this.workspaceService.getActiveWorkspace(); const isMenubarOpen = await this.windowService.isMenubarOpen(); diff --git a/src/services/view/interface.ts b/src/services/view/interface.ts index 12254099..80484f6c 100644 --- a/src/services/view/interface.ts +++ b/src/services/view/interface.ts @@ -27,6 +27,7 @@ export interface IViewService { getAllViewOfWorkspace: (workspaceID: string) => BrowserView[]; getView: (workspaceID: string, windowName: WindowNames) => BrowserView | undefined; getViewCount(): Promise; + getViewCurrentUrl(workspaceID?: string): Promise; realignActiveView: (browserWindow: BrowserWindow, activeId: string) => Promise; reloadActiveBrowserView: () => Promise; reloadViewsWebContents(workspaceID?: string | undefined): Promise; @@ -49,6 +50,7 @@ export const ViewServiceIPCDescriptor = { getAllViewOfWorkspace: ProxyPropertyType.Function, getView: ProxyPropertyType.Function, getViewCount: ProxyPropertyType.Function, + getViewCurrentUrl: ProxyPropertyType.Function, realignActiveView: ProxyPropertyType.Function, reloadActiveBrowserView: ProxyPropertyType.Function, reloadViewsWebContents: ProxyPropertyType.Function, diff --git a/src/services/workspaces/getWorkspaceMenuTemplate.ts b/src/services/workspaces/getWorkspaceMenuTemplate.ts index 90ab7377..e17d7124 100644 --- a/src/services/workspaces/getWorkspaceMenuTemplate.ts +++ b/src/services/workspaces/getWorkspaceMenuTemplate.ts @@ -17,15 +17,20 @@ interface IWorkspaceMenuRequiredServices { auth: Pick; context: Pick; git: Pick; - native: Pick; - view: Pick; + native: Pick; + view: Pick; wiki: Pick; wikiGitWorkspace: Pick; window: Pick; workspace: Pick; workspaceView: Pick< IWorkspaceViewService, - 'wakeUpWorkspaceView' | 'hibernateWorkspaceView' | 'setActiveWorkspaceView' | 'restartWorkspaceViewService' | 'realignActiveWorkspace' + | 'wakeUpWorkspaceView' + | 'hibernateWorkspaceView' + | 'setActiveWorkspaceView' + | 'restartWorkspaceViewService' + | 'realignActiveWorkspace' + | 'openUrlInWorkspace' >; } diff --git a/src/services/workspacesView/interface.ts b/src/services/workspacesView/interface.ts index d2082f03..5bed1303 100644 --- a/src/services/workspacesView/interface.ts +++ b/src/services/workspacesView/interface.ts @@ -33,6 +33,11 @@ export interface IWorkspaceViewService { * @param id workspace id, if omit, will load url in active workspace if existed */ loadURL(url: string, workspaceID?: string): Promise; + /** + * Open url, and if id is valid, we will switch to that workspace first + * @param url + * @param workspaceID + */ openUrlInWorkspace(url: string, workspaceID: string): Promise; printTiddler(tiddlerName?: string | undefined): Promise; realignActiveWorkspace(id?: string): Promise;