Skip to content

Commit

Permalink
Added WNFS check to isReady
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Jan 3, 2023
1 parent db4ca57 commit 80b587c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ await fula.mv(
//checks if fula is ready (initialized through newClient or init)
const result //returns true if succesful and false if fails
=
await fula.isReady();
await fula.isReady(
filesystemCheck: boolean //Default is true. If true it checks if both WNFS and Fula are ready. If false it only checks fula
);

```

Expand Down
10 changes: 8 additions & 2 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,19 @@ public void newClient(String identityString, String storePath, String bloxAddr,
}

@ReactMethod
public void isReady(Promise promise) {
public void isReady(boolean filesystemCheck, Promise promise) {
Log.d("ReactNative", "isReady started");
ThreadUtils.runOnExecutor(() -> {
boolean initialized = false;
try {
if (this.fula != null && this.fula.id() != null) {
initialized = true;
if (filesystemCheck) {
if (this.client != null && this.rootConfig != null && !this.rootConfig.getCid().isEmpty()) {
initialized = true;
}
} else {
initialized = true;
}
}
promise.resolve(initialized);
} catch (Exception e) {
Expand Down
5 changes: 3 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ const App = () => {
94, 225, 7, 153, 168, 239, 94, 7, 187, 123, 158, 149, 149, 227, 170, 32, 54,
203, 243, 211, 78, 120, 114, 199, 1, 197, 134, 6, 91, 87, 152,
];
const bloxAddr = '/dns/relay.dev.fx.land/tcp/4001/p2p/12D3KooWDRrBaAfPwsGJivBoUw5fE7ZpDiyfUjqgiURq2DEcL835/p2p-circuit/p2p/12D3KooWR2EiA8DbULqDAJZCcN2V2Nasmh756R1aLe5t3NniCnAS';
const newClient = async () => {
try {
return fula.newClient(
privateKey.toString(),
'',
'/ip4/192.168.2.14/tcp/40001/p2p/12D3KooWBdzmgXe9uyYoxaeLLKTLWM7mG3ZtBiKHAnSVxtrVJc2A',
bloxAddr,
''
);
} catch (e) {
Expand All @@ -55,7 +56,7 @@ const App = () => {
return fula.init(
privateKey.toString(),
'',
'/ip4/192.168.2.14/tcp/40001/p2p/12D3KooWBdzmgXe9uyYoxaeLLKTLWM7mG3ZtBiKHAnSVxtrVJc2A',
bloxAddr,
''
);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface FulaNativeModule {
exchange: string, //set to 'noope' for testing
autoFlush: boolean //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write
) => Promise<string>;
isReady: () => Promise<boolean>;
isReady: (filesystemCheck: boolean) => Promise<boolean>;
logout: (identity: string, storePath: string) => Promise<boolean>;
checkFailedActions: (retry: boolean) => Promise<boolean>;
checkConnection: () => Promise<boolean>;
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/fula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,6 @@ export const shutdown = (): Promise<void> => {
* @param path
* @returns string: new cid of the root
*/
export const isReady = (): Promise<boolean> => {
return Fula.isReady();
export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
return Fula.isReady(filesystemCheck);
};

0 comments on commit 80b587c

Please sign in to comment.