Skip to content
/ astor Public

astor is a vuejs plugin for communicate with a go-astilectron app

Notifications You must be signed in to change notification settings

Ghardo/astor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 

Repository files navigation

astor

astor is a vuejs plugin for communicate with a go-astilectron app

NOTE vue3 support curently in development

Install

copy astor.js to PROJECTROOT/plugins/astor.js

Usage

Plugin registration

import Vue from 'vue'
import App from './App.vue'
import astor from './plugins/astor';

Vue.config.productionTip = false

Vue.use(
  astor,  {
    debug: true
  }
)


new Vue({
  render: h => h(App)
}).$mount('#app')

Sending and recieving

<template>
  <div>Hello Word</div>
</template>

<script>
export default {
     created () {
      this.$astor.trigger(
        'app-ready', 
        {}, 
        (payload) => {
          window.console.log("ready", payload)
        }
      )
    },
}
</script>

<style>
</style>

Recieving only

<template>
  <div>Hello Word</div>
</template>

<script>
export default {
     created () {
      this.$astor.listen(
        'my-custom-message', 
        this.cbMyCustomMessage
      )
    },
    methods: {
        cbMyCustomMessage(payload) {
            window.console.log('cbMyCustomMessage', payload)
        }
    }
}
</script>

<style>
</style>
type AstorEvent struct {
	Name    string      `json:"name"`
	Payload interface{} `json:"payload"`
}
...
w.OnMessage(func(m *astilectron.EventMessage) interface{} {
    // Unmarshal
    var e AstorEvent
    m.Unmarshal(&e)

    l.Printf("%v", e)

    r := AstorEvent{Name: e.Name, Payload: "Ok"}
    return r
})

See example for more info

cd example/vue
yarn install
yarn build
cd ..
go run main.go