Skip to content

Commit a76c467

Browse files
committed
🐛 Added default settings
Fixed bug where popover window wouldnt be positioned corectly due to display scaling (linux). Additionally fixed rare bug where error would show on quitting the application
1 parent 82b5300 commit a76c467

6 files changed

Lines changed: 68 additions & 25 deletions

File tree

src/main/app/AppController.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const log = require("electron-log");
33
const electron = require("electron");
44
const { crashReporter } = electron;
55

6+
const DefaultSettings = require("../resources/Defaults").defaultSettings;
67
const ShortcutController = require("./ShortcutController");
78
const Updater = require("./../resources/Updater");
89
const TrayController = require("./TrayController");
@@ -123,7 +124,7 @@ class AppController {
123124
};
124125
populatedShortcutObject.shortcut = this._Store.get(
125126
"settings.shortcutOpenMagnifierKeys",
126-
["Control", "I"]
127+
DefaultSettings.shortcutOpenMagnifierKeys
127128
);
128129
populatedShortcutObject.enabled = this._Store.get(
129130
"settings.shortcutOpenMagnifier",
@@ -145,7 +146,7 @@ class AppController {
145146
};
146147
populatedShortcutObject.shortcut = this._Store.get(
147148
"settings.shortcutOpenHistoryKeys",
148-
["Control", "P"]
149+
DefaultSettings.shortcutOpenHistoryKeys
149150
);
150151
populatedShortcutObject.enabled = this._Store.get(
151152
"settings.shortcutOpenHistory",
@@ -175,8 +176,7 @@ class AppController {
175176
* @memberof AppController
176177
*/
177178
_SetFlags() {
178-
// TODO: create default settings object
179-
const currentSettings = this._Store.get("settings", {});
179+
const currentSettings = this._Store.get("settings", DefaultSettings);
180180
this._App.commandLine.appendSwitch(
181181
"force-color-profile",
182182
currentSettings.colorProfile ? "default" : currentSettings.colorProfile
@@ -213,14 +213,22 @@ class AppController {
213213
this._WindowManager.isQuitting = true;
214214

215215
log.info("Removing Close Event Listeners From Windows");
216-
this._WindowManager.windows.history.removeAllListeners("close");
217-
this._WindowManager.windows.history.close();
218-
this._WindowManager.windows.popover.removeAllListeners("close");
219-
this._WindowManager.windows.popover.close();
220-
this._WindowManager.windows.settings.removeAllListeners("close");
221-
this._WindowManager.windows.settings.close();
222-
this._WindowManager.windows.picker.removeAllListeners("close");
223-
this._WindowManager.windows.picker.close();
216+
if (this._WindowManager.windows.history) {
217+
this._WindowManager.windows.history.removeAllListeners("close");
218+
this._WindowManager.windows.history.close();
219+
}
220+
if (this._WindowManager.windows.popover) {
221+
this._WindowManager.windows.popover.removeAllListeners("close");
222+
this._WindowManager.windows.popover.close();
223+
}
224+
if (this._WindowManager.windows.settings) {
225+
this._WindowManager.windows.settings.removeAllListeners("close");
226+
this._WindowManager.windows.settings.close();
227+
}
228+
if (this._WindowManager.windows.picker) {
229+
this._WindowManager.windows.picker.removeAllListeners("close");
230+
this._WindowManager.windows.picker.close();
231+
}
224232
});
225233

226234
this._App.on("window-all-closed", () => {

src/main/ipc/channel_types/PickerChannel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { nativeImage, clipboard } = electron;
33
const log = require("electron-log");
44
const svg2png = require("svg2png");
55

6+
const DefaultSettings = require("../../resources/Defaults").defaultSettings;
67
const Channel = require("./Channel");
78

89
/**
@@ -46,7 +47,7 @@ class PickerChannel extends Channel {
4647
*/
4748
newColorPick(args) {
4849
const color = args.color;
49-
const currentSettings = this.Store.get("settings", {}); // TODO: create default settings object
50+
const currentSettings = this.Store.get("settings", DefaultSettings); // TODO: create default settings object
5051
const paletteStore = this.Store.get("palettes", {
5152
HISTORY: { colors: [], name: "Color History", id: "HISTORY" }
5253
});

src/main/ipc/channel_types/SettingChannel.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const log = require("electron-log");
22

3+
const DefaultSettings = require("../../resources/Defaults").defaultSettings;
34
const Channel = require("./Channel");
45

56
/**
@@ -80,7 +81,7 @@ class SettingChannel extends Channel {
8081
* @memberof SettingChannel
8182
*/
8283
getSetting(args) {
83-
const currentSettings = this.Store.get("settings", {}); // TODO: create default settings object
84+
const currentSettings = this.Store.get("settings", DefaultSettings);
8485
log.log("GET", args.key, currentSettings[args.key]);
8586
return { response: currentSettings[args.key] };
8687
}
@@ -91,7 +92,7 @@ class SettingChannel extends Channel {
9192
* @memberof SettingChannel
9293
*/
9394
getAllSettings() {
94-
const currentSettings = this.Store.get("settings", {}); // TODO: create default settings object
95+
const currentSettings = this.Store.get("settings", DefaultSettings);
9596
log.log("GET_ALL", currentSettings);
9697
return currentSettings;
9798
}
@@ -105,7 +106,7 @@ class SettingChannel extends Channel {
105106
* @memberof SettingChannel
106107
*/
107108
modifySetting(args, autoUpdater, appController) {
108-
const currentSettings = this.Store.get("settings", {}); // TODO: create default settings object
109+
const currentSettings = this.Store.get("settings", DefaultSettings);
109110
currentSettings[args.key] = args.value;
110111
this.Store.set("settings", currentSettings);
111112

src/main/ipc/channel_types/WindowChannel.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ class WindowChannel extends Channel {
113113
*/
114114
showWindow(windowName) {
115115
if (this.WindowManager.windows[windowName]) {
116+
if (windowName === "popover") {
117+
const windowBounds = this.WindowManager.windows.history.getBounds();
118+
const windowScreen = screen.getDisplayNearestPoint({
119+
x: windowBounds.x,
120+
y: windowBounds.y
121+
});
122+
let windowY = windowBounds.y + 30 * windowScreen.scaleFactor;
123+
if (windowY + 260 >= windowScreen.bounds.height) {
124+
windowY = windowY - (260 - 60) * windowScreen.scaleFactor;
125+
}
126+
this.WindowManager.windows.popover.setBounds(
127+
{
128+
x: windowBounds.x + 30,
129+
y: windowY
130+
},
131+
false
132+
);
133+
}
116134
this.WindowManager.windows[windowName].show();
117135
return undefined;
118136
} else if (windowName === "settings") {
@@ -140,14 +158,13 @@ class WindowChannel extends Channel {
140158
});
141159

142160
const windowBounds = this.WindowManager.windows.history.getBounds();
143-
144-
let windowY = windowBounds.y + 50;
145161
const windowScreen = screen.getDisplayNearestPoint({
146162
x: windowBounds.x,
147163
y: windowBounds.y
148164
});
165+
let windowY = windowBounds.y + 30 * windowScreen.scaleFactor;
149166
if (windowY + 260 >= windowScreen.bounds.height) {
150-
windowY = windowY - 260 - 40;
167+
windowY = windowY - (260 - 60) * windowScreen.scaleFactor;
151168
}
152169
const w = new PopoverWindowController(this.WindowManager, popoverItems, {
153170
x: windowBounds.x + 30,

src/main/resources/Defaults.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
exports.defaultSettings = {
2+
lastUpdateCheck: new Date().getTime(),
3+
shortcutOpenMagnifierKeys: ["Control", "i"],
4+
shortcutOpenHistoryKeys: ["Control", "p"],
5+
shortcutMoveLensUpKeys: ["ArrowUp"],
6+
shortcutOpenMagnifier: true,
7+
launchOnStartup: true,
8+
playSounds: true,
9+
isHistoryLimit: false,
10+
showPickedColor: true,
11+
shortcutMoveLensRightKeys: ["ArrowRight"],
12+
shortcutMoveLensRight: true,
13+
shortcutMoveLensUp: true,
14+
shortcutOpenHistory: true,
15+
historyLimit: "30"
16+
};

src/main/resources/Updater.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const log = require("electron-log");
22

33
const { autoUpdater } = require("electron-updater");
4-
4+
const DefaultSettings = require("../resources/Defaults").defaultSettings;
55
/**
66
* Updater Class
77
*
@@ -20,7 +20,7 @@ class Updater {
2020
this._AutoUpdaterInterval = null;
2121
autoUpdater.logger = log;
2222
autoUpdater.logger.transports.file.level = "info";
23-
const settings = store.get("settings", {});
23+
const settings = store.get("settings", DefaultSettings);
2424
this._AutoCheck =
2525
settings.autoCheckDownloadUpdates === undefined ||
2626
settings.autoCheckDownloadUpdates === true
@@ -41,7 +41,7 @@ class Updater {
4141
if (this._AutoCheck) {
4242
log.info("Starting Automatic Update Checking Interval");
4343
this._AutoUpdaterInterval = setInterval(() => {
44-
const settings = this._Store.get("settings", {});
44+
const settings = this._Store.get("settings", DefaultSettings);
4545
this._AutoCheck =
4646
settings.autoCheckDownloadUpdates === undefined ||
4747
settings.autoCheckDownloadUpdates === true
@@ -77,7 +77,7 @@ class Updater {
7777
*/
7878
async checkForUpdates() {
7979
// set last checked for update timestamp to now
80-
const currentSettings = this._Store.get("settings", {});
80+
const currentSettings = this._Store.get("settings", DefaultSettings);
8181
currentSettings.lastUpdateCheck = new Date().getTime();
8282
this._Store.set("settings", currentSettings);
8383
// check for updates
@@ -111,7 +111,7 @@ class Updater {
111111

112112
autoUpdater.on("update-available", info => {
113113
log.info("A newer version is available", info);
114-
const currentSettings = this._Store.get("settings", {}); // TODO: create default settings object
114+
const currentSettings = this._Store.get("settings", DefaultSettings);
115115
if (currentSettings.autoCheckDownloadUpdates === true) {
116116
this.downloadLatestUpdate();
117117
if (this._WindowManager.windows.settings) {
@@ -149,7 +149,7 @@ class Updater {
149149

150150
autoUpdater.on("update-downloaded", info => {
151151
log.info("Update has been downloaded", info);
152-
const currentSettings = this._Store.get("settings", {}); // TODO: create default settings object
152+
const currentSettings = this._Store.get("settings", DefaultSettings);
153153
if (currentSettings.autoInstallUpdates === true) {
154154
autoUpdater.quitAndInstall(true, true);
155155
} else {

0 commit comments

Comments
 (0)