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