Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import { screen } from 'electron';
import { getSavedWindowPosition, hasSavedWindowPosition } from '../settings';
import Pino from '../utils/pino';
const pino = Pino();
function showWindow (trayPos) {
if (!this.fetherApp.window) {
this.createWindow();
}
this.fetherApp.emit('show-window');
const calculatedWindowPosition = this.calculateWindowPosition(trayPos);
pino.info('Calculated window position: ', calculatedWindowPosition);
const mainScreen = screen.getPrimaryDisplay();
// const allScreens = screen.getAllDisplays();
const mainScreenDimensions = mainScreen.size;
const mainScreenWorkAreaSize = mainScreen.workAreaSize;
// workAreaSize does not include the tray depth
this.fetherApp.trayDepth = Math.max(
mainScreenDimensions.width - mainScreenWorkAreaSize.width,
mainScreenDimensions.height - mainScreenWorkAreaSize.height
);
pino.info(
'Previously saved window position exists: ',
hasSavedWindowPosition()
);
const loadedWindowPosition = hasSavedWindowPosition()
? getSavedWindowPosition()
: undefined;
pino.info('Loaded window position: ', loadedWindowPosition);
const fixedWindowPosition = this.fixWindowPosition(loadedWindowPosition);
pino.info('Fixed window position: ', fixedWindowPosition);
/**
* Since the user may change the tray to be on any side of the screen.
* If the user moved the window out of where the tray would be in the screen resolution bounds.
* Restore the window so it is fully visible adjacent to where the tray would be.
*/
const x =
(fixedWindowPosition && fixedWindowPosition.x) ||
(loadedWindowPosition && loadedWindowPosition.x) ||
calculatedWindowPosition.x;
const y =
(fixedWindowPosition && fixedWindowPosition.y) ||
(loadedWindowPosition && loadedWindowPosition.y) ||
calculatedWindowPosition.y;
this.fetherApp.window.setPosition(x, y);
this.fetherApp.window.show();
this.fetherApp.emit('after-show-window');
}
export default showWindow;