mirror of
https://github.com/Starlio-app/Starlio-web.git
synced 2024-11-05 17:03:58 +03:00
Удален автозапуск из-за бага который не получалось исправить
This commit is contained in:
parent
cb672ec1bb
commit
ed1b7d8386
2 changed files with 0 additions and 94 deletions
41
config.py
41
config.py
|
@ -1,41 +0,0 @@
|
|||
import configparser
|
||||
import os
|
||||
|
||||
|
||||
class Config:
|
||||
|
||||
def create_config(self, path):
|
||||
if not os.path.exists(path):
|
||||
config = configparser.ConfigParser()
|
||||
config.add_section("Settings")
|
||||
|
||||
config.set("Settings", "autorun", "False")
|
||||
with open(path, "w") as file:
|
||||
config.write(file)
|
||||
else:
|
||||
return print("The file exists")
|
||||
|
||||
def get_config(self, path):
|
||||
if not os.path.exists(path):
|
||||
self.create_config(path)
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path)
|
||||
return config
|
||||
|
||||
def get_setting(self, path, section, setting):
|
||||
config = self.get_config(path)
|
||||
value = config.get(section, setting)
|
||||
return value
|
||||
|
||||
def update_setting(self, path, section, setting, value):
|
||||
config = self.get_config(path)
|
||||
config.set(section, setting, value)
|
||||
with open(path, "w") as file:
|
||||
config.write(file)
|
||||
|
||||
def delete_setting(self, path, section, setting):
|
||||
config = self.get_config(path)
|
||||
config.remove_option(section, setting)
|
||||
with open(path, "w") as file:
|
||||
config.write(file)
|
53
main.py
53
main.py
|
@ -41,67 +41,15 @@ class Nasa(Config):
|
|||
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'}
|
||||
self.photoName = "everydayphotonasa.jpg"
|
||||
self.toaster = ToastNotifier()
|
||||
self.state = json.loads(
|
||||
Config.get_setting(self,
|
||||
path="config.ini",
|
||||
section="Settings",
|
||||
setting="autorun")
|
||||
.lower())
|
||||
|
||||
def resource_path(self, relative_path):
|
||||
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
|
||||
return os.path.join(base_path, relative_path)
|
||||
|
||||
def autorun(self):
|
||||
self.state = not MenuItem.checked
|
||||
|
||||
if not ctypes.windll.shell32.IsUserAnAdmin() != 0:
|
||||
elevate(show_console=False)
|
||||
|
||||
if self.state is False:
|
||||
print("Автозапуск включен.")
|
||||
path = os.path.dirname(os.path.realpath(__file__))
|
||||
address = os.path.join(path, "start.bat")
|
||||
key_value = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
|
||||
user = getpass.getuser()
|
||||
key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, key_value, 0, reg.KEY_ALL_ACCESS)
|
||||
reg.SetValueEx(key, user, 0, reg.REG_SZ, address)
|
||||
reg.CloseKey(key)
|
||||
Config.update_setting(self,
|
||||
path="config.ini",
|
||||
section="Settings",
|
||||
setting="autorun",
|
||||
value="True")
|
||||
|
||||
self.toaster.show_toast("EveryDayPhotoNasa",
|
||||
"Программа добавлена в автозапуск.",
|
||||
duration=3,
|
||||
icon_path=self.resource_path("nasa.ico"))
|
||||
else:
|
||||
print("Программа удалена из автозапуска.")
|
||||
key_value = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
|
||||
user = getpass.getuser()
|
||||
key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, key_value, 0, reg.KEY_ALL_ACCESS)
|
||||
reg.DeleteValue(key, user)
|
||||
reg.CloseKey(key)
|
||||
Config.update_setting(self,
|
||||
path="config.ini",
|
||||
section="Settings",
|
||||
setting="autorun",
|
||||
value="False")
|
||||
|
||||
self.toaster.show_toast("EveryDayPhotoNasa",
|
||||
"Программа удалена из автозапуска.",
|
||||
duration=3,
|
||||
icon_path=self.resource_path("nasa.ico"))
|
||||
|
||||
def tray(self):
|
||||
tray = Icon("EveryDayPhotoNasa", title="EveryDayPhotoNasa",
|
||||
icon=Image.open(self.resource_path("nasa.ico")),
|
||||
menu=Menu(
|
||||
MenuItem("Автозапуск",
|
||||
self.autorun,
|
||||
checked=lambda item: self.state),
|
||||
MenuItem("Выход",
|
||||
self.tray_close),
|
||||
))
|
||||
|
@ -131,7 +79,6 @@ class Nasa(Config):
|
|||
icon_path=self.resource_path("nasa.ico"))
|
||||
|
||||
def set_wallpaper(self):
|
||||
print(self.state)
|
||||
path = os.path.abspath(self.photoName)
|
||||
ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0)
|
||||
self.toaster.show_toast("EveryDayPhotoNasa",
|
||||
|
|
Loading…
Reference in a new issue