diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 153e2ac..74de637 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,7 @@
-
-
+
@@ -361,7 +360,15 @@
1725991610908
-
+
+
+ 1726349168248
+
+
+
+ 1726349168248
+
+
@@ -399,7 +406,6 @@
-
@@ -424,6 +430,7 @@
-
+
+
\ No newline at end of file
diff --git a/install.py b/install.py
index 0ed4497..baffcff 100755
--- a/install.py
+++ b/install.py
@@ -8,20 +8,21 @@ config_path = Path.home() / ".config" / "wire_py" / "wg_py"
start_file = f'''\
#!/usr/bin/python3
from subprocess import check_call
+from pathlib import Path
-path_to_file = {str(config_path)!r}
+path_to_file = Path.home() / '.config/wire_py/wg_py'
+
+if Path.exists(path_to_file):
+ a_con = Path.read_text(path_to_file)
+ check_call(['nmcli', 'connection', 'up', a_con])
+else:
+ pass
-with open(path_to_file, 'r') as file:
- *_, line = file
-a_con = line[5:]
-check_call(['nmcli', 'connection', 'up', a_con])
'''
Path("start_wg.py").write_text(start_file)
config_path.parent.mkdir(exist_ok=True)
-if not Path.exists(config_path):
- config_path.write_text("false")
# Prompt the user for the sudo password
#sudo_password = getpass('Enter sudo password: ')
diff --git a/main.py b/main.py
index 99d97c8..710af21 100755
--- a/main.py
+++ b/main.py
@@ -148,26 +148,27 @@ class FrameWidgets(ttk.Frame):
self.btn_i.grid(column=0, row=1, padx=15, pady=8)
def delete():
+
try:
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
check_call(['nmcli', 'connection', 'delete', select_tl])
self.l_box.delete(self.select_tunnel[0])
- os.remove(Path.home() / 'tester/' / str(select_tl + '.conf'))
+ Path.unlink(Path.home() / 'tester/' / str(select_tl + '.conf'))
path_to_file = Path.home() / '.config/wire_py/wg_py'
- with open(path_to_file, 'r') as file2:
- for line in file2.readlines():
- a_con = line[5:]
+ if Path.exists(path_to_file):
+ a_con = Path.read_text(path_to_file)
+
if select_tl == a_con:
self.selected_option.set(0)
self.autoconnect_var.set('no Autoconnect')
+ Path.unlink(path_to_file)
# for disable checkbox when Listbox empty
tl = ListTunnels.tl_list()
if len(tl) == 0:
self.wg_autostart.configure(state='disabled')
- with open(path_to_file, 'w') as file2:
- file2.write('false')
+ Path.unlink(path_to_file)
if self.a != '' and self.a == select_tl:
self.StrVar.set(value='')
diff --git a/start_wg.py b/start_wg.py
index 8c13876..53c76cb 100755
--- a/start_wg.py
+++ b/start_wg.py
@@ -1,9 +1,12 @@
#!/usr/bin/python3
from subprocess import check_call
+from pathlib import Path
-path_to_file = '/home/punix/.config/wire_py/wg_py'
+path_to_file = Path.home() / '.config/wire_py/wg_py'
+
+if Path.exists(path_to_file):
+ a_con = Path.read_text(path_to_file)
+ check_call(['nmcli', 'connection', 'up', a_con])
+else:
+ pass
-with open(path_to_file, 'r') as file:
- *_, line = file
-a_con = line[5:]
-check_call(['nmcli', 'connection', 'up', a_con])
diff --git a/wg_func.py b/wg_func.py
index 34a91d7..5b39b90 100755
--- a/wg_func.py
+++ b/wg_func.py
@@ -2,7 +2,7 @@
import os
import shutil
from datetime import datetime
-from tkinter import filedialog, ttk
+from tkinter import filedialog
import tkinter as tk
from pathlib import Path
from subprocess import check_call
@@ -248,15 +248,12 @@ class FileHandle:
select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(select_tunnel[0])
if self.selected_option.get() == 0:
- with open(path_to_file, 'w') as off:
- off.write('false ' + '\n')
+ Path.unlink(path_to_file)
tl = ListTunnels.tl_list()
if len(tl) == 0:
self.wg_autostart.configure(state='disabled')
if self.selected_option.get() >= 1:
- with open(path_to_file, 'w') as set_on:
- set_on.write('true ' + select_tl)
-
+ Path.write_text(path_to_file, select_tl)
except IndexError:
self.selected_option.set(1)
@@ -273,17 +270,14 @@ class OnOff:
self.lb_frame_buttons = None
def on_off(self):
- with open(path_to_file, 'r') as file:
- for line in file.readlines():
- a_connect = line
- if 'true' in a_connect:
- self.selected_option.set(1)
- self.autoconnect_var.set('')
- self.auto_con = a_connect[5:]
- else:
- self.wg_autostart.configure(state='disabled')
- self.auto_con = 'no Autoconnect'
-
+ if Path.exists(path_to_file):
+ self.selected_option.set(1)
+ self.autoconnect_var.set('')
+ self.auto_con = Path.read_text(path_to_file)
+ else:
+ self.wg_autostart.configure(state='disabled')
+ self.auto_con = 'no Autoconnect'
+ self.autoconnect_var.set('')
self.autoconnect_var = tk.StringVar()
self.autoconnect_var.set(self.auto_con)
self.autoconnect = tk.Label(self, textvariable=self.autoconnect_var, fg='blue', padx=5)