2021-02-16 07:23:15 +03:00
|
|
|
import { invoke } from './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
|
|
|
|
*/
|
|
|
|
async function execute(
|
|
|
|
command: string,
|
|
|
|
args?: string | string[]
|
|
|
|
): Promise<string> {
|
|
|
|
if (typeof args === 'object') {
|
|
|
|
Object.freeze(args)
|
|
|
|
}
|
|
|
|
|
2021-02-17 06:38:18 +03:00
|
|
|
return invoke<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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* opens an URL on the user default browser
|
|
|
|
*
|
|
|
|
* @param url the URL to open
|
|
|
|
*/
|
2021-02-16 07:23:15 +03:00
|
|
|
async function open(url: string): Promise<void> {
|
2021-02-17 06:38:18 +03:00
|
|
|
return invoke({
|
2021-02-16 07:23:15 +03:00
|
|
|
__tauriModule: 'Shell',
|
2021-02-12 08:42:40 +03:00
|
|
|
message: {
|
|
|
|
cmd: 'open',
|
|
|
|
uri: url
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export { execute, open }
|