Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz-gutowski committed Jun 23, 2024
2 parents b6ca95e + dc01796 commit 4ac424e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
78 changes: 57 additions & 21 deletions src/openvpn3_indicator/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import gettext
import logging
import re
import time
import traceback

Expand All @@ -41,6 +42,7 @@
import openvpn3

from openvpn3_indicator.about import APPLICATION_ID, APPLICATION_VERSION, APPLICATION_NAME, APPLICATION_TITLE, APPLICATION_SYSTEM_TAG
from openvpn3_indicator.about import MANAGER_VERSION_MINIMUM, MANAGER_VERSION_RECOMMENDED
from openvpn3_indicator.multi_indicator import MultiIndicator
from openvpn3_indicator.multi_notifier import MultiNotifier
from openvpn3_indicator.credential_store import CredentialStore
Expand Down Expand Up @@ -109,6 +111,10 @@ def on_open(self, application, files, n_files, hint):
def on_startup(self, data):
logging.info(f'Startup')
DBusGMainLoop(set_as_default=True)

self.multi_notifier = MultiNotifier(self, f'{APPLICATION_NAME}')
self.notifiers = dict()

self.dbus = dbus.SystemBus()
self.config_manager = openvpn3.ConfigurationManager(self.dbus)
self.session_manager = openvpn3.SessionManager(self.dbus)
Expand All @@ -120,15 +126,24 @@ def on_startup(self, data):
self.manager_version = 0
cmgr_obj = self.dbus.get_object('net.openvpn.v3.configuration','/net/openvpn/v3/configuration')
cmgr_prop = dbus.Interface(cmgr_obj, dbus_interface='org.freedesktop.DBus.Properties')
cmgr_version = str(cmgr_prop.Get('net.openvpn.v3.configuration','version'))
if cmgr_version.startswith('git:'):
# development version: presume all features are available
# and use a high version number
self.manager_version = 9999
elif cmgr_version.startswith('v'):
# Version identifiers may cary a "release label",
# like v19_beta, v22_dev
self.manager_version = int(cmgr_version[1:].split('_')[0])
self.manager_version = 9999
try:
cmgr_version = str(cmgr_prop.Get('net.openvpn.v3.configuration','version'))
if cmgr_version.startswith('git:'):
# development version: presume all features are available
# and use a high version number
pass
elif cmgr_version.startswith('v'):
# Version identifiers may cary a "release label",
# like v19_beta, v22_dev
self.manager_version = int(re.split(r'[^0-9]', cmgr_version[1:], 1)[0])
except:
logging.debug(traceback.format_exc())
logging.warning(f'Backend version check failed')
if self.manager_version < MANAGER_VERSION_MINIMUM:
self.error(f'You are using version {self.manager_version} of OpenVPN3 software which is not supported. Consider an upgrade to a newer version. We recommend version {MANAGER_VERSION_RECOMMENDED}.', notify=True)
elif self.manager_version < MANAGER_VERSION_RECOMMENDED:
self.warning(f'You are using version {self.manager_version} of OpenVPN3 software. Consider an upgrade to a newer version. We recommend version {MANAGER_VERSION_RECOMMENDED}.', notify=True)
logging.debug(f'Running with manager version {self.manager_version}')

self.credential_store = CredentialStore()
Expand All @@ -152,9 +167,6 @@ def on_startup(self, data):
self.default_indicator.order_key='0'
self.default_indicator.active=True
self.indicators = dict()

self.multi_notifier = MultiNotifier(self, f'{APPLICATION_NAME}')
self.notifiers = dict()

self.last_invalid = time.monotonic()
self.invalid_sessions = True
Expand All @@ -163,15 +175,6 @@ def on_startup(self, data):
GLib.timeout_add(1000, self.on_schedule)
self.hold()

self.multi_notifier.new_notifier(
identifier = 'startup',
title = f'{APPLICATION_TITLE}',
body = 'Started',
icon = f'{APPLICATION_NAME}',
active = True,
timespan = 2,
)

def refresh_ui(self):
if self.invalid_ui:
new_indicators = dict()
Expand Down Expand Up @@ -761,3 +764,36 @@ def action_about(self, _object):
def action_quit(self, _object):
logging.info(f'Quit')
self.release()

def logging_notify(self, msg, title=f'{APPLICATION_NAME}', icon='active'):
icon = f'{APPLICATION_NAME}-{icon}'
self.multi_notifier.new_notifier(
identifier = 'logging',
title = title,
body = msg,
icon = icon,
active = True,
timespan = 2,
)
self.multi_notifier.update()

def debug(self, msg, notify=False, *args, **kwargs):
logging.debug(msg, *args, **kwargs)
if notify:
self.logging_notify(msg)

def info(self, msg, notify=False, *args, **kwargs):
logging.info(msg, *args, **kwargs)
if notify:
self.logging_notify(msg)

def warning(self, msg, notify=False, *args, **kwargs):
logging.warning(msg, *args, **kwargs)
if notify:
self.logging_notify(msg, icon='active-error')

def error(self, msg, notify=False, *args, **kwargs):
logging.error(msg, *args, **kwargs)
if notify:
self.logging_notify(msg, icon='active-error')

5 changes: 2 additions & 3 deletions src/openvpn3_indicator/dialogs/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, GObject, Gtk, Gio

from openvpn3_indicator.about import APPLICATION_NAME
from openvpn3_indicator.about import APPLICATION_NAME, CONFIGURATION_MIME_TYPE

DEFAULT_CONFIG_NAME = 'NEW'

Expand All @@ -39,7 +39,7 @@ def construct_configuration_select_dialog(name=None, on_import=None, on_cancel=N
)
ovpn_filter = Gtk.FileFilter()
ovpn_filter.set_name('OpenVPN Configuration Files')
ovpn_filter.add_mime_type('application/x-openvpn-profile')
ovpn_filter.add_mime_type(CONFIGURATION_MIME_TYPE)
dialog.add_filter(ovpn_filter)
text_filter = Gtk.FileFilter()
text_filter.set_name('Text Files')
Expand Down Expand Up @@ -152,5 +152,4 @@ def on_dialog_response(_object, response):
default.set_can_default(True)
default.grab_default()
dialog.show_all()
dialog.show_all()
return dialog

0 comments on commit 4ac424e

Please sign in to comment.