1
0

feat: upgrade to api version 5.0

This commit is contained in:
2026-01-22 12:10:05 +01:00
parent 4f4fe2e8d9
commit e881e5886e

View File

@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from typing import List from typing import Iterable, List
import albert import albert
md_iid = '4.0' md_iid = '5.0'
md_name = "HTTP Status Codes" md_name = "HTTP Status Codes"
md_description = "Show the list of HTTP Status Codes" md_description = "Show the list of HTTP Status Codes"
md_version = "0.0.1" md_version = "0.0.1"
@@ -84,33 +84,27 @@ codes = [
Code(599, "Network Connect Timeout Error", "Network connection timeout error."), Code(599, "Network Connect Timeout Error", "Network connection timeout error."),
] ]
def build_query_items(query): def build_query_items(query: str) -> Iterable[albert.StandardItem]:
results = []
for code in codes: for code in codes:
if code.is_match(query.string): if not query or code.is_match(query):
results.append(
# https://albertlauncher.github.io/reference/classalbert_1_1util_1_1StandardItem.html # https://albertlauncher.github.io/reference/classalbert_1_1util_1_1StandardItem.html
albert.StandardItem( yield albert.StandardItem(
id=str(code.code), id=str(code.code),
text=f"{code.code} {code.name}", text=f"{code.code} {code.name}",
icon_factory=lambda: albert.Icon.grapheme(""),
subtext=code.description, subtext=code.description,
actions=[] actions=[]
) )
)
return results
class Plugin(albert.PluginInstance, albert.TriggerQueryHandler): class Plugin(albert.PluginInstance, albert.GeneratorQueryHandler):
def __init__(self): def __init__(self):
albert.PluginInstance.__init__(self) albert.PluginInstance.__init__(self)
albert.TriggerQueryHandler.__init__(self) albert.GeneratorQueryHandler.__init__(self)
def defaultTrigger(self): def defaultTrigger(self):
return 'http ' return 'http '
# https://albertlauncher.github.io/reference/classalbert_1_1Query.html # https://albertlauncher.github.io/reference/classalbert_1_1Query.html
def handleTriggerQuery(self, query): def items(self, ctx):
if not query.isValid: yield [i for i in build_query_items(ctx.query.strip())]
return
query.add(build_query_items(query))