Skip to content

Commit

Permalink
Merge 'fix/window-bounds' into 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Dec 5, 2018
1 parent ca1d618 commit 08fa75a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
Binary file added src/assets/images/taskbar/win32/display.ico
Binary file not shown.
7 changes: 7 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export const DEFAULT_FEATURES_CONFIG = {
isServiceProxyPremiumFeature: true,
};

export const DEFAULT_WINDOW_OPTIONS = {
width: 800,
height: 600,
x: 0,
y: 0,
};

export const FRANZ_SERVICE_REQUEST = 'https://bit.ly/franz-plugin-docs';
export const FRANZ_TRANSLATION = 'https://bit.ly/franz-translate';

Expand Down
11 changes: 11 additions & 0 deletions src/electron/windowUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint import/prefer-default-export: 0 */

import { screen } from 'electron';

export function isPositionValid(position) {
const displays = screen.getAllDisplays();
const { x, y } = position;
return displays.some(({
workArea,
}) => x >= workArea.x && x <= workArea.x + workArea.width && y >= workArea.y && y <= workArea.y + workArea.height);
}
47 changes: 41 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import ipcApi from './electron/ipc-api';
import Tray from './lib/Tray';
import Settings from './electron/Settings';
import handleDeepLink from './electron/deepLinking';
import { isPositionValid } from './electron/windowUtils';
import { appId } from './package.json'; // eslint-disable-line import/no-unresolved
import './electron/exception';

import { DEFAULT_APP_SETTINGS } from './config';
import {
DEFAULT_APP_SETTINGS,
DEFAULT_WINDOW_OPTIONS,
} from './config';
/* eslint-enable import/first */

const debug = require('debug')('Franz:App');
Expand Down Expand Up @@ -52,6 +56,15 @@ const isSecondInstance = app.makeSingleInstance((argv) => {
}
}
}

if (argv.includes('--reset-window')) {
// Needs to be delayed to not interfere with mainWindow.restore();
setTimeout(() => {
debug('Resetting windows via Task');
mainWindow.setPosition(DEFAULT_WINDOW_OPTIONS.x + 100, DEFAULT_WINDOW_OPTIONS.y + 100);
mainWindow.setSize(DEFAULT_WINDOW_OPTIONS.width, DEFAULT_WINDOW_OPTIONS.height);
}, 1);
}
});

if (isSecondInstance) {
Expand All @@ -78,14 +91,23 @@ if (!settings.get('enableGPUAcceleration')) {
const createWindow = () => {
// Remember window size
const mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600,
defaultWidth: DEFAULT_WINDOW_OPTIONS.width,
defaultHeight: DEFAULT_WINDOW_OPTIONS.height,
});

let posX = mainWindowState.x || DEFAULT_WINDOW_OPTIONS.x;
let posY = mainWindowState.y || DEFAULT_WINDOW_OPTIONS.y;

if (!isPositionValid({ x: posX, y: posY })) {
debug('Window is out of screen bounds, resetting window');
posX = DEFAULT_WINDOW_OPTIONS.x;
posY = DEFAULT_WINDOW_OPTIONS.y;
}

// Create the browser window.
mainWindow = new BrowserWindow({
x: mainWindowState.x,
y: mainWindowState.y,
x: posX,
y: posY,
width: mainWindowState.width,
height: mainWindowState.height,
minWidth: 600,
Expand Down Expand Up @@ -187,7 +209,20 @@ const createWindow = () => {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
app.on('ready', () => {
if (process.platform === 'win32') {
app.setUserTasks([{
program: process.execPath,
arguments: `${isDevMode ? `${__dirname} ` : ''}--reset-window`,
iconPath: path.join(`${__dirname}`, '../src/assets/images/taskbar/win32/display.ico'),
iconIndex: 0,
title: 'Move Franz to Current Display',
description: 'Restore the position and size of Franz',
}]);
}

createWindow();
});

// This is the worst possible implementation as the webview.webContents based callback doesn't work 🖕
app.on('login', (event, webContents, request, authInfo, callback) => {
Expand Down

0 comments on commit 08fa75a

Please sign in to comment.