没有明确的示例说明如何将 ELECTRON JS 应用程序定位到特定区域。 GitHub 上提供了唯一的语法,但它没有很好地描述它。
最佳答案
这非常简单。考虑一下这段代码,一旦 ready 事件触发,它就会定位 mainWindow。您应该能够插入下面的“就绪”事件来演示定位器。
// load the module
const Positioner = require('electron-positioner');
let mainWindow = null;
// create the main window
async function createWindow () {
mainWindow = new BrowserWindow({
height: 420,
width: 600,
x: 0, // default position left
y: 0, // default position top
show: false,
webPreferences: {
nodeIntegration: true,
preload: path.join(__dirname, 'node_modules', 'electron', 'dist', 'electron-bridge.js')
}
});
// reposition after creating the window.
app.on('ready', async () => {
await createWindow();
let positioner = new Positioner(mainWindow);
positioner.move('bottomRight');
});
当然,这种效果可以通过 BrowserWindow 构造函数使用 x 和 y 值来实现,但是使用模块提供的固定位置非常方便。
关于javascript - Electron 定位器的使用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59412647/