Typescript - Downgrade electron version to 3.x and fix api changes

This commit is contained in:
Kiran Niranjan 2019-05-07 11:26:12 +05:30
parent 1957f834d6
commit 4d2609263d
8 changed files with 48 additions and 80 deletions

View File

@ -89,18 +89,12 @@
"@types/node": "10.11.4",
"@types/react": "16.8.3",
"@types/react-dom": "16.0.9",
"babel-cli": "6.26.0",
"babel-eslint": "7.2.3",
"babel-plugin-transform-async-to-generator": "6.24.1",
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-es2016-node5": "1.1.2",
"babel-register": "6.26.0",
"bluebird": "3.5.3",
"browserify": "16.2.3",
"chromedriver": "2.45.0",
"cross-env": "5.2.0",
"del": "3.0.0",
"electron": "5.0.0-beta.8",
"electron": "3.1.6",
"electron-builder": "20.38.4",
"electron-builder-squirrel-windows": "20.38.3",
"electron-chromedriver": "4.0.0-beta.1",
@ -134,13 +128,12 @@
"archiver": "3.0.0",
"async.map": "0.5.2",
"async.mapseries": "0.5.2",
"auto-launch": "5.0.5",
"classnames": "2.2.6",
"electron-dl": "1.12.0",
"electron-fetch": "1.3.0",
"electron-log": "2.2.17",
"electron-spellchecker": "git+https://github.com/symphonyoss/electron-spellchecker.git#v2.0.1",
"ffi": "git+https://github.com/symphonyoss/node-ffi.git#v1.2.9",
"ffi-napi": "2.4.5",
"filesize": "3.6.1",
"jimp": "0.6.0",
"keymirror": "0.1.1",

View File

