added autostart for windows and autostart for devices
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user