mirror of
https://github.com/bottlesdevs/Bottles.git
synced 2026-10-28 23:14:14 +08:00
* refactor: migrate config from dict to object * fix: type hint import * fix: BottleConfig.load() * fix: config loading in BackupManager.import_backup() * fix: Remove unused import * fix: more guard code, type hints and Config object usage * fix: a potential crash when SteamManager.get_app_config() failed * Revert "fix: Remove unused import" This reverts commit2d48a4e08a. * add: new config field * fix: Config object value read * misc: remove review TODO comments * adapt to new BottleConfig object * fix RunAsync usage * add: BottleConfig._fix() * fix: type hint and Config object usage * fix: typo in FSR setting default value * adapt to new BottleConfig object * remove unnecessary DictCompat method * add: BottleConfig._filter() * fix: TemplateManager.new() * misc: critical guard code * fix: typo in commitb7ed61e678* misc: more type hinting * Revert "remove unnecessary DictCompat method" This reverts commit265633e733. * fix crash when user choose Cancel in ProtonAlertDialog * fix force stop all programs not work * adapt NVAPIComponent.check_bottle_nvngx to Config object * Better DictCompatMixIn * InstallerManager.__set_parameters incorrect adopt * fix typo incbe1dc760b* adopt LibraryManager.download_thumbnail to Config object * serialize Config object to yaml automatically * fix translation and remove workaround in0830fddbc9* fix missing locale for Chinese * comment * fix incorrect variable init position * remove 'in' extensions and some bugfix * fix executable filemode Co-authored-by: Mirko Brombin <send@mirko.pm>
79 lines
2.2 KiB
Python
79 lines
2.2 KiB
Python
import os
|
|
from typing import Union
|
|
|
|
from bottles.backend.logger import Logger
|
|
from bottles.backend.globals import Paths
|
|
from bottles.backend.models.config import BottleConfig
|
|
from bottles.backend.wine.winecommand import WineCommand
|
|
|
|
logging = Logger()
|
|
|
|
|
|
class WineProgram:
|
|
program: str = "unknown"
|
|
command: str = ""
|
|
config: BottleConfig
|
|
colors: str = "default"
|
|
is_internal: bool = False
|
|
internal_path: str = ""
|
|
|
|
def __init__(self, config: BottleConfig, silent=False):
|
|
if not isinstance(config, BottleConfig):
|
|
raise TypeError("config should be BottleConfig type, but it was %s" % type(config))
|
|
self.config = config
|
|
self.silent = silent
|
|
|
|
def get_command(self, args: str = None):
|
|
command = self.command
|
|
|
|
if self.is_internal:
|
|
command = os.path.join(Paths.base, self.internal_path, command)
|
|
|
|
if args is not None:
|
|
command += f" {args}"
|
|
|
|
return command
|
|
|
|
def launch(
|
|
self,
|
|
args: Union[tuple, str] = None,
|
|
terminal: bool = False,
|
|
minimal: bool = True,
|
|
communicate: bool = False,
|
|
environment: dict = None,
|
|
cwd: str = None,
|
|
action_name: str = "launch"
|
|
):
|
|
if environment is None:
|
|
environment = {}
|
|
|
|
if not self.silent:
|
|
logging.info(f"Using {self.program} -- {action_name}")
|
|
|
|
if isinstance(args, tuple):
|
|
wineprogram_args = args[0]
|
|
program_args = args[1]
|
|
else:
|
|
wineprogram_args = args
|
|
program_args = None
|
|
|
|
command = self.get_command(wineprogram_args)
|
|
res = WineCommand(
|
|
self.config,
|
|
command=command,
|
|
terminal=terminal,
|
|
minimal=minimal,
|
|
communicate=communicate,
|
|
colors=self.colors,
|
|
environment=environment,
|
|
cwd=cwd,
|
|
arguments=program_args
|
|
).run()
|
|
return res
|
|
|
|
def launch_terminal(self, args: str = None):
|
|
self.launch(args=args, terminal=True, action_name="launch_terminal")
|
|
|
|
def launch_minimal(self, args: str = None):
|
|
self.launch(args=args, minimal=True, action_name="launch_minimal")
|