Skip to content

Commit 08fa75a

Browse files
committed
Merge 'fix/window-bounds' into 'develop'
1 parent ca1d618 commit 08fa75a

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed
98.9 KB
Binary file not shown.

src/config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ export const DEFAULT_FEATURES_CONFIG = {
3939
isServiceProxyPremiumFeature: true,
4040
};
4141

42+
export const DEFAULT_WINDOW_OPTIONS = {
43+
width: 800,
44+
height: 600,
45+
x: 0,
46+
y: 0,
47+
};
48+
4249
export const FRANZ_SERVICE_REQUEST = 'https://bit.ly/franz-plugin-docs';
4350
export const FRANZ_TRANSLATION = 'https://bit.ly/franz-translate';
4451

src/electron/windowUtils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint import/prefer-default-export: 0 */
2+
3+
import { screen } from 'electron';
4+
5+
export function isPositionValid(position) {
6+
const displays = screen.getAllDisplays();
7+
const { x, y } = position;
8+
return displays.some(({
9+
workArea,
10+
}) => x >= workArea.x && x <= workArea.x + workArea.width && y >= workArea.y && y <= workArea.y + workArea.height);
11+
}

src/index.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import ipcApi from './electron/ipc-api';
1515
import Tray from './lib/Tray';
1616
import Settings from './electron/Settings';
1717
import handleDeepLink from './electron/deepLinking';
18+
import { isPositionValid } from './electron/windowUtils';
1819
import { appId } from './package.json'; // eslint-disable-line import/no-unresolved
1920
import './electron/exception';
2021

21-
import { DEFAULT_APP_SETTINGS } from './config';
22+
import {
23+
DEFAULT_APP_SETTINGS,
24+
DEFAULT_WINDOW_OPTIONS,
25+
} from './config';
2226
/* eslint-enable import/first */
2327

2428
const debug = require('debug')('Franz:App');
@@ -52,6 +56,15 @@ const isSecondInstance = app.makeSingleInstance((argv) => {
5256
}
5357
}
5458
}
59+
60+
if (argv.includes('--reset-window')) {
61+
// Needs to be delayed to not interfere with mainWindow.restore();
62+
setTimeout(() => {
63+
debug('Resetting windows via Task');
64+
mainWindow.setPosition(DEFAULT_WINDOW_OPTIONS.x + 100, DEFAULT_WINDOW_OPTIONS.y + 100);
65+
mainWindow.setSize(DEFAULT_WINDOW_OPTIONS.width, DEFAULT_WINDOW_OPTIONS.height);
66+
}, 1);
67+
}
5568
});
5669

5770
if (isSecondInstance) {
@@ -78,14 +91,23 @@ if (!settings.get('enableGPUAcceleration')) {
7891
const createWindow = () => {
7992
// Remember window size
8093
const mainWindowState = windowStateKeeper({
81-
defaultWidth: 800,
82-
defaultHeight: 600,
94+
defaultWidth: DEFAULT_WINDOW_OPTIONS.width,
95+
defaultHeight: DEFAULT_WINDOW_OPTIONS.height,
8396
});
8497

98+
let posX = mainWindowState.x || DEFAULT_WINDOW_OPTIONS.x;
99+
let posY = mainWindowState.y || DEFAULT_WINDOW_OPTIONS.y;
100+
101+
if (!isPositionValid({ x: posX, y: posY })) {
102+
debug('Window is out of screen bounds, resetting window');
103+
posX = DEFAULT_WINDOW_OPTIONS.x;
104+
posY = DEFAULT_WINDOW_OPTIONS.y;
105+
}
106+
85107
// Create the browser window.
86108
mainWindow = new BrowserWindow({
87-
x: mainWindowState.x,
88-
y: mainWindowState.y,
109+
x: posX,
110+
y: posY,
89111
width: mainWindowState.width,
90112
height: mainWindowState.height,
91113
minWidth: 600,
@@ -187,7 +209,20 @@ const createWindow = () => {
187209
// This method will be called when Electron has finished
188210
// initialization and is ready to create browser windows.
189211
// Some APIs can only be used after this event occurs.
190-
app.on('ready', createWindow);
212+
app.on('ready', () => {
213+
if (process.platform === 'win32') {
214+
app.setUserTasks([{
215+
program: process.execPath,
216+
arguments: `${isDevMode ? `${__dirname} ` : ''}--reset-window`,
217+
iconPath: path.join(`${__dirname}`, '../src/assets/images/taskbar/win32/display.ico'),
218+
iconIndex: 0,
219+
title: 'Move Franz to Current Display',
220+
description: 'Restore the position and size of Franz',
221+
}]);
222+
}
223+
224+
createWindow();
225+
});
191226

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

0 commit comments

Comments
 (0)