Add deleting services
This commit is contained in:
parent
ee338bf6e0
commit
8e7e78b2df
@ -167,6 +167,7 @@
|
|||||||
const {
|
const {
|
||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
|
dialog,
|
||||||
} = remote;
|
} = remote;
|
||||||
|
|
||||||
const icons = [];
|
const icons = [];
|
||||||
@ -180,12 +181,26 @@
|
|||||||
|
|
||||||
// Service context menu
|
// Service context menu
|
||||||
const serviceContextMenu = new Menu();
|
const serviceContextMenu = new Menu();
|
||||||
const settingsItem = new MenuItem({
|
serviceContextMenu.append(new MenuItem({
|
||||||
label: 'Edit', click: () => {
|
label: 'Edit', click: () => {
|
||||||
ipcRenderer.send('openServiceSettings', serviceContextMenu.serviceId);
|
ipcRenderer.send('openServiceSettings', serviceContextMenu.serviceId);
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
serviceContextMenu.append(settingsItem);
|
serviceContextMenu.append(new MenuItem({
|
||||||
|
label: 'Delete', click: () => {
|
||||||
|
dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
|
type: 'question',
|
||||||
|
title: 'Confirm',
|
||||||
|
message: 'Are you sure you want to delete this service?',
|
||||||
|
buttons: ['Cancel', 'Confirm'],
|
||||||
|
cancelId: 0,
|
||||||
|
}).then(result => {
|
||||||
|
if (result.response === 1) {
|
||||||
|
ipcRenderer.send('deleteService', serviceContextMenu.serviceId);
|
||||||
|
}
|
||||||
|
}).catch(console.error);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
function openServiceContextMenu(event, index) {
|
function openServiceContextMenu(event, index) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -216,6 +231,10 @@
|
|||||||
for (let i = 0; i < services.length; i++) {
|
for (let i = 0; i < services.length; i++) {
|
||||||
createService(i);
|
createService(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actualSelectedService < 0 || actualSelectedService >= services.length) {
|
||||||
|
actualSelectedService = 0;
|
||||||
|
}
|
||||||
setActiveService(actualSelectedService);
|
setActiveService(actualSelectedService);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -224,7 +243,7 @@
|
|||||||
services.push(data);
|
services.push(data);
|
||||||
createService(services.length - 1);
|
createService(services.length - 1);
|
||||||
} else {
|
} else {
|
||||||
let nav = document.querySelector('#service-selector');
|
const nav = document.querySelector('#service-selector');
|
||||||
|
|
||||||
// Remove nav
|
// Remove nav
|
||||||
const oldNavButton = nav.querySelector('li:nth-of-type(' + (id + 1) + ')');
|
const oldNavButton = nav.querySelector('li:nth-of-type(' + (id + 1) + ')');
|
||||||
@ -246,6 +265,29 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcRenderer.on('deleteService', (e, id) => {
|
||||||
|
const nav = document.querySelector('#service-selector');
|
||||||
|
|
||||||
|
// Remove nav
|
||||||
|
const navButton = nav.querySelector('li:nth-of-type(' + (id + 1) + ')');
|
||||||
|
if (navButton) {
|
||||||
|
nav.removeChild(navButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove webview
|
||||||
|
if (services[id].view) {
|
||||||
|
const serviceContainer = document.querySelector('#services');
|
||||||
|
serviceContainer.removeChild(services[id].view);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parseInt(selectedService) === id) {
|
||||||
|
setActiveService(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete services[id];
|
||||||
|
services = services.filter(s => s !== null);
|
||||||
|
});
|
||||||
|
|
||||||
function createService(index, nextNavButton) {
|
function createService(index, nextNavButton) {
|
||||||
let service = services[index];
|
let service = services[index];
|
||||||
let li = document.createElement('li');
|
let li = document.createElement('li');
|
||||||
@ -335,7 +377,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hide previous service
|
// Hide previous service
|
||||||
if (services[selectedService].view) {
|
if (services[selectedService] && services[selectedService].view) {
|
||||||
services[selectedService].view.classList.remove('active');
|
services[selectedService].view.classList.remove('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ export default class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
|
this.services = this.services.filter(s => s !== null);
|
||||||
fs.writeFileSync(configFile, JSON.stringify(this, null, 4));
|
fs.writeFileSync(configFile, JSON.stringify(this, null, 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -135,6 +135,13 @@ function createWindow() {
|
|||||||
|
|
||||||
window.webContents.send('updateService', id, newService);
|
window.webContents.send('updateService', id, newService);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.on('deleteService', (e, id) => {
|
||||||
|
delete config.services[id];
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
window.webContents.send('deleteService', id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendData() {
|
function sendData() {
|
||||||
|
Loading…
Reference in New Issue
Block a user