From e881e5886ebc95cc6adcb9323284431f8200431c Mon Sep 17 00:00:00 2001 From: Felix Boers Date: Thu, 22 Jan 2026 12:10:05 +0100 Subject: [PATCH] feat: upgrade to api version 5.0 --- __init__.py | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/__init__.py b/__init__.py index 37d7912..7bd8ae9 100644 --- a/__init__.py +++ b/__init__.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -from typing import List +from typing import Iterable, List import albert -md_iid = '4.0' +md_iid = '5.0' md_name = "HTTP Status Codes" md_description = "Show the list of HTTP Status Codes" md_version = "0.0.1" @@ -84,33 +84,27 @@ codes = [ Code(599, "Network Connect Timeout Error", "Network connection timeout error."), ] -def build_query_items(query): - results = [] +def build_query_items(query: str) -> Iterable[albert.StandardItem]: for code in codes: - if code.is_match(query.string): - results.append( - # https://albertlauncher.github.io/reference/classalbert_1_1util_1_1StandardItem.html - albert.StandardItem( - id=str(code.code), - text=f"{code.code} {code.name}", - subtext=code.description, - actions=[] - ) + if not query or code.is_match(query): + # https://albertlauncher.github.io/reference/classalbert_1_1util_1_1StandardItem.html + yield albert.StandardItem( + id=str(code.code), + text=f"{code.code} {code.name}", + icon_factory=lambda: albert.Icon.grapheme("‣"), + subtext=code.description, + actions=[] ) - return results -class Plugin(albert.PluginInstance, albert.TriggerQueryHandler): +class Plugin(albert.PluginInstance, albert.GeneratorQueryHandler): def __init__(self): albert.PluginInstance.__init__(self) - albert.TriggerQueryHandler.__init__(self) + albert.GeneratorQueryHandler.__init__(self) def defaultTrigger(self): return 'http ' # https://albertlauncher.github.io/reference/classalbert_1_1Query.html - def handleTriggerQuery(self, query): - if not query.isValid: - return - - query.add(build_query_items(query)) \ No newline at end of file + def items(self, ctx): + yield [i for i in build_query_items(ctx.query.strip())] \ No newline at end of file