// +build js package main import ( // "honnef.co/go/js/dom" "github.com/gopherjs/gopherjs/js" "github.com/mame82/P4wnP1_aloa/common_web" "github.com/mame82/hvue" "github.com/mame82/mvuex" ) var ( serverAddr = GetBaseURL() //RpcClient = NewRpcClient(serverAddr + ":80") RpcClient = NewRpcClient(serverAddr) ) func GetBaseURL() string { document := js.Global.Get("window").Get("document") location := document.Get("location") port := location.Get("port").String() url := location.Get("protocol").String() + "//" + location.Get("hostname").String() if len(port) > 0 { url = url + ":" + port } return url } type appController struct { *js.Object } func Store(store *mvuex.Store) hvue.ComponentOption { return func(config *hvue.Config) { config.Set("store", store) } } func Router(router *js.Object) hvue.ComponentOption { return func(config *hvue.Config) { config.Set("router", router) } } func main() { //println(GetBaseURL()) store := InitGlobalState() //sets Vuex store in JS window.store router := NewVueRouter( "/usb", // route below could be used for an easter egg //VueRouterRoute("/","", ""), VueRouterRoute("/usb","", ""), VueRouterRoute("/hid","", ""), VueRouterRoute("/hidjobs","", ""), VueRouterRoute("/logger","", ""), VueRouterRoute("/network","", ""), VueRouterRoute("/wifi","", ""), VueRouterRoute("/triggeractions","", ""), VueRouterRoute("/bluetooth","", ""), VueRouterRoute("/generic","", ""), ) InitComponentsDialog() InitCompHIDJobs() InitCompHIDEvents() InitCompModal() InitCompEthernetAddresses2() InitCompToggleSwitch() InitCompUSBSettings() InitComponentsHIDScript() InitCompLogger() InitCompState() InitComponentsNetwork() InitComponentsWiFi() InitComponentsTriggerActions() InitComponentsBluetooth() InitComponentsGeneric() vm := hvue.NewVM( hvue.El("#app"), hvue.Template(templateMainApp), //add console to app as computed property, to allow debug output on vue events hvue.Computed("state", func(vm *hvue.VM) interface{} { return vm.Get("$store").Get("state") //works only with Vuex store option added }), hvue.BeforeMount(func(vm *hvue.VM) { vm.Get("$q").Get("addressbarColor").Call("set", "#027be3") }), Store(store), //include Vuex store in global scope, using own hvue fork, see here: https://github.com/HuckRidgeSW/hvue/pull/6 Router(router), ) // ToDo: remove next lines, debug code js.Global.Set("vm",vm) } const templateMainApp = ` P4wnP1 A.L.O.A. ` + common_web.VERSION + ` by MaMe82
` + common_web.VERSION + ` by MaMe82
`