2022-08-22 09:24:55 +00:00
|
|
|
import {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 () {
|
|
|
|
mainWindow.webContents.openDevTools();
|
|
|
|
}
|
|
|
|
},
|
2022-08-24 15:25:12 +00:00
|
|
|
{
|
|
|
|
label: "Open settings",
|
|
|
|
accelerator: "CmdOrCtrl+Shift+'",
|
|
|
|
click: function () {
|
|
|
|
createSettingsWindow();
|
|
|
|
}
|
|
|
|
},
|
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"},
|
|
|
|
{label: "Zoom out", accelerator: "CmdOrCtrl+-", role: "zoomOut"},
|
|
|
|
]
|
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
|
|
|
}
|