-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckupdate.py
172 lines (151 loc) · 5.7 KB
/
checkupdate.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/python3
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import *
from PIL import ImageTk,Image
import requests
import re
import subprocess
import threading
import sv_ttk
import darkdetect
from tkinter import scrolledtext
import subprocess as sp
import sys
import json
import os
import ctypes
import ctypes as ct
import time
import psutil
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
src = os.path.join(os.getenv("APPDATA"),"Activity-Condenser")
settingssrc = os.path.join(src,"settings.json")
downloadsrc = os.path.join(src,"Activity-Condenser.exe")
errors = os.path.join(src,"errors.json")
noerror = {"Errors":""}
jsonString = json.dumps(noerror, indent=4, default=str)
jsonFile = open(errors, "w")
jsonFile.write(jsonString)
with open(settingssrc) as f:
data = json.load(f)
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"])
getver = re.sub("[^0-9,.]", "", (response.json()["name"]))
print(getver)
with open('version.json') as f:
version = json.load(f)
isdiscordrunning = False
maxcheck = 0
while isdiscordrunning == False:
if maxcheck < -1:
if ("Discord.exe" in (p.name() for p in psutil.process_iter())) == True:
isdiscordrunning = True
else:
time.sleep(6)
maxcheck = maxcheck + 1
else:
break
if data['checkonstart'] == 1:
if getver == version['version']:
sp.Popen(['python','tray.py'])
sys.exit()
else:
pass
else :
sp.Popen(['python','tray.py'])
sys.exit()
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")
checkbutton1 = ttk.Checkbutton(frame2)
self.check2 = tk.IntVar()
self.check2.set(data['checkonstart'])
checkbutton1.configure(command=self.check, variable=self.check2, text="Check updates on start")
checkbutton1.grid(column=0, pady="10 0", row=5, sticky="e")
frame2.pack(side="top")
sv_ttk.set_theme(theme)
# Main widget
self.mainwindow = toplevel1
def check(self):
data['checkonstart'] = self.check2.get()
with open(settingssrc, 'w') as f:
json.dump(data, f, indent=4)
print(data)
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):
sp.Popen(['python','tray.py'])
self.mainwindow.destroy()
sys.exit()
if __name__ == "__main__":
app = UpdateApp()
app.run()