Delete and rename handlers
This commit is contained in:
parent
99ec82795c
commit
6030a78b91
|
@ -112,6 +112,28 @@ class Comms {
|
||||||
BDIpc.on('bd-getPath', (event, paths) => {
|
BDIpc.on('bd-getPath', (event, paths) => {
|
||||||
event.reply(path.resolve(this.bd.config.getPath(paths[0]), ...paths.splice(1)));
|
event.reply(path.resolve(this.bd.config.getPath(paths[0]), ...paths.splice(1)));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
BDIpc.on('bd-rmFile', async (event, paths) => {
|
||||||
|
const fullPath = path.resolve(this.bd.config.getPath(paths[0]), ...paths.splice(1));
|
||||||
|
try {
|
||||||
|
await FileUtils.rm(fullPath);
|
||||||
|
event.reply('ok');
|
||||||
|
} catch (err) {
|
||||||
|
event.reject(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
BDIpc.on('bd-rnFile', async (event, paths) => {
|
||||||
|
const oldPath = path.resolve(this.bd.config.getPath(paths.oldName[0]), ...paths.oldName.splice(1));
|
||||||
|
const newPath = path.resolve(this.bd.config.getPath(paths.newName[0]), ...paths.newName.splice(1));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await FileUtils.rn(oldPath, newPath);
|
||||||
|
event.reply('ok');
|
||||||
|
} catch (err) {
|
||||||
|
event.reject(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async send(channel, message) {
|
async send(channel, message) {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// TODO Use common
|
// TODO Use common
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import rimraf from 'rimraf';
|
||||||
|
|
||||||
import Module from './modulebase';
|
import Module from './modulebase';
|
||||||
import BDIpc from './bdipc';
|
import BDIpc from './bdipc';
|
||||||
|
@ -164,6 +165,27 @@ export class FileUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async rm(path) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
rimraf(path, err => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static async rn(oldPath, newPath) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.rename(oldPath, newPath, err => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WindowUtils extends Module {
|
export class WindowUtils extends Module {
|
||||||
|
|
|
@ -214,6 +214,33 @@
|
||||||
remote.clipboard.writeText(fullPath);
|
remote.clipboard.writeText(fullPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action === 'rename') { // TODO select correct file after
|
||||||
|
this.loading = true;
|
||||||
|
const { oldName, newName } = item;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await ClientIPC.send('rnFile', { oldName: ['userfiles', oldName], newName: ['userfiles', newName] });
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action === 'delete') {
|
||||||
|
this.loading = true;
|
||||||
|
try {
|
||||||
|
await ClientIPC.send('rmFile', ['userfiles', item.name]);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleLiveUpdate(item) {
|
toggleLiveUpdate(item) {
|
||||||
|
|
Loading…
Reference in New Issue