quickCss Editor ( Always on Top / Close Confirmation when CSS is minimized. + Reopens properly when minimized. ) (#825)
* Add QuickCSS editor improvements: always on top and close confirmation * add re-open * prism window management fix
This commit is contained in:
parent
018a994d5b
commit
91e0401ea8
1 changed files with 29 additions and 9 deletions
|
|
@ -22,7 +22,7 @@ import "./settings";
|
|||
|
||||
import { debounce } from "@shared/debounce";
|
||||
import { IpcEvents } from "@shared/IpcEvents";
|
||||
import { BrowserWindow, ipcMain, nativeTheme, shell, systemPreferences } from "electron";
|
||||
import { BrowserWindow, ipcMain, nativeTheme, shell, systemPreferences, app, dialog } from "electron";
|
||||
import monacoHtml from "file://monacoWin.html?minify&base64";
|
||||
import { FSWatcher, mkdirSync, readFileSync, watch, writeFileSync } from "fs";
|
||||
import { open, readdir, readFile, unlink } from "fs/promises";
|
||||
|
|
@ -139,16 +139,17 @@ ipcMain.on(IpcEvents.GET_MONACO_THEME, e => {
|
|||
e.returnValue = nativeTheme.shouldUseDarkColors ? "vs-dark" : "vs-light";
|
||||
});
|
||||
|
||||
let monacoWin: BrowserWindow | null = null;
|
||||
|
||||
ipcMain.handle(IpcEvents.OPEN_MONACO_EDITOR, async () => {
|
||||
const title = "Equicord QuickCSS Editor";
|
||||
const existingWindow = BrowserWindow.getAllWindows().find(w => w.title === title);
|
||||
if (existingWindow && !existingWindow.isDestroyed()) {
|
||||
existingWindow.focus();
|
||||
if (monacoWin && !monacoWin.isDestroyed()) {
|
||||
monacoWin.show();
|
||||
monacoWin.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
const win = new BrowserWindow({
|
||||
title,
|
||||
monacoWin = new BrowserWindow({
|
||||
title: "Equicord QuickCSS Editor",
|
||||
autoHideMenuBar: true,
|
||||
darkTheme: true,
|
||||
webPreferences: {
|
||||
|
|
@ -159,9 +160,28 @@ ipcMain.handle(IpcEvents.OPEN_MONACO_EDITOR, async () => {
|
|||
}
|
||||
});
|
||||
|
||||
makeLinksOpenExternally(win);
|
||||
monacoWin.once("closed", () => { monacoWin = null; });
|
||||
|
||||
await win.loadURL(`data:text/html;base64,${monacoHtml}`);
|
||||
makeLinksOpenExternally(monacoWin);
|
||||
|
||||
await monacoWin.loadURL(`data:text/html;base64,${monacoHtml}`);
|
||||
});
|
||||
|
||||
app.on("before-quit", async (event) => {
|
||||
if (monacoWin && !monacoWin.isDestroyed() && !monacoWin.isVisible()) {
|
||||
const result = await dialog.showMessageBox({
|
||||
type: "question",
|
||||
buttons: ["Cancel", "Close Anyway"],
|
||||
defaultId: 0,
|
||||
title: "QuickCSS Editor Open",
|
||||
message: "QuickCSS editor is still open in the background.",
|
||||
detail: "Do you want to close Discord anyway? This will also close the QuickCSS editor."
|
||||
});
|
||||
|
||||
if (result.response === 1) {
|
||||
app.exit();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle(IpcEvents.GET_RENDERER_CSS, () => readFile(RENDERER_CSS_PATH, "utf-8"));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue