tabs/src/windows/ServiceSettingsWindow.ts

65 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-05-22 10:25:19 +02:00
import path from "path";
import Window from "../Window";
import Application from "../Application";
import Meta from "../Meta";
import Service from "../Service";
export default class ServiceSettingsWindow extends Window {
2020-09-29 20:43:41 +02:00
private readonly serviceId: number | null;
2020-05-22 10:25:19 +02:00
2020-09-29 20:43:41 +02:00
public constructor(application: Application, parent: Window, serviceId: number | null) {
2020-05-22 10:25:19 +02:00
super(application, parent);
this.serviceId = serviceId;
}
2020-09-29 20:43:41 +02:00
public setup(): void {
2020-05-22 10:25:19 +02:00
super.setup({
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
webviewTag: true,
},
modal: true,
autoHideMenuBar: true,
height: 850,
});
const window = this.getWindow();
if (this.application.isDevMode()) {
window.webContents.openDevTools({
2020-09-29 20:43:41 +02:00
mode: 'right',
2020-05-22 10:25:19 +02:00
});
}
this.onIpc('sync-settings', () => {
window.webContents.send('syncIcons', Meta.ICON_SETS);
2020-09-29 20:43:41 +02:00
window.webContents.send('loadService',
this.serviceId, typeof this.serviceId === 'number' ?
this.config.services[this.serviceId] :
undefined,
);
2020-05-22 10:25:19 +02:00
});
2020-09-29 20:43:41 +02:00
this.onIpc('saveService', (e, id: number | null, data: Service) => {
2020-05-22 10:25:19 +02:00
console.log('Saving service', id, data);
const newService = new Service(data);
if (typeof id === 'number') {
this.config.services[id] = newService;
} else {
this.config.services.push(newService);
id = this.config.services.indexOf(newService);
2020-09-29 20:43:41 +02:00
if (id < 0) id = null;
2020-05-22 10:25:19 +02:00
}
this.config.save();
this.parent?.getWindow().webContents.send('updateService', id, newService);
});
window.loadFile(path.resolve(Meta.RESOURCES_PATH, 'service-settings.html'))
.catch(console.error);
}
2020-09-29 20:43:41 +02:00
}