1 Star 9 Fork 5

PHP-Daemon/Recording

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.js 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
PHP-Daemon 提交于 2021-07-23 19:04 +08:00 . 更新完整代码
//用于控制应用程序生命周期和创建本机浏览器窗口的模块
const { app, BrowserWindow, Menu, Tray, ipcMain, shell, nativeImage } = require('electron')
// 在文件头部引入 Node.js 中的 path 模块
const path = require('path')
const icon = path.join(__dirname, '/icon/icon.ico') // 图标
let win = '';
// 创建窗口
function createWindow() {
//创建浏览器窗口。
win = new BrowserWindow({
width: 800,
height: 600,
frame: false,
show: false,
// backgroundColor: '#2e2c29',
webPreferences: {
preload: path.join(__dirname, '/js/preload.js'),
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true
},
icon: icon
})
//并加载应用程序的index.html。
win.loadFile('index.html')
win.once('ready-to-show', () => {
win.show()
})
}
// 系统托盘
let tray = null;
function createTray() {
tray = new Tray(nativeImage.createFromPath(icon))
const contextMenu = Menu.buildFromTemplate([
{
label: '全屏', click: function () {
win.maximize()
}
},
{ label: 'separator', type: 'separator' },
{
label: '最小化', click: function () {
win.minimize()
}
},
{ label: 'separator ', type: 'separator' },
{
label: '默认大小', click: function () {
win.restore()
}
},
{ label: 'separator ', type: 'separator' },
{
label: '退出', click: function () {
win.close()
}
}
])
tray.setToolTip('屏幕录制')
tray.setContextMenu(contextMenu)
}
app.whenReady().then(() => {
createWindow()
createTray();
//在macOS上,当应用程序
//已单击停靠图标,并且没有其他窗口打开。
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
// 监听窗体的创建
app.on('web-contents-created', (e, webContents) => {
webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/PHP-Daemon/recording.git
git@gitee.com:PHP-Daemon/recording.git
PHP-Daemon
recording
Recording
master

搜索帮助