2022-11-20 19:46:37 +00:00
|
|
|
import {BrowserWindow, Menu, app, clipboard, globalShortcut} from "electron";
|
2022-07-14 15:25:59 +00:00
|
|
|
import {mainWindow} from "./window";
|
2022-07-14 18:37:03 +00:00
|
|
|
import {getConfig} from "./utils";
|
2022-08-24 15:25:12 +00:00
|
|
|
import {createSettingsWindow} from "./settings/main";
|
2022-07-14 15:25:59 +00:00
|
|
|
|
|
|
|
function paste(contents: any) {
|
|
|
|
const contentTypes = clipboard.availableFormats().toString();
|
|
|
|
//Workaround: fix pasting the images.
|
2022-08-22 09:24:55 +00:00
|
|
|
if (contentTypes.includes("image/") && contentTypes.includes("text/html")) {
|
2022-07-14 15:25:59 +00:00
|
|
|
clipboard.writeImage(clipboard.readImage());
|
|
|
|
}
|
|
|
|
contents.paste();
|
|
|
|
}
|
2022-07-14 18:37:03 +00:00
|
|
|
export async function setMenu() {
|
2022-08-22 09:24:55 +00:00
|
|
|
if ((await getConfig("alternativePaste")) == true) {
|
2022-07-14 18:37:03 +00:00
|
|
|
mainWindow.on("focus", function () {
|
2022-08-22 09:24:55 +00:00
|
|
|
console.log("[Window state manager] Focus");
|
2022-07-14 18:37:03 +00:00
|
|
|
globalShortcut.register("CmdOrCtrl+V", function () {
|
|
|
|
if (mainWindow.isFocused()) {
|
2022-08-22 09:24:55 +00:00
|
|
|
paste(mainWindow.webContents);
|
2022-07-14 18:37:03 +00:00
|
|
|
}
|
2022-08-22 09:24:55 +00:00
|
|
|
});
|
|
|
|
});
|
2022-07-15 09:17:42 +00:00
|
|
|
mainWindow.on("show", function () {
|
2022-08-22 09:24:55 +00:00
|
|
|
console.log("[Window state manager] Show");
|
|
|
|
mainWindow.focus();
|
2022-07-15 09:17:42 +00:00
|
|
|
globalShortcut.register("CmdOrCtrl+V", function () {
|
|
|
|
if (mainWindow.isFocused()) {
|
2022-08-22 09:24:55 +00:00
|
|
|
paste(mainWindow.webContents);
|
2022-07-15 09:17:42 +00:00
|
|
|
}
|
2022-08-22 09:24:55 +00:00
|
|
|
});
|
|
|
|
});
|
2022-07-14 18:37:03 +00:00
|
|
|
mainWindow.on("blur", function () {
|
2022-08-22 09:24:55 +00:00
|
|
|
console.log("[Window state manager] Defocus");
|
|
|
|
globalShortcut.unregister("CmdOrCtrl+V");
|
|
|
|
});
|
2022-07-15 09:17:42 +00:00
|
|
|
mainWindow.on("hide", function () {
|
2022-08-22 09:24:55 +00:00
|
|
|
console.log("[Window state manager] Hide");
|
|
|
|
globalShortcut.unregister("CmdOrCtrl+V");
|
|
|
|
});
|
2022-07-14 18:37:03 +00:00
|
|
|
}
|
2022-08-22 09:24:55 +00:00
|
|
|
var template: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
{
|
|
|
|
label: "ArmCord",
|
|
|
|
submenu: [
|
|
|
|
{label: "About ArmCord", role: "about"}, //orderFrontStandardAboutPanel
|
|
|
|
{type: "separator"},
|
|
|
|
{
|
|
|
|
label: "Developer tools",
|
|
|
|
accelerator: "CmdOrCtrl+Shift+I",
|
|
|
|
click: function () {
|
2022-11-20 19:46:37 +00:00
|
|
|
BrowserWindow.getFocusedWindow()!.webContents.toggleDevTools();
|
2022-08-22 09:24:55 +00:00
|
|
|
}
|
|
|
|
},
|
2022-08-24 15:25:12 +00:00
|
|
|
{
|
|
|
|
label: "Open settings",
|
|
|
|
accelerator: "CmdOrCtrl+Shift+'",
|
|
|
|
click: function () {
|
|
|
|
createSettingsWindow();
|
|
|
|
}
|
|
|
|
},
|
2022-08-25 12:57:28 +00:00
|
|
|
{
|
|
|
|
label: "Reload",
|
|
|
|
accelerator: "CmdOrCtrl+R",
|
|
|
|
click: function () {
|
2022-09-25 18:30:09 +00:00
|
|
|
mainWindow.reload();
|
2022-08-25 12:57:28 +00:00
|
|
|
}
|
|
|
|
},
|
2022-08-22 09:24:55 +00:00
|
|
|
{
|
|
|
|
label: "Quit",
|
|
|
|
accelerator: "CmdOrCtrl+Q",
|
|
|
|
click: function () {
|
|
|
|
app.quit();
|
|
|
|
}
|
2022-07-14 15:25:59 +00:00
|
|
|
}
|
2022-08-22 09:24:55 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Edit",
|
|
|
|
submenu: [
|
|
|
|
{label: "Undo", accelerator: "CmdOrCtrl+Z", role: "undo"},
|
|
|
|
{label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", role: "redo"},
|
|
|
|
{type: "separator"},
|
|
|
|
{label: "Cut", accelerator: "CmdOrCtrl+X", role: "cut"},
|
|
|
|
{label: "Copy", accelerator: "CmdOrCtrl+C", role: "copy"},
|
|
|
|
{
|
|
|
|
label: "Paste",
|
|
|
|
accelerator: "CmdOrCtrl+V",
|
|
|
|
click: function () {
|
|
|
|
paste(mainWindow.webContents);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{label: "Select All", accelerator: "CmdOrCtrl+A", role: "selectAll"}
|
|
|
|
]
|
2022-08-24 15:25:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Zoom",
|
|
|
|
submenu: [
|
|
|
|
{label: "Zoom in", accelerator: "CmdOrCtrl+Plus", role: "zoomIn"},
|
2022-11-17 20:23:55 +00:00
|
|
|
// Fix for zoom in on keyboards with dedicated + like QWERTZ (or numpad)
|
|
|
|
// See https://github.com/electron/electron/issues/14742 and https://github.com/electron/electron/issues/5256
|
|
|
|
{label: "Zoom in", accelerator: "CmdOrCtrl+=", role: "zoomIn", visible: false},
|
2022-09-25 18:30:09 +00:00
|
|
|
{label: "Zoom out", accelerator: "CmdOrCtrl+-", role: "zoomOut"}
|
2022-08-24 15:25:12 +00:00
|
|
|
]
|
2022-08-22 09:24:55 +00:00
|
|
|
}
|
|
|
|
];
|
2022-07-14 15:25:59 +00:00
|
|
|
|
|
|
|
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
|
2022-08-22 09:24:55 +00:00
|
|
|
}
|