@ -235,9 +235,9 @@ export class AppMenu {
checked: launchOnStartup,
click: async (item) => {
if (item.checked) {
await autoLaunch.enableAutoLaunch();
autoLaunch.enableAutoLaunch();
} else {
await autoLaunch.disableAutoLaunch();
autoLaunch.disableAutoLaunch();
}
launchOnStartup = item.checked;
await config.updateUserConfig({ launchOnStartup });

View File

@ -1,8 +1,6 @@
import AutoLaunch = require('auto-launch');
import { BrowserWindow, dialog } from 'electron';
import { app, LoginItemSettings } from 'electron';
import { isMac } from '../common/env';
import { i18n } from '../common/i18n';
import { logger } from '../common/logger';
import { config, IConfig } from './config-handler';
@ -21,41 +19,16 @@ const props = isMac ? {
: null || process.execPath,
};
export interface IAutoLaunchOptions {
name: string;
path?: string;
isHidden?: boolean;
mac?: {
useLaunchAgent?: boolean;
};
}
class AutoLaunchController extends AutoLaunch {
constructor(opts: IAutoLaunchOptions) {
super(opts);
}
class AutoLaunchController {
/**
* Enable auto launch and displays error dialog on failure
*
* @return {Promise<void>}
*/
public async enableAutoLaunch(): Promise<void> {
public enableAutoLaunch(): void {
logger.info(`Enabling auto launch!`);
const focusedWindow = BrowserWindow.getFocusedWindow();
await this.enable()
.catch((err) => {
const title = 'Error setting AutoLaunch configuration';
logger.error(`auto-launch-controller: ${title}: failed to enable auto launch error: ${err}`);
if (focusedWindow && !focusedWindow.isDestroyed()) {
dialog.showMessageBox(focusedWindow, {
message: i18n.t(title)() + ': ' + err,
title: i18n.t(title)(),
type: 'error',
});
}
});
app.setLoginItemSettings({ openAtLogin: true, path: props.path });
}
/**
@ -63,21 +36,9 @@ class AutoLaunchController extends AutoLaunch {
*
* @return {Promise<void>}
*/
public async disableAutoLaunch(): Promise<void> {
public disableAutoLaunch(): void {
logger.info(`Disabling auto launch!`);
const focusedWindow = BrowserWindow.getFocusedWindow();
await this.disable()
.catch((err) => {
const title = 'Error setting AutoLaunch configuration';
logger.error(`auto-launch-controller: ${title}: failed to disable auto launch error: ${err}`);
if (focusedWindow && !focusedWindow.isDestroyed()) {
dialog.showMessageBox(focusedWindow, {
message: i18n.t(title)() + ': ' + err,
title: i18n.t(title)(),
type: 'error',
});
}
});
app.setLoginItemSettings({ openAtLogin: false, path: props.path });
}
/**
@ -85,8 +46,8 @@ class AutoLaunchController extends AutoLaunch {
*
* @return {Boolean}
*/
public async isAutoLaunchEnabled(): Promise<boolean> {
return await this.isEnabled();
public isAutoLaunchEnabled(): LoginItemSettings {
return app.getLoginItemSettings();
}
/**
@ -94,21 +55,21 @@ class AutoLaunchController extends AutoLaunch {
*/
public async handleAutoLaunch(): Promise<void> {
const { launchOnStartup }: IConfig = config.getConfigFields([ 'launchOnStartup' ]);
const isAutoLaunchEnabled = await this.isAutoLaunchEnabled();
const { openAtLogin: isAutoLaunchEnabled }: LoginItemSettings = this.isAutoLaunchEnabled();
if (typeof launchOnStartup === 'boolean' && launchOnStartup) {
if (!isAutoLaunchEnabled) {
await this.enableAutoLaunch();
this.enableAutoLaunch();
}
return;
}
if (isAutoLaunchEnabled) {
await this.disableAutoLaunch();
this.disableAutoLaunch();
}
}
}
const autoLaunchInstance = new AutoLaunchController(props);
const autoLaunchInstance = new AutoLaunchController();
export {
autoLaunchInstance,

View File

@ -18,7 +18,7 @@ class MemoryMonitor {
this.isInMeeting = false;
this.canReload = true;
this.maxIdleTime = 4 * 60 * 60 * 1000; // 4 hours
this.memoryThreshold = 800 * 1024; // 800MB
this.memoryThreshold = 800; // 800MB
this.memoryRefreshThreshold = 60 * 60 * 1000; // 1 hour
}
@ -54,15 +54,16 @@ class MemoryMonitor {
(electron.powerMonitor as any).querySystemIdleTime((time) => {
const idleTime = time * 1000;
const workingSetSizeInMB = this.memoryInfo && (this.memoryInfo.workingSetSize / 1024) || 0;
if (!(!this.isInMeeting
&& windowHandler.isOnline
&& this.canReload
&& idleTime > this.maxIdleTime
&& (this.memoryInfo && this.memoryInfo.private > this.memoryThreshold))
&& (workingSetSizeInMB > this.memoryThreshold))
) {
logger.info(`Not Reloading the app as
application was refreshed less than a hour ago? ${this.canReload ? 'no' : 'yes'}
memory consumption is ${(this.memoryInfo && this.memoryInfo.private) || 'unknown'}kb is less than? ${this.memoryThreshold}kb
memory consumption is ${(workingSetSizeInMB) || 'unknown'}mb is less than? ${this.memoryThreshold}mb
system idle tick was ${idleTime}ms is less than? ${this.maxIdleTime}ms
user was in a meeting? ${this.isInMeeting}
is network online? ${windowHandler.isOnline}`);
@ -71,7 +72,7 @@ class MemoryMonitor {
const mainWindow = windowHandler.getMainWindow();
if (mainWindow && windowExists(mainWindow)) {
logger.info(`Reloading the app to optimize memory usage as
memory consumption is ${this.memoryInfo.private}kb is greater than? ${this.memoryThreshold}kb threshold
memory consumption is ${workingSetSizeInMB}mb is greater than? ${this.memoryThreshold}mb threshold
system idle tick was ${idleTime}ms is greater than ${this.maxIdleTime}ms
user was in a meeting? ${this.isInMeeting}
is network online? ${windowHandler.isOnline}`);

View File

@ -1,15 +1,26 @@
import { app, MenuItem } from 'electron';
import * as path from 'path';
import { ContextMenuBuilder, SpellCheckHandler } from 'electron-spellchecker';
import { isMac } from '../common/env';
import { ContextMenuBuilder, DictionarySync, SpellCheckHandler } from 'electron-spellchecker';
import { isDevEnv, isMac } from '../common/env';
import { i18n, LocaleType } from '../common/i18n';
export class SpellChecker {
public locale: LocaleType = 'en-US';
private readonly spellCheckHandler: SpellCheckHandler;
private readonly dictionaryPath: string | undefined;
private readonly dictionarySync: DictionarySync;
constructor() {
this.spellCheckHandler = new SpellCheckHandler();
const dictionariesDirName = 'dictionaries';
if (isDevEnv) {
this.dictionaryPath = path.join(app.getAppPath(), dictionariesDirName);
} else {
const execPath = path.dirname(app.getPath('exe'));
this.dictionaryPath = path.join(execPath, isMac ? '..' : '', dictionariesDirName);
}
this.dictionarySync = new DictionarySync(this.dictionaryPath);
this.spellCheckHandler = new SpellCheckHandler(this.dictionarySync);
this.spellCheckHandler.automaticallyIdentifyLanguages = false;
// language is switched w.r.t to the current system language.
if (!isMac) {

View File

@ -855,7 +855,7 @@ export class WindowHandler {
nodeIntegration: false,
preload: path.join(__dirname, '../renderer/_preload-main.js'),
sandbox: true,
contextIsolation: true,
contextIsolation: false,
},
winKey: getGuid(),
};

View File

@ -121,10 +121,15 @@ export const createComponentWindow = (
const browserWindow: ICustomBrowserWindow = new BrowserWindow(options) as ICustomBrowserWindow;
if (shouldFocus) {
browserWindow.once('ready-to-show', () => browserWindow.show());
browserWindow.once('ready-to-show', () => {
if (!browserWindow || !windowExists(browserWindow)) {
return;
}
browserWindow.show();
});
}
browserWindow.webContents.once('did-finish-load', () => {
if (!browserWindow || browserWindow.isDestroyed()) {
if (!browserWindow || !windowExists(browserWindow)) {
return;
}
browserWindow.webContents.send('set-locale-resource', { locale: i18n.getLocale(), resource: i18n.loadedResources });

View File

@ -59,15 +59,12 @@ ipcRenderer.on('page-load', (_event, { locale, resources, origin, enableCustomTi
ReactDOM.render(element, div);
}
webFrame.setSpellCheckProvider('en-US', {
spellCheck(words, callback) {
const misspelled = words.filter((word) => {
return ipcRenderer.sendSync(apiName.symphonyApi, {
cmd: apiCmds.isMisspelled,
word,
});
webFrame.setSpellCheckProvider('en-US', false,{
spellCheck(text) {
return !ipcRenderer.sendSync(apiName.symphonyApi, {
cmd: apiCmds.isMisspelled,
word: text,
});
callback(misspelled);
},
});