2021-03-07 05:19:12 +03:00
|
|
|
import { invokeTauriCommand } from './helpers/tauri'
|
2021-02-12 08:42:40 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* spawns a process
|
|
|
|
*
|
|
|
|
* @param command the name of the cmd to execute e.g. 'mkdir' or 'node'
|
|
|
|
* @param [args] command args
|
|
|
|
* @return promise resolving to the stdout text
|
|
|
|
*/
|
2021-03-10 07:20:54 +03:00
|
|
|
async function execute (
|
2021-02-12 08:42:40 +03:00
|
|
|
command: string,
|
|
|
|
args?: string | string[]
|
|
|
|
): Promise<string> {
|
|
|
|
if (typeof args === 'object') {
|
|
|
|
Object.freeze(args)
|
|
|
|
}
|
|
|
|
|
2021-03-07 05:19:12 +03:00
|
|
|
return invokeTauriCommand<string>({
|
2021-02-16 07:23:15 +03:00
|
|
|
__tauriModule: 'Shell',
|
2021-02-12 08:42:40 +03:00
|
|
|
message: {
|
|
|
|
cmd: 'execute',
|
|
|
|
command,
|
|
|
|
args: typeof args === 'string' ? [args] : args
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-10 07:20:54 +03:00
|
|
|
* opens a path or URL with the system's default app,
|
|
|
|
* or the one specified with `openWith`
|
2021-02-12 08:42:40 +03:00
|
|
|
*
|
2021-03-10 07:20:54 +03:00
|
|
|
* @param path the path or URL to open
|
|
|
|
* @param openWith the app to open the file or URL with
|
2021-02-12 08:42:40 +03:00
|
|
|
*/
|
2021-03-10 07:20:54 +03:00
|
|
|
async function open (path: string, openWith?: string): Promise<void> {
|
2021-03-07 05:19:12 +03:00
|
|
|
return invokeTauriCommand({
|
2021-02-16 07:23:15 +03:00
|
|
|
__tauriModule: 'Shell',
|
2021-02-12 08:42:40 +03:00
|
|
|
message: {
|
|
|
|
cmd: 'open',
|
2021-03-10 07:20:54 +03:00
|
|
|
path,
|
|
|
|
with: openWith
|
2021-02-12 08:42:40 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export { execute, open }
|