Skip to content

Commit

Permalink
1. BUG修复: 在删除软件或修改LOL路径后再次启动软件时, "锁定设置"选项一定会显示为未启用的问题(改为以实际读写权限决定开关状态)
Browse files Browse the repository at this point in the history
2. BUG修复: 在因路径、权限、杀软等原因改写PersistedSettings.json读写权限失败时,弹出提示并将开关状态还原保证逻辑准确。
  • Loading branch information
Hpero4 committed Oct 28, 2023
1 parent 03c86fc commit 3599692
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
34 changes: 31 additions & 3 deletions app/view/auxiliary_interface.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import threading
import os
import stat
from typing import Union
from PyQt5.QtGui import QIcon

from qfluentwidgets import (SettingCardGroup, SwitchSettingCard, ExpandLayout,
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

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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
1 change: 1 addition & 0 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3599692

Please sign in to comment.