纯按照官网的例子,一直都有放大效果。(曾经更改过initial-scale,也设置过zoomFactor,但initial-scale已经是1.0,zoomFactor的设置也被重置了)
index.js(照抄官网示例,仅仅没有打开devtool,以及增加了zoomFactor设置)
const {
app,
BrowserWindow
} = require('electron'),
electron = require('electron'),
Menu = electron.Menu
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
function createWindow() {
// 隐藏菜单栏
Menu.setApplicationMenu(null)
// 创建浏览器窗口。
win = new BrowserWindow({
webPreferences: {
zoomFactor: 1
},
width: 200,
height: 200
})
// 然后加载应用的 index.html。
win.loadFile('index.html')
// 打开开发者工具
// win.webContents.openDevTools()
// 当 window 被关闭,这个事件会被触发。
win.on('closed', () => {
// 取消引用 window 对象,如果你的应用支持多窗口的话,
// 通常会把多个 window 对象存放在一个数组里面,
// 与此同时,你应该删除相应的元素。
win = null
})
}
// Electron 会在初始化后并准备
// 创建浏览器窗口时,调用这个函数。
// 部分 API 在 ready 事件触发后才能使用。
app.on('ready', createWindow)
// 当全部窗口关闭时退出。
app.on('window-all-closed', () => {
// 在 macOS 上,除非用户用 Cmd + Q 确定地退出,
// 否则绝大部分应用及其菜单栏会保持激活。
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// 在macOS上,当单击dock图标并且没有其他窗口打开时,
// 通常在应用程序中重新创建一个窗口。
if (win === null) {
createWindow()
}
})
// 在这个文件中,你可以续写应用剩下主进程代码。
// 也可以拆分成几个文件,然后用 require 导入。
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
p {
color: red;
font-size: 30px;
}
</style>
</head>
<body>
<p>
hi
</p>
</body>
</html>
效果如下(窗口大小的确是200*200的,没有问题):
字体显然远远超过30像素。
这是个bug.
解决方案如下: