mirror of
https://github.com/moraroy/NonSteamLaunchers-On-Steam-Deck.git
synced 2026-06-13 04:04:59 +03:00
Add files via upload
This commit is contained in:
+96
-70
@@ -3713,20 +3713,34 @@ SCANNER_CODE = r"""
|
|||||||
_last_written_state = None
|
_last_written_state = None
|
||||||
|
|
||||||
def write_scan_state_to_file(state: str):
|
def write_scan_state_to_file(state: str):
|
||||||
global _last_written_state
|
|
||||||
if state == _last_written_state: return
|
|
||||||
try:
|
try:
|
||||||
lines = []
|
current = read_scan_state_from_file()
|
||||||
try: lines = open(ENVARS_FILE).readlines()
|
if current == state:
|
||||||
except FileNotFoundError: pass
|
return
|
||||||
lines = [l for l in lines if not l.startswith("NSL_SCAN_STATE=")]
|
|
||||||
lines.append(f"NSL_SCAN_STATE={state}\n")
|
try:
|
||||||
with open(ENVARS_FILE, "w") as f: f.writelines(lines)
|
with open(ENVARS_FILE, "r") as f:
|
||||||
_last_written_state = state
|
lines = f.readlines()
|
||||||
|
except FileNotFoundError:
|
||||||
|
lines = []
|
||||||
|
|
||||||
|
found = False
|
||||||
|
for i, line in enumerate(lines):
|
||||||
|
if line.startswith("NSL_SCAN_STATE="):
|
||||||
|
lines[i] = f"NSL_SCAN_STATE={state}\n"
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
lines.append(f"NSL_SCAN_STATE={state}\n")
|
||||||
|
|
||||||
|
with open(ENVARS_FILE, "w") as f:
|
||||||
|
f.writelines(lines)
|
||||||
|
|
||||||
print(f"[ENVARS] Updated scan state: {state}")
|
print(f"[ENVARS] Updated scan state: {state}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[ENVARS] Failed to write state: {e}")
|
print(f"[ENVARS] Failed to write state: {e}")
|
||||||
|
|
||||||
def read_scan_state_from_file() -> str | None:
|
def read_scan_state_from_file() -> str | None:
|
||||||
try:
|
try:
|
||||||
for line in open(ENVARS_FILE):
|
for line in open(ENVARS_FILE):
|
||||||
@@ -3760,7 +3774,7 @@ def set_initial_state(sock):
|
|||||||
"method": "Runtime.evaluate",
|
"method": "Runtime.evaluate",
|
||||||
"params": {"expression": f"window.__scan_state = '{state_from_envars}'"}
|
"params": {"expression": f"window.__scan_state = '{state_from_envars}'"}
|
||||||
}))
|
}))
|
||||||
write_scan_state_to_file(state_from_envars)
|
#write_scan_state_to_file(state_from_envars)
|
||||||
return state_from_envars
|
return state_from_envars
|
||||||
|
|
||||||
def sync_frontend_state_to_envars(sock):
|
def sync_frontend_state_to_envars(sock):
|
||||||
@@ -3899,16 +3913,17 @@ def create_new_entry(shortcutdirectory, appname, launchoptions, startingdir, lau
|
|||||||
try:
|
try:
|
||||||
with open(gate_file, "r", encoding="utf-8") as f:
|
with open(gate_file, "r", encoding="utf-8") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
if line.strip().startswith("NSL_SCAN_STATE="):
|
||||||
if line.startswith("NSL_SCAN_STATE="):
|
|
||||||
scan_state = line.split("=", 1)[1].strip().upper()
|
scan_state = line.split("=", 1)[1].strip().upper()
|
||||||
break
|
break
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"[NSL] Gate file not found: {gate_file}. Allowing by default.")
|
print(f"[NSL] Gate file not found: {gate_file}. Allowing by default.")
|
||||||
|
|
||||||
if scan_state == "OFF":
|
if scan_state == "OFF":
|
||||||
print(f"[NSL] Scan state is OFF. Skipping shortcut creation for {appname}.")
|
print(f"[NSL] Scan state is OFF. Skipping shortcut creation for {appname}.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Continue shortcut creation here...
|
||||||
global new_shortcuts_added
|
global new_shortcuts_added
|
||||||
global shortcuts_updated
|
global shortcuts_updated
|
||||||
global created_shortcuts
|
global created_shortcuts
|
||||||
@@ -4058,6 +4073,74 @@ def create_new_entry(shortcutdirectory, appname, launchoptions, startingdir, lau
|
|||||||
# Add the new entry to the shortcuts dictionary and add proton
|
# Add the new entry to the shortcuts dictionary and add proton
|
||||||
key = get_next_available_key(shortcuts)
|
key = get_next_available_key(shortcuts)
|
||||||
shortcuts['shortcuts'][key] = new_entry
|
shortcuts['shortcuts'][key] = new_entry
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(gate_file, "r", encoding="utf-8") as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
new_lines = []
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
stripped = line.strip()
|
||||||
|
if stripped.startswith("NSL_SCAN_STATE="):
|
||||||
|
state = line.split("=", 1)[1].strip().upper()
|
||||||
|
|
||||||
|
if state == "MANUAL":
|
||||||
|
new_lines.append("NSL_SCAN_STATE=OFF\n")
|
||||||
|
scan_state = "OFF"
|
||||||
|
changed = True
|
||||||
|
print("[NSL] Scan state was MANUAL. Reset to OFF.")
|
||||||
|
else:
|
||||||
|
new_lines.append(line)
|
||||||
|
scan_state = state
|
||||||
|
else:
|
||||||
|
new_lines.append(line)
|
||||||
|
|
||||||
|
if changed:
|
||||||
|
with open(gate_file, "w", encoding="utf-8") as f:
|
||||||
|
f.writelines(new_lines)
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"[NSL] Gate file not found during reset: {gate_file}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[NSL] Error resetting scan state: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
remove_lines = {
|
||||||
|
'chromelaunchoptions',
|
||||||
|
'websites_str',
|
||||||
|
'custom_website_names_str'
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(env_vars_path, "r", encoding="utf-8") as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
lines_to_keep = []
|
||||||
|
modified = False
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if not any(key in line for key in remove_lines):
|
||||||
|
lines_to_keep.append(line)
|
||||||
|
else:
|
||||||
|
modified = True
|
||||||
|
|
||||||
|
if modified:
|
||||||
|
with open(env_vars_path, "w", encoding="utf-8") as f:
|
||||||
|
f.writelines(lines_to_keep)
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
print(f"Added new entry for {appname} to shortcuts.")
|
print(f"Added new entry for {appname} to shortcuts.")
|
||||||
new_shortcuts_added = True
|
new_shortcuts_added = True
|
||||||
created_shortcuts.append(appname)
|
created_shortcuts.append(appname)
|
||||||
@@ -4118,7 +4201,6 @@ def create_new_entry(shortcutdirectory, appname, launchoptions, startingdir, lau
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Final return
|
#Final return
|
||||||
return new_entry
|
return new_entry
|
||||||
|
|
||||||
@@ -4493,34 +4575,6 @@ for i, website in enumerate(custom_websites):
|
|||||||
os.environ["chrome_startdir"],
|
os.environ["chrome_startdir"],
|
||||||
launcher_name=browser_for_env('customchromelaunchoptions')
|
launcher_name=browser_for_env('customchromelaunchoptions')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def remove_unwanted_lines(lines, remove_keys):
|
|
||||||
lines_to_keep = []
|
|
||||||
modified = False
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
if not any(key in line for key in remove_keys):
|
|
||||||
lines_to_keep.append(line)
|
|
||||||
else:
|
|
||||||
modified = True
|
|
||||||
|
|
||||||
return lines_to_keep, modified
|
|
||||||
|
|
||||||
|
|
||||||
remove_lines = {
|
|
||||||
'chromelaunchoptions',
|
|
||||||
'websites_str',
|
|
||||||
'custom_website_names_str'
|
|
||||||
}
|
|
||||||
|
|
||||||
lines_to_keep, modified = remove_unwanted_lines(lines, remove_lines)
|
|
||||||
|
|
||||||
if modified:
|
|
||||||
with open(env_vars_path, 'w') as f:
|
|
||||||
f.writelines(lines_to_keep)
|
|
||||||
|
|
||||||
#End of Creating Launcher Shortcuts
|
#End of Creating Launcher Shortcuts
|
||||||
|
|
||||||
|
|
||||||
@@ -6797,31 +6851,3 @@ if removed_apps:
|
|||||||
|
|
||||||
if not found_file:
|
if not found_file:
|
||||||
print(f"No .desktop file found for: {game_name}")
|
print(f"No .desktop file found for: {game_name}")
|
||||||
|
|
||||||
|
|
||||||
#Temp location to reset scanner
|
|
||||||
gate_file = f"{logged_in_home}/.config/systemd/user/env_vars"
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(gate_file, "r", encoding="utf-8") as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
|
|
||||||
changed = False
|
|
||||||
with open(gate_file, "w", encoding="utf-8") as f:
|
|
||||||
for line in lines:
|
|
||||||
if line.strip().startswith("NSL_SCAN_STATE="):
|
|
||||||
state = line.split("=", 1)[1].strip().upper()
|
|
||||||
if state == "MANUAL":
|
|
||||||
f.write("NSL_SCAN_STATE=OFF\n")
|
|
||||||
changed = True
|
|
||||||
else:
|
|
||||||
f.write(line)
|
|
||||||
else:
|
|
||||||
f.write(line)
|
|
||||||
|
|
||||||
if changed:
|
|
||||||
print(f"[NSL] Scan state was MANUAL. Reset to OFF.")
|
|
||||||
except FileNotFoundError:
|
|
||||||
print(f"[NSL] Gate file not found: {gate_file}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"[NSL] Failed to reset NSL_SCAN_STATE: {e}")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user