codis 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/plugins/store.py
ADDED
|
@@ -0,0 +1,1178 @@
|
|
|
1
|
+
"""Codis - Plugin Store (src/plugins/store.py).
|
|
2
|
+
|
|
3
|
+
Sistema de busca e instalação de plugins a partir de um repositório GitHub.
|
|
4
|
+
|
|
5
|
+
Estrutura esperada do repositório de plugins (KillovSky/Plugins):
|
|
6
|
+
-----------------------------------------------------------------------------
|
|
7
|
+
Plugins/
|
|
8
|
+
+-- Codis/ <- pasta do projeto (PROJECT_PREFIX)
|
|
9
|
+
| +-- index.json <- indice gerado pelo workflow de CI
|
|
10
|
+
| +-- KillovSky-word-counter-1.0.0/
|
|
11
|
+
| | +-- plugin.py <- entry-point obrigatorio
|
|
12
|
+
| | +-- manifest.json <- metadados do plugin
|
|
13
|
+
| | `-- README.md <- documentacao
|
|
14
|
+
| `-- autor-nome-versao.py <- plugin arquivo unico
|
|
15
|
+
`-- Iris/ <- outro projeto (ignorado pelo Codis)
|
|
16
|
+
`-- index.json
|
|
17
|
+
|
|
18
|
+
Convenção anti-colisão de nomes:
|
|
19
|
+
<autor>-<nome>-<versao>[/] -> id = "<autor>-<nome>"
|
|
20
|
+
Exemplo: KillovSky-word-counter-1.0.0/ -> id="KillovSky-word-counter" v="1.0.0"
|
|
21
|
+
|
|
22
|
+
INDEX_SCHEMA (index.json):
|
|
23
|
+
-----------------------------------------------------------------------------
|
|
24
|
+
{
|
|
25
|
+
"version": 2,
|
|
26
|
+
"project": "Codis",
|
|
27
|
+
"generated": "2025-01-01T00:00:00Z",
|
|
28
|
+
"plugins": [
|
|
29
|
+
{
|
|
30
|
+
"id": "KillovSky-word-counter", // obrigatório
|
|
31
|
+
"name": "Word Counter", // obrigatório
|
|
32
|
+
"description": "Descrição curta.",
|
|
33
|
+
"version": "1.0.0",
|
|
34
|
+
"author": "KillovSky",
|
|
35
|
+
"category": "editor",
|
|
36
|
+
"tags": ["words", "counter"],
|
|
37
|
+
"codis_compat": ">=1.0.0",
|
|
38
|
+
"path": "KillovSky-word-counter-1.0.0", // relativo a Codis/
|
|
39
|
+
"entry": "plugin.py",
|
|
40
|
+
"stars": 0,
|
|
41
|
+
"updated": "2025-01-01",
|
|
42
|
+
"homepage": "https://github.com/KillovSky/Plugins",
|
|
43
|
+
"readme_url": "", // URL raw do README.md (preenchido pelo workflow)
|
|
44
|
+
"download_url": "" // vazio = usa GitHub API (auto-detectado)
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Categorias válidas: editor, git, ui, language, ai, tools, themes, other
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
from __future__ import annotations
|
|
53
|
+
|
|
54
|
+
import contextlib
|
|
55
|
+
import hashlib
|
|
56
|
+
import io
|
|
57
|
+
import json
|
|
58
|
+
import logging
|
|
59
|
+
import tempfile
|
|
60
|
+
import threading
|
|
61
|
+
import time
|
|
62
|
+
import tkinter as tk
|
|
63
|
+
import urllib.error
|
|
64
|
+
import urllib.parse
|
|
65
|
+
import urllib.request
|
|
66
|
+
import webbrowser
|
|
67
|
+
import zipfile
|
|
68
|
+
from collections.abc import Callable
|
|
69
|
+
from dataclasses import dataclass, field
|
|
70
|
+
from pathlib import Path
|
|
71
|
+
from tkinter import messagebox, ttk
|
|
72
|
+
from typing import Any
|
|
73
|
+
|
|
74
|
+
from src.constants import FONT_MONO, FONT_UI
|
|
75
|
+
from src.i18n import _t
|
|
76
|
+
from src.ui.thread_safe_tk import after_alive
|
|
77
|
+
|
|
78
|
+
logger = logging.getLogger("Codis.PluginStore")
|
|
79
|
+
|
|
80
|
+
DEFAULT_REPO = "KillovSky/Plugins"
|
|
81
|
+
INDEX_FILE = "index.json"
|
|
82
|
+
PROJECT_PREFIX = "Codis"
|
|
83
|
+
PAGES_BASE = "https://{owner}.github.io/{reponame}"
|
|
84
|
+
RAW_BASE = "https://raw.githubusercontent.com/{repo}/{branch}"
|
|
85
|
+
API_BASE = "https://api.github.com/repos/{repo}"
|
|
86
|
+
_REQUEST_TIMEOUT = 12
|
|
87
|
+
_MAX_DOWNLOAD_BYTES = 50 * 1024 * 1024
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _require_web_url(url: str, allow_http: bool = False) -> None:
|
|
91
|
+
"""Recusa esquemas que não sejam HTTPS (ou HTTP, se permitido) antes de abrir a URL.
|
|
92
|
+
|
|
93
|
+
Os índices de plugins são dados de terceiros; sem esta checagem uma
|
|
94
|
+
entrada com ``file://`` faria ``urlopen`` ler arquivos locais.
|
|
95
|
+
"""
|
|
96
|
+
scheme = urllib.parse.urlparse(url).scheme.lower()
|
|
97
|
+
allowed = ("https", "http") if allow_http else ("https",)
|
|
98
|
+
if scheme not in allowed:
|
|
99
|
+
raise ValueError(f"Esquema de URL não permitido: {scheme!r}")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _read_limited(resp: Any, limit: int = _MAX_DOWNLOAD_BYTES) -> bytes:
|
|
103
|
+
"""Lê a resposta até ``limit`` bytes, falhando se o conteúdo for maior."""
|
|
104
|
+
data = resp.read(limit + 1)
|
|
105
|
+
if len(data) > limit:
|
|
106
|
+
raise ValueError("Download excede o tamanho máximo permitido.")
|
|
107
|
+
return data
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
CATEGORIES = [
|
|
111
|
+
("all", "plugin.store_cat_all"),
|
|
112
|
+
("editor", "plugin.store_cat_editor"),
|
|
113
|
+
("git", "plugin.store_cat_git"),
|
|
114
|
+
("ui", "plugin.store_cat_ui"),
|
|
115
|
+
("language", "plugin.store_cat_language"),
|
|
116
|
+
("ai", "plugin.store_cat_ai"),
|
|
117
|
+
("tools", "plugin.store_cat_tools"),
|
|
118
|
+
("themes", "plugin.store_cat_themes"),
|
|
119
|
+
("other", "plugin.store_cat_other"),
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@dataclass
|
|
124
|
+
class PluginEntry:
|
|
125
|
+
"""Metadados de um plugin do repositório."""
|
|
126
|
+
|
|
127
|
+
id: str
|
|
128
|
+
name: str
|
|
129
|
+
description: str
|
|
130
|
+
version: str = "0.0.0"
|
|
131
|
+
author: str = ""
|
|
132
|
+
category: str = "other"
|
|
133
|
+
tags: list[str] = field(default_factory=list)
|
|
134
|
+
codis_compat: str = ">=1.0.0"
|
|
135
|
+
path: str = ""
|
|
136
|
+
entry: str = "plugin.py"
|
|
137
|
+
stars: int = 0
|
|
138
|
+
updated: str = ""
|
|
139
|
+
homepage: str = ""
|
|
140
|
+
download_url: str = ""
|
|
141
|
+
sha256: str = "" # opcional; confere o arquivo baixado por download_url
|
|
142
|
+
readme_url: str = ""
|
|
143
|
+
license: str = ""
|
|
144
|
+
permissions: list[str] = field(default_factory=list)
|
|
145
|
+
|
|
146
|
+
@classmethod
|
|
147
|
+
def from_dict(cls, data: dict[str, Any]) -> PluginEntry:
|
|
148
|
+
"""Constrói um PluginEntry a partir de um dict do index.json."""
|
|
149
|
+
return cls(
|
|
150
|
+
id=data.get("id", ""),
|
|
151
|
+
name=data.get("name", data.get("id", "?")),
|
|
152
|
+
description=data.get("description", ""),
|
|
153
|
+
version=data.get("version", "0.0.0"),
|
|
154
|
+
author=data.get("author", ""),
|
|
155
|
+
category=data.get("category", "other"),
|
|
156
|
+
tags=data.get("tags", []),
|
|
157
|
+
codis_compat=data.get("codis_compat", ">=1.0.0"),
|
|
158
|
+
path=data.get("path", ""),
|
|
159
|
+
entry=data.get("entry", "plugin.py"),
|
|
160
|
+
stars=int(data.get("stars", 0)),
|
|
161
|
+
updated=data.get("updated", ""),
|
|
162
|
+
homepage=data.get("homepage", ""),
|
|
163
|
+
download_url=data.get("download_url", ""),
|
|
164
|
+
sha256=str(data.get("sha256", "")).lower(),
|
|
165
|
+
readme_url=data.get("readme_url", ""),
|
|
166
|
+
license=data.get("license", ""),
|
|
167
|
+
permissions=data.get("permissions", []),
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class PluginStoreClient:
|
|
172
|
+
"""
|
|
173
|
+
Cliente de busca e download de plugins a partir de um repositório GitHub.
|
|
174
|
+
|
|
175
|
+
Responsabilidades:
|
|
176
|
+
- Baixar e cachear o index.json do repositório
|
|
177
|
+
- Filtrar, ordenar e buscar plugins
|
|
178
|
+
- Baixar um plugin específico como ZIP
|
|
179
|
+
- Entregar o ZIP ao PluginLoader para instalação
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
def __init__(
|
|
183
|
+
self,
|
|
184
|
+
repo: str = DEFAULT_REPO,
|
|
185
|
+
branch: str = "main",
|
|
186
|
+
cfg: Any = None,
|
|
187
|
+
) -> None:
|
|
188
|
+
"""Inicializa o cliente com o repositório e branch alvo.
|
|
189
|
+
|
|
190
|
+
Args:
|
|
191
|
+
repo: Repositório no formato `owner/repo`.
|
|
192
|
+
branch: Branch do qual ler os arquivos. Padrão: main.
|
|
193
|
+
cfg: ConfigManager para persistir repositório customizado.
|
|
194
|
+
"""
|
|
195
|
+
self._repo = repo
|
|
196
|
+
self._branch = branch
|
|
197
|
+
self._cfg = cfg
|
|
198
|
+
self._cache: list[PluginEntry] = []
|
|
199
|
+
self._last_fetch: float = 0
|
|
200
|
+
self._cache_ttl: float = 300.0
|
|
201
|
+
self._custom_url: str = ""
|
|
202
|
+
self._local_path: str = ""
|
|
203
|
+
|
|
204
|
+
if cfg:
|
|
205
|
+
saved_repo = cfg.get("plugin_store_repo", "")
|
|
206
|
+
saved_branch = cfg.get("plugin_store_branch", "main")
|
|
207
|
+
if saved_repo:
|
|
208
|
+
self._repo = saved_repo
|
|
209
|
+
if saved_branch:
|
|
210
|
+
self._branch = saved_branch
|
|
211
|
+
|
|
212
|
+
def _pages_url(self) -> str:
|
|
213
|
+
"""URL do index.json no GitHub Pages para o projeto Codis.
|
|
214
|
+
|
|
215
|
+
Estrutura: https://<owner>.github.io/<repo>/Codis/index.json
|
|
216
|
+
"""
|
|
217
|
+
owner, reponame = (self._repo + "/x").split("/")[:2]
|
|
218
|
+
base = PAGES_BASE.format(owner=owner.lower(), reponame=reponame)
|
|
219
|
+
return f"{base}/{PROJECT_PREFIX}/{INDEX_FILE}"
|
|
220
|
+
|
|
221
|
+
def _raw_url(self) -> str:
|
|
222
|
+
"""URL de fallback via raw.githubusercontent.
|
|
223
|
+
|
|
224
|
+
Estrutura: https://raw.githubusercontent.com/<repo>/<branch>/Codis/index.json
|
|
225
|
+
"""
|
|
226
|
+
return f"{RAW_BASE.format(repo=self._repo, branch=self._branch)}/{PROJECT_PREFIX}/{INDEX_FILE}"
|
|
227
|
+
|
|
228
|
+
def search(
|
|
229
|
+
self,
|
|
230
|
+
query: str = "",
|
|
231
|
+
category: str = "all",
|
|
232
|
+
sort: str = "name",
|
|
233
|
+
filter_: str = "all",
|
|
234
|
+
installed_ids: set[str] | None = None,
|
|
235
|
+
) -> list[PluginEntry]:
|
|
236
|
+
"""Filtra e ordena a lista de plugins em cache."""
|
|
237
|
+
plugins = list(self._cache)
|
|
238
|
+
|
|
239
|
+
if category and category != "all":
|
|
240
|
+
plugins = [p for p in plugins if p.category == category]
|
|
241
|
+
|
|
242
|
+
if filter_ == "installed" and installed_ids is not None:
|
|
243
|
+
plugins = [p for p in plugins if p.id in installed_ids]
|
|
244
|
+
elif filter_ == "available" and installed_ids is not None:
|
|
245
|
+
plugins = [p for p in plugins if p.id not in installed_ids]
|
|
246
|
+
|
|
247
|
+
if query:
|
|
248
|
+
q = query.lower()
|
|
249
|
+
plugins = [
|
|
250
|
+
p
|
|
251
|
+
for p in plugins
|
|
252
|
+
if q in p.name.lower()
|
|
253
|
+
or q in p.description.lower()
|
|
254
|
+
or q in p.author.lower()
|
|
255
|
+
or any(q in t.lower() for t in p.tags)
|
|
256
|
+
]
|
|
257
|
+
|
|
258
|
+
key_fn: dict[str, Any] = {
|
|
259
|
+
"name": lambda p: p.name.lower(),
|
|
260
|
+
"stars": lambda p: -p.stars,
|
|
261
|
+
"updated": lambda p: p.updated or "",
|
|
262
|
+
}
|
|
263
|
+
plugins.sort(key=key_fn.get(sort, lambda p: p.name.lower()))
|
|
264
|
+
return plugins
|
|
265
|
+
|
|
266
|
+
def fetch_readme(self, entry: PluginEntry) -> str:
|
|
267
|
+
"""Baixa o README.md do plugin via readme_url (Pages) ou raw."""
|
|
268
|
+
if entry.readme_url:
|
|
269
|
+
try:
|
|
270
|
+
_require_web_url(entry.readme_url)
|
|
271
|
+
req = urllib.request.Request(
|
|
272
|
+
entry.readme_url,
|
|
273
|
+
headers={"User-Agent": "Codis-PluginStore/1.0"},
|
|
274
|
+
)
|
|
275
|
+
with urllib.request.urlopen(req, timeout=_REQUEST_TIMEOUT) as resp:
|
|
276
|
+
return _read_limited(resp, 2_000_000).decode("utf-8", errors="replace")
|
|
277
|
+
except Exception:
|
|
278
|
+
logger.debug("fetch_readme: erro ignorado", exc_info=True)
|
|
279
|
+
if not entry.path:
|
|
280
|
+
return ""
|
|
281
|
+
base = f"{RAW_BASE.format(repo=self._repo, branch=self._branch)}/{PROJECT_PREFIX}/{entry.path}"
|
|
282
|
+
for fname in ("README.md", "readme.md", "README.txt"):
|
|
283
|
+
try:
|
|
284
|
+
url = f"{base}/{fname}"
|
|
285
|
+
req = urllib.request.Request(
|
|
286
|
+
url, headers={"User-Agent": "Codis-PluginStore/1.0"}
|
|
287
|
+
)
|
|
288
|
+
with urllib.request.urlopen(req, timeout=_REQUEST_TIMEOUT) as resp:
|
|
289
|
+
return _read_limited(resp, 2_000_000).decode("utf-8", errors="replace")
|
|
290
|
+
except (OSError, ValueError):
|
|
291
|
+
continue
|
|
292
|
+
return ""
|
|
293
|
+
|
|
294
|
+
def download_plugin(self, entry: PluginEntry) -> bytes:
|
|
295
|
+
"""Baixa o plugin como bytes (ZIP).
|
|
296
|
+
|
|
297
|
+
Estratégia:
|
|
298
|
+
1. Usa download_url do manifesto se disponível
|
|
299
|
+
2. Plugin arquivo único: baixa o .py via raw e empacota como ZIP
|
|
300
|
+
3. Plugin em pasta: baixa archive completo do GitHub e extrai a subpasta
|
|
301
|
+
Caminho no archive: <PROJECT_PREFIX>/<entry.path>/
|
|
302
|
+
"""
|
|
303
|
+
if entry.download_url:
|
|
304
|
+
data = self._get_bytes(entry.download_url)
|
|
305
|
+
if entry.sha256 and hashlib.sha256(data).hexdigest() != entry.sha256:
|
|
306
|
+
raise ValueError(f"O arquivo baixado de '{entry.id}' não confere com o hash do índice.")
|
|
307
|
+
return data
|
|
308
|
+
|
|
309
|
+
raw_base = (
|
|
310
|
+
f"{RAW_BASE.format(repo=self._repo, branch=self._branch)}/{PROJECT_PREFIX}"
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
if entry.path.endswith(".py"):
|
|
314
|
+
raw_url = f"{raw_base}/{entry.path}"
|
|
315
|
+
try:
|
|
316
|
+
py_bytes = self._get_bytes(raw_url)
|
|
317
|
+
zip_bytes = self._wrap_in_zip(entry.id, entry.entry, py_bytes)
|
|
318
|
+
return zip_bytes
|
|
319
|
+
except Exception:
|
|
320
|
+
logger.debug(
|
|
321
|
+
"download_plugin: erro ignorado (arquivo único fallback)", exc_info=True)
|
|
322
|
+
|
|
323
|
+
archive_url = (
|
|
324
|
+
f"https://api.github.com/repos/{self._repo}/zipball/{self._branch}"
|
|
325
|
+
)
|
|
326
|
+
all_bytes = self._get_bytes(archive_url)
|
|
327
|
+
return self._extract_plugin_folder(all_bytes, entry, PROJECT_PREFIX)
|
|
328
|
+
|
|
329
|
+
def _get_json(self, url: str) -> Any:
|
|
330
|
+
"""Baixa e desserializa JSON de `url` com User-Agent do Codis."""
|
|
331
|
+
_require_web_url(url, allow_http=True)
|
|
332
|
+
req = urllib.request.Request(
|
|
333
|
+
url, headers={"User-Agent": "Codis-PluginStore/1.0"}
|
|
334
|
+
)
|
|
335
|
+
with urllib.request.urlopen(req, timeout=_REQUEST_TIMEOUT) as resp:
|
|
336
|
+
return json.loads(_read_limited(resp).decode("utf-8"))
|
|
337
|
+
|
|
338
|
+
def _get_bytes(self, url: str) -> bytes:
|
|
339
|
+
"""Baixa o conteúdo binário de `url` (somente HTTPS) com timeout de 60 segundos."""
|
|
340
|
+
_require_web_url(url)
|
|
341
|
+
req = urllib.request.Request(
|
|
342
|
+
url,
|
|
343
|
+
headers={
|
|
344
|
+
"User-Agent": "Codis-PluginStore/1.0",
|
|
345
|
+
"Accept": "application/vnd.github+json",
|
|
346
|
+
},
|
|
347
|
+
)
|
|
348
|
+
with urllib.request.urlopen(req, timeout=60) as resp:
|
|
349
|
+
return _read_limited(resp)
|
|
350
|
+
|
|
351
|
+
@staticmethod
|
|
352
|
+
def _wrap_in_zip(plugin_id: str, filename: str, content: bytes) -> bytes:
|
|
353
|
+
"""Cria um ZIP em memória contendo `filename` com `content`, compatível com PluginLoader."""
|
|
354
|
+
buf = io.BytesIO()
|
|
355
|
+
with zipfile.ZipFile(buf, "w", compression=zipfile.ZIP_DEFLATED) as zf:
|
|
356
|
+
zf.writestr(filename, content)
|
|
357
|
+
return buf.getvalue()
|
|
358
|
+
|
|
359
|
+
@staticmethod
|
|
360
|
+
def _extract_plugin_folder(
|
|
361
|
+
archive_bytes: bytes,
|
|
362
|
+
entry: PluginEntry,
|
|
363
|
+
project_prefix: str = "",
|
|
364
|
+
) -> bytes:
|
|
365
|
+
"""Extrai a subpasta do plugin de um archive ZIP completo do repositório.
|
|
366
|
+
|
|
367
|
+
Considera a estrutura `<project_prefix>/<entry.path>` dentro do arquivo.
|
|
368
|
+
Retorna um novo ZIP contendo apenas os arquivos dessa subpasta.
|
|
369
|
+
"""
|
|
370
|
+
base_path = (
|
|
371
|
+
f"{project_prefix}/{entry.path}".strip("/")
|
|
372
|
+
if project_prefix
|
|
373
|
+
else entry.path.lstrip("/")
|
|
374
|
+
)
|
|
375
|
+
search_path = base_path
|
|
376
|
+
buf_out = io.BytesIO()
|
|
377
|
+
with zipfile.ZipFile(io.BytesIO(archive_bytes)) as zf_in:
|
|
378
|
+
names = zf_in.namelist()
|
|
379
|
+
root_prefix = names[0].split("/")[0] + "/" if names else ""
|
|
380
|
+
target = root_prefix + search_path + "/"
|
|
381
|
+
|
|
382
|
+
matched = [n for n in names if n.startswith(
|
|
383
|
+
target) and not n.endswith("/")]
|
|
384
|
+
if not matched:
|
|
385
|
+
fallback = root_prefix + \
|
|
386
|
+
search_path.rstrip("/") + "/" + entry.entry
|
|
387
|
+
if fallback in names:
|
|
388
|
+
matched = [fallback]
|
|
389
|
+
|
|
390
|
+
if not matched:
|
|
391
|
+
raise FileNotFoundError(
|
|
392
|
+
f"Plugin '{entry.id}' não encontrado no archive do repositório."
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
with zipfile.ZipFile(
|
|
396
|
+
buf_out, "w", compression=zipfile.ZIP_DEFLATED
|
|
397
|
+
) as zf_out:
|
|
398
|
+
for name in matched:
|
|
399
|
+
rel = name[len(target):]
|
|
400
|
+
if rel:
|
|
401
|
+
zf_out.writestr(rel, zf_in.read(name))
|
|
402
|
+
|
|
403
|
+
return buf_out.getvalue()
|
|
404
|
+
|
|
405
|
+
def set_repo(self, repo: str, branch: str = "main") -> None:
|
|
406
|
+
"""Troca o repositório e limpa o cache.
|
|
407
|
+
|
|
408
|
+
Aceita:
|
|
409
|
+
- Formato GitHub curto: ``owner/repo``
|
|
410
|
+
- URL completa GitHub: ``https://github.com/owner/repo``
|
|
411
|
+
- URL direta de JSON: ``https://example.com/my-index.json``
|
|
412
|
+
- Caminho local de JSON: ``/path/to/index.json`` ou ``C:\\path\\index.json``
|
|
413
|
+
"""
|
|
414
|
+
repo = repo.strip()
|
|
415
|
+
self._branch = branch.strip() or "main"
|
|
416
|
+
self._cache = []
|
|
417
|
+
self._last_fetch = 0
|
|
418
|
+
self._custom_url: str = ""
|
|
419
|
+
self._local_path: str = ""
|
|
420
|
+
|
|
421
|
+
if repo.startswith("https://github.com/"):
|
|
422
|
+
self._repo = repo.removeprefix("https://github.com/").strip("/")
|
|
423
|
+
elif repo.startswith(("http://", "https://")):
|
|
424
|
+
self._custom_url = repo.rstrip("/")
|
|
425
|
+
self._repo = self._custom_url
|
|
426
|
+
elif repo.endswith(".json") and ("/" in repo or "\\" in repo):
|
|
427
|
+
# caminho local: a barra inicial de um caminho absoluto precisa ser preservada
|
|
428
|
+
path = Path(repo)
|
|
429
|
+
if path.is_absolute() or path.exists():
|
|
430
|
+
self._local_path = str(path.resolve())
|
|
431
|
+
self._repo = repo
|
|
432
|
+
else:
|
|
433
|
+
self._repo = repo.strip("/")
|
|
434
|
+
|
|
435
|
+
if self._cfg:
|
|
436
|
+
self._cfg.set("plugin_store_repo", self._repo)
|
|
437
|
+
self._cfg.set("plugin_store_branch", self._branch)
|
|
438
|
+
self._cfg.save()
|
|
439
|
+
|
|
440
|
+
def fetch_index(self, force: bool = False) -> list[PluginEntry]:
|
|
441
|
+
"""Baixa o índice do repositório.
|
|
442
|
+
|
|
443
|
+
Fontes suportadas (em ordem de prioridade):
|
|
444
|
+
1. Arquivo JSON local (se set_repo recebeu um caminho local)
|
|
445
|
+
2. URL HTTP/HTTPS arbitrária (se set_repo recebeu uma URL não-GitHub)
|
|
446
|
+
3. GitHub Pages (sem rate limit) - padrão
|
|
447
|
+
4. raw.githubusercontent.com - fallback do GitHub
|
|
448
|
+
"""
|
|
449
|
+
now = time.time()
|
|
450
|
+
if not force and self._cache and (now - self._last_fetch) < self._cache_ttl:
|
|
451
|
+
return self._cache
|
|
452
|
+
|
|
453
|
+
data: Any = None
|
|
454
|
+
local_path = getattr(self, "_local_path", "")
|
|
455
|
+
custom_url = getattr(self, "_custom_url", "")
|
|
456
|
+
|
|
457
|
+
if local_path:
|
|
458
|
+
try:
|
|
459
|
+
data = json.loads(Path(local_path).read_text(encoding="utf-8"))
|
|
460
|
+
logger.info(
|
|
461
|
+
"Plugin store: índice carregado de arquivo local: %s", local_path
|
|
462
|
+
)
|
|
463
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
464
|
+
raise RuntimeError(f"Arquivo local inválido: {exc}") from exc
|
|
465
|
+
elif custom_url:
|
|
466
|
+
try:
|
|
467
|
+
data = self._get_json(custom_url)
|
|
468
|
+
logger.info(
|
|
469
|
+
"Plugin store: índice carregado de URL customizada: %s", custom_url
|
|
470
|
+
)
|
|
471
|
+
except Exception as exc:
|
|
472
|
+
raise RuntimeError(
|
|
473
|
+
f"Falha ao baixar de URL customizada: {exc}"
|
|
474
|
+
) from exc
|
|
475
|
+
else:
|
|
476
|
+
last_err: Exception | None = None
|
|
477
|
+
for url in (self._pages_url(), self._raw_url()):
|
|
478
|
+
try:
|
|
479
|
+
data = self._get_json(url)
|
|
480
|
+
break
|
|
481
|
+
except Exception as exc:
|
|
482
|
+
last_err = exc
|
|
483
|
+
logger.debug("fetch_index fallback: %s - %s", url, exc)
|
|
484
|
+
else:
|
|
485
|
+
raise last_err # type: ignore[misc]
|
|
486
|
+
|
|
487
|
+
try:
|
|
488
|
+
if not isinstance(data, dict) or "plugins" not in data:
|
|
489
|
+
raise ValueError(
|
|
490
|
+
"Formato de índice inválido: esperado objeto JSON com chave 'plugins'"
|
|
491
|
+
)
|
|
492
|
+
self._cache = [
|
|
493
|
+
PluginEntry.from_dict(p) for p in data["plugins"] if p.get("id")
|
|
494
|
+
]
|
|
495
|
+
self._last_fetch = now
|
|
496
|
+
logger.info("Plugin store: %d plugins carregados",
|
|
497
|
+
len(self._cache))
|
|
498
|
+
except urllib.error.HTTPError as exc:
|
|
499
|
+
if exc.code == 403:
|
|
500
|
+
raise RuntimeError("rate_limit") from exc
|
|
501
|
+
if exc.code == 404:
|
|
502
|
+
raise RuntimeError(
|
|
503
|
+
f"index.json não encontrado em {self._repo}"
|
|
504
|
+
) from exc
|
|
505
|
+
raise RuntimeError(str(exc)) from exc
|
|
506
|
+
except urllib.error.URLError as exc:
|
|
507
|
+
raise RuntimeError("network") from exc
|
|
508
|
+
except ValueError:
|
|
509
|
+
raise
|
|
510
|
+
except Exception as exc:
|
|
511
|
+
raise RuntimeError(str(exc)) from exc
|
|
512
|
+
|
|
513
|
+
return self._cache
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
class PluginStorePanel(tk.Toplevel):
|
|
517
|
+
"""
|
|
518
|
+
Janela da loja de plugins do Codis.
|
|
519
|
+
|
|
520
|
+
Exibe uma lista de plugins disponíveis no repositório remoto,
|
|
521
|
+
com busca, filtros por categoria, ordenação e instalação com um clique.
|
|
522
|
+
"""
|
|
523
|
+
|
|
524
|
+
_SORT_KEYS = ("name", "stars", "updated")
|
|
525
|
+
|
|
526
|
+
def __init__(
|
|
527
|
+
self,
|
|
528
|
+
parent: tk.Widget,
|
|
529
|
+
tmgr: Any,
|
|
530
|
+
cfg: Any,
|
|
531
|
+
loader: Any,
|
|
532
|
+
on_refresh: Callable[[], None] | None = None,
|
|
533
|
+
) -> None:
|
|
534
|
+
"""Cria e exibe a janela da Plugin Store.
|
|
535
|
+
|
|
536
|
+
Args:
|
|
537
|
+
loader: PluginLoader usado para instalar e listar plugins.
|
|
538
|
+
on_refresh: Callback chamado após instalação bem-sucedida.
|
|
539
|
+
"""
|
|
540
|
+
super().__init__(parent)
|
|
541
|
+
t = tmgr.theme
|
|
542
|
+
self._tmgr = tmgr
|
|
543
|
+
self._cfg = cfg
|
|
544
|
+
self._loader = loader
|
|
545
|
+
self._on_refresh = on_refresh
|
|
546
|
+
self._client = PluginStoreClient(cfg=cfg)
|
|
547
|
+
self._entries: list[PluginEntry] = []
|
|
548
|
+
self._selected: PluginEntry | None = None
|
|
549
|
+
self._installing = False
|
|
550
|
+
|
|
551
|
+
self.title(_t("plugin.store_title"))
|
|
552
|
+
self.configure(bg=t.panel_bg)
|
|
553
|
+
self.geometry("860x620")
|
|
554
|
+
self.minsize(700, 480)
|
|
555
|
+
self.transient(parent)
|
|
556
|
+
self.focus_set()
|
|
557
|
+
|
|
558
|
+
self._build()
|
|
559
|
+
self._load_store(force=False)
|
|
560
|
+
|
|
561
|
+
def _build(self) -> None:
|
|
562
|
+
"""Constrói toda a UI da janela: barra de topo, filtros, lista, painel de detalhe e status."""
|
|
563
|
+
t = self._tmgr.theme
|
|
564
|
+
|
|
565
|
+
top_bar = tk.Frame(self, bg=t.panel_bg, padx=12, pady=8)
|
|
566
|
+
top_bar.pack(fill="x")
|
|
567
|
+
|
|
568
|
+
tk.Label(
|
|
569
|
+
top_bar,
|
|
570
|
+
text=_t("plugin.store_title"),
|
|
571
|
+
bg=t.panel_bg,
|
|
572
|
+
fg=t.fg,
|
|
573
|
+
font=(FONT_UI, 13, "bold"),
|
|
574
|
+
).pack(side="left")
|
|
575
|
+
|
|
576
|
+
repo_row = tk.Frame(top_bar, bg=t.panel_bg)
|
|
577
|
+
repo_row.pack(side="right")
|
|
578
|
+
tk.Label(
|
|
579
|
+
repo_row,
|
|
580
|
+
text=_t("plugin.store_repo_label"),
|
|
581
|
+
bg=t.panel_bg,
|
|
582
|
+
fg=t.fg_muted,
|
|
583
|
+
font=(FONT_UI, 8),
|
|
584
|
+
).pack(side="left", padx=(0, 4))
|
|
585
|
+
self._repo_var = tk.StringVar(value=self._client._repo)
|
|
586
|
+
repo_entry = tk.Entry(
|
|
587
|
+
repo_row,
|
|
588
|
+
textvariable=self._repo_var,
|
|
589
|
+
bg=t.input_bg,
|
|
590
|
+
fg=t.fg,
|
|
591
|
+
font=(FONT_MONO, 8),
|
|
592
|
+
relief="flat",
|
|
593
|
+
highlightthickness=1,
|
|
594
|
+
highlightbackground=t.border,
|
|
595
|
+
insertbackground=t.cursor,
|
|
596
|
+
width=26,
|
|
597
|
+
)
|
|
598
|
+
repo_entry.pack(side="left")
|
|
599
|
+
repo_entry.bind("<Return>", lambda _: self._apply_repo())
|
|
600
|
+
tk.Label(
|
|
601
|
+
repo_row,
|
|
602
|
+
text=_t("plugin.store_repo_hint_extended"),
|
|
603
|
+
bg=t.panel_bg,
|
|
604
|
+
fg=t.fg_muted,
|
|
605
|
+
font=(FONT_UI, 7),
|
|
606
|
+
).pack(side="left", padx=4)
|
|
607
|
+
tk.Button(
|
|
608
|
+
repo_row,
|
|
609
|
+
text=_t("plugin.store_browse_json"),
|
|
610
|
+
command=self._browse_local_json,
|
|
611
|
+
bg=t.btn_bg,
|
|
612
|
+
fg=t.fg,
|
|
613
|
+
relief="flat",
|
|
614
|
+
font=(FONT_UI, 8),
|
|
615
|
+
cursor="hand2",
|
|
616
|
+
padx=6,
|
|
617
|
+
).pack(side="left", padx=(0, 2))
|
|
618
|
+
tk.Button(
|
|
619
|
+
repo_row,
|
|
620
|
+
text=_t("plugin.store_repo_apply"),
|
|
621
|
+
command=self._apply_repo,
|
|
622
|
+
bg=t.btn_bg,
|
|
623
|
+
fg=t.fg,
|
|
624
|
+
relief="flat",
|
|
625
|
+
font=(FONT_UI, 8),
|
|
626
|
+
cursor="hand2",
|
|
627
|
+
padx=6,
|
|
628
|
+
).pack(side="left")
|
|
629
|
+
|
|
630
|
+
tk.Frame(self, bg=t.border, height=1).pack(fill="x")
|
|
631
|
+
|
|
632
|
+
filter_bar = tk.Frame(self, bg=t.panel_bg, padx=8, pady=6)
|
|
633
|
+
filter_bar.pack(fill="x")
|
|
634
|
+
|
|
635
|
+
search_frame = tk.Frame(
|
|
636
|
+
filter_bar,
|
|
637
|
+
bg=t.input_bg,
|
|
638
|
+
highlightthickness=1,
|
|
639
|
+
highlightbackground=t.border,
|
|
640
|
+
)
|
|
641
|
+
search_frame.pack(side="left", fill="x", expand=True, padx=(0, 8))
|
|
642
|
+
tk.Label(
|
|
643
|
+
search_frame, text="🔍", bg=t.input_bg, fg=t.fg_muted, font=(FONT_UI, 9)
|
|
644
|
+
).pack(side="left", padx=4)
|
|
645
|
+
self._search_var = tk.StringVar()
|
|
646
|
+
self._search_var.trace_add("write", lambda *_: self._refilter())
|
|
647
|
+
tk.Entry(
|
|
648
|
+
search_frame,
|
|
649
|
+
textvariable=self._search_var,
|
|
650
|
+
bg=t.input_bg,
|
|
651
|
+
fg=t.fg,
|
|
652
|
+
relief="flat",
|
|
653
|
+
bd=0,
|
|
654
|
+
font=(FONT_UI, 9),
|
|
655
|
+
insertbackground=t.cursor,
|
|
656
|
+
highlightthickness=0,
|
|
657
|
+
).pack(side="left", fill="x", expand=True, pady=4)
|
|
658
|
+
|
|
659
|
+
tk.Label(
|
|
660
|
+
filter_bar,
|
|
661
|
+
text=_t("plugin.store_category"),
|
|
662
|
+
bg=t.panel_bg,
|
|
663
|
+
fg=t.fg_muted,
|
|
664
|
+
font=(FONT_UI, 8),
|
|
665
|
+
).pack(side="left")
|
|
666
|
+
self._cat_var = tk.StringVar(value="all")
|
|
667
|
+
cat_values = [_t(lk, default=cat) for cat, lk in CATEGORIES]
|
|
668
|
+
self._cat_combo = ttk.Combobox(
|
|
669
|
+
filter_bar,
|
|
670
|
+
textvariable=self._cat_var,
|
|
671
|
+
values=cat_values,
|
|
672
|
+
state="readonly",
|
|
673
|
+
width=14,
|
|
674
|
+
font=(FONT_UI, 8),
|
|
675
|
+
)
|
|
676
|
+
self._cat_combo.pack(side="left", padx=4)
|
|
677
|
+
self._cat_combo.bind("<<ComboboxSelected>>",
|
|
678
|
+
lambda _: self._refilter())
|
|
679
|
+
|
|
680
|
+
tk.Label(
|
|
681
|
+
filter_bar,
|
|
682
|
+
text=_t("plugin.store_sort"),
|
|
683
|
+
bg=t.panel_bg,
|
|
684
|
+
fg=t.fg_muted,
|
|
685
|
+
font=(FONT_UI, 8),
|
|
686
|
+
).pack(side="left")
|
|
687
|
+
self._sort_var = tk.StringVar(value=_t("plugin.store_sort_name"))
|
|
688
|
+
sort_opts = [
|
|
689
|
+
_t("plugin.store_sort_name"),
|
|
690
|
+
_t("plugin.store_sort_stars"),
|
|
691
|
+
_t("plugin.store_sort_updated"),
|
|
692
|
+
]
|
|
693
|
+
self._sort_combo = ttk.Combobox(
|
|
694
|
+
filter_bar,
|
|
695
|
+
textvariable=self._sort_var,
|
|
696
|
+
values=sort_opts,
|
|
697
|
+
state="readonly",
|
|
698
|
+
width=16,
|
|
699
|
+
font=(FONT_UI, 8),
|
|
700
|
+
)
|
|
701
|
+
self._sort_combo.pack(side="left", padx=4)
|
|
702
|
+
self._sort_combo.bind("<<ComboboxSelected>>",
|
|
703
|
+
lambda _: self._refilter())
|
|
704
|
+
|
|
705
|
+
self._filter_var = tk.StringVar(value=_t("plugin.store_filter_all"))
|
|
706
|
+
filter_opts = [
|
|
707
|
+
_t("plugin.store_filter_all"),
|
|
708
|
+
_t("plugin.store_filter_inst"),
|
|
709
|
+
_t("plugin.store_filter_avail"),
|
|
710
|
+
]
|
|
711
|
+
self._filter_combo = ttk.Combobox(
|
|
712
|
+
filter_bar,
|
|
713
|
+
textvariable=self._filter_var,
|
|
714
|
+
values=filter_opts,
|
|
715
|
+
state="readonly",
|
|
716
|
+
width=14,
|
|
717
|
+
font=(FONT_UI, 8),
|
|
718
|
+
)
|
|
719
|
+
self._filter_combo.pack(side="left", padx=4)
|
|
720
|
+
self._filter_combo.bind("<<ComboboxSelected>>",
|
|
721
|
+
lambda _: self._refilter())
|
|
722
|
+
|
|
723
|
+
tk.Button(
|
|
724
|
+
filter_bar,
|
|
725
|
+
text=_t("plugin.store_refresh"),
|
|
726
|
+
command=lambda: self._load_store(force=True),
|
|
727
|
+
bg=t.btn_bg,
|
|
728
|
+
fg=t.fg,
|
|
729
|
+
relief="flat",
|
|
730
|
+
font=(FONT_UI, 8),
|
|
731
|
+
cursor="hand2",
|
|
732
|
+
padx=6,
|
|
733
|
+
).pack(side="right")
|
|
734
|
+
|
|
735
|
+
tk.Frame(self, bg=t.border, height=1).pack(fill="x")
|
|
736
|
+
|
|
737
|
+
body = tk.PanedWindow(
|
|
738
|
+
self,
|
|
739
|
+
orient="horizontal",
|
|
740
|
+
bg=t.panel_bg,
|
|
741
|
+
sashwidth=4,
|
|
742
|
+
sashrelief="flat",
|
|
743
|
+
handlepad=0,
|
|
744
|
+
handlesize=0,
|
|
745
|
+
)
|
|
746
|
+
body.pack(fill="both", expand=True, padx=4, pady=4)
|
|
747
|
+
|
|
748
|
+
list_frame = tk.Frame(body, bg=t.editor_bg)
|
|
749
|
+
body.add(list_frame, minsize=280, width=320)
|
|
750
|
+
|
|
751
|
+
scroll_y = ttk.Scrollbar(list_frame, orient="vertical")
|
|
752
|
+
scroll_y.pack(side="right", fill="y")
|
|
753
|
+
|
|
754
|
+
self._listbox = tk.Listbox(
|
|
755
|
+
list_frame,
|
|
756
|
+
bg=t.editor_bg,
|
|
757
|
+
fg=t.fg,
|
|
758
|
+
font=(FONT_UI, 9),
|
|
759
|
+
relief="flat",
|
|
760
|
+
bd=0,
|
|
761
|
+
selectbackground=t.sel_bg,
|
|
762
|
+
selectforeground=t.sel_fg,
|
|
763
|
+
yscrollcommand=scroll_y.set,
|
|
764
|
+
activestyle="none",
|
|
765
|
+
cursor="hand2",
|
|
766
|
+
)
|
|
767
|
+
self._listbox.pack(fill="both", expand=True)
|
|
768
|
+
scroll_y.config(command=self._listbox.yview)
|
|
769
|
+
self._listbox.bind("<<ListboxSelect>>", self._on_select)
|
|
770
|
+
self._listbox.bind("<Double-Button-1>",
|
|
771
|
+
lambda _: self._install_selected())
|
|
772
|
+
|
|
773
|
+
detail_outer = tk.Frame(body, bg=t.panel_bg)
|
|
774
|
+
body.add(detail_outer, minsize=320)
|
|
775
|
+
|
|
776
|
+
detail_header = tk.Frame(detail_outer, bg=t.panel_bg, padx=12, pady=8)
|
|
777
|
+
detail_header.pack(fill="x")
|
|
778
|
+
self._name_lbl = tk.Label(
|
|
779
|
+
detail_header,
|
|
780
|
+
text="",
|
|
781
|
+
bg=t.panel_bg,
|
|
782
|
+
fg=t.fg,
|
|
783
|
+
font=(FONT_UI, 13, "bold"),
|
|
784
|
+
anchor="w",
|
|
785
|
+
wraplength=340,
|
|
786
|
+
)
|
|
787
|
+
self._name_lbl.pack(side="left", fill="x", expand=True)
|
|
788
|
+
|
|
789
|
+
self._install_btn = tk.Button(
|
|
790
|
+
detail_header,
|
|
791
|
+
text=_t("plugin.store_install"),
|
|
792
|
+
command=self._install_selected,
|
|
793
|
+
bg=getattr(t, "accent", "#4fc3f7"),
|
|
794
|
+
fg="#ffffff",
|
|
795
|
+
relief="flat",
|
|
796
|
+
font=(FONT_UI, 9, "bold"),
|
|
797
|
+
cursor="hand2",
|
|
798
|
+
padx=10,
|
|
799
|
+
pady=4,
|
|
800
|
+
state="disabled",
|
|
801
|
+
)
|
|
802
|
+
self._install_btn.pack(side="right")
|
|
803
|
+
|
|
804
|
+
self._gh_btn = tk.Button(
|
|
805
|
+
detail_header,
|
|
806
|
+
text=_t("plugin.store_open_gh"),
|
|
807
|
+
command=self._open_github,
|
|
808
|
+
bg=t.btn_bg,
|
|
809
|
+
fg=t.fg,
|
|
810
|
+
relief="flat",
|
|
811
|
+
font=(FONT_UI, 8),
|
|
812
|
+
cursor="hand2",
|
|
813
|
+
padx=6,
|
|
814
|
+
pady=4,
|
|
815
|
+
)
|
|
816
|
+
self._gh_btn.pack(side="right", padx=4)
|
|
817
|
+
|
|
818
|
+
meta_frame = tk.Frame(detail_outer, bg=t.panel_bg, padx=12)
|
|
819
|
+
meta_frame.pack(fill="x")
|
|
820
|
+
self._meta_lbl = tk.Label(
|
|
821
|
+
meta_frame,
|
|
822
|
+
text="",
|
|
823
|
+
bg=t.panel_bg,
|
|
824
|
+
fg=t.fg_muted,
|
|
825
|
+
font=(FONT_UI, 8),
|
|
826
|
+
anchor="w",
|
|
827
|
+
justify="left",
|
|
828
|
+
wraplength=380,
|
|
829
|
+
)
|
|
830
|
+
self._meta_lbl.pack(anchor="w")
|
|
831
|
+
|
|
832
|
+
self._tags_frame = tk.Frame(detail_outer, bg=t.panel_bg, padx=12)
|
|
833
|
+
self._tags_frame.pack(fill="x", pady=(2, 6))
|
|
834
|
+
|
|
835
|
+
tk.Frame(detail_outer, bg=t.border, height=1).pack(fill="x", padx=8)
|
|
836
|
+
|
|
837
|
+
readme_nb = ttk.Notebook(detail_outer)
|
|
838
|
+
readme_nb.pack(fill="both", expand=True, padx=4, pady=4)
|
|
839
|
+
|
|
840
|
+
readme_frame = tk.Frame(readme_nb, bg=t.editor_bg)
|
|
841
|
+
readme_nb.add(readme_frame, text=_t("plugin.store_readme"))
|
|
842
|
+
|
|
843
|
+
readme_scroll = ttk.Scrollbar(readme_frame, orient="vertical")
|
|
844
|
+
readme_scroll.pack(side="right", fill="y")
|
|
845
|
+
|
|
846
|
+
self._readme_txt = tk.Text(
|
|
847
|
+
readme_frame,
|
|
848
|
+
bg=t.editor_bg,
|
|
849
|
+
fg=t.fg,
|
|
850
|
+
font=(FONT_MONO, 8),
|
|
851
|
+
relief="flat",
|
|
852
|
+
bd=0,
|
|
853
|
+
wrap="word",
|
|
854
|
+
state="disabled",
|
|
855
|
+
highlightthickness=0,
|
|
856
|
+
padx=10,
|
|
857
|
+
pady=8,
|
|
858
|
+
yscrollcommand=readme_scroll.set,
|
|
859
|
+
)
|
|
860
|
+
self._readme_txt.pack(fill="both", expand=True)
|
|
861
|
+
readme_scroll.config(command=self._readme_txt.yview)
|
|
862
|
+
|
|
863
|
+
status_bar = tk.Frame(self, bg=t.panel_bg, height=24)
|
|
864
|
+
status_bar.pack(fill="x", side="bottom")
|
|
865
|
+
status_bar.pack_propagate(False)
|
|
866
|
+
self._status_lbl = tk.Label(
|
|
867
|
+
status_bar,
|
|
868
|
+
text="",
|
|
869
|
+
bg=t.panel_bg,
|
|
870
|
+
fg=t.fg_muted,
|
|
871
|
+
font=(FONT_UI, 8),
|
|
872
|
+
anchor="w",
|
|
873
|
+
)
|
|
874
|
+
self._status_lbl.pack(side="left", padx=8)
|
|
875
|
+
|
|
876
|
+
tk.Button(
|
|
877
|
+
self,
|
|
878
|
+
text=_t("plugin.store_close"),
|
|
879
|
+
command=self.destroy,
|
|
880
|
+
bg=t.btn_bg,
|
|
881
|
+
fg=t.fg,
|
|
882
|
+
relief="flat",
|
|
883
|
+
font=(FONT_UI, 8),
|
|
884
|
+
cursor="hand2",
|
|
885
|
+
padx=8,
|
|
886
|
+
pady=2,
|
|
887
|
+
).pack(side="bottom", anchor="e", padx=8, pady=4)
|
|
888
|
+
|
|
889
|
+
self._show_no_selection()
|
|
890
|
+
|
|
891
|
+
def _load_store(self, force: bool = False) -> None:
|
|
892
|
+
"""Dispara fetch do índice em thread separada e atualiza a lista ao concluir."""
|
|
893
|
+
self._set_status(_t("plugin.store_loading"))
|
|
894
|
+
self._listbox.delete(0, "end")
|
|
895
|
+
self._listbox.insert("end", " " + _t("plugin.store_loading"))
|
|
896
|
+
|
|
897
|
+
def _fetch():
|
|
898
|
+
try:
|
|
899
|
+
entries = self._client.fetch_index(force=force)
|
|
900
|
+
after_alive(self, self._on_loaded, entries)
|
|
901
|
+
except RuntimeError as exc:
|
|
902
|
+
msg = str(exc)
|
|
903
|
+
if msg == "rate_limit":
|
|
904
|
+
after_alive(self, self._on_error, _t("plugin.store_rate_limit"))
|
|
905
|
+
elif msg == "network":
|
|
906
|
+
after_alive(self, self._on_error, _t("plugin.store_net_err"))
|
|
907
|
+
else:
|
|
908
|
+
after_alive(
|
|
909
|
+
self, self._on_error, _t("plugin.store_error", err=msg)
|
|
910
|
+
)
|
|
911
|
+
|
|
912
|
+
threading.Thread(target=_fetch, daemon=True).start()
|
|
913
|
+
|
|
914
|
+
def _on_loaded(self, entries: list[PluginEntry]) -> None:
|
|
915
|
+
"""Callback de sucesso do fetch: armazena entradas e reaplica filtros."""
|
|
916
|
+
self._entries = entries
|
|
917
|
+
self._refilter()
|
|
918
|
+
self._set_status(f"{len(entries)} plugins")
|
|
919
|
+
|
|
920
|
+
def _on_error(self, msg: str) -> None:
|
|
921
|
+
"""Exibe mensagem de erro na lista e no status bar."""
|
|
922
|
+
self._listbox.delete(0, "end")
|
|
923
|
+
self._listbox.insert("end", " " + msg)
|
|
924
|
+
self._set_status(msg)
|
|
925
|
+
|
|
926
|
+
def _refilter(self) -> None:
|
|
927
|
+
"""Lê os controles de filtro/busca/ordenação e repopula a listbox."""
|
|
928
|
+
query = self._search_var.get()
|
|
929
|
+
cat_idx = self._cat_combo.current()
|
|
930
|
+
cat_key = CATEGORIES[cat_idx][0] if 0 <= cat_idx < len(
|
|
931
|
+
CATEGORIES) else "all"
|
|
932
|
+
sort_idx = self._sort_combo.current()
|
|
933
|
+
sort_key = (
|
|
934
|
+
self._SORT_KEYS[sort_idx]
|
|
935
|
+
if 0 <= sort_idx < len(self._SORT_KEYS)
|
|
936
|
+
else "name"
|
|
937
|
+
)
|
|
938
|
+
filt_idx = self._filter_combo.current()
|
|
939
|
+
filt_map = {0: "all", 1: "installed", 2: "available"}
|
|
940
|
+
filt_key = filt_map.get(filt_idx, "all")
|
|
941
|
+
|
|
942
|
+
installed = set(self._loader.all_plugin_ids()
|
|
943
|
+
) if self._loader else set()
|
|
944
|
+
filtered = self._client.search(
|
|
945
|
+
query, cat_key, sort_key, filt_key, installed)
|
|
946
|
+
|
|
947
|
+
self._listbox.delete(0, "end")
|
|
948
|
+
if not filtered:
|
|
949
|
+
self._listbox.insert("end", " " + _t("plugin.store_empty"))
|
|
950
|
+
return
|
|
951
|
+
for entry in filtered:
|
|
952
|
+
is_inst = entry.id in installed
|
|
953
|
+
icon = "✅" if is_inst else " "
|
|
954
|
+
stars = f" ★{entry.stars}" if entry.stars else ""
|
|
955
|
+
text = f"{icon} {entry.name}{stars}"
|
|
956
|
+
self._listbox.insert("end", f" {text}")
|
|
957
|
+
|
|
958
|
+
def _on_select(self, _: Any) -> None:
|
|
959
|
+
"""Exibe o detalhe do plugin selecionado na listbox."""
|
|
960
|
+
sel = self._listbox.curselection()
|
|
961
|
+
if not sel:
|
|
962
|
+
return
|
|
963
|
+
idx = sel[0]
|
|
964
|
+
q = self._search_var.get()
|
|
965
|
+
cat_idx = self._cat_combo.current()
|
|
966
|
+
cat_key = CATEGORIES[cat_idx][0] if 0 <= cat_idx < len(
|
|
967
|
+
CATEGORIES) else "all"
|
|
968
|
+
s_idx = self._sort_combo.current()
|
|
969
|
+
s_key = self._SORT_KEYS[s_idx] if 0 <= s_idx < len(
|
|
970
|
+
self._SORT_KEYS) else "name"
|
|
971
|
+
f_idx = self._filter_combo.current()
|
|
972
|
+
f_map = {0: "all", 1: "installed", 2: "available"}
|
|
973
|
+
f_key = f_map.get(f_idx, "all")
|
|
974
|
+
installed = set(self._loader.all_plugin_ids()
|
|
975
|
+
) if self._loader else set()
|
|
976
|
+
filtered = self._client.search(q, cat_key, s_key, f_key, installed)
|
|
977
|
+
|
|
978
|
+
if idx >= len(filtered):
|
|
979
|
+
return
|
|
980
|
+
entry = filtered[idx]
|
|
981
|
+
self._selected = entry
|
|
982
|
+
self._show_detail(entry, installed)
|
|
983
|
+
|
|
984
|
+
def _show_no_selection(self) -> None:
|
|
985
|
+
"""Reseta o painel de detalhe para o estado sem seleção."""
|
|
986
|
+
self._name_lbl.config(text="")
|
|
987
|
+
self._meta_lbl.config(text=_t("plugin.store_detail_none"))
|
|
988
|
+
self._install_btn.config(
|
|
989
|
+
state="disabled", text=_t("plugin.store_install"))
|
|
990
|
+
self._gh_btn.config(state="disabled")
|
|
991
|
+
self._set_readme(_t("plugin.store_detail_none"))
|
|
992
|
+
for w in self._tags_frame.winfo_children():
|
|
993
|
+
w.destroy()
|
|
994
|
+
|
|
995
|
+
def _show_detail(self, entry: PluginEntry, installed: set[str]) -> None:
|
|
996
|
+
"""Popula o painel de detalhe com os metadados de `entry` e dispara fetch do README."""
|
|
997
|
+
t = self._tmgr.theme
|
|
998
|
+
is_inst = entry.id in installed
|
|
999
|
+
|
|
1000
|
+
self._name_lbl.config(text=entry.name)
|
|
1001
|
+
|
|
1002
|
+
meta_parts = [entry.description]
|
|
1003
|
+
if entry.version:
|
|
1004
|
+
meta_parts.append(_t("plugin.store_detail_ver", ver=entry.version))
|
|
1005
|
+
if entry.author:
|
|
1006
|
+
meta_parts.append(
|
|
1007
|
+
_t("plugin.store_detail_author", author=entry.author))
|
|
1008
|
+
if entry.codis_compat:
|
|
1009
|
+
meta_parts.append(
|
|
1010
|
+
_t("plugin.store_detail_compat", compat=entry.codis_compat)
|
|
1011
|
+
)
|
|
1012
|
+
if entry.stars:
|
|
1013
|
+
meta_parts.append(f"★ {entry.stars}")
|
|
1014
|
+
if entry.updated:
|
|
1015
|
+
meta_parts.append(entry.updated)
|
|
1016
|
+
self._meta_lbl.config(text=" | ".join(meta_parts))
|
|
1017
|
+
|
|
1018
|
+
for w in self._tags_frame.winfo_children():
|
|
1019
|
+
w.destroy()
|
|
1020
|
+
for tag in entry.tags[:8]:
|
|
1021
|
+
tk.Label(
|
|
1022
|
+
self._tags_frame,
|
|
1023
|
+
text=f" {tag} ",
|
|
1024
|
+
bg=getattr(t, "sel_bg", t.input_bg),
|
|
1025
|
+
fg=t.fg_muted,
|
|
1026
|
+
font=(FONT_UI, 7),
|
|
1027
|
+
relief="flat",
|
|
1028
|
+
padx=2,
|
|
1029
|
+
pady=1,
|
|
1030
|
+
).pack(side="left", padx=2)
|
|
1031
|
+
|
|
1032
|
+
self._install_btn.config(
|
|
1033
|
+
text=(
|
|
1034
|
+
_t("plugin.store_installed") if is_inst else _t(
|
|
1035
|
+
"plugin.store_install")
|
|
1036
|
+
),
|
|
1037
|
+
state="normal" if not is_inst and not self._installing else "disabled",
|
|
1038
|
+
bg="#555555" if is_inst else getattr(t, "accent", "#4fc3f7"),
|
|
1039
|
+
)
|
|
1040
|
+
self._gh_btn.config(state="normal" if entry.homepage else "disabled")
|
|
1041
|
+
|
|
1042
|
+
self._set_readme("⟳ " + _t("plugin.store_loading"))
|
|
1043
|
+
threading.Thread(
|
|
1044
|
+
target=self._fetch_readme_async,
|
|
1045
|
+
args=(entry,),
|
|
1046
|
+
daemon=True,
|
|
1047
|
+
).start()
|
|
1048
|
+
|
|
1049
|
+
def _fetch_readme_async(self, entry: PluginEntry) -> None:
|
|
1050
|
+
"""Baixa o README de `entry` em thread separada e atualiza o widget de texto."""
|
|
1051
|
+
try:
|
|
1052
|
+
text = self._client.fetch_readme(entry)
|
|
1053
|
+
except Exception:
|
|
1054
|
+
text = ""
|
|
1055
|
+
display = text or _t("plugin.store_no_readme")
|
|
1056
|
+
after_alive(self, self._set_readme, display)
|
|
1057
|
+
|
|
1058
|
+
def _set_readme(self, text: str) -> None:
|
|
1059
|
+
"""Substitui o conteúdo do widget de README pelo texto fornecido."""
|
|
1060
|
+
self._readme_txt.config(state="normal")
|
|
1061
|
+
self._readme_txt.delete("1.0", "end")
|
|
1062
|
+
self._readme_txt.insert("1.0", text)
|
|
1063
|
+
self._readme_txt.config(state="disabled")
|
|
1064
|
+
|
|
1065
|
+
def _install_selected(self) -> None:
|
|
1066
|
+
"""Inicia o download e instalação do plugin selecionado em thread separada."""
|
|
1067
|
+
if not self._selected or self._installing:
|
|
1068
|
+
return
|
|
1069
|
+
entry = self._selected
|
|
1070
|
+
installed = set(self._loader.all_plugin_ids()
|
|
1071
|
+
) if self._loader else set()
|
|
1072
|
+
if entry.id in installed:
|
|
1073
|
+
return
|
|
1074
|
+
|
|
1075
|
+
self._installing = True
|
|
1076
|
+
self._install_btn.config(
|
|
1077
|
+
state="disabled", text=_t("plugin.store_installing", name=entry.name)
|
|
1078
|
+
)
|
|
1079
|
+
self._set_status(_t("plugin.store_installing", name=entry.name))
|
|
1080
|
+
|
|
1081
|
+
def _fail(message: str, name: str = entry.name) -> None:
|
|
1082
|
+
self._installing = False
|
|
1083
|
+
self._set_status(_t("plugin.store_install_err", name=name, err=message))
|
|
1084
|
+
self._install_btn.config(state="normal", text=_t("plugin.store_install"))
|
|
1085
|
+
|
|
1086
|
+
def _confirm_cb(pid, blocked, warned):
|
|
1087
|
+
lines = [f"O plugin '{pid}' pede atenção antes de ser instalado."]
|
|
1088
|
+
if blocked:
|
|
1089
|
+
lines.append("\nBloqueado pela verificação:\n " + "\n ".join(blocked))
|
|
1090
|
+
if warned:
|
|
1091
|
+
lines.append("\nUsa módulos sensíveis:\n " + "\n ".join(warned))
|
|
1092
|
+
lines.append("\nInstalar mesmo assim?")
|
|
1093
|
+
return messagebox.askyesno("Plugin", "\n".join(lines), parent=self)
|
|
1094
|
+
|
|
1095
|
+
def _install_on_ui(tmp_path: Path) -> None:
|
|
1096
|
+
"""Instala e ativa na thread da interface: o plugin cria widgets ao ativar."""
|
|
1097
|
+
try:
|
|
1098
|
+
ok = self._loader.install_from_path(tmp_path, confirm_cb=_confirm_cb, plugin_id=entry.id)
|
|
1099
|
+
except Exception as exc:
|
|
1100
|
+
_fail(str(exc))
|
|
1101
|
+
return
|
|
1102
|
+
finally:
|
|
1103
|
+
tmp_path.unlink(missing_ok=True)
|
|
1104
|
+
if not ok:
|
|
1105
|
+
reason = self._loader.errors.get(entry.id, "")
|
|
1106
|
+
_fail(reason.strip().splitlines()[-1] if reason else "instalação cancelada ou recusada")
|
|
1107
|
+
return
|
|
1108
|
+
self._installing = False
|
|
1109
|
+
self._set_status(_t("plugin.store_install_ok", name=entry.name))
|
|
1110
|
+
self._refilter()
|
|
1111
|
+
if self._on_refresh:
|
|
1112
|
+
self._on_refresh()
|
|
1113
|
+
if self._selected and self._selected.id == entry.id:
|
|
1114
|
+
self._show_detail(entry, set(self._loader.all_plugin_ids()))
|
|
1115
|
+
|
|
1116
|
+
def _do_install():
|
|
1117
|
+
try:
|
|
1118
|
+
zip_bytes = self._client.download_plugin(entry)
|
|
1119
|
+
with tempfile.NamedTemporaryFile(
|
|
1120
|
+
suffix=".zip", prefix=f"codis_plugin_{entry.id}_", delete=False
|
|
1121
|
+
) as tmp:
|
|
1122
|
+
tmp.write(zip_bytes)
|
|
1123
|
+
tmp_path = Path(tmp.name)
|
|
1124
|
+
except Exception as exc:
|
|
1125
|
+
after_alive(self, lambda e=str(exc): _fail(e))
|
|
1126
|
+
return
|
|
1127
|
+
after_alive(self, lambda p=tmp_path: _install_on_ui(p))
|
|
1128
|
+
|
|
1129
|
+
threading.Thread(target=_do_install, daemon=True).start()
|
|
1130
|
+
|
|
1131
|
+
def _open_github(self) -> None:
|
|
1132
|
+
"""Abre a homepage do plugin selecionado no navegador padrão do sistema."""
|
|
1133
|
+
if self._selected and self._selected.homepage:
|
|
1134
|
+
webbrowser.open(self._selected.homepage)
|
|
1135
|
+
|
|
1136
|
+
def _apply_repo(self) -> None:
|
|
1137
|
+
"""Aplica a fonte de plugins digitada no campo.
|
|
1138
|
+
|
|
1139
|
+
Aceita:
|
|
1140
|
+
- GitHub curto: ``owner/repo``
|
|
1141
|
+
- URL GitHub: ``https://github.com/owner/repo``
|
|
1142
|
+
- URL direta: ``https://example.com/index.json``
|
|
1143
|
+
- Arquivo local: ``/home/user/meus-plugins.json``
|
|
1144
|
+
"""
|
|
1145
|
+
repo = self._repo_var.get().strip()
|
|
1146
|
+
if not repo:
|
|
1147
|
+
return
|
|
1148
|
+
self._client.set_repo(repo)
|
|
1149
|
+
self._load_store(force=True)
|
|
1150
|
+
|
|
1151
|
+
def _browse_local_json(self) -> None:
|
|
1152
|
+
"""Abre diálogo de seleção de arquivo JSON local para usar como índice de plugins."""
|
|
1153
|
+
from tkinter import filedialog
|
|
1154
|
+
|
|
1155
|
+
path = filedialog.askopenfilename(
|
|
1156
|
+
parent=self,
|
|
1157
|
+
title=_t("plugin.store_browse_json"),
|
|
1158
|
+
filetypes=[("JSON", "*.json"), ("Todos", "*.*")],
|
|
1159
|
+
)
|
|
1160
|
+
if path:
|
|
1161
|
+
self._repo_var.set(path)
|
|
1162
|
+
self._apply_repo()
|
|
1163
|
+
|
|
1164
|
+
def _set_status(self, text: str) -> None:
|
|
1165
|
+
"""Atualiza o texto da barra de status, ignorando erros se a janela foi fechada."""
|
|
1166
|
+
with contextlib.suppress(tk.TclError):
|
|
1167
|
+
self._status_lbl.config(text=text)
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
def open_plugin_store(
|
|
1171
|
+
parent: tk.Widget,
|
|
1172
|
+
tmgr: Any,
|
|
1173
|
+
cfg: Any,
|
|
1174
|
+
loader: Any,
|
|
1175
|
+
on_refresh: Callable[[], None] | None = None,
|
|
1176
|
+
) -> PluginStorePanel:
|
|
1177
|
+
"""Abre a janela da Plugin Store e a retorna."""
|
|
1178
|
+
return PluginStorePanel(parent, tmgr, cfg, loader, on_refresh)
|