mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-18 04:33:21 +00:00
Provide silent & seamless reload for the app.
This commit is contained in:
@@ -16,7 +16,7 @@ class ServerManagerView {
|
||||
const $actionsContainer = document.getElementById('actions-container');
|
||||
this.$reloadButton = $actionsContainer.querySelector('#reload-action');
|
||||
this.$settingsButton = $actionsContainer.querySelector('#settings-action');
|
||||
this.$content = document.getElementById('content');
|
||||
this.$webviewsContainer = document.getElementById('webviews-container');
|
||||
|
||||
this.activeTabIndex = -1;
|
||||
this.tabs = [];
|
||||
@@ -39,6 +39,8 @@ class ServerManagerView {
|
||||
} else {
|
||||
this.openSettings('Servers');
|
||||
}
|
||||
|
||||
ipcRenderer.send('local-shortcuts', true);
|
||||
}
|
||||
|
||||
initServer(server, index) {
|
||||
@@ -48,7 +50,7 @@ class ServerManagerView {
|
||||
onClick: this.activateTab.bind(this, index),
|
||||
index,
|
||||
webview: new WebView({
|
||||
$root: this.$content,
|
||||
$root: this.$webviewsContainer,
|
||||
index,
|
||||
url: server.url,
|
||||
name: server.alias,
|
||||
@@ -89,7 +91,7 @@ class ServerManagerView {
|
||||
onClick: this.activateTab.bind(this, this.functionalTabs[tabProps.name]),
|
||||
onDestroy: this.destroyTab.bind(this, tabProps.name, this.functionalTabs[tabProps.name]),
|
||||
webview: new WebView({
|
||||
$root: this.$content,
|
||||
$root: this.$webviewsContainer,
|
||||
index: this.functionalTabs[tabProps.name],
|
||||
url: tabProps.url,
|
||||
name: tabProps.name,
|
||||
@@ -164,6 +166,25 @@ class ServerManagerView {
|
||||
}
|
||||
}
|
||||
|
||||
destroyView() {
|
||||
// Clear global variables
|
||||
this.activeTabIndex = -1;
|
||||
this.tabs = [];
|
||||
this.functionalTabs = {};
|
||||
|
||||
// Clear DOM elements
|
||||
this.$tabsContainer.innerHTML = '';
|
||||
this.$webviewsContainer.innerHTML = '';
|
||||
|
||||
// Destroy shortcuts
|
||||
ipcRenderer.send('local-shortcuts', false);
|
||||
}
|
||||
|
||||
reloadView() {
|
||||
this.destroyView();
|
||||
this.initTabs();
|
||||
}
|
||||
|
||||
updateBadge() {
|
||||
let messageCountAll = 0;
|
||||
for (let i = 0; i < this.tabs.length; i++) {
|
||||
@@ -204,6 +225,7 @@ class ServerManagerView {
|
||||
this.openSettings(settingNav);
|
||||
});
|
||||
ipcRenderer.on('open-about', this.openAbout.bind(this));
|
||||
ipcRenderer.on('reload-viewer', this.reloadView.bind(this));
|
||||
ipcRenderer.on('switch-server-tab', (event, index) => {
|
||||
this.activateTab(index);
|
||||
});
|
||||
@@ -213,8 +235,9 @@ class ServerManagerView {
|
||||
window.onload = () => {
|
||||
const serverManagerView = new ServerManagerView();
|
||||
serverManagerView.init();
|
||||
};
|
||||
|
||||
window.addEventListener('online', () => {
|
||||
ipcRenderer.send('reload-main');
|
||||
});
|
||||
|
||||
window.addEventListener('online', () => {
|
||||
serverManagerView.reloadView();
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user