优化缩放倍率

This commit is contained in:
yj 2024-09-18 15:38:00 +08:00
parent 1c5a7aa4a9
commit 6f882d030c
5 changed files with 35 additions and 21 deletions

12
main.js
View File

@ -142,9 +142,9 @@ app.on('ready', () => {
// 监听f12打开控制台 // 监听f12打开控制台
mainWindow.webContents.on('before-input-event', (event, input) => { mainWindow.webContents.on('before-input-event', (event, input) => {
// if (env === 'development') { // if (env === 'development') {
if (input.key === 'F12') { if (input.key === 'F12') {
mainWindow.webContents.openDevTools() mainWindow.webContents.openDevTools()
} }
// } // }
}); });
// 监听移动 // 监听移动
@ -242,6 +242,12 @@ app.on('ready', () => {
} }
} }
}); });
// 获取桌面大小
ipcMain.handle('getWindowSize', (event, config) => {
const primaryDisplay = screen.getPrimaryDisplay()
const { width, height } = primaryDisplay.workAreaSize
return { width, height }
});
// 设置桌面应用基础属性 // 设置桌面应用基础属性
ipcMain.handle('setMainWindowSize', (event, config) => { ipcMain.handle('setMainWindowSize', (event, config) => {
// 设置最小窗口尺寸 // 设置最小窗口尺寸

View File

@ -5,6 +5,10 @@ window.electron = {
setMainWindowSize: (config) => { setMainWindowSize: (config) => {
ipcRenderer.invoke('setMainWindowSize', { ...config }) ipcRenderer.invoke('setMainWindowSize', { ...config })
}, },
// 获取窗口大小
getWindowSize: (config) => {
return ipcRenderer.invoke('getWindowSize')
},
// 设置窗口状态 // 设置窗口状态
setViewStatus: (status) => { setViewStatus: (status) => {
ipcRenderer.invoke('setViewStatus', status) ipcRenderer.invoke('setViewStatus', status)

View File

@ -197,21 +197,22 @@ const App: React.FC = () => {
}) })
} }
const toSrc = (path: string): void => { const toSrc = (path: string): void => {
switch (path) { window.electron.getWindowSize().then((res: any) => {
case '/login': switch (path) {
storage.removeItem('user') case '/login':
storage.setItem('userLogin', false) storage.removeItem('user')
navigate('/login') storage.setItem('userLogin', false)
break; navigate('/login')
case '/home': break;
window.electron.setMainWindowSize({ case '/home':
width: 1200, window.electron.setMainWindowSize({
height: 800, width: Math.ceil(res.width / 1.5),
}) height: Math.ceil(res.height / 1.3),
navigate('/home') })
break; navigate('/home')
break;
} }
})
}; };
const leaveChannel = async (bool?: boolean): Promise<void> => { const leaveChannel = async (bool?: boolean): Promise<void> => {
if (location.hash.indexOf('/meeting') === 1) { if (location.hash.indexOf('/meeting') === 1) {

View File

@ -142,9 +142,11 @@ const Login: React.FC = () => {
storage.setItem('user', JSON.stringify(res.data)) storage.setItem('user', JSON.stringify(res.data))
storage.setItem('userLogin', true) storage.setItem('userLogin', true)
try { try {
window.electron.setMainWindowSize({ window.electron.getWindowSize().then((res: any) => {
width: 1200, window.electron.setMainWindowSize({
height: 800, width: Math.ceil(res.width / 1.5),
height: Math.ceil(res.height / 1.3),
})
}) })
} catch { } catch {

1
src/render.d.ts vendored
View File

@ -1,6 +1,7 @@
// electron-env.d.ts // electron-env.d.ts
export interface IElectronAPI { export interface IElectronAPI {
setMainWindowSize: (config: any) => void; setMainWindowSize: (config: any) => void;
getWindowSize: () => any;
setViewStatus: (status: 'quit' | 'maximize' | 'minimize' | 'unmaximize' | 'hide') => void; setViewStatus: (status: 'quit' | 'maximize' | 'minimize' | 'unmaximize' | 'hide') => void;
getIsMaximized: () => Promise<boolean>; getIsMaximized: () => Promise<boolean>;
setWriteText: (text: string) => void; setWriteText: (text: string) => void;