from ulauncher.utils.AutostartPreference import AutostartPreference from ulauncher.ui.AppIndicator import AppIndicator from ulauncher.search.shortcuts.ShortcutsDb import ShortcutsDb from ulauncher.config import get_data_file, get_options, get_version, EXTENSIONS_DIR logger = logging.getLogger(__name__) rt = Router() class PrefsApiError(UlauncherAPIError): pass ExtError = TypedDict('ExtError', { 'errorName': str, 'message': str }) ExtensionInfo = TypedDict('ExtensionInfo', { 'id': str, 'url': str, 'updated_at': str, 'last_commit': str, 'last_commit_time': str, 'name': str, 'icon': str, 'description': str, 'developer_name': str, 'is_running': bool, 'runtime_error': Optional[ExtRunError], 'preferences': PreferenceItems,
from typing import Any, Dict from ulauncher.utils.mypy_extensions import TypedDict from ulauncher.utils.decorator.singleton import singleton from ulauncher.utils.image_loader import get_app_icon_pixbuf from ulauncher.search.apps.AppResultItem import AppResultItem CachedItem = TypedDict('CachedItem', { 'icon': Any, 'name': str, 'sizes': Dict[int, Any] }) class AppIconCache: _icons = None # type: Dict[str, CachedItem] @classmethod @singleton def get_instance(cls): return cls() def __init__(self): self._icons = {} def add_icon(self, desktop_file: str, icon: Any, name: str): """ :param str desktop_file: :param Gio.Icon icon: :param str name:
from ulauncher.utils.semver import satisfies from ulauncher.utils.mypy_extensions import TypedDict # change add import import gi gi.require_version("Gtk", "3.0") from gi.repository import Gtk # isort:skip # noqa: E261 class ExtensionManifestError(UlauncherAPIError): pass OptionItemExtended = TypedDict('OptionItemExtended', { 'value': str, 'text': str }) OptionItem = Union[str, OptionItemExtended] OptionItems = List[OptionItem] Options = TypedDict('Options', {'query_debounce': float}) ManifestPreferenceItem = TypedDict( 'ManifestPreferenceItem', { 'id': str, 'type': str, 'name': str, 'description': str, 'default_value': str, 'options': OptionItems, # change add icon field
from urllib.error import HTTPError from typing import Dict, List, cast from ulauncher.utils.mypy_extensions import TypedDict from ulauncher.utils.date import iso_to_datetime from ulauncher.api.version import api_version from ulauncher.api.shared.errors import ErrorName, UlauncherAPIError from ulauncher.utils.semver import satisfies, valid_range DEFAULT_GITHUB_BRANCH = 'master' logger = logging.getLogger(__name__) ManifestPreference = TypedDict('ManifestPreference', { 'default_value': str, 'id': str, 'name': str, 'type': str }) ManifestOptions = TypedDict('ManifestOptions', { 'query_debounce': float }) Manifest = TypedDict('Manifest', { 'required_api_version': str, 'description': str, 'developer_name': str, 'icon': str, 'name': str, 'options': ManifestOptions, 'preferences': List[ManifestPreference]
from ulauncher.api.server.ExtensionRunner import ExtensionRunner, ExtensionIsNotRunningError from ulauncher.api.server.extension_finder import find_extensions logger = logging.getLogger(__name__) class ExtensionDownloaderError(UlauncherAPIError): pass class ExtensionIsUpToDateError(Exception): pass LastCommit = TypedDict('LastCommit', { 'last_commit': str, 'last_commit_time': str }) class ExtensionDownloader: @classmethod @singleton def get_instance(cls) -> 'ExtensionDownloader': ext_db = ExtensionDb.get_instance() ext_runner = ExtensionRunner.get_instance() return cls(ext_db, ext_runner) def __init__(self, ext_db: ExtensionDb, ext_runner: ExtensionRunner): super(ExtensionDownloader, self).__init__() self.ext_db = ext_db self.ext_runner = ext_runner
from functools import lru_cache from ulauncher.config import EXT_PREFERENCES_DIR from ulauncher.utils.db.KeyValueJsonDb import KeyValueJsonDb from ulauncher.utils.mypy_extensions import TypedDict from ulauncher.modes.extensions.ExtensionManifest import ExtensionManifest, OptionItems logger = logging.getLogger() ValueType = Union[str, int] # Bool is a subclass of int PreferenceItem = TypedDict( 'PreferenceItem', { 'id': str, 'type': str, 'name': str, 'description': str, 'default_value': ValueType, 'min': Optional[int], 'max': Optional[int], 'options': OptionItems, 'icon': Optional[str], 'user_value': ValueType, 'value': ValueType, }) PreferenceItems = List[PreferenceItem] class ExtensionPreferences: """ Manages extension preferences. Stores them as json files in config directory """ manifest = None # type: ExtensionManifest
from typing import Dict, Optional from time import time, sleep from enum import Enum from ulauncher.config import EXTENSIONS_DIR, ULAUNCHER_APP_DIR, get_options from ulauncher.utils.decorator.run_async import run_async from ulauncher.utils.mypy_extensions import TypedDict from ulauncher.utils.decorator.singleton import singleton from ulauncher.api.server.ExtensionManifest import ExtensionManifest from ulauncher.api.server.ExtensionServer import ExtensionServer from ulauncher.api.server.ProcessErrorExtractor import ProcessErrorExtractor from ulauncher.api.server.extension_finder import find_extensions logger = logging.getLogger(__name__) ExtRunError = TypedDict('ExtRunError', {'name': str, 'message': str}) class ExtRunErrorName(Enum): NoExtensionsFlag = 'NoExtensionsFlag' Terminated = 'Terminated' ExitedInstantly = 'ExitedInstantly' Exited = 'Exited' MissingModule = 'MissingModule' class ExtensionRunner: @classmethod @singleton def get_instance(cls) -> 'ExtensionRunner': return cls(ExtensionServer.get_instance())
import logging from typing import List, Optional, Dict from functools import lru_cache from ulauncher.config import EXT_PREFERENCES_DIR from ulauncher.utils.db.KeyValueDb import KeyValueDb from ulauncher.utils.mypy_extensions import TypedDict from ulauncher.api.server.ExtensionManifest import ExtensionManifest, OptionItems logger = logging.getLogger(__name__) PreferenceItem = TypedDict( 'PreferenceItem', { 'id': str, 'type': str, 'name': str, 'description': str, 'options': OptionItems, 'default_value': str, 'user_value': str, 'value': str, }) PreferenceItems = List[PreferenceItem] class ExtensionPreferences: """ Manages extension preferences. Stores them in pickled file in cache directory """ manifest = None # type: ExtensionManifest
import os from typing import Type from ulauncher.utils.mypy_extensions import TypedDict from ulauncher.config import CONFIG_DIR from ulauncher.utils.db.KeyValueJsonDb import KeyValueJsonDb from ulauncher.utils.decorator.singleton import singleton ExtensionRecord = TypedDict('ExtensionRecord', { 'id': str, 'url': str, 'updated_at': str, 'last_commit': str, 'last_commit_time': str }) class ExtensionDb(KeyValueJsonDb[str, ExtensionRecord]): @classmethod @singleton def get_instance(cls: Type['ExtensionDb']) -> 'ExtensionDb': db_path = os.path.join(CONFIG_DIR, 'extensions.json') db = cls(db_path) db.open() return db
import json from pathlib import Path from typing import Optional, List, Union from ulauncher.config import API_VERSION, EXTENSIONS_DIR from ulauncher.api.shared.errors import UlauncherAPIError, ExtensionError from ulauncher.utils.version import satisfies from ulauncher.utils.mypy_extensions import TypedDict class ExtensionManifestError(UlauncherAPIError): pass OptionItemExtended = TypedDict('OptionItemExtended', { 'value': str, 'text': str }) OptionItem = Union[str, OptionItemExtended] OptionItems = List[OptionItem] Options = TypedDict('Options', { 'query_debounce': float }) ManifestPreference = TypedDict( 'ManifestPreference', { 'id': str, 'type': str, 'name': str, 'description': str, 'default_value': Union[str, int], # Bool is a subclass of int 'options': OptionItems, 'min': Optional[int],