spothomelight 1.0.1__py3-none-any.whl → 1.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
spothomelight/service.py CHANGED
@@ -9,31 +9,67 @@ def setup_autostart():
9
9
  script_cmd = f'"{python_exec}" -m spothomelight.main'
10
10
 
11
11
  if system == "Linux":
12
- service_dir = os.path.expanduser("~/.config/systemd/user")
13
- if not os.path.exists(service_dir):
14
- os.makedirs(service_dir)
15
-
16
- service_content = f"""[Unit]
17
- Description=SpotHomeLight Service
12
+ is_root = (os.geteuid() == 0)
13
+
14
+ if is_root:
15
+ service_dir = "/etc/systemd/system"
16
+ service_file = "spothomelight.service"
17
+ service_path = os.path.join(service_dir, service_file)
18
+ service_content = f"""[Unit]
19
+ Description=SpotHomeLight Service (System)
20
+ After=network.target
21
+
22
+ [Service]
23
+ ExecStart={script_cmd}
24
+ Restart=always
25
+ RestartSec=10
26
+ User=root
27
+ Environment=PYTHONUNBUFFERED=1
28
+
29
+ [Install]
30
+ WantedBy=multi-user.target
31
+ """
32
+ with open(service_path, "w") as f:
33
+ f.write(service_content)
34
+
35
+ print(f"检测到 Root 用户,已生成系统级服务文件: {service_path}")
36
+ print("正在启用服务...")
37
+
38
+ os.system("systemctl daemon-reload")
39
+ os.system("systemctl enable --now spothomelight")
40
+ print("完成。请使用 'systemctl status spothomelight' 查看状态。")
41
+
42
+ else:
43
+ service_dir = os.path.expanduser("~/.config/systemd/user")
44
+ if not os.path.exists(service_dir):
45
+ os.makedirs(service_dir)
46
+
47
+ service_content = f"""[Unit]
48
+ Description=SpotHomeLight Service (User)
18
49
  After=network.target
19
50
 
20
51
  [Service]
21
52
  ExecStart={script_cmd}
22
53
  Restart=always
23
54
  RestartSec=10
55
+ Environment=PYTHONUNBUFFERED=1
24
56
 
25
57
  [Install]
26
58
  WantedBy=default.target
27
59
  """
28
- service_path = os.path.join(service_dir, "spothomelight.service")
29
- with open(service_path, "w") as f:
30
- f.write(service_content)
31
-
32
- print(f"已生成 Systemd 服务文件: {service_path}")
33
- print("正在启用服务...")
34
- os.system("systemctl --user daemon-reload")
35
- os.system("systemctl --user enable --now spothomelight")
36
- print("完成。请使用 'systemctl --user status spothomelight' 查看状态。")
60
+ service_path = os.path.join(service_dir, "spothomelight.service")
61
+ with open(service_path, "w") as f:
62
+ f.write(service_content)
63
+
64
+ print(f"检测到普通用户,已生成用户级服务文件: {service_path}")
65
+ print("正在启用服务...")
66
+
67
+ ret = os.system("systemctl --user daemon-reload")
68
+ if ret != 0:
69
+ print("警告: 无法重载 daemon,可能是 DBus 环境变量缺失。尝试手动运行: systemctl --user daemon-reload")
70
+
71
+ os.system("systemctl --user enable --now spothomelight")
72
+ print("完成。请使用 'systemctl --user status spothomelight' 查看状态。")
37
73
 
38
74
  elif system == "Windows":
39
75
  task_name = "SpotHomeLightAutoStart"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spothomelight
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: Sync Spotify cover color to Home Assistant via Webhook
5
5
  Author-email: "ZGQ Inc." <zgqinc@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/ZGQ-inc/SpotHomeLight
@@ -97,7 +97,7 @@ mode: restart
97
97
  trigger:
98
98
  - platform: webhook
99
99
  webhook_id: ""
100
- local_only: true
100
+ local_only: false
101
101
  condition: []
102
102
  action:
103
103
  - service: light.turn_on
@@ -3,12 +3,12 @@ spothomelight/auth.py,sha256=TGmR28lIBZnEVkMv7jIDBToZT3rcFUaqv4ZineIO-Do,1706
3
3
  spothomelight/config.py,sha256=URC1WwzZN2gRIfwNlMRwHNVtoviayYzmf6F0w3lMhLA,2274
4
4
  spothomelight/core.py,sha256=u87Q3BTdwbpjQIT4sZAK9-g79Rr-KHOepSLs2jDufPo,3002
5
5
  spothomelight/main.py,sha256=jX8esko2yj8c09HKBb1qmQloWE0mUQEc0F_CL27l5t8,1377
6
- spothomelight/service.py,sha256=jrlnIn9LL1YIEUrWoiVzPQgEFNvh0L0QBUSqNBMvAOg,1649
6
+ spothomelight/service.py,sha256=hoVW79VDUG4P3upS3gPD79j1CqfrDnLJRlxk-lnOUkI,2943
7
7
  spothomelight/utils.py,sha256=TnGji05MKMTsoqWUq5wFPx6jLthqA-KWVH-dCu5VbIc,1814
8
8
  spothomelight/utils_median_cut.py,sha256=9sqUBk0ZpHWwfoPl4YPRcljE_K05w8trZFQo8bVCMds,1991
9
- spothomelight-1.0.1.dist-info/licenses/LICENSE,sha256=_r815CZLcqdQJmXH7FeFNoBT8gmiGtsdqo4aynUS-DM,1065
10
- spothomelight-1.0.1.dist-info/METADATA,sha256=Sl-lIhnLB9Pl9Fk1LY6xya3JNPu4zY4SI0D5dN1cpq4,4545
11
- spothomelight-1.0.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
- spothomelight-1.0.1.dist-info/entry_points.txt,sha256=f9haGAoi-aXDTCkoxuSkdN78sHbvfbrr9gwaOIewuvw,58
13
- spothomelight-1.0.1.dist-info/top_level.txt,sha256=70ecLHIP1BNR5ZLYC-IfQ6ceydH0AZaDGIoH_wGrQZY,14
14
- spothomelight-1.0.1.dist-info/RECORD,,
9
+ spothomelight-1.0.3.dist-info/licenses/LICENSE,sha256=_r815CZLcqdQJmXH7FeFNoBT8gmiGtsdqo4aynUS-DM,1065
10
+ spothomelight-1.0.3.dist-info/METADATA,sha256=JkxLAjdc4r2-VgxP1hpxXinkzDukG-pcR3CKOLcl8eE,4546
11
+ spothomelight-1.0.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
+ spothomelight-1.0.3.dist-info/entry_points.txt,sha256=f9haGAoi-aXDTCkoxuSkdN78sHbvfbrr9gwaOIewuvw,58
13
+ spothomelight-1.0.3.dist-info/top_level.txt,sha256=70ecLHIP1BNR5ZLYC-IfQ6ceydH0AZaDGIoH_wGrQZY,14
14
+ spothomelight-1.0.3.dist-info/RECORD,,