-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckupdate2.py
114 lines (103 loc) · 4.19 KB
/
checkupdate2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/python3
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import *
import requests
import re
import subprocess
import threading
import sv_ttk
import darkdetect
from tkinter import scrolledtext
import sys
import os
import ctypes
import ctypes as ct
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
src = os.path.join(os.getenv("APPDATA"),"Activity-Condenser")
downloadsrc = os.path.join(src,"Activity-Condenser.exe")
if darkdetect.isDark():
theme = 'dark'
icontheme = 'about-white.ico'
else:
theme = 'light'
icontheme = 'about-dark.ico'
response = requests.get("https://api.github.com/repos/Fefedu973/Activity-Condenser/releases/latest")
getchangelog = (response.json()["body"])
class UpdateApp:
def __init__(self, master=None):
# build ui
toplevel1 = tk.Tk() if master is None else tk.Toplevel(master)
toplevel1.iconbitmap(icontheme)
toplevel1.configure(height=200, width=200)
toplevel1.resizable(False, False)
toplevel1.title("update")
frame2 = tk.Frame(toplevel1)
frame2.configure(height=200, padx=50, pady=10, width=200)
label1 = ttk.Label(frame2)
label1.configure(text="New update avalaible !")
label1.grid(column=0, pady="0 15", row=0)
button1 = ttk.Button(frame2)
button1.configure(cursor="hand2", text="Install", width=12)
button1.grid(column=0, pady="30 0", row=8, sticky="e")
button1.configure(command=self.install)
button2 = ttk.Button(frame2)
button2.configure(cursor="hand2", text="Ignore", width=12)
button2.grid(column=0, pady="30 0", row=8, sticky="w")
button2.configure(command=self.cancel)
separator3 = ttk.Separator(frame2)
separator3.configure(orient="horizontal")
separator3.grid(column=0, ipadx=120, pady="10 40", row=8)
separator4 = ttk.Separator(frame2)
separator4.configure(orient="horizontal")
separator4.grid(column=0, ipadx=120, pady="0 10", row=1)
ScrolledText = scrolledtext.ScrolledText(frame2)
ScrolledText.configure(height=10, width=50)
ScrolledText.grid(column=0, pady="0 0", row=2)
ScrolledText.insert(tk.INSERT, getchangelog)
ScrolledText.configure(state="disabled")
self.label3 = ttk.Label(frame2)
self.update = tk.StringVar()
self.update.set("")
self.label3.configure(foreground='red', textvariable=self.update)
self.label3.grid(column=0, row=5, sticky="w")
frame2.pack(side="top")
sv_ttk.set_theme(theme)
# Main widget
self.mainwindow = toplevel1
def run(self):
if darkdetect.isDark():
self.mainwindow.update()
DWMWA_USE_IMMERSIVE_DARK_MODE = 20
set_window_attribute = ct.windll.dwmapi.DwmSetWindowAttribute
get_parent = ct.windll.user32.GetParent
hwnd = get_parent(self.mainwindow.winfo_id())
rendering_policy = DWMWA_USE_IMMERSIVE_DARK_MODE
value = 2
value = ct.c_int(value)
set_window_attribute(hwnd, rendering_policy, ct.byref(value),ct.sizeof(value))
else:
pass
self.mainwindow.mainloop()
def install(self):
self.label3.configure(foreground='red')
self.update.set("Downloading... please wait")
t1 = threading.Thread(target=self.downloadFunc)
t1.start()
def downloadFunc(self):
response = requests.get("https://api.github.com/repos/Fefedu973/Activity-Condenser/releases/latest")
getver = re.sub("[^0-9,.]", "", (response.json()["name"]))
r = requests.get(f'https://github.com/Fefedu973/Activity-Condenser/releases/download/{getver}/Activity-Condenser.exe')
print(r)
with open(downloadsrc, "wb") as code:
code.write(r.content)
self.label3.configure(foreground='green')
self.update.set("Download complete ! Please wait for the installer to start")
subprocess.call(downloadsrc, shell=True)
def cancel(self):
self.mainwindow.destroy()
sys.exit()
if __name__ == "__main__":
app = UpdateApp()
app.run()