Electron: Fixes #312 (maybe): Removed power saving feature, which wasn\'t doing anything and added a possible fix to the UI freezing issue on Linux

pull/896/head
Laurent Cozic 2018-10-12 23:44:00 +01:00
parent 1634fdb421
commit e4166e9da7
3 changed files with 31 additions and 33 deletions

View File

@ -49,7 +49,6 @@ class Application extends BaseApplication {
constructor() { constructor() {
super(); super();
this.lastMenuScreen_ = null; this.lastMenuScreen_ = null;
this.powerSaveBlockerId_ = null;
} }
hasGui() { hasGui() {
@ -221,17 +220,6 @@ class Application extends BaseApplication {
Setting.setValue('sidebarVisibility', newState.sidebarVisibility); Setting.setValue('sidebarVisibility', newState.sidebarVisibility);
} }
if (action.type === 'SYNC_STARTED') {
if (!this.powerSaveBlockerId_) this.powerSaveBlockerId_ = bridge().powerSaveBlockerStart('prevent-app-suspension');
}
if (action.type === 'SYNC_COMPLETED') {
if (this.powerSaveBlockerId_) {
bridge().powerSaveBlockerStop(this.powerSaveBlockerId_);
this.powerSaveBlockerId_ = null;
}
}
return result; return result;
} }
@ -741,8 +729,6 @@ class Application extends BaseApplication {
ids: Setting.value('collapsedFolderIds'), ids: Setting.value('collapsedFolderIds'),
}); });
if (shim.isLinux()) bridge().setAllowPowerSaveBlockerToggle(true);
// Note: Auto-update currently doesn't work in Linux: it downloads the update // Note: Auto-update currently doesn't work in Linux: it downloads the update
// but then doesn't install it on exit. // but then doesn't install it on exit.
if (shim.isWindows() || shim.isMac()) { if (shim.isWindows() || shim.isMac()) {

View File

@ -1,7 +1,6 @@
const { _, setLocale } = require('lib/locale.js'); const { _, setLocale } = require('lib/locale.js');
const { dirname } = require('lib/path-utils.js'); const { dirname } = require('lib/path-utils.js');
const { Logger } = require('lib/logger.js'); const { Logger } = require('lib/logger.js');
const { powerSaveBlocker } = require('electron');
class Bridge { class Bridge {
@ -9,7 +8,6 @@ class Bridge {
this.electronWrapper_ = electronWrapper; this.electronWrapper_ = electronWrapper;
this.autoUpdateLogger_ = null; this.autoUpdateLogger_ = null;
this.lastSelectedPath_ = null; this.lastSelectedPath_ = null;
this.allowPowerSaveBlockerToggle_ = false;
} }
electronApp() { electronApp() {
@ -24,10 +22,6 @@ class Bridge {
return this.electronWrapper_.window(); return this.electronWrapper_.window();
} }
setAllowPowerSaveBlockerToggle(v) {
this.allowPowerSaveBlockerToggle_ = v;
}
windowContentSize() { windowContentSize() {
if (!this.window()) return { width: 0, height: 0 }; if (!this.window()) return { width: 0, height: 0 };
const s = this.window().getContentSize(); const s = this.window().getContentSize();
@ -126,19 +120,7 @@ class Bridge {
const { checkForUpdates } = require('./checkForUpdates.js'); const { checkForUpdates } = require('./checkForUpdates.js');
checkForUpdates(inBackground, window, logFilePath); checkForUpdates(inBackground, window, logFilePath);
} }
powerSaveBlockerStart(type) {
if (!this.allowPowerSaveBlockerToggle_) return null;
console.info('Enable powerSaveBlockerStart: ' + type);
return powerSaveBlocker.start(type);
}
powerSaveBlockerStop(id) {
if (!this.allowPowerSaveBlockerToggle_) return null;
console.info('Disable powerSaveBlocker: ' + id);
return powerSaveBlocker.stop(id);
}
} }
let bridge_ = null; let bridge_ = null;

View File

@ -12,6 +12,7 @@ const { bridge } = require("electron").remote.require("./bridge");
const Menu = bridge().Menu; const Menu = bridge().Menu;
const MenuItem = bridge().MenuItem; const MenuItem = bridge().MenuItem;
const InteropServiceHelper = require("../InteropServiceHelper.js"); const InteropServiceHelper = require("../InteropServiceHelper.js");
const { shim } = require('lib/shim');
class SideBarComponent extends React.Component { class SideBarComponent extends React.Component {
@ -178,6 +179,35 @@ class SideBarComponent extends React.Component {
return style; return style;
} }
clearForceUpdateDuringSync() {
if (this.forceUpdateDuringSyncIID_) {
clearInterval(this.forceUpdateDuringSyncIID_);
this.forceUpdateDuringSyncIID_ = null;
}
}
componentDidUpdate(prevProps) {
if (shim.isLinux()) {
// For some reason, the UI seems to sleep in some Linux distro during
// sync. Cannot find the reason for it and cannot replicate, so here
// as a test force the update at regular intervals.
// https://github.com/laurent22/joplin/issues/312#issuecomment-429472193
if (!prevProps.syncStarted && this.props.syncStarted) {
this.clearForceUpdateDuringSync();
this.forceUpdateDuringSyncIID_ = setInterval(() => {
this.forceUpdate();
}, 2000);
}
if (prevProps.syncStarted && !this.props.syncStarted) this.clearForceUpdateDuringSync();
}
}
componentWillUnmount() {
this.clearForceUpdateDuringSync();
}
itemContextMenu(event) { itemContextMenu(event) {
const itemId = event.target.getAttribute("data-id"); const itemId = event.target.getAttribute("data-id");
if (itemId === Folder.conflictFolderId()) return; if (itemId === Folder.conflictFolderId()) return;