如何禁用电子应用程序的缩放?我尝试了这个片段,但它不起作用。我仍然可以使用 CMD+/- 缩放内容。我需要禁用其他东西吗?
const win = new BrowserWindow({
width: 1200,
height: 1000,
title: "MyApp",
resizable: false, // Prevent resizing
webPreferences: {
preload: path.join(__dirname, "preload.js"),
contextIsolation: true,
enableRemoteModule: false,
webSecurity: true,
zoomFactor: 1,
disableZoom: true,
},
window.webContents.on("before-input-event", (event, input) => {
if (
(input.control || input.meta) && // Control for Windows/Linux, Command (meta) for macOS
(input.key === "+" || input.key === "-" || input.key === "0")
) {
event.preventDefault();
console.log(`Blocked zoom action: ${input.key}`);
}
});
这会阻止键盘缩放命令并解决它