Skip to content

Commit

Permalink
sidebar: Update domain order only when app quits.
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishk98 committed Aug 14, 2019
1 parent 1c1fa47 commit eed368c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ app.on('ready', () => {
});

app.on('before-quit', () => {
mainWindow.webContents.send('save-domains');
isQuitting = true;
});

Expand Down
25 changes: 13 additions & 12 deletions app/renderer/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ServerManagerView {
$fullscreenEscapeKey: string;
loading: AnyObject;
activeTabIndex: number;
servers: ServerOrFunctionalTab[];
servers: any[];
tabs: ServerOrFunctionalTab[];
functionalTabs: AnyObject;
tabIndex: number;
Expand Down Expand Up @@ -135,7 +135,7 @@ class ServerManagerView {

this.loading = {};
this.activeTabIndex = -1;
this.servers = [];
this.servers = DomainUtil.getDomains();
this.tabs = [];
this.presetOrgs = [];
this.functionalTabs = {};
Expand Down Expand Up @@ -245,18 +245,13 @@ class ServerManagerView {

onEnd(): void {
const newServers: any[] | ServerOrFunctionalTab[] = [];
const tabMap: any = {};
const tabElements = document.querySelectorAll('#tabs-container .tab');
tabElements.forEach((el, index) => {
const oldIndex = Number(el.getAttribute('data-tab-id')) % this.servers.length;
tabMap[index] = oldIndex;
newServers.push(this.servers[index]);
newServers.push(this.servers[oldIndex]);
el.setAttribute('data-tab-id', index.toString());
});

for (let server = 0; server < newServers.length; ++server) {
DomainUtil.updateDomain(server, newServers[tabMap[server]]);
}
this.servers = newServers;

this.reloadView();
}
Expand Down Expand Up @@ -336,7 +331,7 @@ class ServerManagerView {
}
}

initTabs(): void {
initTabs(refresh: boolean = false): void {
const servers = DomainUtil.getDomains();
this.servers = servers;
if (servers.length > 0) {
Expand Down Expand Up @@ -696,14 +691,14 @@ class ServerManagerView {
this.$webviewsContainer.innerHTML = '';
}

reloadView(): void {
reloadView(refresh: boolean = false): void {
// Save and remember the index of last active tab so that we can use it later
const lastActiveTab = this.tabs[this.activeTabIndex].props.index;
ConfigUtil.setConfigItem('lastActiveTab', lastActiveTab);

// Destroy the current view and re-initiate it
this.destroyView();
this.initTabs();
this.initTabs(refresh);
this.initServerActions();
}

Expand Down Expand Up @@ -808,6 +803,12 @@ class ServerManagerView {
});
}

ipcRenderer.on('save-domains', () => {
for (let server = 0; server < this.servers.length; ++server) {
DomainUtil.updateDomain(server, this.servers[server]);
}
});

ipcRenderer.on('open-settings', (event: Event, settingNav: string) => {
this.openSettings(settingNav);
});
Expand Down

0 comments on commit eed368c

Please sign in to comment.