This commit is contained in:
parent
f48a5a5613
commit
dc9307e3a3
343
main.js
343
main.js
|
|
@ -109,195 +109,190 @@ function createWindow() {
|
|||
mainWindow = new AppWindow();
|
||||
mainWindow.focus();
|
||||
}
|
||||
|
||||
// 处理单实例
|
||||
app.on('session-created', (session) => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.focus();
|
||||
}
|
||||
})
|
||||
const additionalData = { myKey: 'myValue' }
|
||||
// 退出房间
|
||||
app.on('will-quit', async (event) => {
|
||||
await mainWindow.webContents.send('quitAndInstall');
|
||||
});
|
||||
|
||||
app.on('ready', () => {
|
||||
env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1];
|
||||
if (env === 'development') {
|
||||
Object.defineProperty(app, 'isPackaged', {
|
||||
get() {
|
||||
return true
|
||||
}
|
||||
})
|
||||
autoUpdater.updateConfigPath = path.join('latest.yml')
|
||||
}
|
||||
createWindow()
|
||||
updateHandle() // 检查更新
|
||||
createTray()
|
||||
// 获取当前脚本所在目录的绝对路径
|
||||
const currentDirectory = __dirname;
|
||||
// 获取安装父目录
|
||||
const parentDirectory = path.resolve(currentDirectory, '..');
|
||||
const customFolderPath = path.join(parentDirectory, 'Downloads');
|
||||
if (!fs.existsSync(customFolderPath)) {
|
||||
// 如果不存在,则创建文件夹
|
||||
fs.mkdirSync(customFolderPath);
|
||||
}
|
||||
// 监听f12打开控制台
|
||||
mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||
const gotTheLock = app.requestSingleInstanceLock(additionalData)
|
||||
if (gotTheLock) {
|
||||
env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1];
|
||||
if (env === 'development') {
|
||||
if (input.key === 'F12') {
|
||||
mainWindow.webContents.openDevTools()
|
||||
}
|
||||
Object.defineProperty(app, 'isPackaged', {
|
||||
get() {
|
||||
return true
|
||||
}
|
||||
})
|
||||
autoUpdater.updateConfigPath = path.join('latest.yml')
|
||||
}
|
||||
});
|
||||
// 监听移动
|
||||
mainWindow.on('move', () => {
|
||||
// 如果是全屏自动恢复到上次窗口大小
|
||||
if (isMaximized) {
|
||||
mainWindow.setResizable(true)
|
||||
mainWindow.unmaximize()
|
||||
isMaximized = false;
|
||||
createWindow()
|
||||
updateHandle() // 检查更新
|
||||
createTray()
|
||||
// 获取当前脚本所在目录的绝对路径
|
||||
const currentDirectory = __dirname;
|
||||
// 获取安装父目录
|
||||
const parentDirectory = path.resolve(currentDirectory, '..');
|
||||
const customFolderPath = path.join(parentDirectory, 'Downloads');
|
||||
if (!fs.existsSync(customFolderPath)) {
|
||||
// 如果不存在,则创建文件夹
|
||||
fs.mkdirSync(customFolderPath);
|
||||
}
|
||||
if (mainWindow.isMaximized()) {
|
||||
isMaximized = true;
|
||||
}
|
||||
});
|
||||
// 放大缩小退出窗口
|
||||
ipcMain.handle('setViewStatus', async (event, status) => {
|
||||
switch (status) {
|
||||
case 'quit':
|
||||
await mainWindow.webContents.send('onQuit');
|
||||
break;
|
||||
case 'maximize':
|
||||
mainWindow.maximize()
|
||||
mainWindow.setResizable(false)
|
||||
break;
|
||||
case 'unmaximize':
|
||||
mainWindow.setResizable(true)
|
||||
mainWindow.unmaximize()
|
||||
break;
|
||||
case 'minimize':
|
||||
mainWindow.minimize()
|
||||
break;
|
||||
case 'hide':
|
||||
mainWindow.hide()
|
||||
break;
|
||||
}
|
||||
});
|
||||
// 导出是否全屏
|
||||
ipcMain.handle('getIsMaximized', () => {
|
||||
return mainWindow.isMaximized();
|
||||
});
|
||||
// 获取版本号
|
||||
ipcMain.handle('getVersion', () => {
|
||||
return app.getVersion();
|
||||
});
|
||||
// 获取共享屏幕列表
|
||||
ipcMain.handle('getSources', async () => {
|
||||
return await desktopCapturer.getSources({
|
||||
types: ['screen']
|
||||
});
|
||||
});
|
||||
// 复制文字
|
||||
ipcMain.handle('setWriteText', (event, text) => {
|
||||
clipboard.writeText(text)
|
||||
});
|
||||
// 退出
|
||||
ipcMain.handle('quit', async (event) => {
|
||||
await mainWindow.webContents.send('quitAndInstall');
|
||||
quit()
|
||||
});
|
||||
// 加入房间通知
|
||||
ipcMain.handle('joinNotification', (event, user) => {
|
||||
mainWindow.show()
|
||||
mainWindow.focus();
|
||||
});
|
||||
// 通知下载包
|
||||
ipcMain.handle('updateDownload', (event, data) => {
|
||||
if (data === '0') { // 取消下载
|
||||
cancleDownloadUpdate()
|
||||
} else if (data === '1') { // 开始下载
|
||||
downloadUpdate()
|
||||
} else if (data === '2') { // 下载完成 点击安装
|
||||
quitAndInstall()
|
||||
}
|
||||
});
|
||||
// 选择文件夹
|
||||
ipcMain.handle('selectFilePath', async (event, data) => {
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory']
|
||||
});
|
||||
if (result.canceled) {
|
||||
|
||||
} else {
|
||||
switch (data.key) {
|
||||
case 'shareFilesPath':
|
||||
case 'recordingFilesPath':
|
||||
mainWindow.webContents.send('onFilePath', result.filePaths[0] + '\\', data.key);
|
||||
break;
|
||||
default:
|
||||
mainWindow.webContents.send('downFile', {
|
||||
downFilePaths: result.filePaths[0] + '\\',
|
||||
fileName: data.fileName,
|
||||
filePath: data.filePath,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
// 设置桌面应用基础属性
|
||||
ipcMain.handle('setMainWindowSize', (event, config) => {
|
||||
// 设置最小窗口尺寸
|
||||
mainWindow.setMinimumSize(config.width, config.height);
|
||||
// 设置最大尺寸
|
||||
const primaryDisplay = screen.getPrimaryDisplay()
|
||||
const { width, height } = primaryDisplay.workAreaSize
|
||||
if (config.key === 'login') {
|
||||
mainWindow.setMaximumSize(config.width, config.height);
|
||||
} else {
|
||||
mainWindow.setMaximumSize(width, height);
|
||||
}
|
||||
// 设置窗口尺寸
|
||||
mainWindow.setSize(config.width, config.height)
|
||||
// 设置窗口位置使其居中于当前屏幕
|
||||
const display = screen.getDisplayMatching({ ...mainWindow.getBounds() });
|
||||
const x = Math.round((display.workArea.width - mainWindow.getSize()[0]) / 2);
|
||||
const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2);
|
||||
mainWindow.setPosition(x, y);
|
||||
});
|
||||
// 打开新窗口
|
||||
ipcMain.handle('oepnWindow', (event, data) => {
|
||||
const newWindow = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 800,
|
||||
minWidth: 1200,
|
||||
minHeight: 800,
|
||||
webPreferences: {
|
||||
contextIsolation: false,
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true,
|
||||
nodeIntegrationInWorker: true,
|
||||
allowMediaDevices: true,
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
},
|
||||
frame: false,
|
||||
backgroundColor: '#00000000',
|
||||
transparent: true,
|
||||
});
|
||||
newWindow.loadURL(data.url);
|
||||
newWindow.focus();
|
||||
newWindow.webContents.on('before-input-event', (event, input) => {
|
||||
// 监听f12打开控制台
|
||||
mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||
if (env === 'development') {
|
||||
if (input.key === 'F12') {
|
||||
newWindow.webContents.openDevTools()
|
||||
mainWindow.webContents.openDevTools()
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
// 监听移动
|
||||
mainWindow.on('move', () => {
|
||||
// 如果是全屏自动恢复到上次窗口大小
|
||||
if (isMaximized) {
|
||||
mainWindow.setResizable(true)
|
||||
mainWindow.unmaximize()
|
||||
isMaximized = false;
|
||||
}
|
||||
if (mainWindow.isMaximized()) {
|
||||
isMaximized = true;
|
||||
}
|
||||
});
|
||||
// 放大缩小退出窗口
|
||||
ipcMain.handle('setViewStatus', async (event, status) => {
|
||||
switch (status) {
|
||||
case 'quit':
|
||||
await mainWindow.webContents.send('onQuit');
|
||||
break;
|
||||
case 'maximize':
|
||||
mainWindow.maximize()
|
||||
mainWindow.setResizable(false)
|
||||
break;
|
||||
case 'unmaximize':
|
||||
mainWindow.setResizable(true)
|
||||
mainWindow.unmaximize()
|
||||
break;
|
||||
case 'minimize':
|
||||
mainWindow.minimize()
|
||||
break;
|
||||
case 'hide':
|
||||
mainWindow.hide()
|
||||
break;
|
||||
}
|
||||
});
|
||||
// 导出是否全屏
|
||||
ipcMain.handle('getIsMaximized', () => {
|
||||
return mainWindow.isMaximized();
|
||||
});
|
||||
// 获取版本号
|
||||
ipcMain.handle('getVersion', () => {
|
||||
return app.getVersion();
|
||||
});
|
||||
// 获取共享屏幕列表
|
||||
ipcMain.handle('getSources', async () => {
|
||||
return await desktopCapturer.getSources({
|
||||
types: ['screen']
|
||||
});
|
||||
});
|
||||
// 复制文字
|
||||
ipcMain.handle('setWriteText', (event, text) => {
|
||||
clipboard.writeText(text)
|
||||
});
|
||||
// 退出
|
||||
ipcMain.handle('quit', async (event) => {
|
||||
await mainWindow.webContents.send('quitAndInstall');
|
||||
quit()
|
||||
});
|
||||
// 加入房间通知
|
||||
ipcMain.handle('joinNotification', (event, user) => {
|
||||
mainWindow.show()
|
||||
mainWindow.focus();
|
||||
});
|
||||
// 通知下载包
|
||||
ipcMain.handle('updateDownload', (event, data) => {
|
||||
if (data === '0') { // 取消下载
|
||||
cancleDownloadUpdate()
|
||||
} else if (data === '1') { // 开始下载
|
||||
downloadUpdate()
|
||||
} else if (data === '2') { // 下载完成 点击安装
|
||||
quitAndInstall()
|
||||
}
|
||||
});
|
||||
// 选择文件夹
|
||||
ipcMain.handle('selectFilePath', async (event, data) => {
|
||||
const result = await dialog.showOpenDialog({
|
||||
properties: ['openDirectory']
|
||||
});
|
||||
if (result.canceled) {
|
||||
|
||||
} else {
|
||||
switch (data.key) {
|
||||
case 'shareFilesPath':
|
||||
case 'recordingFilesPath':
|
||||
mainWindow.webContents.send('onFilePath', result.filePaths[0] + '\\', data.key);
|
||||
break;
|
||||
default:
|
||||
mainWindow.webContents.send('downFile', {
|
||||
downFilePaths: result.filePaths[0] + '\\',
|
||||
fileName: data.fileName,
|
||||
filePath: data.filePath,
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
// 设置桌面应用基础属性
|
||||
ipcMain.handle('setMainWindowSize', (event, config) => {
|
||||
// 设置最小窗口尺寸
|
||||
mainWindow.setMinimumSize(config.width, config.height);
|
||||
// 设置最大尺寸
|
||||
const primaryDisplay = screen.getPrimaryDisplay()
|
||||
const { width, height } = primaryDisplay.workAreaSize
|
||||
if (config.key === 'login') {
|
||||
mainWindow.setMaximumSize(config.width, config.height);
|
||||
} else {
|
||||
mainWindow.setMaximumSize(width, height);
|
||||
}
|
||||
// 设置窗口尺寸
|
||||
mainWindow.setSize(config.width, config.height)
|
||||
// 设置窗口位置使其居中于当前屏幕
|
||||
const display = screen.getDisplayMatching({ ...mainWindow.getBounds() });
|
||||
const x = Math.round((display.workArea.width - mainWindow.getSize()[0]) / 2);
|
||||
const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2);
|
||||
mainWindow.setPosition(x, y);
|
||||
});
|
||||
// 打开新窗口
|
||||
ipcMain.handle('oepnWindow', (event, data) => {
|
||||
const newWindow = new BrowserWindow({
|
||||
width: 1200,
|
||||
height: 800,
|
||||
minWidth: 1200,
|
||||
minHeight: 800,
|
||||
webPreferences: {
|
||||
contextIsolation: false,
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true,
|
||||
nodeIntegrationInWorker: true,
|
||||
allowMediaDevices: true,
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
},
|
||||
frame: false,
|
||||
backgroundColor: '#00000000',
|
||||
transparent: true,
|
||||
});
|
||||
newWindow.loadURL(data.url);
|
||||
newWindow.focus();
|
||||
newWindow.webContents.on('before-input-event', (event, input) => {
|
||||
if (env === 'development') {
|
||||
if (input.key === 'F12') {
|
||||
newWindow.webContents.openDevTools()
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
// 检测更新,在你想要检查更新的时候执行,renderer事件触发后的操作自行编写
|
||||
function updateHandle() {
|
||||
autoUpdater.checkForUpdates()
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
.isUpdateModal {
|
||||
height: 500px;
|
||||
background-color: rgb(21, 25, 29);
|
||||
background-size: 100% auto;
|
||||
background-repeat: no-repeat;
|
||||
color: #ffffff;
|
||||
padding: 140px 30px 0;
|
||||
padding: 130px 30px 0;
|
||||
box-sizing: border-box;
|
||||
|
||||
.remarks {
|
||||
width: 100%;
|
||||
color: #C8C8C8;
|
||||
height: 70%;
|
||||
min-height: 240px;
|
||||
max-height: 240px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
text-align: center;
|
||||
|
||||
.button2 {
|
||||
margin-top: 10px;
|
||||
padding: 10px 0;
|
||||
color: #555454;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ $pagination-hover-background-color: #5575F2;
|
|||
}
|
||||
|
||||
.ant-modal-body {
|
||||
max-height: 80vh;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue