Skip to content

Commit

Permalink
fix(color-picker): dismiss color picker by clicking outside color picker
Browse files Browse the repository at this point in the history
fixes #461
  • Loading branch information
2xAA committed Nov 13, 2022
1 parent e62f47a commit 9fca1cd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ app.on("ready", async () => {
"true"
);

createWindow("mainWindow");
createWindow("splashScreen");
createWindow({ windowName: "mainWindow" });
createWindow({ windowName: "splashScreen" });
createWindow({ windowName: "colorPicker", options: { show: false } });
});

// Exit cleanly on request from parent process in development mode.
Expand Down
21 changes: 18 additions & 3 deletions src/background/window-prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import store from "../media-manager/store";
import { autoUpdater } from "electron-updater";
import { checkMediaPermission } from "./check-media-permission";
import { setProjectNames, setCurrentProject } from "./projects";
import { createWindow, windows } from "./windows";
import { closeWindow, createWindow, windows } from "./windows";
import { updateMenu } from "./menu-bar";
import { getMediaManager } from "./media-manager";

Expand All @@ -29,7 +29,18 @@ const windowPrefs = {
skipTaskbar: true,
fullscreenable: false
},
unique: true
unique: true,
create(window) {
window.on("close", e => {
e.preventDefault();

window.hide();
});

window.on("blur", () => {
window.hide();
});
}
},

mainWindow: {
Expand Down Expand Up @@ -95,7 +106,11 @@ const windowPrefs = {
};

ipcMain.on("open-window", (event, message) => {
createWindow(message, event);
createWindow({ windowName: message }, event);
});

ipcMain.on("close-window", (event, message) => {
closeWindow({ windowName: message });
});

ipcMain.on("modv-ready", () => {
Expand Down
14 changes: 11 additions & 3 deletions src/background/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { windowPrefs } from "./window-prefs";

const windows = {};

function createWindow(windowName, event) {
function createWindow({ windowName, options = {} }, event) {
updateMenu();

if (windowPrefs[windowName].unique && windows[windowName]) {
windows[windowName].focus();
windows[windowName].show();

if (event) {
event.reply("window-ready", {
Expand All @@ -31,7 +32,8 @@ function createWindow(windowName, event) {

// Create the browser window.
windows[windowName] = new BrowserWindow({
...windowOptions
...windowOptions,
...options
});

if (typeof windowPrefs[windowName].create === "function") {
Expand Down Expand Up @@ -72,4 +74,10 @@ function createWindow(windowName, event) {
}
}

export { windows, createWindow };
function closeWindow({ windowName }) {
if (windows[windowName]) {
windows[windowName].close();
}
}

export { windows, createWindow, closeWindow };

0 comments on commit 9fca1cd

Please sign in to comment.