Skip to content

Commit

Permalink
ui:use appimages pattern as default target if found
Browse files Browse the repository at this point in the history
If the path of a process starts with /tmp/.mount_*, which is the common
path for appimages, use it as the default target on the popups.

Previously it was only added to the list of targets, but preselecting it
will help users to create rules for appimages.

(cherry picked from commit 016f484)
  • Loading branch information
gustavo-iniguez-goya committed Feb 8, 2024
1 parent b99714f commit dd3aba1
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ui/opensnitch/dialogs/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,20 @@ def _set_app_args(self, app_name, app_args):
self.argsLabel.setVisible(False)
self.argsLabel.setText("")

def _set_default_target(self, combo, con, app_name, app_args):
# set appimage as default target if the process path starts with
# /tmp/._mount
if con.process_path.startswith(self.APPIMAGE_PREFIX):
idx = combo.findData(self.FIELD_APPIMAGE)
if idx != -1:
combo.setCurrentIndex(idx)
return

if int(con.process_id) > 0 and app_name != "" and app_args != "":
self.whatCombo.setCurrentIndex(int(self._cfg.getSettings(self._cfg.DEFAULT_TARGET_KEY)))
else:
self.whatCombo.setCurrentIndex(2)

def _render_connection(self, con):
app_name, app_icon, description, _ = self._apps_parser.get_info_by_path(con.process_path, "terminal")
app_args = " ".join(con.process_args)
Expand Down Expand Up @@ -415,11 +429,7 @@ def _render_connection(self, con):

self._configure_default_duration()

if int(con.process_id) > 0 and app_name != "" and app_args != "":
self.whatCombo.setCurrentIndex(int(self._cfg.getSettings(self._cfg.DEFAULT_TARGET_KEY)))
else:
self.whatCombo.setCurrentIndex(2)

self._set_default_target(self.whatCombo, con, app_name, app_args)

self.checkDstIP.setChecked(self._cfg.getBool(self._cfg.DEFAULT_POPUP_ADVANCED_DSTIP))
self.checkDstPort.setChecked(self._cfg.getBool(self._cfg.DEFAULT_POPUP_ADVANCED_DSTPORT))
Expand All @@ -444,7 +454,7 @@ def closeEvent(self, e):
e.ignore()

def _add_appimage_pattern_to_combo(self, combo, con):
"""appimages' absolute path usually starts with /tmp/.mount_<
"""appimages' absolute path usually starts with /tmp/.mount_
"""
appimage_bin = os.path.basename(con.process_path)
appimage_path = os.path.dirname(con.process_path)
Expand Down

0 comments on commit dd3aba1

Please # to comment.