--- a +++ b @@ -47,6 +47,10 @@ if identifier in self._indicators: print("Not creating the same identifier twice") return + with open("/tmp/appindicators.created", "a") as myfile: + myfile.write(identifier + "\n") + with open("/tmp/appindicators.visible", "a") as myfile: + myfile.write(identifier + "\n") indicator = AppIndicator3.Indicator.new( identifier, icon, AppIndicator3.IndicatorCategory.APPLICATION_STATUS @@ -70,9 +74,13 @@ indicator.set_label(args, args) def _hide(self, indicator, args): + identifier = indicator.get_id() + os.system("sed -i '/^" + identifier + "$/ d' /tmp/appindicators.visible") indicator.set_status(AppIndicator3.IndicatorStatus.PASSIVE) def _show(self, indicator, args): + identifier = indicator.get_id() + os.system("grep -q " + identifier + " /tmp/appindicators.visible || echo '" + identifier + "' >>/tmp/appindicators.visible") indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) def _menu_clear(self, indicator, args): @@ -81,9 +89,12 @@ indicator.set_menu(menu) def _menu_add(self, indicator, args): - cmd, _, label = args.partition(' ') + cmd_with_args_str, label = args.split('#') + cmd_with_args_list = cmd_with_args_str.split() + cmd = cmd_with_args_list[0] + args = cmd_with_args_list[1:] menuitem = Gtk.MenuItem.new_with_label(label) - menuitem.connect('activate', lambda item : self._execute(cmd)) + menuitem.connect('activate', lambda item : self._execute(cmd, args)) indicator.get_menu().append(menuitem) def _destroy(self, indicator, args): @@ -99,7 +110,7 @@ # del self._indicators[indicator.get_id()] - def _execute(self, command): + def _execute(self, command, arguments): # We double fork to reparent the child process to pid 1 pid = os.fork() @@ -114,8 +125,9 @@ # child process try: + argv = [command] + arguments c_pid = os.posix_spawnp( - command, (command,), os.environ, + command, argv, os.environ, # Not supported on my Python version so can't test. # # The named pipe uses O_CLOEXEC but not sure if