mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-04 14:03:27 +00:00
Integrate actions from menu and tray with webview.
This commit is contained in:
committed by
akashnimare
parent
de34a22740
commit
ae3c595d82
@@ -8,9 +8,8 @@ const app = electron.app;
|
||||
const BrowserWindow = electron.BrowserWindow;
|
||||
const shell = electron.shell;
|
||||
const appName = app.getName();
|
||||
// Const tray = require('./tray');
|
||||
|
||||
const {addDomain, about} = require('./windowmanager');
|
||||
const {about} = require('./windowmanager');
|
||||
|
||||
function sendAction(action) {
|
||||
const win = BrowserWindow.getAllWindows()[0];
|
||||
@@ -35,8 +34,7 @@ const viewSubmenu = [
|
||||
label: 'Reload',
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
focusedWindow.reload();
|
||||
focusedWindow.webContents.send('destroytray');
|
||||
sendAction('reload');
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -136,10 +134,12 @@ const darwinTpl = [
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Change Zulip Server',
|
||||
label: 'Manage Zulip Servers',
|
||||
accelerator: 'Cmd+,',
|
||||
click() {
|
||||
addDomain();
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
sendAction('open-settings');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -269,10 +269,12 @@ const otherTpl = [
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Change Zulip Server',
|
||||
label: 'Manage Zulip Servers',
|
||||
accelerator: 'Ctrl+,',
|
||||
click() {
|
||||
addDomain();
|
||||
click(item, focusedWindow) {
|
||||
if (focusedWindow) {
|
||||
sendAction('open-settings');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -89,11 +89,6 @@ ipc.on('trayabout', event => {
|
||||
}
|
||||
});
|
||||
|
||||
ipc.on('traychangeserver', event => {
|
||||
if (event) {
|
||||
addDomain();
|
||||
}
|
||||
});
|
||||
module.exports = {
|
||||
addDomain,
|
||||
about
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const path = require("path");
|
||||
const DomainUtil = require(path.resolve(('app/renderer/js/utils/domain-util.js')));
|
||||
const { linkIsInternal, skipImages } = require(path.resolve(('app/main/link-helper')));
|
||||
const { shell, ipcRenderer } = require('electron');
|
||||
const { shell, ipcRenderer, webFrame } = require('electron');
|
||||
require(path.resolve(('app/renderer/js/tray.js')));
|
||||
|
||||
class ServerManagerView {
|
||||
@@ -18,6 +18,7 @@ class ServerManagerView {
|
||||
this.isLoading = false;
|
||||
this.settingsTabIndex = -1;
|
||||
this.activeTabIndex = -1;
|
||||
this.zoomFactors = [];
|
||||
}
|
||||
|
||||
init() {
|
||||
@@ -73,6 +74,7 @@ class ServerManagerView {
|
||||
this.isLoading = true;
|
||||
$webView.addEventListener('dom-ready', this.endLoading.bind(this, index));
|
||||
this.registerListeners($webView);
|
||||
this.zoomFactors[index] = 1;
|
||||
}
|
||||
|
||||
startLoading(url, index) {
|
||||
@@ -165,23 +167,63 @@ class ServerManagerView {
|
||||
}
|
||||
|
||||
registerIpcs() {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
|
||||
ipcRenderer.on('reload', () => {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
activeWebview.reload();
|
||||
});
|
||||
|
||||
ipcRenderer.on('back', () => {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
if (activeWebview.canGoBack()) {
|
||||
activeWebview.goBack();
|
||||
}
|
||||
});
|
||||
|
||||
ipcRenderer.on('forward', () => {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
if (activeWebview.canGoForward()) {
|
||||
activeWebview.goForward();
|
||||
}
|
||||
});
|
||||
|
||||
// Handle zooming functionality
|
||||
ipcRenderer.on('zoomIn', () => {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
this.zoomFactors[this.activeTabIndex] += 0.1;
|
||||
activeWebview.setZoomFactor(this.zoomFactors[this.activeTabIndex]);
|
||||
});
|
||||
|
||||
ipcRenderer.on('zoomOut', () => {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
this.zoomFactors[this.activeTabIndex] -= 0.1;
|
||||
activeWebview.setZoomFactor(this.zoomFactors[this.activeTabIndex]);
|
||||
});
|
||||
|
||||
ipcRenderer.on('zoomActualSize', () => {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
this.zoomFactors[this.activeTabIndex] = 1;
|
||||
activeWebview.setZoomFactor(this.zoomFactors[this.activeTabIndex]);
|
||||
});
|
||||
|
||||
ipcRenderer.on('log-out', () => {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
activeWebview.executeJavaScript('logout()');
|
||||
});
|
||||
|
||||
ipcRenderer.on('shortcut', () => {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
activeWebview.executeJavaScript('shortcut()');
|
||||
});
|
||||
|
||||
ipcRenderer.on('open-settings', () => {
|
||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||
if (this.settingsTabIndex == -1) {
|
||||
this.openSettings();
|
||||
} else {
|
||||
this.activateTab(this.settingsTabIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,54 +1,21 @@
|
||||
'use strict';
|
||||
const ipcRenderer = require('electron').ipcRenderer;
|
||||
const {webFrame} = require('electron');
|
||||
const {spellChecker} = require('./spellchecker');
|
||||
|
||||
const _setImmediate = setImmediate;
|
||||
const _clearImmediate = clearImmediate;
|
||||
process.once('loaded', () => {
|
||||
global.setImmediate = _setImmediate;
|
||||
global.clearImmediate = _clearImmediate;
|
||||
global.logout = logout;
|
||||
global.shortcut = shortcut;
|
||||
});
|
||||
|
||||
// eslint-disable-next-line import/no-unassigned-import
|
||||
// require('./tray.js');
|
||||
// Calling Tray.js in renderer process everytime app window loads
|
||||
|
||||
// Handle zooming functionality
|
||||
const zoomIn = () => {
|
||||
webFrame.setZoomFactor(webFrame.getZoomFactor() + 0.1);
|
||||
};
|
||||
|
||||
const zoomOut = () => {
|
||||
webFrame.setZoomFactor(webFrame.getZoomFactor() - 0.1);
|
||||
};
|
||||
|
||||
const zoomActualSize = () => {
|
||||
webFrame.setZoomFactor(1);
|
||||
};
|
||||
|
||||
// Get zooming actions from main process
|
||||
ipcRenderer.on('zoomIn', () => {
|
||||
zoomIn();
|
||||
});
|
||||
|
||||
ipcRenderer.on('zoomOut', () => {
|
||||
zoomOut();
|
||||
});
|
||||
|
||||
ipcRenderer.on('zoomActualSize', () => {
|
||||
zoomActualSize();
|
||||
});
|
||||
|
||||
ipcRenderer.on('log-out', () => {
|
||||
const logout = () => {
|
||||
// Create the menu for the below
|
||||
document.querySelector('.dropdown-toggle').click();
|
||||
|
||||
const nodes = document.querySelectorAll('.dropdown-menu li:last-child a');
|
||||
nodes[nodes.length - 1].click();
|
||||
});
|
||||
};
|
||||
|
||||
ipcRenderer.on('shortcut', () => {
|
||||
const shortcut = () => {
|
||||
// Create the menu for the below
|
||||
const node = document.querySelector('a[data-overlay-trigger=keyboard-shortcuts]');
|
||||
// Additional check
|
||||
@@ -58,7 +25,7 @@ ipcRenderer.on('shortcut', () => {
|
||||
// Atleast click the dropdown
|
||||
document.querySelector('.dropdown-toggle').click();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// To prevent failing this script on linux we need to load it after the document loaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
@@ -5,7 +5,7 @@ const electron = require('electron');
|
||||
|
||||
const {ipcRenderer, remote} = electron;
|
||||
|
||||
const {Tray, Menu, nativeImage} = remote;
|
||||
const {Tray, Menu, nativeImage, BrowserWindow} = remote;
|
||||
|
||||
const APP_ICON = path.join(__dirname, '../../resources/tray', 'tray');
|
||||
|
||||
@@ -102,6 +102,16 @@ const renderNativeImage = function (arg) {
|
||||
});
|
||||
};
|
||||
|
||||
function sendAction(action) {
|
||||
const win = BrowserWindow.getAllWindows()[0];
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
win.restore();
|
||||
}
|
||||
|
||||
win.webContents.send(action);
|
||||
}
|
||||
|
||||
const createTray = function () {
|
||||
window.tray = new Tray(iconPath());
|
||||
const contextMenu = Menu.buildFromTemplate([{
|
||||
@@ -116,7 +126,7 @@ const createTray = function () {
|
||||
{
|
||||
label: 'Change Zulip server',
|
||||
click() {
|
||||
ipcRenderer.send('traychangeserver');
|
||||
sendAction('open-settings');
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -125,8 +135,8 @@ const createTray = function () {
|
||||
{
|
||||
label: 'Reload',
|
||||
click() {
|
||||
remote.getCurrentWindow().reload();
|
||||
window.tray.destroy();
|
||||
sendAction('reload');
|
||||
// window.tray.destroy();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user