feat(plugin): add ctx.base.openExternal ctx.base.openPath methods

This commit is contained in:
purocean
2021-12-09 16:08:46 +08:00
parent 45fe27014e
commit 7fa995da77
2 changed files with 26 additions and 1 deletions
+17 -1
View File
@@ -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)})`)
}
+9
View File
@@ -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')