diff --git a/src/renderer/services/base.ts b/src/renderer/services/base.ts index a5b627ef..92b24394 100644 --- a/src/renderer/services/base.ts +++ b/src/renderer/services/base.ts @@ -3,7 +3,7 @@ import type { Doc } from '@fe/types' import * as api from '@fe/support/api' import { getSettings } from './setting' import { FLAG_DEMO } from '@fe/support/args' -import { binMd5, fileToBase64URL, getLogger } from '@fe/utils' +import { binMd5, quote, fileToBase64URL, getLogger } from '@fe/utils' import { basename, resolve, extname, dirname, relative } from '@fe/utils/path' import { dayjs } from '@fe/context/lib' import { useModal } from '@fe/support/ui/modal' @@ -66,3 +66,19 @@ export async function inputPassword (title: string, hint: string, throwError = f return password } + +/** + * open an external uri + * @param uri + */ +export async function openExternal (uri: string) { + api.rpc(`require('electron').shell.openExternal(${quote(uri)})`) +} + +/** + * open a path + * @param uri + */ +export async function openPath (path: string) { + api.rpc(`require('electron').shell.openPath(${quote(path)})`) +} diff --git a/src/renderer/utils/index.ts b/src/renderer/utils/index.ts index 511fbdc6..d258027f 100644 --- a/src/renderer/utils/index.ts +++ b/src/renderer/utils/index.ts @@ -7,6 +7,15 @@ export * as path from './path' export * as storage from './storage' export * as crypto from './crypto' +/** + * quote string + * @param str + * @param quote + */ +export function quote (str: string, quote = '`') { + return quote + str.replaceAll(quote, '\\' + quote) + quote +} + export const encodeMarkdownLink = (path: string) => { return path .replace(/\(/g, '%28')