From 616255cdfdd9119a7c9994ecbaa91f295e83c344 Mon Sep 17 00:00:00 2001 From: Wuruipeng Date: Fri, 10 May 2024 09:02:41 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=88=9D?= =?UTF-8?q?=E6=AC=A1=E7=AA=97=E5=8F=A3=E6=8B=96=E5=8A=A8=E5=B0=BA=E5=AF=B8?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.js | 5 ++++- app/render/preload.js | 4 ++-- package.json | 2 +- src/components/TitleBar.tsx | 18 +++++++++--------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/main.js b/app/main.js index 7f4ca00..13feeeb 100644 --- a/app/main.js +++ b/app/main.js @@ -2,7 +2,7 @@ * @Author: wuruipeng * @Date: 2024-03-06 17:39:06 * @LastEditors: wuruipeng - * @LastEditTime: 2024-04-26 14:37:53 + * @LastEditTime: 2024-05-09 17:55:48 * @description: 主进程配置 */ @@ -35,6 +35,9 @@ function initApp(rootPath) { mainWindow.on('close', event => { confirmExit(event) }) + // 解决初次拖拽窗口尺寸变化问题,手动初始化改变一下size + const mainWindowSize = mainWindow.getSize() + mainWindow.setSize(mainWindowSize[0] - 1, mainWindowSize[1] - 2) } // 应用加载完成配置 app.whenReady().then(() => { diff --git a/app/render/preload.js b/app/render/preload.js index 84bffeb..1f23dd8 100644 --- a/app/render/preload.js +++ b/app/render/preload.js @@ -2,11 +2,11 @@ * @Author: wuruipeng * @Date: 2024-04-08 09:55:51 * @LastEditors: wuruipeng - * @LastEditTime: 2024-04-28 10:06:26 + * @LastEditTime: 2024-05-09 16:41:58 * @description: 渲染进程预加载脚本(用于搭建传递主进程与渲染进程的属性使用和方法) */ -const { app, contextBridge, ipcRenderer } = require('electron') +const { contextBridge, ipcRenderer } = require('electron') const common = require('../utils/common.js') // 可发送通信消息至主进程控制调用 diff --git a/package.json b/package.json index 806d29b..967c343 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "WuRuipeng", "license": "ISC", - "name": "MTLH", + "name": "mantianliuhuo", "version": "1.0.0", "description": "electron-project", "main": "app/main.js", diff --git a/src/components/TitleBar.tsx b/src/components/TitleBar.tsx index faa6748..6893802 100644 --- a/src/components/TitleBar.tsx +++ b/src/components/TitleBar.tsx @@ -2,12 +2,12 @@ * @Author: wuruipeng * @Date: 2024-04-25 14:07:08 * @LastEditors: wuruipeng - * @LastEditTime: 2024-04-30 17:21:14 + * @LastEditTime: 2024-05-09 17:07:05 * @description:自定义应用操作栏组件 */ import React, { ReactElement } from 'react' -import { useEffect, useState } from 'react' +import { useEffect, useState, useRef } from 'react' import '@/styles/components/TitleBar.less' import { keyboardKey } from '@testing-library/user-event' @@ -38,6 +38,7 @@ const TitleBar: React.FC = () => { { context: '◻', role: 'maximize' }, { context: '×', role: 'close' } ]) + const titleBarRef = useRef(null) // 更新应用当前信息和状态 const updateAppInfo = (): void => { ;(window as any).resultAPI.invoke('get-app-info') @@ -118,9 +119,8 @@ const TitleBar: React.FC = () => { // 更改全屏状态操作 const changeFullScreen = (status: boolean): void => { // 如果为全屏状态,应隐藏边框和操作栏 - const titleBar: TitleBarType = document.getElementById('title-bar') const app: TitleBarType = document.getElementById('app') - if (!titleBar || !app) return + if (!titleBarRef.current || !app) return // 获取根元素(:root)并修改CSS变量 const _root = document.documentElement if (status) { @@ -155,12 +155,12 @@ const TitleBar: React.FC = () => { } }, []) return ( -
-
+
+
-
-
+
+
    {controls.map((item, index) => (
  • { ))}
-
+
    {menus?.map((item, index) => (
  • -- Gitee