Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Urgent electron upgrade #850

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/main/autoupdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export function appUpdater(updateFromMenu = false): void {
message: messageText,
detail: (error).toString() + `\n\nThe latest version of Zulip Desktop is available at -\nhttps://zulipchat.com/apps/.\n
Current Version: ${app.getVersion()}`
}, response => {
}).then(res => {
const { response } = res;
if (response === 0) {
shell.openExternal('https://zulipchat.com/apps/');
}
Expand All @@ -91,7 +92,9 @@ Current Version: ${app.getVersion()}`
defaultId: 0,
message: `A new update ${event.version} has been downloaded`,
detail: 'It will be installed the next time you restart the application'
}, response => {
}).then(res => {
// response actually contains index of clicked button
const { response } = res;
if (response === 0) {
setTimeout(() => {
autoUpdater.quitAndInstall();
Expand Down
25 changes: 13 additions & 12 deletions app/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ function createMainWindow(): Electron.BrowserWindow {
webPreferences: {
plugins: true,
nodeIntegration: true,
partition: 'persist:webviewsession'
partition: 'persist:webviewsession',
webviewTag: true
},
show: false
});
Expand Down Expand Up @@ -262,39 +263,39 @@ app.on('ready', () => {
BadgeSettings.updateBadge(badgeCount, mainWindow);
});

ipcMain.on('toggle-menubar', (_event: Electron.IpcMessageEvent, showMenubar: boolean) => {
ipcMain.on('toggle-menubar', (_event: Electron.IpcMainEvent, showMenubar: boolean) => {
mainWindow.setAutoHideMenuBar(showMenubar);
mainWindow.setMenuBarVisibility(!showMenubar);
page.send('toggle-autohide-menubar', showMenubar, true);
});

ipcMain.on('update-badge', (_event: Electron.IpcMessageEvent, messageCount: number) => {
ipcMain.on('update-badge', (_event: Electron.IpcMainEvent, messageCount: number) => {
badgeCount = messageCount;
BadgeSettings.updateBadge(badgeCount, mainWindow);
page.send('tray', messageCount);
});

ipcMain.on('update-taskbar-icon', (_event: Electron.IpcMessageEvent, data: any, text: string) => {
ipcMain.on('update-taskbar-icon', (_event: Electron.IpcMainEvent, data: any, text: string) => {
BadgeSettings.updateTaskbarIcon(data, text, mainWindow);
});

ipcMain.on('forward-message', (_event: Electron.IpcMessageEvent, listener: any, ...params: any[]) => {
ipcMain.on('forward-message', (_event: Electron.IpcMainEvent, listener: any, ...params: any[]) => {
page.send(listener, ...params);
});

ipcMain.on('update-menu', (_event: Electron.IpcMessageEvent, props: any) => {
ipcMain.on('update-menu', (_event: Electron.IpcMainEvent, props: any) => {
AppMenu.setMenu(props);
const activeTab = props.tabs[props.activeTabIndex];
if (activeTab) {
mainWindow.setTitle(`Zulip - ${activeTab.webview.props.name}`);
}
});

ipcMain.on('toggleAutoLauncher', (_event: Electron.IpcMessageEvent, AutoLaunchValue: boolean) => {
ipcMain.on('toggleAutoLauncher', (_event: Electron.IpcMainEvent, AutoLaunchValue: boolean) => {
setAutoLaunch(AutoLaunchValue);
});

ipcMain.on('downloadFile', (_event: Electron.IpcMessageEvent, url: string, downloadPath: string) => {
ipcMain.on('downloadFile', (_event: Electron.IpcMainEvent, url: string, downloadPath: string) => {
page.downloadURL(url);
page.session.once('will-download', (_event: Event, item) => {
const filePath = path.join(downloadPath, item.getFilename());
Expand Down Expand Up @@ -352,21 +353,21 @@ app.on('ready', () => {
});
});

ipcMain.on('realm-name-changed', (_event: Electron.IpcMessageEvent, serverURL: string, realmName: string) => {
ipcMain.on('realm-name-changed', (_event: Electron.IpcMainEvent, serverURL: string, realmName: string) => {
page.send('update-realm-name', serverURL, realmName);
});

ipcMain.on('realm-icon-changed', (_event: Electron.IpcMessageEvent, serverURL: string, iconURL: string) => {
ipcMain.on('realm-icon-changed', (_event: Electron.IpcMainEvent, serverURL: string, iconURL: string) => {
page.send('update-realm-icon', serverURL, iconURL);
});

// Using event.sender.send instead of page.send here to
// make sure the value of errorReporting is sent only once on load.
ipcMain.on('error-reporting', (event: Electron.IpcMessageEvent) => {
ipcMain.on('error-reporting', (event: Electron.IpcMainEvent) => {
event.sender.send('error-reporting-val', errorReporting);
});

ipcMain.on('save-last-tab', (_event: Electron.IpcMessageEvent, index: number) => {
ipcMain.on('save-last-tab', (_event: Electron.IpcMainEvent, index: number) => {
ConfigUtil.setConfigItem('lastActiveTab', index);
});

Expand Down
15 changes: 8 additions & 7 deletions app/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class AppMenu {
role: 'togglefullscreen'
}, {
label: t.__('Zoom In'),
role: 'zoomin',
role: 'zoomIn',
click(_item: any, focusedWindow: any) {
if (focusedWindow) {
AppMenu.sendAction('zoomIn');
Expand Down Expand Up @@ -351,7 +351,7 @@ class AppMenu {
role: 'hide'
}, {
label: t.__('Hide Others'),
role: 'hideothers'
role: 'hideOthers'
}, {
label: t.__('Unhide'),
role: 'unhide'
Expand Down Expand Up @@ -388,10 +388,10 @@ class AppMenu {
role: 'paste'
}, {
label: t.__('Paste and Match Style'),
role: 'pasteandmatchstyle'
role: 'pasteAndMatchStyle'
}, {
label: t.__('Select All'),
role: 'selectall'
role: 'selectAll'
}]
}, {
label: t.__('View'),
Expand Down Expand Up @@ -504,12 +504,12 @@ class AppMenu {
role: 'paste'
}, {
label: t.__('Paste and Match Style'),
role: 'pasteandmatchstyle'
role: 'pasteAndMatchStyle'
}, {
type: 'separator'
}, {
label: t.__('Select All'),
role: 'selectall'
role: 'selectAll'
}]
}, {
label: t.__('View'),
Expand Down Expand Up @@ -572,7 +572,8 @@ class AppMenu {
defaultId: 0,
message: 'Are you sure?',
detail: resetAppSettingsMessage
}, response => {
}).then(res => {
const { response } = res;
if (response === 0) {
settingFiles.forEach(settingFileName => {
const getSettingFilesPath = path.join(app.getPath('appData'), appName, settingFileName);
Expand Down
14 changes: 10 additions & 4 deletions app/renderer/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,17 @@ class ServerManagerView {
pacScript: ConfigUtil.getConfigItem('proxyPAC', ''),
proxyRules: ConfigUtil.getConfigItem('proxyRules', ''),
proxyBypassRules: ConfigUtil.getConfigItem('proxyBypass', '')
}, resolve);
}).then(res => {
resolve();
});
} else {
session.fromPartition('persist:webviewsession').setProxy({
pacScript: '',
proxyRules: '',
proxyBypassRules: ''
}, resolve);
}).then(res => {
resolve();
});
}
});
}
Expand Down Expand Up @@ -283,7 +287,8 @@ class ServerManagerView {
buttons: ['Yes', 'Later'],
defaultId: 0,
message: 'New server' + (domainsAdded.length > 1 ? 's' : '') + ' added. Reload app now?'
}, response => {
}).then(res => {
const { response } = res;
if (response === 0) {
ipcRenderer.send('reload-full-app');
}
Expand Down Expand Up @@ -750,7 +755,8 @@ class ServerManagerView {
buttons: ['YES', 'NO'],
defaultId: 0,
message: 'Are you sure you want to disconnect this organization?'
}, response => {
}).then(res => {
const { response } = res;
if (response === 0) {
if (DomainUtil.removeDomain(index)) {
ipcRenderer.send('reload-full-app');
Expand Down
14 changes: 8 additions & 6 deletions app/renderer/js/pages/preference/add-certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ class AddCertificate extends BaseComponent {
properties: ['openFile'],
filters: [{ name: 'crt, pem', extensions: ['crt', 'pem'] }]
};
dialog.showOpenDialog(showDialogOptions, selectedFile => {
if (selectedFile) {
this._certFile = selectedFile[0] || '';
this.validateAndAdd();
}
});
dialog.showOpenDialog(showDialogOptions)
.then((res: Electron.OpenDialogReturnValue) => {
const { filePaths } = res;
if (filePaths && filePaths.length > 0) {
this._certFile = filePaths[0];
this.validateAndAdd();
}
});
}

initListeners(): void {
Expand Down
19 changes: 11 additions & 8 deletions app/renderer/js/pages/preference/general-section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ class GeneralSection extends BaseSection {
defaultId: 0,
message: 'Are you sure',
detail: clearAppDataMessage
}, response => {
}).then(res => {
const { response } = res;
if (response === 0) {
fs.remove(getAppPath);
setTimeout(() => ipcRenderer.send('forward-message', 'hard-reload'), 1000);
Expand All @@ -387,9 +388,10 @@ class GeneralSection extends BaseSection {
filters: [{ name: 'CSS file', extensions: ['css'] }]
};

dialog.showOpenDialog(showDialogOptions, selectedFile => {
if (selectedFile) {
ConfigUtil.setConfigItem('customCSS', selectedFile[0]);
dialog.showOpenDialog(showDialogOptions).then((res: Electron.OpenDialogReturnValue) => {
const { filePaths } = res;
if (filePaths && filePaths.length > 0) {
ConfigUtil.setConfigItem('customCSS', filePaths[0]);
ipcRenderer.send('forward-message', 'hard-reload');
}
});
Expand Down Expand Up @@ -442,11 +444,12 @@ class GeneralSection extends BaseSection {
properties: ['openDirectory']
};

dialog.showOpenDialog(showDialogOptions, selectedFolder => {
if (selectedFolder) {
ConfigUtil.setConfigItem('downloadsPath', selectedFolder[0]);
dialog.showOpenDialog(showDialogOptions).then((res: Electron.OpenDialogReturnValue) => {
const { filePaths } = res;
if (filePaths && filePaths.length > 0) {
ConfigUtil.setConfigItem('downloadsPath', filePaths[0]);
const downloadFolderPath: HTMLElement = document.querySelector('.download-folder-path');
downloadFolderPath.innerText = selectedFolder[0];
downloadFolderPath.innerText = filePaths[0];
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/js/pages/preference/server-info-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class ServerInfoForm extends BaseComponent {
buttons: [t.__('YES'), t.__('NO')],
defaultId: 0,
message: t.__('Are you sure you want to disconnect this organization?')
}, response => {
}).then(res => {
const { response } = res;
if (response === 0) {
if (DomainUtil.removeDomain(this.props.index)) {
ipcRenderer.send('reload-full-app');
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/js/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ window.addEventListener('load', (event: any): void => {

// electron's globalShortcut can cause unexpected results
// so adding the reload shortcut in the old-school way
// Zoom from numpad keys is not supported by electron, so adding it through listeners.
// electron does not support adding multiple accelerators for a menu item
// so adding numpad shortcuts here
document.addEventListener('keydown', event => {
const cmdOrCtrl = event.ctrlKey || event.metaKey;
if (event.code === 'F5') {
Expand Down
8 changes: 4 additions & 4 deletions app/renderer/js/utils/proxy-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ProxyUtil {

// Check HTTP Proxy
const httpProxy = new Promise(resolve => {
ses.resolveProxy('http://' + resolveProxyUrl, (proxy: string) => {
ses.resolveProxy('http://' + resolveProxyUrl).then((proxy: string) => {
let httpString = '';
if (proxy !== 'DIRECT') {
// in case of proxy HTTPS url:port, windows gives first word as HTTPS while linux gives PROXY
Expand All @@ -82,7 +82,7 @@ class ProxyUtil {
});
// Check HTTPS Proxy
const httpsProxy = new Promise(resolve => {
ses.resolveProxy('https://' + resolveProxyUrl, (proxy: string) => {
ses.resolveProxy('https://' + resolveProxyUrl).then((proxy: string) => {
let httpsString = '';
if (proxy !== 'DIRECT' || proxy.includes('HTTPS')) {
// in case of proxy HTTPS url:port, windows gives first word as HTTPS while linux gives PROXY
Expand All @@ -97,7 +97,7 @@ class ProxyUtil {

// Check FTP Proxy
const ftpProxy = new Promise(resolve => {
ses.resolveProxy('ftp://' + resolveProxyUrl, (proxy: string) => {
ses.resolveProxy('ftp://' + resolveProxyUrl).then((proxy: string) => {
let ftpString = '';
if (proxy !== 'DIRECT') {
if (proxy.includes('PROXY')) {
Expand All @@ -110,7 +110,7 @@ class ProxyUtil {

// Check SOCKS Proxy
const socksProxy = new Promise(resolve => {
ses.resolveProxy('socks4://' + resolveProxyUrl, (proxy: string) => {
ses.resolveProxy('socks4://' + resolveProxyUrl).then((proxy: string) => {
let socksString = '';
if (proxy !== 'DIRECT') {
if (proxy.includes('SOCKS5')) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"assert": "1.4.1",
"cp-file": "5.0.0",
"devtron": "1.4.0",
"electron": "3.1.10",
"electron": "7.1.2",
"electron-builder": "20.43.0",
"electron-connect": "0.6.2",
"electron-debug": "1.4.0",
Expand Down