mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-13 02:17:09 +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 BrowserWindow = electron.BrowserWindow;
|
||||||
const shell = electron.shell;
|
const shell = electron.shell;
|
||||||
const appName = app.getName();
|
const appName = app.getName();
|
||||||
// Const tray = require('./tray');
|
|
||||||
|
|
||||||
const {addDomain, about} = require('./windowmanager');
|
const {about} = require('./windowmanager');
|
||||||
|
|
||||||
function sendAction(action) {
|
function sendAction(action) {
|
||||||
const win = BrowserWindow.getAllWindows()[0];
|
const win = BrowserWindow.getAllWindows()[0];
|
||||||
@@ -35,8 +34,7 @@ const viewSubmenu = [
|
|||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
if (focusedWindow) {
|
if (focusedWindow) {
|
||||||
focusedWindow.reload();
|
sendAction('reload');
|
||||||
focusedWindow.webContents.send('destroytray');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -136,10 +134,12 @@ const darwinTpl = [
|
|||||||
type: 'separator'
|
type: 'separator'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Change Zulip Server',
|
label: 'Manage Zulip Servers',
|
||||||
accelerator: 'Cmd+,',
|
accelerator: 'Cmd+,',
|
||||||
click() {
|
click(item, focusedWindow) {
|
||||||
addDomain();
|
if (focusedWindow) {
|
||||||
|
sendAction('open-settings');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -269,10 +269,12 @@ const otherTpl = [
|
|||||||
type: 'separator'
|
type: 'separator'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Change Zulip Server',
|
label: 'Manage Zulip Servers',
|
||||||
accelerator: 'Ctrl+,',
|
accelerator: 'Ctrl+,',
|
||||||
click() {
|
click(item, focusedWindow) {
|
||||||
addDomain();
|
if (focusedWindow) {
|
||||||
|
sendAction('open-settings');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -89,11 +89,6 @@ ipc.on('trayabout', event => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.on('traychangeserver', event => {
|
|
||||||
if (event) {
|
|
||||||
addDomain();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addDomain,
|
addDomain,
|
||||||
about
|
about
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const DomainUtil = require(path.resolve(('app/renderer/js/utils/domain-util.js')));
|
const DomainUtil = require(path.resolve(('app/renderer/js/utils/domain-util.js')));
|
||||||
const { linkIsInternal, skipImages } = require(path.resolve(('app/main/link-helper')));
|
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')));
|
require(path.resolve(('app/renderer/js/tray.js')));
|
||||||
|
|
||||||
class ServerManagerView {
|
class ServerManagerView {
|
||||||
@@ -18,6 +18,7 @@ class ServerManagerView {
|
|||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
this.settingsTabIndex = -1;
|
this.settingsTabIndex = -1;
|
||||||
this.activeTabIndex = -1;
|
this.activeTabIndex = -1;
|
||||||
|
this.zoomFactors = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
@@ -72,7 +73,8 @@ class ServerManagerView {
|
|||||||
this.$content.appendChild($webView);
|
this.$content.appendChild($webView);
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
$webView.addEventListener('dom-ready', this.endLoading.bind(this, index));
|
$webView.addEventListener('dom-ready', this.endLoading.bind(this, index));
|
||||||
this.registerListeners($webView);
|
this.registerListeners($webView);
|
||||||
|
this.zoomFactors[index] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
startLoading(url, index) {
|
startLoading(url, index) {
|
||||||
@@ -165,23 +167,63 @@ class ServerManagerView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerIpcs() {
|
registerIpcs() {
|
||||||
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
|
||||||
|
|
||||||
ipcRenderer.on('reload', () => {
|
ipcRenderer.on('reload', () => {
|
||||||
|
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||||
activeWebview.reload();
|
activeWebview.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on('back', () => {
|
ipcRenderer.on('back', () => {
|
||||||
|
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||||
if (activeWebview.canGoBack()) {
|
if (activeWebview.canGoBack()) {
|
||||||
activeWebview.goBack();
|
activeWebview.goBack();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcRenderer.on('forward', () => {
|
ipcRenderer.on('forward', () => {
|
||||||
|
const activeWebview = document.getElementById(`webview-${this.activeTabIndex}`);
|
||||||
if (activeWebview.canGoForward()) {
|
if (activeWebview.canGoForward()) {
|
||||||
activeWebview.goForward();
|
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';
|
'use strict';
|
||||||
const ipcRenderer = require('electron').ipcRenderer;
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
const {webFrame} = require('electron');
|
|
||||||
const {spellChecker} = require('./spellchecker');
|
const {spellChecker} = require('./spellchecker');
|
||||||
|
|
||||||
const _setImmediate = setImmediate;
|
|
||||||
const _clearImmediate = clearImmediate;
|
|
||||||
process.once('loaded', () => {
|
process.once('loaded', () => {
|
||||||
global.setImmediate = _setImmediate;
|
global.logout = logout;
|
||||||
global.clearImmediate = _clearImmediate;
|
global.shortcut = shortcut;
|
||||||
});
|
});
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-unassigned-import
|
const logout = () => {
|
||||||
// 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', () => {
|
|
||||||
// Create the menu for the below
|
// Create the menu for the below
|
||||||
document.querySelector('.dropdown-toggle').click();
|
document.querySelector('.dropdown-toggle').click();
|
||||||
|
|
||||||
const nodes = document.querySelectorAll('.dropdown-menu li:last-child a');
|
const nodes = document.querySelectorAll('.dropdown-menu li:last-child a');
|
||||||
nodes[nodes.length - 1].click();
|
nodes[nodes.length - 1].click();
|
||||||
});
|
};
|
||||||
|
|
||||||
ipcRenderer.on('shortcut', () => {
|
const shortcut = () => {
|
||||||
// Create the menu for the below
|
// Create the menu for the below
|
||||||
const node = document.querySelector('a[data-overlay-trigger=keyboard-shortcuts]');
|
const node = document.querySelector('a[data-overlay-trigger=keyboard-shortcuts]');
|
||||||
// Additional check
|
// Additional check
|
||||||
@@ -58,7 +25,7 @@ ipcRenderer.on('shortcut', () => {
|
|||||||
// Atleast click the dropdown
|
// Atleast click the dropdown
|
||||||
document.querySelector('.dropdown-toggle').click();
|
document.querySelector('.dropdown-toggle').click();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
// To prevent failing this script on linux we need to load it after the document loaded
|
// To prevent failing this script on linux we need to load it after the document loaded
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const electron = require('electron');
|
|||||||
|
|
||||||
const {ipcRenderer, remote} = 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');
|
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 () {
|
const createTray = function () {
|
||||||
window.tray = new Tray(iconPath());
|
window.tray = new Tray(iconPath());
|
||||||
const contextMenu = Menu.buildFromTemplate([{
|
const contextMenu = Menu.buildFromTemplate([{
|
||||||
@@ -116,7 +126,7 @@ const createTray = function () {
|
|||||||
{
|
{
|
||||||
label: 'Change Zulip server',
|
label: 'Change Zulip server',
|
||||||
click() {
|
click() {
|
||||||
ipcRenderer.send('traychangeserver');
|
sendAction('open-settings');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -125,8 +135,8 @@ const createTray = function () {
|
|||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
click() {
|
click() {
|
||||||
remote.getCurrentWindow().reload();
|
sendAction('reload');
|
||||||
window.tray.destroy();
|
// window.tray.destroy();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user