-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (54 loc) · 2.14 KB
/
main.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
from tasktails import TaskTails
import platform
import os
import sys
import ctypes
import tkinter as tk
from easy_json import edit_value
from settings import Settings
settings = Settings()
def check_root():
if platform.system() == "Linux":
if os.getuid() != 0:
return False
else:
return True
elif platform.system() == "Windows":
if not ctypes.windll.shell32.IsUserAnAdmin():
return False
else:
return True
def request_admin_access():
if platform.system() == "Linux":
root.destroy()
args = ['sudo', sys.executable, "tasktails.py"] + sys.argv + [os.environ]
# Relaunch the script with sudo
edit_value('website_blocking', True, 'data/settings.json')
os.execlpe('sudo', *args)
elif platform.system() == "Windows":
root.destroy()
script = "tasktails.py"
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, script, None, 1)
edit_value('website_blocking', True, 'data/settings.json')
def press_yes():
if check_root() != True:
request_admin_access()
else:
root.destroy()
edit_value('website_blocking', True, 'data/settings.json')
TaskTails()
def press_no():
root.destroy()
edit_value('website_blocking', False, 'data/settings.json' )
TaskTails()
root = tk.Tk()
root.configure(bg=settings.root_color)
root.iconphoto(True, tk.PhotoImage(file='images/logo.png'))
root.title('Task Tails')
question = tk.Label(root, text='proceed with site blocking feature?\n(You have to permit admin access to modify "host" file)', bg=settings.root_color, fg=settings.fg_color)
question.grid(row=0, columnspan=2, padx=5, pady=5)
yes = tk.Button(root, text='yes', command=press_yes, bg=settings.button_color, fg=settings.fg_color, highlightthickness=0)
yes.grid(row=1, column=0, padx=10, pady=10, sticky='ew')
no = tk.Button(root, text='no', command=press_no, bg=settings.button_color, fg=settings.fg_color, highlightthickness=0)
no.grid(row=1, column=1, padx=10, pady=10, sticky='ew')
root.mainloop()