Skip to content

Commit

Permalink
Fix MSP and add immortal delete file support
Browse files Browse the repository at this point in the history
  • Loading branch information
icewolfz committed Jul 2, 2017
1 parent b8c4b4a commit 8814476
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 14 deletions.
77 changes: 64 additions & 13 deletions build/immortal.html
Expand Up @@ -24,7 +24,7 @@
<script>
//cSpell:ignore hellip vscroll hscroll ungroup crosshairs haspopup tablist tabpanel labelledby
const { IED, fileInfo, } = require('./js/ied');
const { IEDError, TempType } = require('./js/types');
const { IEDError, TempType, IEDCmdStatus } = require('./js/types');
const { remote, ipcRenderer, shell } = require('electron');
const { app, nativeImage, dialog, Menu, MenuItem } = remote;
const { parseTemplate } = require('./js/library');
Expand Down Expand Up @@ -140,6 +140,7 @@
label: '&Delete',
enabled: false,
accelerator: "CmdOrCtrl+Delete",
click: deleteLocal
},
/*
{
Expand Down Expand Up @@ -1050,7 +1051,6 @@
remoteTable.row.add(_remote[path.basename(item.remote)]).draw();
info.uploads--;
}
info.downloads--;
updateStatus();
}
});
Expand All @@ -1067,6 +1067,32 @@
}).draw();
});

_ied.on('cmd', (data) => {
if (data.cmd == "rm") {
if (data.code == IEDCmdStatus.success) {
logMessage(`Deleted: ${obj.path}/${obj.file}`);

var row = remoteTable.row(function (idx, data, node) {
return data.name == path.basename(data.file) ?
true : false;
});
delete _remote[data.file];
if (row && row.length == 1)
row.remove();
info.remotefiles--;
updateStatus();
}
else {
logMessage(`Failed to delete: ${obj.path}/${obj.file}`);
dialog.showMessageBox(remote.getCurrentWindow(), {
type: 'error',
title: "Could not delete",
message: "Could not delete: " + obj.path + "/" + obj.file,
});
}
}
});

localTable = $('#local-list').DataTable();
remoteTable = $('#remote-list').DataTable();
queueTable = $('#queue-list').DataTable();
Expand Down Expand Up @@ -1299,22 +1325,25 @@
event.preventDefault();
}
break;
/*
case 46:
if (!event.altKey && !event.ctrlKey && !event.shiftKey && !event.metaKey) {
console.log("Delete");
event.preventDefault();
}
break;
*/
case 46:
if (!event.altKey && !event.ctrlKey && !event.shiftKey && !event.metaKey) {
if ($("#local-list").hasClass("focused"))
deleteLocal()
else if ($("#remote-list").hasClass("focused"))
deleteRemote()
//else if ($("#queue-list").hasClass("focused"))
//queueTable.rows().select();
event.preventDefault();
}
break;
case 65://select all, hack as menu acceleartor doenst work
if (!event.altKey && event.ctrlKey && !event.shiftKey && !event.metaKey) {
//if ($("#local-list").hasClass("focused"))
localTable.rows().select();
localTable.rows().select();
//else if ($("#remote-list").hasClass("focused"))
//remoteTable.rows().select();
//remoteTable.rows().select();
//else if ($("#queue-list").hasClass("focused"))
//queueTable.rows().select();
//queueTable.rows().select();
event.preventDefault();
}
break;
Expand Down Expand Up @@ -1563,6 +1592,28 @@
updateStatus();
}

function deleteLocal() {
var data = localTable.rows({ selected: true }).data().pluck('path');
for (var d = 0, dl = data.length; d < dl; d++)
shell.moveItemToTrash(data[d]);
}

function deleteRemote() {
var data = localTable.rows({ selected: true }).data();
dialog.showMessageBox(remote.getCurrentWindow(), {
type: 'warning',
title: "Delete?",
message: data.length > 1 ? "Delete remote files?" : "Delete remote file: " + data[0].name + "?",
buttons: ['Yes', 'No'],
defaultId: 1,
}, (response) => {
if (response == 0) {
for (var d = 0, dl = data.length; d < dl; d++)
_ied.deleteFile(data[d].path);
}
})
}

ipcRenderer.on('GMCP-received', (event, data) => {
if (options && options.debug)
console.log(data.mod);
Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Expand Up @@ -4,11 +4,13 @@
- Immortal tools
- Download files and open in an editor
- Upload files
- Delete files, local files moved to trash, remote deleted permanently
- **Change:**
- Updated to electron 1.7.4 beta
- **Fixed:**
- Preferences: Log path browse button now works
- Triggers where trigger on raw line instead of text
- MSP: fixed an issue with mal-formed urls breaking streaming sound
##### 0.4.0 2017-06-23
- **New:**
- Display control
Expand Down
21 changes: 20 additions & 1 deletion src/common/IED.ts
Expand Up @@ -150,6 +150,9 @@ export class IED extends EventEmitter {
case "browse":
this.getDir(obj.path, true);
break;
case "delete":
this.deleteFile(obj.path + "/" + obj.file);
break;
default:
if (obj.tag && obj.tag.startsWith('download:'))
this.download(obj.path + "/" + obj.file, false, obj.tag);
Expand Down Expand Up @@ -238,6 +241,10 @@ export class IED extends EventEmitter {
}
break;
}
case "cmd":
if (mods.length > 2 && mods[2] == "status")
this.emit('cmd', obj);
break;
}
this.nextGMCP();
}
Expand Down Expand Up @@ -322,6 +329,18 @@ export class IED extends EventEmitter {
}
}

public deleteFile(file, resolve?: boolean) {
if (resolve) {
delete this._data["delete"];
ipcRenderer.send('send-gmcp', "IED.resolve " + JSON.stringify({ path: path.dirname(file), file: path.basename(file), tag: 'delete' }));
this.emit('message', "Resolving: " + file);
}
else {
ipcRenderer.send('send-gmcp', "IED.cmd " + JSON.stringify({ cmd: "rm", path: path.dirname(file), file: path.basename(file), tag: 'delete' }));
this.emit('message', "Deleting: " + file);
}
}

public static isHidden(p, skipwin?: boolean) {
const basename = path.basename(p);
var dirname = path.dirname(p);
Expand Down Expand Up @@ -480,7 +499,7 @@ export class Item {
}
this._tmp = value;
if (value == TempType.file)
this._tmpObj = tmp.fileSync({prefix: 'jiMUD-'});
this._tmpObj = tmp.fileSync({ prefix: 'jiMUD-' });
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/common/client.ts
Expand Up @@ -255,6 +255,8 @@ export class Client extends EventEmitter {
this.commandInput = command;

this.MSP = new MSP();
this.MSP.forcedDefaultMusicURL = "";
this.MSP.forcedDefaultSoundURL = "";
this.MSP.on('playing', (data) => {
if (this.enableDebug) this.debug('MSP ' + (data.type ? 'Music' : 'Sound') + ' Playing ' + data.file + ' for ' + data.duration);
if (!this.options.notifyMSPPlay) return;
Expand Down

0 comments on commit 8814476

Please sign in to comment.