added autostart for windows and autostart for devices

This commit is contained in:
2026-02-19 09:34:38 +01:00
parent e2b853840d
commit 486cf6d239
10 changed files with 290 additions and 19 deletions
+32
View File
@@ -24,6 +24,8 @@ type Handler struct {
GetDevices func() interface{}
AttachDevice func(clientID, busID string) error
DetachDevice func(clientID, busID string) error
SetAutoConnect func(vendorID, productID string, enabled bool) error
IsAutoConnect func(vendorID, productID string) bool
InstallService func() error
UninstallService func() error
GetStatus func() map[string]interface{}
@@ -54,6 +56,7 @@ func (h *Handler) setupRoutes() {
h.mux.HandleFunc("/api/config", h.handleConfig)
h.mux.HandleFunc("/api/generate-token", h.handleGenerateToken)
h.mux.HandleFunc("/api/apply-tokens", h.handleApplyTokens)
h.mux.HandleFunc("/api/auto-connect", h.handleAutoConnect)
h.mux.HandleFunc("/api/service/install", h.handleServiceInstall)
h.mux.HandleFunc("/api/service/uninstall", h.handleServiceUninstall)
}
@@ -252,6 +255,35 @@ func (h *Handler) handleApplyTokens(w http.ResponseWriter, r *http.Request) {
writeJSON(w, map[string]interface{}{"ok": true, "hash": hash})
}
func (h *Handler) handleAutoConnect(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "Method not allowed", 405)
return
}
var req struct {
VendorID string `json:"vendor_id"`
ProductID string `json:"product_id"`
Enabled bool `json:"enabled"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeJSON(w, map[string]interface{}{"ok": false, "error": "invalid request"})
return
}
if h.SetAutoConnect == nil {
writeJSON(w, map[string]interface{}{"ok": false, "error": "not in use mode"})
return
}
if err := h.SetAutoConnect(req.VendorID, req.ProductID, req.Enabled); err != nil {
writeJSON(w, map[string]interface{}{"ok": false, "error": err.Error()})
return
}
writeJSON(w, map[string]interface{}{"ok": true})
}
func (h *Handler) handleServiceInstall(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "Method not allowed", 405)
+26 -1
View File
@@ -94,13 +94,19 @@ function renderUseDevices(container, available, attached) {
html += attached.map(dev => `
<div class="device-card">
<div class="device-info">
<div class="device-name">${escapeHtml(dev.bus_id)}</div>
<div class="device-name">${escapeHtml(dev.name || dev.bus_id)}</div>
<div class="device-details">
<span>Von: ${escapeHtml(dev.client_name || dev.client_id)}</span>
${dev.vendor_id ? `<span>VID:PID: ${dev.vendor_id}:${dev.product_id}</span>` : ''}
<span>VHCI Port: ${dev.vhci_port}</span>
</div>
</div>
<div class="device-status">
<label class="auto-connect-label" title="Beim Start automatisch verbinden">
<input type="checkbox" ${dev.auto_connect ? 'checked' : ''}
onchange="toggleAutoConnect('${dev.vendor_id}', '${dev.product_id}', this.checked)">
Autostart
</label>
<span class="badge attached">Verbunden</span>
<button class="btn small danger" onclick="detachDevice('${dev.client_id}', '${dev.bus_id}')">Trennen</button>
</div>
@@ -191,6 +197,25 @@ async function detachDevice(clientId, busId) {
}
}
// Auto-connect toggle
async function toggleAutoConnect(vendorId, productId, enabled) {
try {
const resp = await fetch(API_BASE + '/api/auto-connect', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ vendor_id: vendorId, product_id: productId, enabled: enabled })
});
const data = await resp.json();
if (!data.ok) {
alert('Fehler: ' + (data.error || 'Unbekannt'));
updateDevices();
}
} catch (e) {
alert('Fehler: ' + e.message);
updateDevices();
}
}
// Settings
async function loadSettings() {
try {
+15
View File
@@ -279,3 +279,18 @@ nav {
color: #666;
padding: 2rem;
}
.auto-connect-label {
display: flex;
align-items: center;
gap: 0.3rem;
font-size: 0.8rem;
color: #888;
cursor: pointer;
user-select: none;
}
.auto-connect-label input[type="checkbox"] {
accent-color: #00d4ff;
cursor: pointer;
}