87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
// Open file chooser to select a source directory
|
|
app.ports.selectSourceDirectory.subscribe(function (directoryName, title) {
|
|
window.go.main.App.SelectDirectory(directoryName, title)
|
|
.then((result) => {
|
|
app.ports.receiveSelectedSourceDirectory.send(result);
|
|
})
|
|
.catch((msg) => {
|
|
console.error(msg);
|
|
app.ports.receiveError.send(msg);
|
|
});
|
|
});
|
|
|
|
// Open file chooser to select a destination directory
|
|
app.ports.selectDestinationDirectory.subscribe(function (directoryName, title) {
|
|
window.go.main.App.SelectDirectory(directoryName, title)
|
|
.then((result) => {
|
|
app.ports.receiveSelectedDestinationDirectory.send(result);
|
|
})
|
|
.catch((msg) => {
|
|
console.error(msg);
|
|
app.ports.receiveError.send(msg);
|
|
});
|
|
});
|
|
|
|
// Moves a list of files to the given directory
|
|
app.ports.moveFiles.subscribe(function (params) {
|
|
let sourceFiles = params[0];
|
|
let directoryName = params[1];
|
|
console.log("move", params);
|
|
window.go.main.App.Move(sourceFiles, directoryName)
|
|
.then((result) => {
|
|
app.ports.receiveMovedFiles.send(result);
|
|
})
|
|
.catch((msg) => {
|
|
console.error(msg);
|
|
app.ports.receiveError.send(msg);
|
|
});
|
|
});
|
|
|
|
// Rename multiple files
|
|
app.ports.renameFiles.subscribe(function (renamings) {
|
|
window.go.main.App.Rename(renamings)
|
|
.then((result) => {
|
|
app.ports.filesRenamed.send(result);
|
|
})
|
|
.catch((msg) => {
|
|
console.error(msg);
|
|
app.ports.receiveError.send(msg);
|
|
});
|
|
});
|
|
|
|
// Delete a file
|
|
app.ports.removeFile.subscribe(function (filePath) {
|
|
window.go.main.App.Remove(filePath)
|
|
.then((result) => {
|
|
app.ports.fileRemoved.send(result);
|
|
})
|
|
.catch((msg) => {
|
|
console.error(msg);
|
|
app.ports.receiveError.send(msg);
|
|
});
|
|
});
|
|
|
|
// Open a file using the default app
|
|
app.ports.openFile.subscribe(function (filePath) {
|
|
window.go.main.App.OpenFile(filePath).catch((msg) => {
|
|
console.error(msg);
|
|
app.ports.receiveError.send(msg);
|
|
});
|
|
});
|
|
|
|
// Create a directory
|
|
app.ports.createDirectory.subscribe(function (dirPath) {
|
|
window.go.main.App.CreateDirectory(dirPath)
|
|
.then((result) => {
|
|
app.ports.receiveCreatedDirectory.send(result);
|
|
})
|
|
.catch((msg) => {
|
|
console.error(msg);
|
|
app.ports.receiveError.send(msg);
|
|
});
|
|
});
|
|
|
|
// Quit the app
|
|
app.ports.quit.subscribe(function () {
|
|
window.go.main.App.Exit();
|
|
});
|