mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-15 15:10:31 -08:00
feat: dragging import support auto copy file to wiki folder
This commit is contained in:
parent
b91cd5879d
commit
ecf64e3c86
4 changed files with 37 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { NativeChannel, ViewChannel, WindowChannel } from '@/constants/channels';
|
||||
import { rendererMenuItemProxy } from '@services/menu/contextMenu/rendererMenuItemProxy';
|
||||
import { IOnContextMenuInfo } from '@services/menu/interface';
|
||||
import { contextBridge, ipcRenderer, MenuItemConstructorOptions, webFrame } from 'electron';
|
||||
import { contextBridge, ipcRenderer, MenuItemConstructorOptions, webFrame, webUtils } from 'electron';
|
||||
|
||||
import { WindowNames } from '@services/windows/WindowProperties';
|
||||
import { windowName } from './browserViewMetaData';
|
||||
|
|
@ -41,6 +41,7 @@ export const remoteMethods = {
|
|||
}
|
||||
return -1;
|
||||
},
|
||||
getPathForFile: (file: File) => webUtils.getPathForFile(file),
|
||||
};
|
||||
contextBridge.exposeInMainWorld('remote', remoteMethods);
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,29 @@ export class NativeService implements INativeService {
|
|||
return toFilePath;
|
||||
}
|
||||
|
||||
public async movePath(fromFilePath: string, toFilePath: string, options?: { fileToDir?: boolean }): Promise<false | string> {
|
||||
if (!fromFilePath.trim() || !toFilePath.trim()) {
|
||||
logger.error('NativeService.movePath() fromFilePath or toFilePath is empty', { fromFilePath, toFilePath });
|
||||
return false;
|
||||
}
|
||||
if (!(await fs.exists(fromFilePath))) {
|
||||
logger.error('NativeService.movePath() fromFilePath not exists', { fromFilePath, toFilePath });
|
||||
return false;
|
||||
}
|
||||
logger.debug(`NativeService.movePath() move from ${fromFilePath} to ${toFilePath}`, options);
|
||||
try {
|
||||
if (options?.fileToDir === true) {
|
||||
const folderPath = path.dirname(toFilePath);
|
||||
await fs.ensureDir(folderPath);
|
||||
}
|
||||
await fs.move(fromFilePath, toFilePath);
|
||||
return toFilePath;
|
||||
} catch (error) {
|
||||
logger.error('NativeService.movePath() failed', { error });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public executeZxScript$(zxWorkerArguments: IZxFileInput, workspaceID?: string): Observable<string> {
|
||||
const zxWorker = this.wikiService.getWorker(workspaceID ?? this.workspaceService.getActiveWorkspaceSync()?.id ?? '');
|
||||
if (zxWorker === undefined) {
|
||||
|
|
|
|||
|
|
@ -44,6 +44,14 @@ export interface INativeService {
|
|||
getLocalHostUrlWithActualInfo(urlToReplace: string, workspaceID: string): Promise<string>;
|
||||
log(level: string, message: string, meta?: Record<string, unknown>): Promise<void>;
|
||||
mkdir(absoulutePath: string): Promise<void>;
|
||||
/**
|
||||
* Move a file or directory. The directory can have contents.
|
||||
* @param fromFilePath Note that if src is a directory it will copy everything inside of this directory, not the entire directory itself (see fs.extra issue #537).
|
||||
* @param toFilePath Note that if src is a file, dest cannot be a directory (see fs.extra issue #323). (but you can set `options.fileToDir` to true)
|
||||
* @param options.fileToDir true means dest is a directory, create if not exist
|
||||
* @returns false if failed. If success, returns the absolute path of the copied file or directory.
|
||||
*/
|
||||
movePath(fromFilePath: string, toFilePath: string, options?: { fileToDir?: boolean }): Promise<false | string>;
|
||||
openInEditor(filePath: string, editorName?: string | undefined): Promise<boolean>;
|
||||
openInGitGuiApp(filePath: string, editorName?: string | undefined): Promise<boolean>;
|
||||
openNewGitHubIssue(error: Error): Promise<void>;
|
||||
|
|
@ -79,16 +87,17 @@ export const NativeServiceIPCDescriptor = {
|
|||
properties: {
|
||||
copyPath: ProxyPropertyType.Function,
|
||||
executeZxScript$: ProxyPropertyType.Function$,
|
||||
formatFileUrlToAbsolutePath: ProxyPropertyType.Function,
|
||||
getLocalHostUrlWithActualInfo: ProxyPropertyType.Function,
|
||||
log: ProxyPropertyType.Function,
|
||||
open: ProxyPropertyType.Function,
|
||||
mkdir: ProxyPropertyType.Function,
|
||||
movePath: ProxyPropertyType.Function,
|
||||
open: ProxyPropertyType.Function,
|
||||
openInEditor: ProxyPropertyType.Function,
|
||||
openInGitGuiApp: ProxyPropertyType.Function,
|
||||
openNewGitHubIssue: ProxyPropertyType.Function,
|
||||
openPath: ProxyPropertyType.Function,
|
||||
openURI: ProxyPropertyType.Function,
|
||||
formatFileUrlToAbsolutePath: ProxyPropertyType.Function,
|
||||
path: ProxyPropertyType.Function,
|
||||
pickDirectory: ProxyPropertyType.Function,
|
||||
pickFile: ProxyPropertyType.Function,
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 2866320a926f71691470c443d26df350c83ffa58
|
||||
Subproject commit 03fef65e5b08dda4c9d07d4a50be131c7afc4ce2
|
||||
Loading…
Add table
Add a link
Reference in a new issue