mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
basic installation options
This commit is contained in:
@@ -38,7 +38,7 @@ class InputOption:
|
|||||||
if not label:
|
if not label:
|
||||||
raise Exception("'label' must be a not blank string")
|
raise Exception("'label' must be a not blank string")
|
||||||
|
|
||||||
if not value:
|
if value is None:
|
||||||
raise Exception("'value' must be a not blank string")
|
raise Exception("'value' must be a not blank string")
|
||||||
|
|
||||||
self.label = label
|
self.label = label
|
||||||
@@ -66,6 +66,10 @@ class SingleSelectComponent(InputViewComponent):
|
|||||||
self.value = default_option
|
self.value = default_option
|
||||||
self.max_per_line = max_per_line
|
self.max_per_line = max_per_line
|
||||||
|
|
||||||
|
def get_selected_value(self):
|
||||||
|
if self.value:
|
||||||
|
return self.value.value
|
||||||
|
|
||||||
|
|
||||||
class MultipleSelectComponent(InputViewComponent):
|
class MultipleSelectComponent(InputViewComponent):
|
||||||
|
|
||||||
@@ -80,6 +84,13 @@ class MultipleSelectComponent(InputViewComponent):
|
|||||||
self.values = default_options if default_options else set()
|
self.values = default_options if default_options else set()
|
||||||
self.max_per_line = max_per_line
|
self.max_per_line = max_per_line
|
||||||
|
|
||||||
|
def get_selected_values(self) -> list:
|
||||||
|
selected = []
|
||||||
|
if self.values:
|
||||||
|
selected.extend([op.value for op in self.values])
|
||||||
|
|
||||||
|
return selected
|
||||||
|
|
||||||
|
|
||||||
class TextComponent(ViewComponent):
|
class TextComponent(ViewComponent):
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,15 @@ import subprocess
|
|||||||
import traceback
|
import traceback
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from typing import List, Type, Set
|
from typing import List, Type, Set, Tuple
|
||||||
|
|
||||||
from bauh.api.abstract.context import ApplicationContext
|
from bauh.api.abstract.context import ApplicationContext
|
||||||
from bauh.api.abstract.controller import SoftwareManager, SearchResult
|
from bauh.api.abstract.controller import SoftwareManager, SearchResult
|
||||||
from bauh.api.abstract.disk import DiskCacheLoader
|
from bauh.api.abstract.disk import DiskCacheLoader
|
||||||
from bauh.api.abstract.handler import ProcessWatcher
|
from bauh.api.abstract.handler import ProcessWatcher
|
||||||
from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory
|
from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory
|
||||||
from bauh.api.abstract.view import MessageType
|
from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \
|
||||||
|
SelectViewType
|
||||||
from bauh.commons.html import bold
|
from bauh.commons.html import bold
|
||||||
from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str
|
from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str
|
||||||
from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN
|
from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN
|
||||||
@@ -159,16 +160,54 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
def get_history(self, pkg: SoftwarePackage) -> PackageHistory:
|
def get_history(self, pkg: SoftwarePackage) -> PackageHistory:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def install(self, pkg: WebApplication, root_password: str, watcher: ProcessWatcher) -> bool:
|
def _ask_install_options(self, watcher: ProcessWatcher) -> Tuple[bool, List[str]]:
|
||||||
|
|
||||||
watcher.change_substatus(self.i18n['web.install.substatus.options'])
|
watcher.change_substatus(self.i18n['web.install.substatus.options'])
|
||||||
|
|
||||||
bt_continue = self.i18n['continue'].capitalize()
|
bt_continue = self.i18n['continue'].capitalize()
|
||||||
if not watcher.request_confirmation(title=self.i18n['web.install.options_dialog.title'],
|
|
||||||
body=self.i18n['web.install.options_dialog.body'].format(bold(bt_continue)),
|
option_single_instance = InputOption(label="Single", value="--single-instance", tooltip="It will not allow the application to be opened again if it is already opened")
|
||||||
components=[],
|
option_maximized = InputOption(label="Open maximized", value="--maximize", tooltip="If the installed app should always open maximized")
|
||||||
confirmation_label=bt_continue,
|
option_fullscren = InputOption(label="Fullscreen", value="--full-screen",
|
||||||
deny_label=self.i18n['cancel'].capitalize()):
|
tooltip="If the installed app should always open in fullscreen mode")
|
||||||
|
option_no_frame = InputOption(label="No frame", value="--hide-window-frame", tooltip="If the installed app should not have a frame around it like browsers have")
|
||||||
|
|
||||||
|
tray_option_off = InputOption(label="Off", value=0, tooltip="Tray mode disabled")
|
||||||
|
tray_option_default = InputOption(label="Default", value='--tray', tooltip="The app icon will be attached to the system tray")
|
||||||
|
tray_option_min = InputOption(label="Start minimzed", value='--tray=start-in-tray', tooltip="The app will start minized as an icon in the system tray")
|
||||||
|
input_tray = SingleSelectComponent(type_=SelectViewType.COMBO, options=[tray_option_off, tray_option_default, tray_option_min], label="Tray mode")
|
||||||
|
check_options = MultipleSelectComponent(options=[option_single_instance, option_maximized, option_fullscren, option_no_frame],
|
||||||
|
default_options={option_single_instance}, label='')
|
||||||
|
|
||||||
|
# input_internal_urls = TextInput()
|
||||||
|
components = [
|
||||||
|
check_options,
|
||||||
|
input_tray
|
||||||
|
]
|
||||||
|
res = watcher.request_confirmation(title=self.i18n['web.install.options_dialog.title'],
|
||||||
|
body=self.i18n['web.install.options_dialog.body'].format(bold(bt_continue)),
|
||||||
|
components=components,
|
||||||
|
confirmation_label=bt_continue,
|
||||||
|
deny_label=self.i18n['cancel'].capitalize())
|
||||||
|
|
||||||
|
if res:
|
||||||
|
selected = []
|
||||||
|
|
||||||
|
if check_options.values:
|
||||||
|
selected.extend(check_options.get_selected_values())
|
||||||
|
|
||||||
|
if input_tray.value != 0:
|
||||||
|
selected.append(input_tray.get_selected_value())
|
||||||
|
|
||||||
|
return res, selected
|
||||||
|
|
||||||
|
return False, []
|
||||||
|
|
||||||
|
def install(self, pkg: WebApplication, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||||
|
|
||||||
|
continue_install, install_options = self._ask_install_options(watcher)
|
||||||
|
|
||||||
|
if not continue_install:
|
||||||
|
watcher.print("Installation aborted by the user")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.env_updater and self.env_updater.is_alive():
|
if self.env_updater and self.env_updater.is_alive():
|
||||||
@@ -196,9 +235,11 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
app_dir = '{}/{}'.format(INSTALLED_PATH, app_name_id)
|
app_dir = '{}/{}'.format(INSTALLED_PATH, app_name_id)
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
watcher.change_substatus(self.i18n['web.install.substatus.call_nativefier'].format(bold('Nativefier')))
|
watcher.change_substatus(self.i18n['web.install.substatus.call_nativefier'].format(bold('nativefier')))
|
||||||
installed = handler.handle_simple(nativefier.install(url=pkg.url, name=pkg_name, output_dir=app_dir,
|
installed = handler.handle_simple(nativefier.install(url=pkg.url, name=pkg_name, output_dir=app_dir,
|
||||||
electron_version=self.env_settings['electron']['version'], cwd=INSTALLED_PATH))
|
electron_version=self.env_settings['electron']['version'],
|
||||||
|
cwd=INSTALLED_PATH,
|
||||||
|
extra_options=install_options))
|
||||||
|
|
||||||
if not installed:
|
if not installed:
|
||||||
msg = '{}.{}.'.format(self.i18n['wen.install.error'].format(bold(pkg.name)),
|
msg = '{}.{}.'.format(self.i18n['wen.install.error'].format(bold(pkg.name)),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
from bauh.api.abstract.model import SoftwarePackage
|
from bauh.api.abstract.model import SoftwarePackage
|
||||||
from bauh.api.constants import CACHE_PATH
|
|
||||||
from bauh.commons import resource
|
from bauh.commons import resource
|
||||||
from bauh.gems.web import ROOT_DIR
|
from bauh.gems.web import ROOT_DIR
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
from bauh.commons.system import SimpleProcess
|
from bauh.commons.system import SimpleProcess
|
||||||
from bauh.gems.web import NATIVEFIER_BIN_PATH
|
from bauh.gems.web import NATIVEFIER_BIN_PATH
|
||||||
|
|
||||||
|
|
||||||
def install(url: str, name: str, output_dir: str, electron_version: str, cwd: str) -> SimpleProcess:
|
def install(url: str, name: str, output_dir: str, electron_version: str, cwd: str, extra_options: List[str] = None) -> SimpleProcess:
|
||||||
return SimpleProcess([NATIVEFIER_BIN_PATH, url, '--name', name, '-e', electron_version, output_dir], cwd=cwd)
|
cmd = [NATIVEFIER_BIN_PATH, url, '--name', name, '-e', electron_version, output_dir]
|
||||||
|
|
||||||
|
if extra_options:
|
||||||
|
cmd.extend(extra_options)
|
||||||
|
|
||||||
|
return SimpleProcess(cmd, cwd=cwd)
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ class ComboBoxQt(QComboBox):
|
|||||||
for idx, op in enumerate(self.model.options):
|
for idx, op in enumerate(self.model.options):
|
||||||
self.addItem(op.label, op.value)
|
self.addItem(op.label, op.value)
|
||||||
|
|
||||||
|
if op.tooltip:
|
||||||
|
self.setItemData(idx, op.tooltip, Qt.ToolTipRole)
|
||||||
|
|
||||||
if model.value and model.value == op: # default
|
if model.value and model.value == op: # default
|
||||||
self.setCurrentIndex(idx)
|
self.setCurrentIndex(idx)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user