Add fixes for pasting images using keyboard shortcuts

This commit is contained in:
smartfridge 2022-07-14 17:25:59 +02:00
parent 83b4f75e87
commit c933981420
5 changed files with 55 additions and 8 deletions

View file

@ -8,6 +8,7 @@
"watch": "tsc -w",
"start": "npm run build && electron ./ts-out/main.js",
"package": "npm run build && electron-builder",
"packageQuick": "npm run build && electron-builder --dir",
"format": "prettier --write src/**/*",
"CIbuild": "npm run build && electron-builder --linux zip && electron-builder --windows zip && electron-builder --macos zip",
"postinstall": "husky install"
@ -26,7 +27,7 @@
"@types/node": "^17.0.42",
"@types/ws": "^8.5.3",
"copyfiles": "^2.4.1",
"electron": "^19.0.7",
"electron": "^19.0.8",
"electron-builder": "^23.0.3",
"husky": "^8.0.1",
"prettier": "^2.7.0",

View file

@ -6,7 +6,6 @@ import "./extensions/mods";
import "./extensions/plugin";
import "./tray";
import {createCustomWindow, createNativeWindow} from "./window";
import "./shortcuts";
export var settings: any;
export var customTitlebar: boolean;

51
src/menu.ts Normal file
View file

@ -0,0 +1,51 @@
import { Menu, app, clipboard, globalShortcut } from "electron";
import {mainWindow} from "./window";
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();
}
export function setMenu() {
globalShortcut.register("CmdOrCtrl+V", function () {
if (mainWindow.isFocused()) {
paste(mainWindow.webContents)
}
})
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()
}
},
{
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"}
]
}
]
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}

View file

@ -1,5 +0,0 @@
import {app} from "electron";
import {mainWindow} from "./window";
//https://github.com/electron/electron/issues/1334#issuecomment-716080005
// TO-DO add more

View file

@ -6,6 +6,7 @@ import { BrowserWindow, shell, app, dialog } from "electron";
import path from "path";
import { checkIfConfigIsBroken, firstRun, getConfig, contentPath, setConfig, setLang, setWindowState } from "./utils";
import { registerIpc } from "./ipc";
import { setMenu } from "./menu";
import * as fs from "fs";
import startServer from "./socket";
import contextMenu from "electron-context-menu";
@ -94,7 +95,7 @@ async function doAfterDefiningTheWindow() {
}
});
});
setMenu()
mainWindow.on("close", async (e) => {
let [width, height] = mainWindow.getSize()
setWindowState({