mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
fix: snap launch
This commit is contained in:
@@ -232,3 +232,7 @@ class SoftwareManager(ABC):
|
||||
"""
|
||||
:return: if the instance is enabled by default when there is no user settings defining which gems are enabled.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def launch(self, pkg: SoftwarePackage):
|
||||
pass
|
||||
|
||||
@@ -149,13 +149,6 @@ class SoftwarePackage(ABC):
|
||||
:return: whether the app can be run via the GUI
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_command(self) -> str:
|
||||
"""
|
||||
:return: the command to run the application
|
||||
"""
|
||||
pass
|
||||
|
||||
def is_trustable(self) -> bool:
|
||||
"""
|
||||
:return: if the package is distributed by a trustable source
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
@@ -580,3 +581,7 @@ class ArchManager(SoftwareManager):
|
||||
|
||||
def is_default_enabled(self) -> bool:
|
||||
return False
|
||||
|
||||
def launch(self, pkg: ArchPackage):
|
||||
if pkg.command:
|
||||
subprocess.Popen(pkg.command.split(' '))
|
||||
|
||||
@@ -102,9 +102,6 @@ class ArchPackage(SoftwarePackage):
|
||||
# only returns if there is a desktop entry set for the application to avoid running command-line applications
|
||||
return bool(self.desktop_entry)
|
||||
|
||||
def get_command(self) -> str:
|
||||
return self.command
|
||||
|
||||
def get_publisher(self):
|
||||
return self.maintainer
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
from threading import Thread
|
||||
from typing import List, Set, Type
|
||||
@@ -210,3 +211,6 @@ class FlatpakManager(SoftwareManager):
|
||||
|
||||
def is_default_enabled(self) -> bool:
|
||||
return True
|
||||
|
||||
def launch(self, pkg: SoftwarePackage):
|
||||
flatpak.run(pkg.id)
|
||||
|
||||
@@ -278,3 +278,9 @@ def set_default_remotes():
|
||||
|
||||
def has_remotes_set() -> bool:
|
||||
return bool(run_cmd('{} remotes'.format(BASE_CMD)).strip())
|
||||
|
||||
|
||||
def run(app_id: str):
|
||||
subprocess.Popen([BASE_CMD, 'run', app_id])
|
||||
|
||||
|
||||
|
||||
@@ -59,9 +59,6 @@ class FlatpakApplication(SoftwarePackage):
|
||||
if data.get(attr) and not getattr(self, attr):
|
||||
setattr(self, attr, data[attr])
|
||||
|
||||
def get_command(self) -> str:
|
||||
return "flatpak run {}".format(self.id)
|
||||
|
||||
def can_be_run(self) -> bool:
|
||||
return self.installed and not self.runtime
|
||||
|
||||
|
||||
@@ -173,3 +173,6 @@ class SnapManager(SoftwareManager):
|
||||
|
||||
def is_default_enabled(self) -> bool:
|
||||
return True
|
||||
|
||||
def launch(self, pkg: SnapApplication):
|
||||
snap.run(pkg)
|
||||
|
||||
@@ -79,9 +79,6 @@ class SnapApplication(SoftwarePackage):
|
||||
if data.get('confinement'):
|
||||
self.confinement = data['confinement']
|
||||
|
||||
def get_command(self) -> str:
|
||||
return "snap run " + self.name
|
||||
|
||||
def can_be_run(self) -> bool:
|
||||
return self.installed and self.is_application()
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import time
|
||||
from typing import List
|
||||
|
||||
from bauh.commons.system import new_root_subprocess, run_cmd, new_subprocess
|
||||
from bauh.gems.snap.model import SnapApplication
|
||||
|
||||
BASE_CMD = 'snap'
|
||||
|
||||
@@ -65,7 +66,7 @@ def get_info(app_name: str, attrs: tuple = None):
|
||||
|
||||
if not attrs or 'commands' in attrs:
|
||||
commands = re.findall(r'commands:\s*\n*((\s+-\s.+\s*\n)+)', full_info_lines)
|
||||
data['commands'] = commands[0][0].replace('-', '').strip().split('\n') if commands else None
|
||||
data['commands'] = commands[0][0].strip().replace('- ', '').split('\n') if commands else None
|
||||
|
||||
return data
|
||||
|
||||
@@ -152,3 +153,11 @@ def downgrade_and_stream(app_name: str, root_password: str) -> subprocess.Popen:
|
||||
|
||||
def refresh_and_stream(app_name: str, root_password: str) -> subprocess.Popen:
|
||||
return new_root_subprocess([BASE_CMD, 'refresh', app_name], root_password)
|
||||
|
||||
|
||||
def run(app: SnapApplication):
|
||||
info = get_info(app.name, 'commands')
|
||||
|
||||
if info.get('commands'):
|
||||
subprocess.Popen([BASE_CMD, 'run', info['commands'][0]])
|
||||
|
||||
|
||||
@@ -231,14 +231,6 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
if man:
|
||||
return man.requires_root(action, app)
|
||||
|
||||
def refresh(self, app: SoftwarePackage, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||
self._wait_to_be_ready()
|
||||
|
||||
man = self._get_manager_for(app)
|
||||
|
||||
if man:
|
||||
return man.refresh(app, root_password, watcher)
|
||||
|
||||
def _prepare(self):
|
||||
if self.managers:
|
||||
for man in self.managers:
|
||||
@@ -317,3 +309,11 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
def is_default_enabled(self) -> bool:
|
||||
return True
|
||||
|
||||
def launch(self, pkg: SoftwarePackage):
|
||||
self._wait_to_be_ready()
|
||||
|
||||
man = self._get_manager_for(pkg)
|
||||
|
||||
if man:
|
||||
man.launch(pkg)
|
||||
|
||||
@@ -373,7 +373,7 @@ class AppsTable(QTableWidget):
|
||||
def _set_col_settings(self, idx: int, col: int, pkg: PackageView):
|
||||
item = QToolBar()
|
||||
|
||||
if pkg.model.can_be_run() and pkg.model.get_command():
|
||||
if pkg.model.can_be_run():
|
||||
|
||||
def run():
|
||||
self.window.run_app(pkg)
|
||||
|
||||
@@ -395,18 +395,19 @@ class ListWarnings(QThread):
|
||||
self.signal_warnings.emit(warnings)
|
||||
|
||||
|
||||
class RunApp(AsyncAction):
|
||||
class LaunchApp(AsyncAction):
|
||||
|
||||
def __init__(self, app: PackageView = None):
|
||||
super(RunApp, self).__init__()
|
||||
def __init__(self, manager: SoftwareManager, app: PackageView = None):
|
||||
super(LaunchApp, self).__init__()
|
||||
self.app = app
|
||||
self.manager = manager
|
||||
|
||||
def run(self):
|
||||
|
||||
if self.app:
|
||||
try:
|
||||
time.sleep(0.25)
|
||||
subprocess.Popen(self.app.model.get_command().split(' '))
|
||||
self.manager.launch(self.app.model)
|
||||
self.notify_finished(True)
|
||||
except:
|
||||
self.notify_finished(False)
|
||||
|
||||
@@ -27,7 +27,7 @@ from bauh.view.qt.root import is_root, ask_root_password
|
||||
from bauh.view.qt.styles import StylesComboBox
|
||||
from bauh.view.qt.thread import UpdateSelectedApps, RefreshApps, UninstallApp, DowngradeApp, GetAppInfo, \
|
||||
GetAppHistory, SearchPackages, InstallApp, AnimateProgress, VerifyModels, FindSuggestions, ListWarnings, \
|
||||
AsyncAction, RunApp, ApplyFilters, CustomAction
|
||||
AsyncAction, LaunchApp, ApplyFilters, CustomAction
|
||||
from bauh.view.qt.view_model import PackageView
|
||||
from bauh.view.qt.view_utils import load_icon
|
||||
|
||||
@@ -207,7 +207,7 @@ class ManageWindow(QWidget):
|
||||
self.thread_search = self._bind_async_action(SearchPackages(self.manager), finished_call=self._finish_search, only_finished=True)
|
||||
self.thread_downgrade = self._bind_async_action(DowngradeApp(self.manager, self.i18n), finished_call=self._finish_downgrade)
|
||||
self.thread_suggestions = self._bind_async_action(FindSuggestions(man=self.manager), finished_call=self._finish_search, only_finished=True)
|
||||
self.thread_run_app = self._bind_async_action(RunApp(), finished_call=self._finish_run_app, only_finished=False)
|
||||
self.thread_run_app = self._bind_async_action(LaunchApp(self.manager), finished_call=self._finish_run_app, only_finished=False)
|
||||
self.thread_custom_action = self._bind_async_action(CustomAction(manager=self.manager), finished_call=self._finish_custom_action)
|
||||
|
||||
self.thread_apply_filters = ApplyFilters()
|
||||
|
||||
Reference in New Issue
Block a user