mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-03-20 13:50:37 -07:00
feat: add moveToTrash for external-attachment plugin
This commit is contained in:
parent
1aecc6094f
commit
e89d70677b
2 changed files with 22 additions and 1 deletions
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
import { app, dialog, ipcMain, MessageBoxOptions, shell } from 'electron';
|
||||
import fs from 'fs-extra';
|
||||
|
|
@ -278,6 +277,21 @@ ${message.message}
|
|||
}
|
||||
}
|
||||
|
||||
public async moveToTrash(filePath: string): Promise<boolean> {
|
||||
if (!filePath) {
|
||||
logger.error('NativeService.moveToTrash() filePath is empty', { filePath });
|
||||
return false;
|
||||
}
|
||||
logger.debug(`NativeService.moveToTrash() Moving to trash: ${filePath}`);
|
||||
try {
|
||||
await shell.trashItem(filePath);
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.error('NativeService.moveToTrash() failed', { error, filePath });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public formatFileUrlToAbsolutePath(urlWithFileProtocol: string): string {
|
||||
logger.info('getting url', { url: urlWithFileProtocol, function: 'formatFileUrlToAbsolutePath' });
|
||||
let pathname = '';
|
||||
|
|
|
|||
|
|
@ -70,6 +70,12 @@ export interface INativeService {
|
|||
path(method: 'basename' | 'dirname' | 'join', pathString: string | undefined, ...paths: string[]): Promise<string | undefined>;
|
||||
pickDirectory(defaultPath?: string, options?: IPickDirectoryOptions): Promise<string[]>;
|
||||
pickFile(filters?: Electron.OpenDialogOptions['filters']): Promise<string[]>;
|
||||
/**
|
||||
* Move a file or directory to the trash bin.
|
||||
* @param filePath The absolute path of the file or directory to move to the trash.
|
||||
* @returns A promise that resolves to true if the operation was successful, false otherwise.
|
||||
*/
|
||||
moveToTrash(filePath: string): Promise<boolean>;
|
||||
quit(): void;
|
||||
showElectronMessageBox(options: Electron.MessageBoxOptions, windowName?: WindowNames): Promise<Electron.MessageBoxReturnValue | undefined>;
|
||||
/**
|
||||
|
|
@ -92,6 +98,7 @@ export const NativeServiceIPCDescriptor = {
|
|||
log: ProxyPropertyType.Function,
|
||||
mkdir: ProxyPropertyType.Function,
|
||||
movePath: ProxyPropertyType.Function,
|
||||
moveToTrash: ProxyPropertyType.Function,
|
||||
open: ProxyPropertyType.Function,
|
||||
openInEditor: ProxyPropertyType.Function,
|
||||
openInGitGuiApp: ProxyPropertyType.Function,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue