'use strict';
const { ipcRenderer } = require('electron');
const BaseSection = require(__dirname + '/base-section.js');
const ConfigUtil = require(__dirname + '/../../utils/config-util.js');
class GeneralSection extends BaseSection {
constructor(props) {
super();
this.props = props;
}
template() {
return `
Appearance
Show app icon in system tray
Desktop Notification
Mute all sounds from Zulip (requires reload)
App Updates
`;
}
init() {
this.props.$root.innerHTML = this.template();
this.updateTrayOption();
this.updateDockOption();
this.updateUpdateOption();
this.updateSilentOption();
this.updateSidebarOption();
}
updateTrayOption() {
this.generateSettingOption({
$element: document.querySelector('#tray-option .setting-control'),
value: ConfigUtil.getConfigItem('trayIcon', true),
clickHandler: () => {
const newValue = !ConfigUtil.getConfigItem('trayIcon');
ConfigUtil.setConfigItem('trayIcon', newValue);
ipcRenderer.send('forward-message', 'toggletray');
this.updateTrayOption();
}
});
}
updateDockOption() {
this.generateSettingOption({
$element: document.querySelector('#dock-option .setting-control'),
value: ConfigUtil.getConfigItem('dockOption', true),
clickHandler: () => {
const newValue = !ConfigUtil.getConfigItem('dockOption');
ConfigUtil.setConfigItem('dockOption', newValue);
ipcRenderer.send('dock-unread-option', newValue);
this.updateDockOption();
}
});
}
updateUpdateOption() {
this.generateSettingOption({
$element: document.querySelector('#betaupdate-option .setting-control'),
value: ConfigUtil.getConfigItem('betaUpdate', false),
clickHandler: () => {
const newValue = !ConfigUtil.getConfigItem('betaUpdate');
ConfigUtil.setConfigItem('betaUpdate', newValue);
this.updateUpdateOption();
}
});
}
updateSilentOption() {
this.generateSettingOption({
$element: document.querySelector('#silent-option .setting-control'),
value: ConfigUtil.getConfigItem('silent', false),
clickHandler: () => {
const newValue = !ConfigUtil.getConfigItem('silent', true);
ConfigUtil.setConfigItem('silent', newValue);
this.updateSilentOption();
}
});
}
updateSidebarOption() {
this.generateSettingOption({
$element: document.querySelector('#sidebar-option .setting-control'),
value: ConfigUtil.getConfigItem('showSidebar', true),
clickHandler: () => {
const newValue = !ConfigUtil.getConfigItem('showSidebar');
ConfigUtil.setConfigItem('showSidebar', newValue);
ipcRenderer.send('forward-message', 'toggle-sidebar', newValue);
this.updateSidebarOption();
}
});
}
}
module.exports = GeneralSection;