Skip to content

Commit

Permalink
fix: quick & dirty fix for functions with multiple return on Darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddi committed Dec 1, 2019
1 parent 06b102a commit 047addf
Show file tree
Hide file tree
Showing 15 changed files with 390 additions and 55 deletions.
20 changes: 14 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ func (c *config) Set(raw_json []byte) (err error) {
return
}

func (c *config) Get() ([]byte, error) {
return json.Marshal(c.cfg)
func (c *config) Get() *ByteErr {
b, err := json.Marshal(c.cfg)
return &ByteErr{
b: b,
err: err,
}
}

func (c *config) SetKey(key string, raw_value []byte) error {
Expand All @@ -58,16 +62,20 @@ func (c *config) SetKey(key string, raw_value []byte) error {
return err
}

func (c *config) GetKey(key string) ([]byte, error) {
func (c *config) GetKey(key string) *ByteErr {
cfg, err := ipfs_config.ToMap(c.cfg)
if err != nil {
return nil, err
return &ByteErr{err: err}
}

val, err := ipfs_common.MapGetKV(cfg, key)
if err != nil {
return nil, err
return &ByteErr{err: err}
}

return json.Marshal(&val)
b, err := json.Marshal(&val)
return &ByteErr{
b: b,
err: err,
}
}
60 changes: 40 additions & 20 deletions example/react-native/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,49 @@ import {
} from 'react-native';


const asyncTimeout = (cb, time) =>
new Promise(res => setTimeout(cb, time))

class App extends Component {
state = {
loading: true,
url: '',
}

checkGateway = async () => {
try {
const res = await fetch('http://127.0.0.1:5001/webui')
if (res.ok) {
this.setState({
loading: false,
url: res.url,
})
}
} catch (err) {
console.warn(err)
return asyncTimeout(this.checkGateway, 2000)
}
}

checkGateway = () => {
fetch('http://127.0.0.1:5001/webui')
.then(res => {
if (res.ok) {
this.setState({ loading: false })
} else {
throw new Error(`gateway unavailable: [${res.status}] ${res.statusText}`)
}
}).catch(err => {
console.warn(err)
setTimeout(this.checkGateway, 1000)
})
startDaemon = async () => {
try {
const res = await fetch('http://127.0.0.1:5001/api/v0/id')
const id = await res.json()
return id.ID
} catch (err) {
console.warn(err)
}

await NativeModules.BridgeModule.start()
return this.startDaemon()
}

componentDidMount() {
NativeModules.BridgeModule.start()
.then(() => {})
this.startDaemon()
.then(id => console.info('peerID:', id))
.catch(err => console.error(err))
.then(() => this.checkGateway())
.then(this.checkGateway)
.catch(err => console.Warn(err))
}

render() {
Expand All @@ -54,13 +73,14 @@ class App extends Component {

return (
<Fragment>
<StatusBar barStyle="dark-content" />
<SafeAreaView>

<WebView
source={{uri: 'http://127.0.0.1:5001/webui'}}
style={{marginTop: 20}}
source={{uri: this.state.url}}
originWhitelist={['*']}
onError={err => console.warn(err)}
onMessage={msg => console.log(msg)}

/>
</SafeAreaView>
</Fragment>
);
};
Expand Down
2 changes: 1 addition & 1 deletion example/react-native/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ROOT = $(PWD)/../../
BUILD_DIR_IOS = $(PWD)/ios/framework
BUILD_DIR_IOS = $(PWD)/ios/Frameworks
BUILD_DIR_ANDROID = $(PWD)/android/app/libs/ipfs

build.go: build.go.ios build.go.android
Expand Down
6 changes: 6 additions & 0 deletions example/react-native/ios/ipfs-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "React/RCTBridge.h"
#import <ipfs/Mobile.h>

0 comments on commit 047addf

Please sign in to comment.