Files
ClassContent/历届学生/17届课程/myshop_app/ApiTest/ApiTest-Mac/index.js
2024-09-27 02:06:13 +08:00

53 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { app, BrowserWindow } = require('electron')
// 保持对window对象的全局引用如果不这么做的话当JavaScript对象被
// 垃圾回收的时候window对象将会自动的关闭
let win
function createWindow () {
// 创建浏览器窗口。
win = new BrowserWindow({
title: 'YeSeApiTest',
width: 955,
height: 620,
resizable: false,
titleBarStyle: 'hidden',
allowRunningInsecureContent: true
})
// 然后加载应用的 index.html。
win.loadFile('dist/index.html')
// 当 window 被关闭,这个事件会被触发。
win.on('closed', () => {
// 取消引用 window 对象,如果你的应用支持多窗口的话,
// 通常会把多个 window 对象存放在一个数组里面,
// 与此同时,你应该删除相应的元素。
win = null
})
}
require('./menu');
// 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()
}
})