Files
Electron.NET/ElectronNET.Host/api/shell.ts

65 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-12-13 17:33:00 +01:00
import {Socket} from 'net';
import {shell} from 'electron';
let electronSocket;
export = (socket: Socket) => {
electronSocket = socket;
socket.on('shell-showItemInFolder', (fullPath) => {
shell.showItemInFolder(fullPath);
electronSocket.emit('shell-showItemInFolderCompleted');
});
socket.on('shell-openPath', async (path) => {
const errorMessage = await shell.openPath(path);
electronSocket.emit('shell-openPathCompleted', errorMessage);
2020-05-26 15:09:47 +02:00
});
socket.on('shell-openExternal', async (url, options) => {
let result = '';
2019-05-16 03:13:35 +02:00
if (options) {
await shell.openExternal(url, options).catch(e => {
result = e.message;
});
} else {
await shell.openExternal(url).catch((e) => {
result = e.message;
2019-05-16 03:13:35 +02:00
});
}
electronSocket.emit('shell-openExternalCompleted', result);
});
socket.on('shell-trashItem', async (fullPath, deleteOnFail) => {
let success = false;
try {
await shell.trashItem(fullPath);
success = true;
} catch (error) {
2021-12-13 17:33:00 +01:00
success = false;
}
electronSocket.emit('shell-trashItem-completed', success);
});
socket.on('shell-beep', () => {
shell.beep();
});
socket.on('shell-writeShortcutLink', (shortcutPath, operation, options) => {
const success = shell.writeShortcutLink(shortcutPath, operation, options);
electronSocket.emit('shell-writeShortcutLinkCompleted', success);
});
socket.on('shell-readShortcutLink', (shortcutPath) => {
const shortcutDetails = shell.readShortcutLink(shortcutPath);
electronSocket.emit('shell-readShortcutLinkCompleted', shortcutDetails);
});
};