Skip to content

The only downloader you need. 下载器的集大成者。

fix(linux): 使用 getpass替代 os.getlogin 获取用户名在 Linux 系统中,os.getlogin() 方法可能无法正确获取当前用户名。 使用 getpass.getuser() 作为更可靠的替代方案,确保能够正确获取用户名。 修改了配置文件路径和自动启动桌面文件路径的生成逻辑。

LittleSong20241b3a607047ff
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.py
index 5b77853f..9953213f 100644
--- a/Ghost-Downloader-3.py
+++ b/Ghost-Downloader-3.py
@@ -1,5 +1,5 @@
# coding:utf-8
-
+import getpass
import os
import sys
@@ -78,7 +78,7 @@ if sys.platform == "linux":
import configparser
config = configparser.ConfigParser()
- config.read(f"/home/{os.getlogin()}/.config/kdeglobals")
+ config.read(f"/home/{getpass.getuser()}/.config/kdeglobals")
# 获取 DecorationFocus 的值
if 'Colors:Window' in config:
diff --git a/app/view/setting_interface.py b/app/view/setting_interface.py
index 8c7433e1..ab207fe6 100644
--- a/app/view/setting_interface.py
+++ b/app/view/setting_interface.py
@@ -1,5 +1,7 @@
# coding:utf-8
import os
+import getpass
+
import sys
from pathlib import Path
from typing import Union
@@ -684,12 +686,12 @@ class SettingInterface(ScrollArea):
)
elif sys.platform == "linux":
if value:
- autoStartPath = Path(f"/home/{os.getlogin()}/.config/autostart/")
+ autoStartPath = Path(f"/home/{getpass.getuser()}/.config/autostart/")
if not autoStartPath.exists():
autoStartPath.mkdir(parents=True, exist_ok=True)
with open(
- f"/home/{os.getlogin()}/.config/autostart/gd3.desktop",
+ f"/home/{getpass.getuser()}/.config/autostart/gd3.desktop",
"w",
encoding="utf-8",
) as f:
@@ -707,7 +709,7 @@ class SettingInterface(ScrollArea):
f.flush()
else:
- os.remove(f"/home/{os.getlogin()}/.config/autostart/gd3.desktop")
+ os.remove(f"/home/{getpass.getuser()}/.config/autostart/gd3.desktop")
else:
InfoBar.warning(