From 3599692ab9e00a22be2ba0306d04254fdaa57673 Mon Sep 17 00:00:00 2001 From: Hpero4 Date: Sun, 29 Oct 2023 00:05:14 +0800 Subject: [PATCH] =?UTF-8?q?1.=20BUG=E4=BF=AE=E5=A4=8D:=20=E5=9C=A8?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BD=AF=E4=BB=B6=E6=88=96=E4=BF=AE=E6=94=B9?= =?UTF-8?q?LOL=E8=B7=AF=E5=BE=84=E5=90=8E=E5=86=8D=E6=AC=A1=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E8=BD=AF=E4=BB=B6=E6=97=B6,=20"=E9=94=81=E5=AE=9A?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE"=E9=80=89=E9=A1=B9=E4=B8=80=E5=AE=9A?= =?UTF-8?q?=E4=BC=9A=E6=98=BE=E7=A4=BA=E4=B8=BA=E6=9C=AA=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98(=E6=94=B9=E4=B8=BA=E4=BB=A5?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E8=AF=BB=E5=86=99=E6=9D=83=E9=99=90=E5=86=B3?= =?UTF-8?q?=E5=AE=9A=E5=BC=80=E5=85=B3=E7=8A=B6=E6=80=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2. BUG修复: 在因路径、权限、杀软等原因改写PersistedSettings.json读写权限失败时,弹出提示并将开关状态还原保证逻辑准确。 --- app/view/auxiliary_interface.py | 34 ++++++++++++++++++++++++++++++--- app/view/main_window.py | 1 + 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/view/auxiliary_interface.py b/app/view/auxiliary_interface.py index 13b4542f..4e59f3b2 100644 --- a/app/view/auxiliary_interface.py +++ b/app/view/auxiliary_interface.py @@ -1,5 +1,6 @@ import threading import os +import stat from typing import Union from PyQt5.QtGui import QIcon @@ -7,7 +8,7 @@ SmoothScrollArea, SettingCard, LineEdit, setCustomStyleSheet, PushButton, ComboBox, SwitchButton, ConfigItem, qconfig, IndicatorPosition, InfoBar, InfoBarPosition, SpinBox, ExpandGroupSettingCard) -from PyQt5.QtCore import Qt +from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtWidgets import QWidget, QLabel, QCompleter, QVBoxLayout, QHBoxLayout, QGridLayout from qfluentwidgets.common.icon import FluentIconBase @@ -984,6 +985,8 @@ def __init__(self, title, content, parent): class LockConfigCard(SettingCard): + loadNowMode = pyqtSignal() + def __init__(self, title, content, configItem: ConfigItem, parent): super().__init__(Icon.LOCK, title, content, parent) @@ -995,6 +998,15 @@ def __init__(self, title, content, configItem: ConfigItem, parent): self.hBoxLayout.addSpacing(16) self.switchButton.checkedChanged.connect(self.__onCheckedChanged) + self.loadNowMode.connect(self.__onLoadNowMode) + + def __onLoadNowMode(self): + path = f"{cfg.get(cfg.lolFolder)}/../Game/Config/PersistedSettings.json" + + if os.path.exists(path): + current_mode = stat.S_IMODE(os.lstat(path).st_mode) + if current_mode == 0o444: + self.switchButton.setChecked(True) def setValue(self, isChecked: bool): qconfig.set(self.configItem, isChecked) @@ -1003,13 +1015,29 @@ def setValue(self, isChecked: bool): def __onCheckedChanged(self, isChecked: bool): self.setValue(isChecked) - self.setConfigFileReadOnlyEnabled(isChecked) + if not self.setConfigFileReadOnlyEnabled(isChecked): + InfoBar.error( + title=self.tr("Error"), + content=self.tr("Failed to set file permissions"), + orient=Qt.Vertical, + isClosable=True, + position=InfoBarPosition.BOTTOM_RIGHT, + duration=5000, + parent=self, + ) + self.setValue(not isChecked) def setConfigFileReadOnlyEnabled(self, enable): path = f"{cfg.get(cfg.lolFolder)}/../Game/Config/PersistedSettings.json" if not os.path.exists(path): - return + return False mode = 0o444 if enable else 0o666 os.chmod(path, mode) + + current_mode = stat.S_IMODE(os.lstat(path).st_mode) + if current_mode != mode: + return False + + return True diff --git a/app/view/main_window.py b/app/view/main_window.py index 42cf6ed1..eb485ba9 100644 --- a/app/view/main_window.py +++ b/app/view/main_window.py @@ -401,6 +401,7 @@ def _(): self.auxiliaryFuncInterface.profileBackgroundCard.updateCompleter() self.auxiliaryFuncInterface.autoSelectChampionCard.updateCompleter() + self.auxiliaryFuncInterface.lockConfigCard.loadNowMode.emit() status = connector.getGameStatus() self.eventListener.gameStatusChanged.emit(status)