fix: PluginManager — proper await with real Wails imports; no dead code, no safety timer

This commit is contained in:
mirivlad 2026-06-16 15:39:30 +08:00
parent 1d20b833f2
commit d72ebeb7ec
3 changed files with 54 additions and 218 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
frontend/node_modules/ frontend/node_modules/
frontend/dist/ frontend/dist/
build/bin/verstak-desktop

Binary file not shown.

View File

@ -1,6 +1,7 @@
<script> <script>
import PluginCard from './PluginCard.svelte'; import PluginCard from './PluginCard.svelte';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { GetPlugins, GetCapabilities, GetPermissions, ReloadPlugins } from '../../../wailsjs/go/api/App';
let plugins = []; let plugins = [];
let capabilities = []; let capabilities = [];
@ -8,82 +9,36 @@
let loading = true; let loading = true;
let error = ''; let error = '';
// Wails v2 + webkit2gtk-4.1 production bridge workaround: async function loadAll() {
// `await window.go.api.App.Xxx()` deadlocks the JS event loop.
// Use .then() instead — doesn't suspend the microtask queue.
// Safety timer guarantees loading=false even if the bridge Promise never settles.
function call(method, args) {
return new Promise((resolve, reject) => {
try {
if (window.runtime && window.runtime.Call) {
window.runtime.Call(method, JSON.stringify(args || []))
.then(result => resolve(result))
.catch(err => reject(err));
} else {
const parts = method.split('.');
let obj = window.go;
for (const p of parts) obj = obj[p];
resolve(obj.apply(null, args || []));
}
} catch (e) {
reject(e);
}
});
}
function loadPlugins() {
error = ''; error = '';
call('api.App.GetPlugins').then(p => { loading = true;
try {
const p = await GetPlugins();
plugins = p || []; plugins = p || [];
loading = false; } catch (e) {
}).catch(e => {
error = 'GetPlugins: ' + String(e); error = 'GetPlugins: ' + String(e);
loading = false; loading = false;
}); return;
} }
// Capabilities and permissions are non-critical — load async
function loadCaps() { GetCapabilities().then(c => { capabilities = c || []; }).catch(() => {});
call('api.App.GetCapabilities').then(c => { GetPermissions().then(p => { permissions = p || []; }).catch(() => {});
capabilities = c || [];
}).catch(e => {
console.warn('[PluginManager] GetCapabilities:', e);
});
}
function loadPerms() {
call('api.App.GetPermissions').then(p => {
permissions = p || [];
}).catch(e => {
console.warn('[PluginManager] GetPermissions:', e);
});
}
onMount(() => {
loadPlugins();
loadCaps();
loadPerms();
// Safety timeout: force loading=false if APIs never respond
setTimeout(() => {
if (loading) {
loading = false; loading = false;
error = 'Plugin discovery timed out. Check backend logs.';
} }
}, 10000);
});
function reload() { onMount(() => { loadAll(); });
async function reload() {
loading = true; loading = true;
error = ''; error = '';
call('api.App.ReloadPlugins').then(() => { try {
loadPlugins(); await ReloadPlugins();
loadCaps(); } catch (e) {
loadPerms();
}).catch(e => {
error = 'Reload: ' + String(e); error = 'Reload: ' + String(e);
loading = false; loading = false;
}); return;
}
await loadAll();
} }
$: totalPlugins = plugins.length; $: totalPlugins = plugins.length;
@ -105,17 +60,15 @@
<div class="error"> <div class="error">
<div class="error-icon"></div> <div class="error-icon"></div>
<div class="error-message">{error}</div> <div class="error-message">{error}</div>
<button class="retry-btn" on:click={loadPlugins} type="button">⟳ Retry</button> <button class="retry-btn" on:click={loadAll} type="button">⟳ Retry</button>
</div> </div>
{:else} {:else}
<!-- Plugin Count -->
<div class="summary"> <div class="summary">
<span class="badge">{totalPlugins} plugin(s) discovered</span> <span class="badge">{totalPlugins} plugin(s) discovered</span>
<span class="badge">{totalCaps} capabilities registered</span> <span class="badge">{totalCaps} capabilities registered</span>
<span class="badge">{totalPerms} permissions known</span> <span class="badge">{totalPerms} permissions known</span>
</div> </div>
<!-- Plugin List -->
{#if plugins.length === 0} {#if plugins.length === 0}
<div class="empty"> <div class="empty">
<div class="empty-icon">📂</div> <div class="empty-icon">📂</div>
@ -135,17 +88,12 @@
</div> </div>
{/if} {/if}
<!-- Capabilities Registry -->
{#if capabilities.length > 0} {#if capabilities.length > 0}
<details class="registry-section"> <details class="registry-section">
<summary>Capability Registry ({totalCaps})</summary> <summary>Capability Registry ({totalCaps})</summary>
<table> <table>
<thead> <thead>
<tr> <tr><th>Capability</th><th>Provider</th><th>Status</th></tr>
<th>Capability</th>
<th>Provider</th>
<th>Status</th>
</tr>
</thead> </thead>
<tbody> <tbody>
{#each capabilities as cap} {#each capabilities as cap}
@ -163,176 +111,63 @@
</div> </div>
<style> <style>
.plugin-manager { .plugin-manager { max-width: 900px; }
max-width: 900px;
}
header { header {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
margin-bottom: 1rem; margin-bottom: 1rem;
} }
h2 { color: #e0e0e0; font-size: 1.3rem; }
h2 {
color: #e0e0e0;
font-size: 1.3rem;
}
.reload-btn { .reload-btn {
background: #0f3460; background: #0f3460; color: #e0e0e0; border: 1px solid #533483;
color: #e0e0e0; padding: 0.4rem 1rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
border: 1px solid #533483;
padding: 0.4rem 1rem;
border-radius: 6px;
cursor: pointer;
font-size: 0.85rem;
} }
.reload-btn:hover:not(:disabled) { background: #533483; }
.reload-btn:hover:not(:disabled) { .reload-btn:disabled { opacity: 0.5; cursor: not-allowed; }
background: #533483;
}
.reload-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.loading, .error { .loading, .error {
padding: 2rem; padding: 2rem; text-align: center; color: #a0a0b8;
text-align: center;
color: #a0a0b8;
} }
.error { color: #e94560; }
.error { .error-icon { font-size: 2rem; margin-bottom: 0.5rem; }
color: #e94560;
}
.error-icon {
font-size: 2rem;
margin-bottom: 0.5rem;
}
.error-message { .error-message {
font-family: monospace; font-family: monospace; font-size: 0.85rem; margin-bottom: 1rem; word-break: break-word;
font-size: 0.85rem;
margin-bottom: 1rem;
word-break: break-word;
} }
.retry-btn { .retry-btn {
background: #0f3460; background: #0f3460; color: #e0e0e0; border: 1px solid #533483;
color: #e0e0e0; padding: 0.4rem 1rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
border: 1px solid #533483;
padding: 0.4rem 1rem;
border-radius: 6px;
cursor: pointer;
font-size: 0.85rem;
} }
.retry-btn:hover { background: #533483; }
.retry-btn:hover {
background: #533483;
}
.summary { .summary {
display: flex; display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap;
gap: 0.5rem;
margin-bottom: 1rem;
flex-wrap: wrap;
} }
.badge { .badge {
background: #16213e; background: #16213e; padding: 0.25rem 0.75rem; border-radius: 12px;
padding: 0.25rem 0.75rem; font-size: 0.8rem; color: #a0a0b8; border: 1px solid #0f3460;
border-radius: 12px;
font-size: 0.8rem;
color: #a0a0b8;
border: 1px solid #0f3460;
} }
.empty { .empty {
padding: 2rem; padding: 2rem; text-align: center; color: #a0a0b8;
text-align: center; background: #16213e; border-radius: 8px; border: 1px dashed #0f3460;
color: #a0a0b8;
background: #16213e;
border-radius: 8px;
border: 1px dashed #0f3460;
} }
.empty-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.empty-icon { .hint { font-size: 0.85rem; margin-top: 0.5rem; opacity: 0.7; }
font-size: 2rem; .hint-list { list-style: none; padding: 0; margin: 0.5rem 0; font-size: 0.8rem; opacity: 0.7; }
margin-bottom: 0.5rem; .hint-list li { margin: 0.25rem 0; }
} .hint code { background: #0f3460; padding: 0.1rem 0.3rem; border-radius: 3px; }
.plugin-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; }
.hint {
font-size: 0.85rem;
margin-top: 0.5rem;
opacity: 0.7;
}
.hint-list {
list-style: none;
padding: 0;
margin: 0.5rem 0;
font-size: 0.8rem;
opacity: 0.7;
}
.hint-list li {
margin: 0.25rem 0;
}
.hint code {
background: #0f3460;
padding: 0.1rem 0.3rem;
border-radius: 3px;
}
.plugin-list {
display: flex;
flex-direction: column;
gap: 0.75rem;
margin-bottom: 1.5rem;
}
.registry-section { .registry-section {
background: #16213e; background: #16213e; border: 1px solid #0f3460;
border: 1px solid #0f3460; border-radius: 8px; padding: 0.75rem; margin-top: 1rem;
border-radius: 8px;
padding: 0.75rem;
margin-top: 1rem;
} }
.registry-section summary { .registry-section summary {
cursor: pointer; cursor: pointer; color: #a0a0b8; font-size: 0.9rem; font-weight: 600;
color: #a0a0b8;
font-size: 0.9rem;
font-weight: 600;
} }
table { width: 100%; margin-top: 0.5rem; border-collapse: collapse; font-size: 0.85rem; }
table {
width: 100%;
margin-top: 0.5rem;
border-collapse: collapse;
font-size: 0.85rem;
}
th { th {
text-align: left; text-align: left; padding: 0.4rem 0.5rem; color: #a0a0b8; border-bottom: 1px solid #0f3460;
padding: 0.4rem 0.5rem;
color: #a0a0b8;
border-bottom: 1px solid #0f3460;
} }
td { padding: 0.3rem 0.5rem; border-bottom: 1px solid #0f3460; }
td { td code { color: #e0e0e0; }
padding: 0.3rem 0.5rem;
border-bottom: 1px solid #0f3460;
}
td code {
color: #e0e0e0;
}
:global(.status-stable) { color: #4ecca3; } :global(.status-stable) { color: #4ecca3; }
:global(.status-draft) { color: #ffc857; } :global(.status-draft) { color: #ffc857; }
:global(.status-deprecated) { color: #e94560; } :global(.status-deprecated) { color: #e94560; }