assistant-note/main.js

49 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-01-30 03:15:29 -05:00
// npm start
2024-01-05 03:24:35 -05:00
const { app,Menu, BrowserWindow , ipcMain } = require('electron')
2023-11-01 22:15:06 -04:00
const path = require('path')
2024-01-02 03:15:30 -05:00
const fs = require('fs')
const https = require('https')
const {menuRebuild} = require('./src/comment/TopMenu.js')
2023-11-01 22:15:06 -04:00
// electorn
2023-01-30 03:15:29 -05:00
const createWindow = () => {
2023-11-01 22:31:23 -04:00
// Create the browser window.
2023-01-30 03:15:29 -05:00
const win = new BrowserWindow({
width: 800,
2023-11-01 22:15:06 -04:00
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
2023-11-01 22:31:23 -04:00
}
2023-01-30 03:15:29 -05:00
})
2023-11-01 22:31:23 -04:00
// 加载 index.html
2023-01-30 03:15:29 -05:00
win.loadFile('index.html')
2024-01-02 03:15:30 -05:00
// win.loadURL('http://localhost/show/sync?current=1&pageSize=5')
2023-11-01 22:31:23 -04:00
// 打开开发工具
2024-01-02 03:15:30 -05:00
win.webContents.openDevTools()
Menu.setApplicationMenu(Menu.buildFromTemplate(menuRebuild(win)))
2023-01-30 03:15:29 -05:00
}
2024-01-02 03:15:30 -05:00
const iconName = path.join(__dirname, 'iconForDragAndDrop.png')
2023-01-30 03:15:29 -05:00
// 这段程序将会在 Electron 结束初始化和创建浏览器窗口的时候调用
2023-11-01 22:31:23 -04:00
// 部分 API 在 ready 事件触发后才能使用。
2023-01-30 03:15:29 -05:00
app.whenReady().then(() => {
2024-01-02 03:15:30 -05:00
// ipcMain.handle('ping', () => 'pong')
2023-01-30 03:15:29 -05:00
createWindow()
2023-11-01 22:31:23 -04:00
// 在 macOS 系统内, 如果没有已开启的应用窗口
// 点击托盘图标时通常会重新创建一个新窗口
2023-11-01 22:15:06 -04:00
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
2023-11-01 22:14:40 -04:00
})
2023-11-01 22:31:23 -04:00
// 除了 macOS 外,当所有窗口都被关闭的时候退出程序。 因此, 通常
// 对应用程序和它们的菜单栏来说应该时刻保持激活状态,
// 直到用户使用 Cmd + Q 明确退出
2023-11-01 22:14:40 -04:00
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
2024-01-02 03:15:30 -05:00
})
ipcMain.on('ondragstart', (event, filePath) => {
event.sender.startDrag({
file: path.join(__dirname, filePath),
icon: iconName
})
2023-11-01 22:15:06 -04:00
})