mirror of
https://github.com/QYG2297248353/IYUUPlus-Windows.git
synced 2025-12-29 08:01:35 +08:00
v1.0.0
This commit is contained in:
+102
@@ -0,0 +1,102 @@
|
||||
const { BrowserWindow } = require('electron')
|
||||
const path = require('node:path')
|
||||
const log = require('electron-log')
|
||||
|
||||
const url = require('url').format({
|
||||
protocol: 'http',
|
||||
hostname: '127.0.0.1',
|
||||
port: 8787
|
||||
})
|
||||
|
||||
/** @type {BrowserWindow | null} */
|
||||
let mainWindow = null
|
||||
|
||||
const createWindow = () => {
|
||||
if (mainWindow === null) {
|
||||
log.info('Create main window')
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, '..', 'preload.js')
|
||||
}
|
||||
})
|
||||
|
||||
// mainWindow.webContents.openDevTools()
|
||||
|
||||
require("../menu/menu")
|
||||
|
||||
mainWindow.webContents.loadURL(url)
|
||||
// mainWindow.loadURL(url)
|
||||
|
||||
mainWindow.on('minimize', (event) => {
|
||||
event.preventDefault()
|
||||
mainWindow.hide()
|
||||
})
|
||||
mainWindow.on('close', (event) => {
|
||||
event.preventDefault()
|
||||
mainWindow.hide()
|
||||
})
|
||||
} else {
|
||||
log.info('Main window already created')
|
||||
}
|
||||
}
|
||||
|
||||
const showWindows = () => {
|
||||
log.info('Show main window')
|
||||
if (!mainWindow) {
|
||||
createWindow()
|
||||
return
|
||||
}
|
||||
if (!mainWindow.isVisible()) {
|
||||
mainWindow.show()
|
||||
}
|
||||
}
|
||||
|
||||
const hideWindows = () => {
|
||||
log.info('Hide main window')
|
||||
if (!mainWindow) {
|
||||
createWindow()
|
||||
}
|
||||
if (visibleWindows()) {
|
||||
mainWindow.hide()
|
||||
}
|
||||
}
|
||||
|
||||
const closeWindows = () => {
|
||||
log.info('Close main window')
|
||||
if (visibleWindows()) {
|
||||
mainWindow.close()
|
||||
mainWindow = null
|
||||
}
|
||||
}
|
||||
|
||||
const refreshWindows = () => {
|
||||
log.info('Refresh main window')
|
||||
hideWindows()
|
||||
if (visibleWindows()) {
|
||||
mainWindow.reload()
|
||||
}
|
||||
}
|
||||
|
||||
const refreshUrl = () => {
|
||||
log.info('Refresh main window')
|
||||
if (visibleWindows()) {
|
||||
mainWindow.loadURL(url)
|
||||
}
|
||||
}
|
||||
|
||||
const rebootWindows = () => {
|
||||
log.info('Reboot main window')
|
||||
hideWindows()
|
||||
if (visibleWindows()) {
|
||||
mainWindow.reload()
|
||||
}
|
||||
}
|
||||
|
||||
const visibleWindows = () => {
|
||||
return mainWindow && mainWindow.isVisible()
|
||||
}
|
||||
|
||||
|
||||
module.exports = { hideWindows, showWindows, createWindow, closeWindows, refreshWindows, rebootWindows, visibleWindows, refreshUrl };
|
||||
Reference in New Issue
Block a user