Skip to content

Commit

Permalink
重构游戏设置锁定选项卡逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Jun 10, 2024
1 parent c7a6048 commit 6abb22a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
2 changes: 0 additions & 2 deletions app/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ class Config(QConfig):

lastNoticeSha = ConfigItem("Other", "LastNoticeSha", "")

lockConfig = ConfigItem("Functions", "LockConfig", False, BoolValidator())

enableCloseToTray = ConfigItem(
"General", "EnableCloseToTray", None, OptionsValidator([None, True, False]))

Expand Down
41 changes: 21 additions & 20 deletions app/view/auxiliary_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, parent=None):
self.lockConfigCard = LockConfigCard(
self.tr("Lock config"),
self.tr("Make your game config unchangeable"),
cfg.lockConfig, self.gameGroup)
self.gameGroup)

self.fixDpiCard = FixClientDpiCard(
self.tr("Fix client window"),
Expand Down Expand Up @@ -1022,36 +1022,34 @@ def __init__(self, title, content, parent):


class LockConfigCard(SettingCard):
loadNowMode = pyqtSignal()

def __init__(self, title, content, configItem: ConfigItem, parent):
def __init__(self, title, content, parent):
super().__init__(Icon.LOCK, title, content, parent)

self.configItem = configItem

self.switchButton = SwitchButton(indicatorPos=IndicatorPosition.RIGHT)

self.hBoxLayout.addWidget(self.switchButton)
self.hBoxLayout.addSpacing(16)

self.switchButton.checkedChanged.connect(self.__onCheckedChanged)
self.loadNowMode.connect(self.__onLoadNowMode)

def __onLoadNowMode(self):
def loadNowMode(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)
if not os.path.exists(path):
self.switchButton.setChecked(False)
self.switchButton.setEnabled(False)
return

def setValue(self, isChecked: bool):
qconfig.set(self.configItem, isChecked)
self.switchButton.setChecked(isChecked)
try:
currentMode = stat.S_IMODE(os.lstat(path).st_mode)
if currentMode == 0o444:
self.switchButton.setChecked(True)
except:
self.switchButton.setEnabled(False)
pass

def __onCheckedChanged(self, isChecked: bool):
self.setValue(isChecked)

if not self.setConfigFileReadOnlyEnabled(isChecked):
InfoBar.error(
title=self.tr("Error"),
Expand All @@ -1074,10 +1072,13 @@ def setConfigFileReadOnlyEnabled(self, enable):
return False

mode = 0o444 if enable else 0o666
os.chmod(path, mode)

currentMode = stat.S_IMODE(os.lstat(path).st_mode)
if currentMode != mode:
try:
os.chmod(path, mode)
currentMode = stat.S_IMODE(os.lstat(path).st_mode)
if currentMode != mode:
return False
except:
self.switchButton.setEnabled(False)
return False

return True
Expand Down
2 changes: 1 addition & 1 deletion app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ async def __onLolClientStarted(self, pid):

asyncio.create_task(self.auxiliaryFuncInterface.initChampionList())

self.auxiliaryFuncInterface.lockConfigCard.loadNowMode.emit()
self.auxiliaryFuncInterface.lockConfigCard.loadNowMode()

# 加载大乱斗buff -- By Hpero4
aramInitT = asyncio.create_task(AramHome.checkAndUpdate())
Expand Down

0 comments on commit 6abb22a

Please sign in to comment.