Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
perfect-privacy-lars committed Mar 31, 2023
1 parent d7cb9eb commit 3893169
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
10 changes: 10 additions & 0 deletions gui/default/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class DashboardView(PyHtmlView):
TEMPLATE_STR = '''
<div class="head" style="height: 10vh;width: 100%;">
<img src="/static/img/logo_dark.png" style="width: fit-content; position: absolute; top: 1em; left: 2em;">
<div style="width: fit-content; position: absolute; top: 1.5em; right: 3em;">
Expand Down Expand Up @@ -101,6 +102,15 @@ def bg_thread(self):
class VpnStatusView(PyHtmlView):
DOM_ELEMENT_EXTRAS = "style='width:100%;text-align:center;'"
TEMPLATE_STR = '''
<script>
{% if pyview.subject.session.state.get() == "idle" %}
pyhtmlapp.set_icon_state("disconnected")
{% elif pyview.subject.session.state.get() == "connected" and pyview.subject.ipcheck.vpn_connected == true %}
pyhtmlapp.set_icon_state("connected")
{% else %}
pyhtmlapp.set_icon_state("working")
{% endif %}
</script>
{% if pyview.subject.session.state.get() == "idle" %}
<h3 class="status_red">VPN Not Connected</h3>
{% elif pyview.subject.session.state.get() == "connecting" %}
Expand Down
46 changes: 43 additions & 3 deletions launcher/perfect_privacy_frontend.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import os, sys
import platform
import subprocess
import time
import webbrowser
from shlex import quote

PROJECT_ROOT_DIRECTORY = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))
sys.path.insert(0, PROJECT_ROOT_DIRECTORY)
sys.path.insert(0, os.path.dirname(PROJECT_ROOT_DIRECTORY))

from core.libs.web.reporter import ReporterInstance

PROJECT_ROOT_DIRECTORY = os.path.abspath(os.path.dirname(os.path.realpath(sys.argv[0])))

import psutil
try:
Expand Down Expand Up @@ -91,7 +96,7 @@ def __init__(self):
except:
self.minimized = False

errormsg = ""
errormsg = '<button style="background-image:linear-gradient(to bottom,#5cb85c 0,#419641 100%); border-color: #3e8f3e; cursor: pointer;webkit-user-select: none;user-select: none;border: 1px solid;border-radius: 6px;line-height: 20px;font-size:14px;" onclick="pyhtmlapp.fix_service_as_admin()">Try to repair background service (as Admin)</button><br>'
self.restart = False
self.update_on_exit = False

Expand Down Expand Up @@ -124,6 +129,7 @@ def __init__(self):
self.tray.addJavascriptFunction("show_app", self.window.show)
self.tray.addJavascriptFunction("hide_app", self.window.hide)
self.tray.addJavascriptFunction("set_icon_state", self.animatedTrayIcon.set_state)
self.window.addJavascriptFunction("set_icon_state", self.animatedTrayIcon.set_state)

if PLATFORM == PLATFORMS.macos:
def confirm_exit():
Expand All @@ -134,12 +140,30 @@ def confirm_exit():
self.window.on_closed_event.attach_observer(self.app.hide_osx_dock)
self.window.on_show_event.attach_observer(self.app.show_osx_dock)
self.app.on_activated_event.attach_observer(self.window.show)
if platform.processor() == "arm": # just fixes for flickering webview
self.window.on_show_event.attach_observer(self.hide_tray_menu) # on osx arm hide tray menu if window is show, because for some reason the webview will flicker white if its visible more than once
self.window.on_closed_event.attach_observer(self.load_tray_page) # load tray page if main window is hidden so tray icon stays updated
self.tray.on_show_event.attach_observer(self.tray._webWidget.load_page)
self.tray.on_closed_event.attach_observer(self.on_tray_close)
else:
#self.window.on_minimized_event.attach_observer(self.window.hide)
self.tray.on_left_clicked.attach_observer(self.window.show)

self.window._webWidget.web.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu)
self.tray._webWidget.web.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu)

# on osx arm hide tray menu if window is show, because for some reason the webview will flicker white if its visible more than once
def hide_tray_menu(self, *args):
if self.tray._menu_is_open is True:
self.tray._trayAction.trigger()
self.tray._webWidget.unload_page()

def load_tray_page(self, *args):
if self.tray._menu_is_open is False:
self.tray._webWidget.load_page()
def on_tray_close(self, *args):
if self.window._qMainWindow.isVisible():
self.tray._webWidget.unload_page() # unload page while main window is visible to prevent flickering on arm mac


def open_url(self, url):
webbrowser.open(url)
Expand Down Expand Up @@ -188,6 +212,22 @@ def fix_service_as_admin(self, *args):
self.restart = True
self.stop()

elif PLATFORM == PLATFORMS.macos:
try:
cmd = [ "launchctl","load","/Library/LaunchDaemons/perfect-privacy-service.plist"]
subprocess.Popen(["osascript", "-e","do shell script %s with administrator privileges without altering line endings" % self.quote_applescript(self.quote_shell(cmd))])
except OSError as e:
print(e)

def quote_shell(self, args):
return " ".join(quote(arg) for arg in args)

def quote_applescript(self, string):
charmap = { "\n": "\\n", "\r": "\\r", "\t": "\\t", "\"": "\\\"", "\\": "\\\\", }
return '"%s"' % "".join(charmap.get(char, char) for char in string)



class StartupCheckerWin():

def check(self):
Expand Down
1 change: 1 addition & 0 deletions var/mpass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5168adf2-c4b1-4e2f-ac7b-ff4f70ae57ab

0 comments on commit 3893169

Please sign in to comment.