退出优化
This commit is contained in:
parent
cf587bc27b
commit
14c5142fdd
16
main.js
16
main.js
|
|
@ -35,7 +35,6 @@ class AppWindow extends BrowserWindow {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
function showWindow() {
|
||||
// 如果主窗口已经存在但被最小化了,则恢复显示
|
||||
if (mainWindow && mainWindow.isMinimized()) {
|
||||
|
|
@ -63,7 +62,8 @@ function createTray() {
|
|||
// icon: iconPath,
|
||||
},
|
||||
{
|
||||
label: '退出', click: () => {
|
||||
label: '退出', click: async () => {
|
||||
await mainWindow.webContents.send('quit');
|
||||
app.quit();
|
||||
mainWindow = null;
|
||||
},
|
||||
|
|
@ -86,12 +86,10 @@ function createTray() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
mainWindow = new AppWindow();
|
||||
mainWindow.focus();
|
||||
}
|
||||
|
||||
function createNotification(user) {
|
||||
const notification = new Notification({
|
||||
title: `${user.name} 邀请你加入`,
|
||||
|
|
@ -101,7 +99,6 @@ function createNotification(user) {
|
|||
notification.show();
|
||||
mainWindow.focus();
|
||||
}
|
||||
|
||||
app.on('ready', () => {
|
||||
createWindow()
|
||||
createTray()
|
||||
|
|
@ -111,7 +108,6 @@ app.on('ready', () => {
|
|||
mainWindow.webContents.openDevTools()
|
||||
}
|
||||
});
|
||||
|
||||
// 监听移动
|
||||
mainWindow.on('move', () => {
|
||||
// 如果是全屏自动恢复到上次窗口大小
|
||||
|
|
@ -125,9 +121,10 @@ app.on('ready', () => {
|
|||
}
|
||||
});
|
||||
// 放大缩小退出窗口
|
||||
ipcMain.handle('setViewStatus', (event, status) => {
|
||||
ipcMain.handle('setViewStatus', async (event, status) => {
|
||||
switch (status) {
|
||||
case 'quit':
|
||||
await mainWindow.webContents.send('quit');
|
||||
app.quit();
|
||||
mainWindow = null;
|
||||
break;
|
||||
|
|
@ -148,17 +145,14 @@ app.on('ready', () => {
|
|||
ipcMain.handle('getIsMaximized', () => {
|
||||
return mainWindow.isMaximized();
|
||||
});
|
||||
|
||||
// 复制文字
|
||||
ipcMain.handle('setWriteText', (event, text) => {
|
||||
clipboard.writeText(text)
|
||||
});
|
||||
|
||||
// 加入房间通知
|
||||
ipcMain.handle('joinNotification', (event, user) => {
|
||||
createNotification(user)
|
||||
});
|
||||
|
||||
// 设置桌面应用基础属性
|
||||
ipcMain.handle('setMainWindowSize', (event, config) => {
|
||||
// 设置最小窗口尺寸
|
||||
|
|
@ -179,7 +173,6 @@ app.on('ready', () => {
|
|||
const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2);
|
||||
mainWindow.setPosition(x, y);
|
||||
});
|
||||
|
||||
// 打开新页面
|
||||
ipcMain.handle('openNewPage', (event, url) => {
|
||||
const env = process.argv.find((arg) => arg.startsWith('--env='))?.split('=')[1];
|
||||
|
|
@ -187,6 +180,5 @@ app.on('ready', () => {
|
|||
? `http://localhost:3000`
|
||||
: path.resolve(__dirname, './dist/index.html')
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -24,5 +24,9 @@ window.electron = {
|
|||
// 打开新页面
|
||||
openNewPage: (url) => {
|
||||
ipcRenderer.invoke('openNewPage', url)
|
||||
}
|
||||
},
|
||||
// 监听退出
|
||||
onQuit: (callback) => {
|
||||
ipcRenderer.on('quit', callback)
|
||||
},
|
||||
}
|
||||
20
src/App.tsx
20
src/App.tsx
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
import { useEffect, useState, useRef } from "react";
|
||||
import '@/utils/styles/App.scss'
|
||||
import { Route, Routes, useNavigate, Navigate } from 'react-router-dom';
|
||||
import { Route, Routes, useNavigate, Navigate, useLocation } from 'react-router-dom';
|
||||
import Home from '@/page/Home/index'
|
||||
import Index from '@/page/Home/Index/index'
|
||||
import User from '@/page/Home/User/index'
|
||||
|
|
@ -15,15 +15,18 @@ import JoinMeetingModal from "./components/JoinMeetingModal";
|
|||
import * as CryptoJS from 'crypto-js';
|
||||
import { PostLogin } from "@/api/Login";
|
||||
import { startSignalr } from '@/utils/package/signalr';
|
||||
import agora from "./utils/package/agora";
|
||||
|
||||
const App: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const { state } = useLocation();
|
||||
const joinMeetingModalRef = useRef<any>();
|
||||
const [_windowSize, setWindowSize] = useState({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
});
|
||||
const [spinning, setSpinning] = useState(false);
|
||||
const [isState, setIsState] = useState(true);
|
||||
useEffect(() => {
|
||||
function toLogin() {
|
||||
try {
|
||||
|
|
@ -112,6 +115,21 @@ const App: React.FC = () => {
|
|||
storage.setItem('reconnect', true)
|
||||
})
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
if (isState) {
|
||||
setIsState(false)
|
||||
window.electron.onQuit(async () => {
|
||||
if (location.hash.indexOf('/meeting') !== -1) {
|
||||
const data = JSON.parse(localStorage.stateInfo);
|
||||
await onInvoke('levelChannel', {
|
||||
roomNum: data.channelId
|
||||
})
|
||||
await agora.leaveChannel()
|
||||
}
|
||||
})
|
||||
}
|
||||
storage.setItem('stateInfo', JSON.stringify(state))
|
||||
}, [state])
|
||||
const handleResize = (): void => {
|
||||
setWindowSize({
|
||||
width: window.innerWidth,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ export interface IElectronAPI {
|
|||
getIsMaximized: () => Promise<boolean>;
|
||||
setWriteText: (text: string) => void;
|
||||
openNewPage: (url: string) => void;
|
||||
onQuit: (callBack:Function) => void;
|
||||
joinNotification: (data: { name: string, body: string }) => void
|
||||
}
|
||||
declare global {
|
||||
|
|
|
|||
Loading…
Reference in New Issue