Skip to content

Commit

Permalink
Deduplicated code in both handlers
Browse files Browse the repository at this point in the history
Signed-off-by: tarun8718 <tarunkumar8718@gmail.com>
  • Loading branch information
tarun8718 committed Mar 18, 2021
1 parent 9ccd1fe commit 468676b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
30 changes: 0 additions & 30 deletions app/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,21 +344,6 @@ function getDarwinTpl(props: MenuProps): Electron.MenuItemConstructorOptions[] {
accelerator: 'Cmd+,',
click(_item, focusedWindow) {
if (focusedWindow) {
let numberServers = 0;
tabs.forEach(tab => {
if (tab.role === 'server') {
numberServers++;
}
});
if (numberServers === 1) {
const value = ConfigUtil.getConfigItem('showSidebar');
if (!value) {
const newValue = !value;
focusedWindow.webContents.send('toggle-sidebar', newValue);
ConfigUtil.setConfigItem('showSidebar', newValue);
}
}

sendAction('open-settings');
}
}
Expand Down Expand Up @@ -491,21 +476,6 @@ function getOtherTpl(props: MenuProps): Electron.MenuItemConstructorOptions[] {
accelerator: 'Ctrl+,',
click(_item, focusedWindow) {
if (focusedWindow) {
let numberServers = 0;
tabs.forEach(tab => {
if (tab.role === 'server') {
numberServers++;
}
});
if (numberServers === 1) {
const value = ConfigUtil.getConfigItem('showSidebar');
if (!value) {
const newValue = !value;
focusedWindow.webContents.send('toggle-sidebar', newValue);
ConfigUtil.setConfigItem('showSidebar', newValue);
}
}

sendAction('open-settings');
}
}
Expand Down
17 changes: 17 additions & 0 deletions app/renderer/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,23 @@ class ServerManagerView {
});

ipcRenderer.on('open-settings', async (event: Event, settingNav: string) => {
let numberServers = 0;
for (const tab of this.tabs) {
if (tab.props.role === 'server') {
numberServers++;
}
}

if (numberServers === 1) {
const value = ConfigUtil.getConfigItem('showSidebar');
if (!value) {
const newValue = !value;
this.toggleSidebar(newValue);
this.updateGeneralSettings('toggle-sidebar-setting', newValue);
ConfigUtil.setConfigItem('showSidebar', newValue);
}
}

await this.openSettings(settingNav);
});

Expand Down

0 comments on commit 468676b

Please sign in to comment.