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

perf: Improve away detection #1542

Merged
merged 2 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const MAIN_WINDOW_STATE_CHANGED = 'main-window/state-changed';
export const MAIN_WINDOW_WEBCONTENTS_FOCUSED = 'main-window/webcontents-focused';
export const MENU_BAR_ABOUT_CLICKED = 'menu-bar/about-clicked';
export const MENU_BAR_ADD_NEW_SERVER_CLICKED = 'menu-bar/add-new-server-clicked';
export const MENU_BAR_DISABLE_GPU = 'menu-bar/disable-gpu';
export const MENU_BAR_CLEAR_TRUSTED_CERTIFICATES_CLICKED = 'menu-bar/clear-trusted-certificates-clicked';
export const MENU_BAR_GO_BACK_CLICKED = 'menu-bar/go-back-clicked';
export const MENU_BAR_GO_FORWARD_CLICKED = 'menu-bar/go-forward-clicked';
Expand Down
6 changes: 6 additions & 0 deletions src/components/MainWindow/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MENU_BAR_GO_BACK_CLICKED,
MENU_BAR_GO_FORWARD_CLICKED,
MENU_BAR_QUIT_CLICKED,
MENU_BAR_DISABLE_GPU,
MENU_BAR_RELOAD_APP_CLICKED,
MENU_BAR_RELOAD_SERVER_CLICKED,
MENU_BAR_RESET_ZOOM_CLICKED,
Expand Down Expand Up @@ -304,6 +305,11 @@ function *takeActions(browserWindow) {
], function *() {
browserWindow.destroy();
});

yield takeEvery(MENU_BAR_DISABLE_GPU, function *() {
remote.app.relaunch({ args: remote.process.argv.slice(1).concat('--disable-gpu') });
remote.app.exit();
});
}

export function *mainWindowStateSaga(browserWindow) {
Expand Down
7 changes: 7 additions & 0 deletions src/components/MenuBar/AppMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
MENU_BAR_ABOUT_CLICKED,
MENU_BAR_ADD_NEW_SERVER_CLICKED,
MENU_BAR_QUIT_CLICKED,
MENU_BAR_DISABLE_GPU,
} from '../../actions';
import { Menu } from '../electron/Menu';
import { MenuItem } from '../electron/MenuItem';
Expand Down Expand Up @@ -51,6 +52,12 @@ export const AppMenu = forwardRef(function AppMenu(_, ref) {
/>
<MenuItem type='separator' />
</>}
<MenuItem
label={t('Disable GPU')}
enabled={!remote.app.commandLine.hasSwitch('disable-gpu')}
onClick={() => dispatch({ type: MENU_BAR_DISABLE_GPU })}
/>
<MenuItem type='separator' />
<MenuItem
label={t('menus.quit', { appName })}
accelerator={'CommandOrControl+Q'}
Expand Down
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const prepareApp = () => {
process.argv.slice(app.isPackaged ? 1 : 2),
];

if (args.includes('--disable-gpu')) {
app.commandLine.appendSwitch('--disable-2d-canvas-image-chromium');
app.commandLine.appendSwitch('--disable-accelerated-2d-canvas');
app.commandLine.appendSwitch('--disable-gpu');
}

if (args.includes('--reset-app-data')) {
const dataDir = app.getPath('userData');
rimraf.sync(dataDir);
Expand Down
14 changes: 13 additions & 1 deletion src/preload/userPresence.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { remote } from 'electron';
import { remote, app } from 'electron';

import { getMeteor, getTracker, getGetUserPreference, getUserPresence } from './rocketChat';

Expand Down Expand Up @@ -41,6 +41,18 @@ const handleUserPresence = () => {
}, 1000);
};

// if the system is put to sleep or screen is locked(windows OS), set userPresence to away
const handleSystemActions = () => {
const Meteor = getMeteor();
remote.powerMonitor.on('suspend', () => {
Meteor.call('UserPresence:away');
});
// windows OS only
remote.powerMonitor.on('lock-screen', () => {
Meteor.call('UserPresence:away');
});
};
export default () => {
window.addEventListener('load', handleUserPresence);
window.addEventListener('load', handleSystemActions);
};