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:
@@ -139,11 +139,9 @@ function createMainWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function registerLocalShortcuts(page) {
|
function registerLocalShortcuts(page) {
|
||||||
// TODO - use global shortcut instead
|
// Somehow, reload action cannot be overwritten by the menu item
|
||||||
electronLocalshortcut.register(mainWindow, 'CommandOrControl+R', () => {
|
electronLocalshortcut.register(mainWindow, 'CommandOrControl+R', () => {
|
||||||
// page.send('reload');
|
page.send('reload-viewer');
|
||||||
mainWindow.reload();
|
|
||||||
page.send('destroytray');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,9 +181,9 @@ app.on('ready', () => {
|
|||||||
appUpdater();
|
appUpdater();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
electron.powerMonitor.on('resume', () => {
|
electron.powerMonitor.on('resume', () => {
|
||||||
mainWindow.reload();
|
page.send('reload-viewer');
|
||||||
page.send('destroytray');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.on('focus-app', () => {
|
ipc.on('focus-app', () => {
|
||||||
@@ -196,13 +194,6 @@ app.on('ready', () => {
|
|||||||
app.quit();
|
app.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.on('reload-main', () => {
|
|
||||||
page.reload();
|
|
||||||
page.send('destroytray');
|
|
||||||
electronLocalshortcut.unregisterAll(mainWindow);
|
|
||||||
registerLocalShortcuts(page);
|
|
||||||
});
|
|
||||||
|
|
||||||
ipc.on('toggle-app', () => {
|
ipc.on('toggle-app', () => {
|
||||||
if (mainWindow.isVisible()) {
|
if (mainWindow.isVisible()) {
|
||||||
mainWindow.hide();
|
mainWindow.hide();
|
||||||
@@ -229,6 +220,14 @@ app.on('ready', () => {
|
|||||||
page.send('switch-server-tab', index - 1);
|
page.send('switch-server-tab', index - 1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipc.on('local-shortcuts', (event, enable) => {
|
||||||
|
if (enable) {
|
||||||
|
registerLocalShortcuts(page);
|
||||||
|
} else {
|
||||||
|
electronLocalshortcut.unregisterAll(mainWindow);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('will-quit', () => {
|
app.on('will-quit', () => {
|
||||||
|
|||||||
@@ -51,9 +51,10 @@ const historySubmenu = [
|
|||||||
const viewSubmenu = [
|
const viewSubmenu = [
|
||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
|
accelerator: 'CommandOrControl+R',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if (focusedWindow) {
|
if (focusedWindow) {
|
||||||
sendAction('reload');
|
sendAction('reload-viewer');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -181,6 +181,12 @@ html, body {
|
|||||||
/*******************
|
/*******************
|
||||||
* Webview Area *
|
* Webview Area *
|
||||||
*******************/
|
*******************/
|
||||||
|
#webviews-container {
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
webview {
|
webview {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transition: opacity 0.3s;
|
transition: opacity 0.3s;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class ServerManagerView {
|
|||||||
const $actionsContainer = document.getElementById('actions-container');
|
const $actionsContainer = document.getElementById('actions-container');
|
||||||
this.$reloadButton = $actionsContainer.querySelector('#reload-action');
|
this.$reloadButton = $actionsContainer.querySelector('#reload-action');
|
||||||
this.$settingsButton = $actionsContainer.querySelector('#settings-action');
|
this.$settingsButton = $actionsContainer.querySelector('#settings-action');
|
||||||
this.$content = document.getElementById('content');
|
this.$webviewsContainer = document.getElementById('webviews-container');
|
||||||
|
|
||||||
this.activeTabIndex = -1;
|
this.activeTabIndex = -1;
|
||||||
this.tabs = [];
|
this.tabs = [];
|
||||||
@@ -39,6 +39,8 @@ class ServerManagerView {
|
|||||||
} else {
|
} else {
|
||||||
this.openSettings('Servers');
|
this.openSettings('Servers');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipcRenderer.send('local-shortcuts', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
initServer(server, index) {
|
initServer(server, index) {
|
||||||
@@ -48,7 +50,7 @@ class ServerManagerView {
|
|||||||
onClick: this.activateTab.bind(this, index),
|
onClick: this.activateTab.bind(this, index),
|
||||||
index,
|
index,
|
||||||
webview: new WebView({
|
webview: new WebView({
|
||||||
$root: this.$content,
|
$root: this.$webviewsContainer,
|
||||||
index,
|
index,
|
||||||
url: server.url,
|
url: server.url,
|
||||||
name: server.alias,
|
name: server.alias,
|
||||||
@@ -89,7 +91,7 @@ class ServerManagerView {
|
|||||||
onClick: this.activateTab.bind(this, this.functionalTabs[tabProps.name]),
|
onClick: this.activateTab.bind(this, this.functionalTabs[tabProps.name]),
|
||||||
onDestroy: this.destroyTab.bind(this, tabProps.name, this.functionalTabs[tabProps.name]),
|
onDestroy: this.destroyTab.bind(this, tabProps.name, this.functionalTabs[tabProps.name]),
|
||||||
webview: new WebView({
|
webview: new WebView({
|
||||||
$root: this.$content,
|
$root: this.$webviewsContainer,
|
||||||
index: this.functionalTabs[tabProps.name],
|
index: this.functionalTabs[tabProps.name],
|
||||||
url: tabProps.url,
|
url: tabProps.url,
|
||||||
name: tabProps.name,
|
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() {
|
updateBadge() {
|
||||||
let messageCountAll = 0;
|
let messageCountAll = 0;
|
||||||
for (let i = 0; i < this.tabs.length; i++) {
|
for (let i = 0; i < this.tabs.length; i++) {
|
||||||
@@ -204,6 +225,7 @@ class ServerManagerView {
|
|||||||
this.openSettings(settingNav);
|
this.openSettings(settingNav);
|
||||||
});
|
});
|
||||||
ipcRenderer.on('open-about', this.openAbout.bind(this));
|
ipcRenderer.on('open-about', this.openAbout.bind(this));
|
||||||
|
ipcRenderer.on('reload-viewer', this.reloadView.bind(this));
|
||||||
ipcRenderer.on('switch-server-tab', (event, index) => {
|
ipcRenderer.on('switch-server-tab', (event, index) => {
|
||||||
this.activateTab(index);
|
this.activateTab(index);
|
||||||
});
|
});
|
||||||
@@ -213,8 +235,9 @@ class ServerManagerView {
|
|||||||
window.onload = () => {
|
window.onload = () => {
|
||||||
const serverManagerView = new ServerManagerView();
|
const serverManagerView = new ServerManagerView();
|
||||||
serverManagerView.init();
|
serverManagerView.init();
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener('online', () => {
|
|
||||||
ipcRenderer.send('reload-main');
|
window.addEventListener('online', () => {
|
||||||
});
|
serverManagerView.reloadView();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class NetworkTroubleshootingView {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.$reconnectButton.addEventListener('click', () => {
|
this.$reconnectButton.addEventListener('click', () => {
|
||||||
ipcRenderer.send('reload-main');
|
ipcRenderer.send('forward-message', 'reload-viewer');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,8 +119,9 @@ class GeneralSection extends BaseComponent {
|
|||||||
this.initSilentOption();
|
this.initSilentOption();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleServerInfoChange() {
|
handleServerInfoChange() {
|
||||||
ipcRenderer.send('reload-main');
|
ipcRenderer.send('forward-message', 'reload-viewer');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class ServersSection extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleServerInfoChange() {
|
handleServerInfoChange() {
|
||||||
ipcRenderer.send('reload-main');
|
ipcRenderer.send('forward-message', 'reload-viewer');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
// redirect users to network troubleshooting page
|
// redirect users to network troubleshooting page
|
||||||
document.querySelector('.restart_get_events_button').addEventListener('click', () => {
|
document.querySelector('.restart_get_events_button').addEventListener('click', () => {
|
||||||
ipcRenderer.send('reload-main');
|
ipcRenderer.send('forward-message', 'reload-viewer');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="webviews-container"/>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script src="js/main.js"></script>
|
<script src="js/main.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user