You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.3 KiB
116 lines
3.3 KiB
import { app, BrowserWindow, ipcMain, Menu, screen, shell } from "electron"
|
|
import Shared from "@main/share"
|
|
import { getFileUrl } from "@main/util"
|
|
// webContents
|
|
// console.log(webContents.getAllWebContents())
|
|
|
|
const window: any = null //BrowserWindow.fromWebContents(webContents.getFocusedWebContents())
|
|
|
|
/**
|
|
* @方法:悬浮:设置位置
|
|
*/
|
|
ipcMain.on("@func:float:setPosition", (event, x, y) => {
|
|
if (Shared.data.floatWindow) {
|
|
const size = screen.getPrimaryDisplay().workAreaSize // 获取显示器的宽高
|
|
const winSize = Shared.data.floatWindow.getSize() // 获取窗口宽高
|
|
let rx = x,
|
|
ry = y
|
|
if (x < 0) {
|
|
rx = 0
|
|
}
|
|
if (y < 0) {
|
|
ry = 0
|
|
}
|
|
if (x > size.width - winSize[0]) {
|
|
rx = size.width - winSize[0]
|
|
}
|
|
if (y > size.height - winSize[1]) {
|
|
ry = size.height - winSize[1]
|
|
}
|
|
Shared.data.floatWindow.setPosition(rx, ry)
|
|
}
|
|
})
|
|
/**
|
|
* @方法:悬浮:展示
|
|
*/
|
|
ipcMain.on("@func:float:show", () => {
|
|
if (Shared.data.floatWindow) {
|
|
if (Shared.data.floatWindow.isVisible()) {
|
|
// createSuspensionWindow()
|
|
} else {
|
|
Shared.data.floatWindow.showInactive()
|
|
}
|
|
} else {
|
|
createSuspensionWindow()
|
|
}
|
|
})
|
|
|
|
ipcMain.on("@func:float:showRightMenu", e => {
|
|
const rightM = Menu.buildFromTemplate([
|
|
{
|
|
label: "添加闹钟",
|
|
click: () => {
|
|
ipcMain.emit("@func:render:addClock")
|
|
// Shared.data.floatWindow?.hide()
|
|
},
|
|
},
|
|
{ type: "separator" },
|
|
{
|
|
label: "隐藏悬浮时钟",
|
|
click: () => {
|
|
Shared.data.floatWindow?.hide()
|
|
},
|
|
},
|
|
{ type: "separator" },
|
|
{
|
|
label: "仓库地址",
|
|
click: () => {
|
|
shell.openExternal("https://github.com/lihaotian0607/auth")
|
|
},
|
|
},
|
|
{
|
|
label: "退出软件",
|
|
click: () => {
|
|
Shared.data.forceClose = true
|
|
app.quit()
|
|
},
|
|
},
|
|
])
|
|
rightM.popup({})
|
|
})
|
|
|
|
function createSuspensionWindow() {
|
|
Shared.data.floatWindow = new BrowserWindow({
|
|
width: 260, // 悬浮窗口的宽度 比实际DIV的宽度要多2px 因为有1px的边框
|
|
height: 95, // 悬浮窗口的高度 比实际DIV的高度要多2px 因为有1px的边框
|
|
type: "toolbar", // 创建的窗口类型为工具栏窗口
|
|
frame: false, // 要创建无边框窗口
|
|
resizable: false, // 禁止窗口大小缩放
|
|
show: false, // 先不让窗口显示
|
|
webPreferences: {
|
|
devTools: false, // 关闭调试工具
|
|
nodeIntegration: true,
|
|
contextIsolation: false,
|
|
},
|
|
transparent: true, // 设置透明
|
|
alwaysOnTop: true, // 窗口是否总是显示在其他窗口之前
|
|
})
|
|
const size = screen.getPrimaryDisplay().workAreaSize // 获取显示器的宽高
|
|
const winSize = Shared.data.floatWindow.getSize() // 获取窗口宽高
|
|
// 设置窗口的位置 注意x轴要桌面的宽度 - 窗口的宽度
|
|
Shared.data.floatWindow.setPosition(size.width - winSize[0], size.height - winSize[1] - 40)
|
|
// Shared.data.floatWindow.setPosition(size.width / 2, size.height / 2)
|
|
|
|
Shared.data.floatWindow.loadURL(getFileUrl("float"))
|
|
|
|
Shared.data.floatWindow.once("ready-to-show", () => {
|
|
Shared.data.floatWindow?.show()
|
|
})
|
|
// Shared.data.floatWindow.on("double-click", () => {
|
|
// alert(123)
|
|
// })
|
|
Shared.data.floatWindow.on("close", () => {
|
|
Shared.data.floatWindow?.destroy()
|
|
Shared.data.floatWindow = null
|
|
})
|
|
}
|
|
|