merging dan gomobile with erinn ui

This commit is contained in:
erinn 2021-01-22 00:00:03 -08:00
parent 9c7a22d472
commit 240c4d36e0
1 changed files with 24 additions and 1 deletions

25
lib.go
View File

@ -106,13 +106,29 @@ func GetAppBusEvent() string {
return fmt.Sprintf("%v", event) return fmt.Sprintf("%v", event)
} }
type Profile struct {
Name string `json:"name"`
Onion string `json:"onion"`
ImagePath string `json:"imagePath"`
}
//export c_GetProfiles //export c_GetProfiles
func c_GetProfiles() *C.char { func c_GetProfiles() *C.char {
return C.CString(GetProfiles()) return C.CString(GetProfiles())
} }
func GetProfiles() string { func GetProfiles() string {
profiles := application.ListPeers() peerList := application.ListPeers()
profiles := make([]Profile, len(peerList))
i := 0
for onion, name := range peerList {
profiles[i] = Profile{
Name: name,
Onion: onion,
ImagePath: "",
}
i += 1
}
jsonBytes,_ := json.Marshal(profiles) jsonBytes,_ := json.Marshal(profiles)
return string(jsonBytes) return string(jsonBytes)
} }
@ -147,7 +163,14 @@ func GetContacts(onion string)string {
return string(bytes) return string(bytes)
} }
//export c_CreateProfile
func c_CreateProfile(nick_ptr *C.char, nick_len C.int, pass_ptr *C.char, pass_len C.int) {
CreateProfile(C.GoStringN(nick_ptr, nick_len), C.GoStringN(pass_ptr, pass_len))
}
func CreateProfile(nick, pass string) {
application.CreatePeer(nick, pass)
}
//export c_SelectProfile //export c_SelectProfile
func c_SelectProfile(onion_ptr *C.char, onion_len C.int) *C.char { func c_SelectProfile(onion_ptr *C.char, onion_len C.int) *C.char {