armcord/src/menu.ts

110 lines
4.1 KiB
TypeScript
Raw Normal View History

import {BrowserWindow, Menu, app, clipboard, globalShortcut} from "electron";
import {mainWindow} from "./window";
2022-07-14 18:37:03 +00:00
import {getConfig} from "./utils";
import {createSettingsWindow} from "./settings/main";
function paste(contents: any) {
const contentTypes = clipboard.availableFormats().toString();
//Workaround: fix pasting the images.
if (contentTypes.includes("image/") && contentTypes.includes("text/html")) {
clipboard.writeImage(clipboard.readImage());
}
contents.paste();
}
2022-07-14 18:37:03 +00:00
export async function setMenu() {
if ((await getConfig("alternativePaste")) == true) {
2022-07-14 18:37:03 +00:00
mainWindow.on("focus", function () {
console.log("[Window state manager] Focus");
2022-07-14 18:37:03 +00:00
globalShortcut.register("CmdOrCtrl+V", function () {
if (mainWindow.isFocused()) {
paste(mainWindow.webContents);
2022-07-14 18:37:03 +00:00
}
});
});
2022-07-15 09:17:42 +00:00
mainWindow.on("show", function () {
console.log("[Window state manager] Show");
mainWindow.focus();
2022-07-15 09:17:42 +00:00
globalShortcut.register("CmdOrCtrl+V", function () {
if (mainWindow.isFocused()) {
paste(mainWindow.webContents);
2022-07-15 09:17:42 +00:00
}
});
});
2022-07-14 18:37:03 +00:00
mainWindow.on("blur", function () {
console.log("[Window state manager] Defocus");
globalShortcut.unregister("CmdOrCtrl+V");
});
2022-07-15 09:17:42 +00:00
mainWindow.on("hide", function () {
console.log("[Window state manager] Hide");
globalShortcut.unregister("CmdOrCtrl+V");
});
2022-07-14 18:37:03 +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 () {
BrowserWindow.getFocusedWindow()!.webContents.toggleDevTools();
}
},
{
label: "Open settings",
accelerator: "CmdOrCtrl+Shift+'",
click: function () {
createSettingsWindow();
}
},
2022-08-25 12:57:28 +00:00
{
label: "Reload",
accelerator: "CmdOrCtrl+R",
click: function () {
mainWindow.reload();
2022-08-25 12:57:28 +00:00
}
},
{
label: "Quit",
accelerator: "CmdOrCtrl+Q",
click: function () {
app.quit();
}
}
]
},
{
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"}
]
},
{
label: "Zoom",
submenu: [
{label: "Zoom in", accelerator: "CmdOrCtrl+Plus", role: "zoomIn"},
// 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},
{label: "Zoom out", accelerator: "CmdOrCtrl+-", role: "zoomOut"}
]
}
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}