From c05452c4593c44a0bd430e3842ebcde39dfbf9dc Mon Sep 17 00:00:00 2001 From: MaMe82 Date: Thu, 25 Oct 2018 15:44:53 +0200 Subject: [PATCH] Webclient,proto,server: bluetooth store&load; fix websocket timeout; fix start tab; other --- service/dwc2_connect_watcher.go | 4 +- service/rpc_server.go | 125 +++++++++++++++++------ web_client/hvueComponentsBluetooth.go | 141 ++++++++++++++++++++++++-- web_client/main.go | 5 +- web_client/mvuexGlobalState.go | 81 +++++++++++++++ web_client/rpcClient.go | 46 ++++++++- web_client/vueRouter.go | 8 +- 7 files changed, 360 insertions(+), 50 deletions(-) diff --git a/service/dwc2_connect_watcher.go b/service/dwc2_connect_watcher.go index 6776176..8cfe75e 100644 --- a/service/dwc2_connect_watcher.go +++ b/service/dwc2_connect_watcher.go @@ -57,12 +57,12 @@ func (d * Dwc2ConnectWatcher) update(newStateConnected bool) { if d.connected { fmt.Println("Connected to USB host") d.rootSvc.SubSysEvent.Emit(ConstructEventTrigger(common_web.TRIGGER_EVT_TYPE_USB_GADGET_CONNECTED)) - d.rootSvc.SubSysEvent.Emit(ConstructEventLog("USB watcher", 1, "Connected to USB host")) + //d.rootSvc.SubSysEvent.Emit(ConstructEventLog("USB watcher", 1, "Connected to USB host")) } else { fmt.Println("Disconnected from USB host") d.rootSvc.SubSysEvent.Emit(ConstructEventTrigger(common_web.TRIGGER_EVT_TYPE_USB_GADGET_DISCONNECTED)) - d.rootSvc.SubSysEvent.Emit(ConstructEventLog("USB watcher", 1, "Disconnected from USB host")) + //d.rootSvc.SubSysEvent.Emit(ConstructEventLog("USB watcher", 1, "Disconnected from USB host")) } } diff --git a/service/rpc_server.go b/service/rpc_server.go index 1a3dc6c..928e7e9 100644 --- a/service/rpc_server.go +++ b/service/rpc_server.go @@ -36,6 +36,7 @@ const ( cSTORE_PREFIX_USB_SETTINGS = "usbs_" cSTORE_PREFIX_ETHERNET_INTERFACE_SETTINGS = "eis_" cSTORE_PREFIX_TRIGGER_ACTION_SET = "tas_" + cSTORE_PREFIX_BLUETOOTH_SETTINGS = "bt_" ) @@ -52,6 +53,65 @@ type server struct { listenAddrWeb string } +func (s *server) DeployBluetoothSettings(ctx context.Context, settings *pb.BluetoothSettings) (resultSettings *pb.BluetoothSettings, err error) { + as := settings.As + ci := settings.Ci + resultSettings = &pb.BluetoothSettings{} + resultSettings.Ci,err = s.DeployBluetoothControllerInformation(ctx, ci) + if err != nil { + resultSettings.As,_ = s.GetBluetoothAgentSettings(ctx,&pb.Empty{}) + return + } + resultSettings.As,err = s.DeployBluetoothAgentSettings(ctx, as) + return +} + +func (s *server) StoreBluetoothSettings(ctx context.Context, req *pb.BluetoothRequestSettingsStorage) (e *pb.Empty, err error) { + e = &pb.Empty{} + err = s.rootSvc.SubSysDataStore.Put(cSTORE_PREFIX_BLUETOOTH_SETTINGS + req.TemplateName, req.Settings, true) + return +} + +func (s *server) GetStoredBluetoothSettings(ctx context.Context, templateName *pb.StringMessage) (result *pb.BluetoothSettings, err error) { + result = &pb.BluetoothSettings{} + err = s.rootSvc.SubSysDataStore.Get(cSTORE_PREFIX_BLUETOOTH_SETTINGS + templateName.Msg, result) + return +} + +func (s *server) DeployStoredBluetoothSettings(ctx context.Context, templateName *pb.StringMessage) (e *pb.BluetoothSettings, err error) { + bts,err := s.GetStoredBluetoothSettings(ctx,templateName) + if err != nil { return bts,err } + return s.DeployBluetoothSettings(ctx, bts) +} + +func (s *server) DeleteStoredBluetoothSettings(ctx context.Context, templateName *pb.StringMessage) (e *pb.Empty, err error) { + e = &pb.Empty{} + err = s.rootSvc.SubSysDataStore.Delete(cSTORE_PREFIX_BLUETOOTH_SETTINGS + templateName.Msg) + return +} + +func (s *server) StoreDeployedBluetoothSettings(ctx context.Context, templateName *pb.StringMessage) (e *pb.Empty, err error) { + e = &pb.Empty{} + currentSettings := &pb.BluetoothSettings{} + currentSettings.Ci,err = s.GetBluetoothControllerInformation(ctx, e) + if err != nil { return e,err } + currentSettings.As,err = s.GetBluetoothAgentSettings(ctx,e) + if err != nil { return e,err } + + return s.StoreBluetoothSettings(ctx, &pb.BluetoothRequestSettingsStorage{ + Settings: currentSettings, + TemplateName: templateName.Msg, + }) +} + +func (s *server) ListStoredBluetoothSettings(ctx context.Context, e *pb.Empty) (sa *pb.StringMessageArray, err error) { + sa = &pb.StringMessageArray{} + res,err := s.rootSvc.SubSysDataStore.KeysPrefix(cSTORE_PREFIX_BLUETOOTH_SETTINGS, true) + if err != nil { return sa,err } + sa.MsgArray = res + return +} + func (s *server) DeleteStoredUSBSettings(ctx context.Context, name *pb.StringMessage) (e *pb.Empty, err error) { e = &pb.Empty{} err = s.rootSvc.SubSysDataStore.Delete(cSTORE_PREFIX_USB_SETTINGS + name.Msg) @@ -100,21 +160,22 @@ func (s *server) DBRestore(ctx context.Context, filename *pb.StringMessage) (e * return } -func (s *server) ListStoredDBBackups(context.Context, *pb.Empty) (*pb.StringMessageArray, error) { +func (s *server) ListStoredDBBackups(ctx context.Context, e *pb.Empty) (ma *pb.StringMessageArray, err error) { + ma = &pb.StringMessageArray{} scripts,err := ListFilesOfFolder(PATH_DATA_STORE_BACKUP, ".db") - if err != nil { return nil,err } - - return &pb.StringMessageArray{MsgArray:scripts}, nil + if err != nil { return ma,err } + ma.MsgArray = scripts + return } func (s *server) GetBluetoothAgentSettings(ctx context.Context, e *pb.Empty) (as *pb.BluetoothAgentSettings, err error) { + as = &pb.BluetoothAgentSettings{} + pin,err := s.rootSvc.SubSysBluetooth.GetPIN() - if err != nil { return nil,err } - as = &pb.BluetoothAgentSettings{ - Pin: pin, - } + if err != nil { return as,err } + as.Pin = pin return } @@ -125,6 +186,7 @@ func (s *server) DeployBluetoothAgentSettings(ctx context.Context, src *pb.Bluet // Unused, Server services are deployed via BluetoothControllerInformation func (s *server) SetBluetoothNetworkService(ctx context.Context, btNwSvc *pb.BluetoothNetworkService) (e *pb.Empty, err error) { + e = &pb.Empty{} uuid := toolz.UUID_NETWORK_SERVER_NAP switch btNwSvc.Type { case pb.BluetoothNetworkServiceType_NAP: @@ -161,12 +223,13 @@ func (s *server) DeployBluetoothControllerInformation(ctx context.Context, newBt bridgeNameGn := BT_ETHERNET_BRIDGE_NAME updatedCi,err := s.rootSvc.SubSysBluetooth.Controller.UpdateSettingsFromChangedControllerInformation(btCi, bridgeNameNap, bridgeNamePanu, bridgeNameGn) fmt.Printf("Deployed bluetooth settings\n%+v\n%v\n", updatedCi, err) - if err != nil { return nil,err } + if err != nil { return &pb.BluetoothControllerInformation{},err } updateBtCiRpc = bluetooth.BluetoothControllerInformationToRpc(updatedCi) return updateBtCiRpc, nil } func (s *server) GetBluetoothControllerInformation(ctx context.Context, e *pb.Empty) (res *pb.BluetoothControllerInformation, err error) { + res = &pb.BluetoothControllerInformation{} btCi,err := s.rootSvc.SubSysBluetooth.Controller.ReadControllerInformation() if err != nil { return res,err } btCiRpc := bluetooth.BluetoothControllerInformationToRpc(btCi) @@ -189,7 +252,7 @@ func (s *server) GetStoredUSBSettings(ctx context.Context, m *pb.StringMessage) func (s *server) DeployStoredUSBSettings(ctx context.Context, m *pb.StringMessage) (st *pb.GadgetSettings, err error) { ws,err := s.GetStoredUSBSettings(ctx,m) - if err != nil { return st,err } + if err != nil { return &pb.GadgetSettings{},err } st,err = s.SetGadgetSettings(ctx, ws) if err != nil { return @@ -200,7 +263,7 @@ func (s *server) DeployStoredUSBSettings(ctx context.Context, m *pb.StringMessag func (s *server) StoreDeployedUSBSettings(ctx context.Context, m *pb.StringMessage) (e *pb.Empty, err error) { gstate, err := ParseGadgetState(USB_GADGET_NAME) - if err != nil { return nil,err } + if err != nil { return &pb.Empty{},err } return s.StoreUSBSettings(ctx, &pb.USBRequestSettingsStorage{ Settings: gstate, @@ -209,26 +272,27 @@ func (s *server) StoreDeployedUSBSettings(ctx context.Context, m *pb.StringMessa } func (s *server) ListStoredUSBSettings(ctx context.Context, e *pb.Empty) (sa *pb.StringMessageArray, err error) { + sa = &pb.StringMessageArray{} res,err := s.rootSvc.SubSysDataStore.KeysPrefix(cSTORE_PREFIX_USB_SETTINGS, true) if err != nil { return sa,err } - sa = &pb.StringMessageArray{ - MsgArray: res, - } + sa.MsgArray = res return } -func (s *server) ListStoredHIDScripts(context.Context, *pb.Empty) (*pb.StringMessageArray, error) { +func (s *server) ListStoredHIDScripts(context.Context, *pb.Empty) (sa *pb.StringMessageArray, err error) { + sa = &pb.StringMessageArray{} scripts,err := ListFilesOfFolder(PATH_HID_SCRIPTS, ".js", ".javascript") - if err != nil { return nil,err } - - return &pb.StringMessageArray{MsgArray:scripts}, nil + if err != nil { return sa,err } + sa.MsgArray = scripts + return } -func (s *server) ListStoredBashScripts(context.Context, *pb.Empty) (*pb.StringMessageArray, error) { +func (s *server) ListStoredBashScripts(context.Context, *pb.Empty) (sa *pb.StringMessageArray, err error) { + sa = &pb.StringMessageArray{} scripts,err := ListFilesOfFolder(PATH_BASH_SCRIPTS, ".sh", ".bash") - if err != nil { return nil,err } - - return &pb.StringMessageArray{MsgArray:scripts}, nil + if err != nil { return sa,err } + sa.MsgArray = scripts + return } func (s *server) DeployStoredTriggerActionSetReplace(ctx context.Context, msg *pb.StringMessage) (tas *pb.TriggerActionSet, err error) { @@ -256,13 +320,12 @@ func (s *server) StoreTriggerActionSet(ctx context.Context, set *pb.TriggerActio } func (s *server) ListStoredTriggerActionSets(ctx context.Context, e *pb.Empty) (tas *pb.StringMessageArray, err error) { + tas = &pb.StringMessageArray{} res, err := s.rootSvc.SubSysDataStore.KeysPrefix(cSTORE_PREFIX_TRIGGER_ACTION_SET, true) if err != nil { return tas, err } - tas = &pb.StringMessageArray{ - MsgArray: res, - } + tas.MsgArray = res return } @@ -323,7 +386,7 @@ func (s *server) StoreDeployedWifiSettings(ctx context.Context, m *pb.StringMess func (s *server) DeployStoredWifiSettings(ctx context.Context, m *pb.StringMessage) (st *pb.WiFiState, err error) { ws,err := s.GetStoredWifiSettings(ctx,m) - if err != nil { return st,err } + if err != nil { return &pb.WiFiState{},err } return s.DeployWiFiSettings(ctx, ws) } @@ -340,11 +403,10 @@ func (s *server) GetStoredWifiSettings(ctx context.Context, m *pb.StringMessage) } func (s *server) ListStoredWifiSettings(ctx context.Context, e *pb.Empty) (sa *pb.StringMessageArray, err error) { + sa = &pb.StringMessageArray{} res,err := s.rootSvc.SubSysDataStore.KeysPrefix(cSTORE_PREFIX_WIFI_SETTINGS, true) if err != nil { return sa,err } - sa = &pb.StringMessageArray{ - MsgArray: res, - } + sa.MsgArray = res return } @@ -641,11 +703,10 @@ func (s *server) DeployStoredEthernetInterfaceSettings(ctx context.Context, msg } func (s *server) ListStoredEthernetInterfaceSettings(ctx context.Context, empty *pb.Empty) (messages *pb.StringMessageArray, err error) { + messages = &pb.StringMessageArray{} res,err := s.rootSvc.SubSysDataStore.KeysPrefix(cSTORE_PREFIX_ETHERNET_INTERFACE_SETTINGS, true) if err != nil { return messages,err } - messages = &pb.StringMessageArray{ - MsgArray: res, - } + messages.MsgArray = res return } diff --git a/web_client/hvueComponentsBluetooth.go b/web_client/hvueComponentsBluetooth.go index 8af5d1e..c07e9a9 100644 --- a/web_client/hvueComponentsBluetooth.go +++ b/web_client/hvueComponentsBluetooth.go @@ -8,6 +8,73 @@ import ( pb "github.com/mame82/P4wnP1_go/proto/gopherjs" ) +type jsBluetoothRequestSettingsStorage struct { + *js.Object + TemplateName string `js:"TemplateName"` + Settings *jsBluetoothSettings `js:"Settings"` +} + +func (rs *jsBluetoothRequestSettingsStorage) toGo() *pb.BluetoothRequestSettingsStorage { + return &pb.BluetoothRequestSettingsStorage{ + TemplateName: rs.TemplateName, + Settings: rs.Settings.toGo(), + } +} + +func (rs *jsBluetoothRequestSettingsStorage) fromGo(src *pb.BluetoothRequestSettingsStorage) { + rs.TemplateName = src.TemplateName + rs.Settings = NewBluetoothSettings() + rs.Settings.fromGo(src.Settings) +} + +func NewBluetoothRequestSettingsStorage() (res *jsBluetoothRequestSettingsStorage) { + res = &jsBluetoothRequestSettingsStorage{Object:O()} + res.TemplateName = "" + res.Settings = NewBluetoothSettings() + return res +} + +func NewBluetoothRequestSettingsStorageFromArgs(as *jsBluetoothAgentSettings, ci *jsBluetoothControllerInformation, templateName string) (res *jsBluetoothRequestSettingsStorage) { + res = &jsBluetoothRequestSettingsStorage{Object:O()} + res.TemplateName = templateName + res.Settings = NewBluetoothSettings() + res.Settings.fromASandCI(as,ci) + return res +} + +type jsBluetoothSettings struct { + *js.Object + Ci *jsBluetoothControllerInformation `js:"Ci"` + As *jsBluetoothAgentSettings `js:"As"` +} + +func (target *jsBluetoothSettings) fromGo(src *pb.BluetoothSettings) { + target.As = NewBluetoothAgentSettings() + target.As.fromGo(src.As) + target.Ci = NewBluetoothControllerInformation() + target.Ci.fromGo(src.Ci) +} + +func (target *jsBluetoothSettings) fromASandCI(as *jsBluetoothAgentSettings, ci *jsBluetoothControllerInformation) { + target.As = as + target.Ci = ci +} + +func (src *jsBluetoothSettings) toGo() (target *pb.BluetoothSettings) { + target = &pb.BluetoothSettings{ + Ci: src.Ci.toGo(), + As: src.As.toGo(), + } + return target +} + +func NewBluetoothSettings() (res *jsBluetoothSettings) { + res = &jsBluetoothSettings{Object:O()} + res.As = NewBluetoothAgentSettings() + res.Ci = NewBluetoothControllerInformation() + return +} + type jsBluetoothAgentSettings struct { *js.Object Pin string `js:"Pin"` @@ -186,14 +253,16 @@ func InitComponentsBluetooth() { "bluetooth", hvue.Template(templateBluetoothPage), hvue.DataFunc(func(vm *hvue.VM) interface{} { - data := &struct { + data := struct { *js.Object - // ControllerInfo *jsBluetoothControllerInformation `js:"ControllerInfo"` + ShowStoreModal bool `js:"showStoreModal"` + ShowDeployStoredModal bool `js:"showDeployStoredModal"` +// TemplateName string `js:"templateName"` }{Object: O()} - - // data.ControllerInfo = NewBluetoothControllerInformation() - - return data + data.ShowStoreModal = false + data.ShowDeployStoredModal = false +// data.TemplateName = "" + return &data }), hvue.Computed("CurrentControllerInfo", func(vm *hvue.VM) interface{} { @@ -202,6 +271,38 @@ func InitComponentsBluetooth() { hvue.Computed("available", func(vm *hvue.VM) interface{} { return true }), + hvue.Computed("CurrentBluetoothAgentSettings", + func(vm *hvue.VM) interface{} { + return vm.Get("$store").Get("state").Get("CurrentBluetoothAgentSettings") + }), + hvue.Method("store", + func(vm *hvue.VM, name *js.Object) { + ci := &jsBluetoothControllerInformation{ + Object: vm.Get("$store").Get("state").Get("CurrentBluetoothControllerInformation"), + } + as := &jsBluetoothAgentSettings{ + Object: vm.Get("$store").Get("state").Get("CurrentBluetoothAgentSettings"), + } + sReq := NewBluetoothRequestSettingsStorageFromArgs(as,ci,name.String()) + println("Storing :", sReq) + vm.Get("$store").Call("dispatch", VUEX_ACTION_STORE_BLUETOOTH_SETTINGS, sReq) + vm.Set("showStoreModal", false) + }), + hvue.Method("deleteStored", + func(vm *hvue.VM, name *js.Object) { + println("Loading :", name.String()) + vm.Get("$store").Call("dispatch", VUEX_ACTION_DELETE_STORED_BLUETOOTH_SETTINGS, name) + }), + hvue.Method("deployStored", + func(vm *hvue.VM, name *js.Object) { + println("Loading :", name.String()) + vm.Get("$store").Call("dispatch", VUEX_ACTION_DEPLOY_STORED_BLUETOOTH_SETTINGS, name) + }), + hvue.Method("updateStoredSettingsList", + func(vm *hvue.VM) { + vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_STORED_BLUETOOTH_SETTINGS_LIST) + }), + hvue.Mounted(func(vm *hvue.VM) { vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_CURRENT_BLUETOOTH_CONTROLLER_INFORMATION) }), @@ -227,10 +328,7 @@ func InitComponentsBluetooth() { hvue.NewComponent( "bluetooth-agent", hvue.Template(templateBluetoothAgent), - hvue.Computed("CurrentBluetoothAgentSettings", - func(vm *hvue.VM) interface{} { - return vm.Get("$store").Get("state").Get("CurrentBluetoothAgentSettings") - }), + hvue.PropObj("bluetoothAgent"), hvue.Mounted(func(vm *hvue.VM) { vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_CURRENT_BLUETOOTH_AGENT_SETTINGS) }), @@ -240,7 +338,28 @@ func InitComponentsBluetooth() { const templateBluetoothPage = ` + + + +
+ +
+ + + Bluetooth Settings + + + +
+
+
+
+
+
+
+ +
{{ CurrentControllerInfo }}
@@ -409,7 +528,7 @@ const templateBluetoothAgent = ` Pin PIN requested from remote devices on bonding (only if SSP is off) - + diff --git a/web_client/main.go b/web_client/main.go index 6921c23..25a5b8a 100644 --- a/web_client/main.go +++ b/web_client/main.go @@ -55,9 +55,10 @@ func main() { // ToDo: delete because debug RpcClient.GetAllDeployedEthernetInterfaceSettings(time.Second*10) - router := NewVueRouter( + router := NewVueRouter("/usb", VueRouterRoute("/usb","", ""), - VueRouterRoute("/","", ""), + // route below could be used for an easter egg + //VueRouterRoute("/","", ""), VueRouterRoute("/hid","", ""), VueRouterRoute("/hidjobs","", ""), VueRouterRoute("/logger","", ""), diff --git a/web_client/mvuexGlobalState.go b/web_client/mvuexGlobalState.go index c385b10..775b9bd 100644 --- a/web_client/mvuexGlobalState.go +++ b/web_client/mvuexGlobalState.go @@ -15,6 +15,8 @@ import ( var globalState *GlobalState + + const ( maxLogEntries = 500 @@ -23,9 +25,14 @@ const ( VUEX_ACTION_DEPLOY_CURRENT_BLUETOOTH_CONTROLLER_INFORMATION = "deployCurrentBluetoothControllerInformation" VUEX_ACTION_UPDATE_CURRENT_BLUETOOTH_AGENT_SETTINGS = "updateCurrentBluetoothAgentSettings" VUEX_ACTION_DEPLOY_CURRENT_BLUETOOTH_AGENT_SETTINGS = "deployCurrentBluetoothAgentSettings" + VUEX_ACTION_STORE_BLUETOOTH_SETTINGS = "storedBluetoothSettings" + VUEX_ACTION_DELETE_STORED_BLUETOOTH_SETTINGS = "deleteStoredBluetoothSettings" + VUEX_ACTION_DEPLOY_STORED_BLUETOOTH_SETTINGS = "deployStoredBluetoothSettings" + VUEX_ACTION_UPDATE_STORED_BLUETOOTH_SETTINGS_LIST = "setStoredBluetoothSettingsList" VUEX_MUTATION_SET_CURRENT_BLUETOOTH_CONTROLLER_INFORMATION = "setCurrentBluetoothControllerInformation" VUEX_MUTATION_SET_CURRENT_BLUETOOTH_AGENT_SETTINGS = "setCurrentBluetoothAgentSettings" + VUEX_MUTATION_SET_STORED_BLUETOOTH_SETTINGS_LIST = "setStoredBluetoothSettingsList" //HIDScripts and jobs VUEX_ACTION_UPDATE_RUNNING_HID_JOBS = "updateRunningHidJobs" @@ -122,6 +129,7 @@ type GlobalState struct { StoredBashScriptsList []string `js:"StoredBashScriptsList"` StoredHIDScriptsList []string `js:"StoredHIDScriptsList"` StoredUSBSettingsList []string `js:"StoredUSBSettingsList"` + StoredBluetoothSettingsList []string `js:"StoredBluetoothSettingsList"` } func createGlobalStateStruct() GlobalState { @@ -143,6 +151,8 @@ func createGlobalStateStruct() GlobalState { state.StoredBashScriptsList = []string{} state.StoredHIDScriptsList = []string{} state.StoredUSBSettingsList = []string{} + state.StoredBluetoothSettingsList = []string{} + //Retrieve Interface settings state.InterfaceSettings = NewEthernetSettingsList() state.CurrentBluetoothControllerInformation = NewBluetoothControllerInformation() @@ -159,6 +169,68 @@ func createGlobalStateStruct() GlobalState { return state } +func actionUpdateStoredBluetoothSettingsList(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState) { + go func() { + println("Trying to fetch bluetooth settings list") + //fetch deployed gadget settings + btsList, err := RpcClient.GetStoredBluetoothSettingsList(defaultTimeout) + if err != nil { + println("Couldn't retrieve BluetoothSettings list") + return + } + + //commit to current + + context.Commit(VUEX_MUTATION_SET_STORED_BLUETOOTH_SETTINGS_LIST, btsList) + //context.Commit(VUEX_MUTATION_SET_STORED_WIFI_SETTINGS_LIST, []string{"test1", "test2"}) + }() + + return +} + +func actionDeployStoredBluetoothSettings(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, settingsName *js.Object) { + go func() { + println("Vuex dispatch load Bluetooth settings: ", settingsName.String()) + // convert to Go type + goBluetoothStettings, err := RpcClient.DeployStoredBluetoothSettings(defaultTimeoutMid, &pb.StringMessage{Msg: settingsName.String()}) + if err != nil { + QuasarNotifyError("Error deploying stored Bluetooth Settings", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM) + } + QuasarNotifySuccess("New Bluetooth settings deployed", "", QUASAR_NOTIFICATION_POSITION_TOP) + jsBluetoothSettings := NewBluetoothSettings() + jsBluetoothSettings.fromGo(goBluetoothStettings) + println("New bluetooth settings", jsBluetoothSettings) + context.Commit(VUEX_MUTATION_SET_CURRENT_BLUETOOTH_AGENT_SETTINGS, jsBluetoothSettings.As) + context.Commit(VUEX_MUTATION_SET_CURRENT_BLUETOOTH_CONTROLLER_INFORMATION, jsBluetoothSettings.Ci) + }() +} + +func actionDeleteStoredBluetoothSettings(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, settingsName *js.Object) { + go func() { + println("Vuex dispatch delete Bluetooth settings: ", settingsName.String()) + // convert to Go type + err := RpcClient.DeleteStoredBluetoothSettings(defaultTimeout, &pb.StringMessage{Msg: settingsName.String()}) + if err != nil { + QuasarNotifyError("Error deleting stored Bluetooth Settings", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM) + } + QuasarNotifySuccess("Bluetooth settings deleted", "", QUASAR_NOTIFICATION_POSITION_TOP) + actionUpdateStoredBluetoothSettingsList(store,context,state) + }() +} + +func actionStoreBluetoothSettings(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, req *jsBluetoothRequestSettingsStorage) { + go func() { + println("Vuex dispatch store Bluetooth settings: ", req.TemplateName) + // convert to Go type + err := RpcClient.StoreBluetoothSettings(defaultTimeout, req.toGo()) + if err != nil { + QuasarNotifyError("Error storing Bluetooth Settings", err.Error(), QUASAR_NOTIFICATION_POSITION_BOTTOM) + } + QuasarNotifySuccess("New Bluetooth settings stored", "", QUASAR_NOTIFICATION_POSITION_TOP) + }() +} + + func actionDeleteStoredUSBSettings(store *mvuex.Store, context *mvuex.ActionContext, state *GlobalState, settingsName *js.Object) { go func() { println("Vuex dispatch delete USB settings: ", settingsName.String()) @@ -875,6 +947,10 @@ func initMVuex() *mvuex.Store { println("New ws list", wsList) hvue.Set(state, "StoredWifiSettingsList", wsList) }), + mvuex.Mutation(VUEX_MUTATION_SET_STORED_BLUETOOTH_SETTINGS_LIST, func(store *mvuex.Store, state *GlobalState, wsList []interface{}) { + println("New Bluetooth list", wsList) + hvue.Set(state, "StoredBluetoothSettingsList", wsList) + }), mvuex.Mutation(VUEX_MUTATION_SET_STORED_USB_SETTINGS_LIST, func(store *mvuex.Store, state *GlobalState, usbList []interface{}) { println("New USB settings list", usbList) hvue.Set(state, "StoredUSBSettingsList", usbList) @@ -922,6 +998,11 @@ func initMVuex() *mvuex.Store { mvuex.Action(VUEX_ACTION_DEPLOY_CURRENT_BLUETOOTH_CONTROLLER_INFORMATION, actionDeployCurrentBluetoothControllerInformation), mvuex.Action(VUEX_ACTION_UPDATE_CURRENT_BLUETOOTH_AGENT_SETTINGS, actionUpdateCurrentBluetoothAgentSettings), mvuex.Action(VUEX_ACTION_DEPLOY_CURRENT_BLUETOOTH_AGENT_SETTINGS, actionDeployCurrentBluetoothAgentSettings), + mvuex.Action(VUEX_ACTION_STORE_BLUETOOTH_SETTINGS, actionStoreBluetoothSettings), + mvuex.Action(VUEX_ACTION_DELETE_STORED_BLUETOOTH_SETTINGS, actionDeleteStoredBluetoothSettings), + mvuex.Action(VUEX_ACTION_DEPLOY_STORED_BLUETOOTH_SETTINGS, actionDeployStoredBluetoothSettings), + mvuex.Action(VUEX_ACTION_UPDATE_STORED_BLUETOOTH_SETTINGS_LIST, actionUpdateStoredBluetoothSettingsList), + mvuex.Action(VUEX_ACTION_UPDATE_CURRENT_USB_SETTINGS, actionUpdateGadgetSettingsFromDeployed), mvuex.Action(VUEX_ACTION_DEPLOY_CURRENT_USB_SETTINGS, actionDeployCurrentGadgetSettings), diff --git a/web_client/rpcClient.go b/web_client/rpcClient.go index 09df095..8ec781c 100644 --- a/web_client/rpcClient.go +++ b/web_client/rpcClient.go @@ -30,6 +30,50 @@ func NewRpcClient(addr string) Rpc { return rcl } +func (rpc *Rpc) GetStoredBluetoothSettingsList(timeout time.Duration) (ws []string, err error) { + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + ma, err := rpc.Client.ListStoredBluetoothSettings(ctx, &pb.Empty{}) + if err != nil { return ws, err } + return ma.MsgArray, err +} + +func (rpc *Rpc) StoreBluetoothSettings(timeout time.Duration, req *pb.BluetoothRequestSettingsStorage) (err error) { + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + _, err = rpc.Client.StoreBluetoothSettings(ctx, req) + + return +} + +func (rpc *Rpc) GetStoredBluetoothSettings(timeout time.Duration, req *pb.StringMessage) (settings *pb.BluetoothSettings, err error) { + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + settings, err = rpc.Client.GetStoredBluetoothSettings(ctx, req) + + return +} + +func (rpc *Rpc) DeployStoredBluetoothSettings(timeout time.Duration, req *pb.StringMessage) (state *pb.BluetoothSettings, err error) { + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + + state, err = rpc.Client.DeployStoredBluetoothSettings(ctx, req) + + return +} + + +func (rpc *Rpc) DeleteStoredBluetoothSettings(timeout time.Duration, req *pb.StringMessage) (err error) { + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + _, err = rpc.Client.DeleteStoredBluetoothSettings(ctx, req) + return +} + func (rpc *Rpc) DeleteStoredUSBSettings(timeout time.Duration, req *pb.StringMessage) (err error) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -112,7 +156,6 @@ func (rpc *Rpc) GetStoredUSBSettingsList(timeout time.Duration) (ws []string, er return ma.MsgArray, err } - func (rpc *Rpc) StoreUSBSettings(timeout time.Duration, req *pb.USBRequestSettingsStorage) (err error) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -539,6 +582,7 @@ func (rpc *Rpc) StartListening() { globalState.EventReceiver.HandleEvent(event) } // we end here on connection error + evStream.CloseSend() // fix for half-open websockets, for which the server wouldn't send a TCP RST after crash/restart, as no active client to server communication takes place cancel() println("EVENTLISTENING ABORTED") diff --git a/web_client/vueRouter.go b/web_client/vueRouter.go index 6cf99b5..98aad72 100644 --- a/web_client/vueRouter.go +++ b/web_client/vueRouter.go @@ -37,7 +37,7 @@ func VueRouterRoute(path, name, template string) VueRouterOption { } } -func NewVueRouter(opts ...VueRouterOption) *js.Object { +func NewVueRouter(defaultRoute string, opts ...VueRouterOption) *js.Object { c := &VueRouterConfig{Object:O()} c.Routes = js.Global.Get("Array").New() @@ -45,7 +45,11 @@ func NewVueRouter(opts ...VueRouterOption) *js.Object { opt(c) } - return js.Global.Get("VueRouter").New(c) + jsrouter := js.Global.Get("VueRouter").New(c) + if len(defaultRoute) > 0 { + jsrouter.Call("replace", defaultRoute) + } + return jsrouter }