Skip to content

Commit

Permalink
Android: Fixes #7691: Sharing file to Joplin does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Feb 10, 2023
1 parent 02e8307 commit a1a10a6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
17 changes: 16 additions & 1 deletion packages/app-mobile/components/biometrics/BiometricPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { _ } from '@joplin/lib/locale';
interface Props {
themeId: number;
sensorInfo: SensorInfo;
dispatch: Function;
}

export default (props: Props) => {
Expand Down Expand Up @@ -49,6 +50,11 @@ export default (props: Props) => {
} else {
setTryBiometricsCheck(true);
}

props.dispatch({
type: 'BIOMETRICS_DONE_SET',
value: true,
});
};

Alert.alert(
Expand All @@ -67,7 +73,7 @@ export default (props: Props) => {
},
]
);
}, [initialPromptDone, props.sensorInfo.supportedSensors, display]);
}, [initialPromptDone, props.sensorInfo.supportedSensors, display, props.dispatch]);

const windowSize = useMemo(() => {
return {
Expand All @@ -76,6 +82,15 @@ export default (props: Props) => {
};
}, []);

useEffect(() => {
if (!display) {
props.dispatch({
type: 'BIOMETRICS_DONE_SET',
value: true,
});
}
}, [display, props.dispatch]);

const renderTryAgainButton = () => {
if (!display || tryBiometricsCheck || !initialPromptDone) return null;
return <Button title={_('Try again')} onPress={() => setTryBiometricsCheck(true)} />;
Expand Down
17 changes: 12 additions & 5 deletions packages/app-mobile/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,10 @@ class AppComponent extends React.Component {
};

this.handleOpenURL_ = (event: any) => {
if (event.url === ShareExtension.shareURL) {
// If this is called while biometrics haven't been done yet, we can
// ignore the call, because handleShareData() will be called once
// biometricsDone is `true`.
if (event.url === ShareExtension.shareURL && this.props.biometricsDone) {
void this.handleShareData();
}
};
Expand Down Expand Up @@ -812,8 +815,6 @@ class AppComponent extends React.Component {
this.appStateChangeListener_ = RNAppState.addEventListener('change', this.onAppStateChange_);
this.unsubscribeScreenWidthChangeHandler_ = Dimensions.addEventListener('change', this.handleScreenWidthChange_);

await this.handleShareData();

setupQuickActions(this.props.dispatch, this.props.selectedFolderId);

await setupNotifications(this.props.dispatch);
Expand Down Expand Up @@ -848,6 +849,10 @@ class AppComponent extends React.Component {
duration: 600,
}).start();
}

if (this.props.biometricsDone !== prevProps.biometricsDone && this.props.biometricsDone) {
void this.handleShareData();
}
}

private async backButtonHandler() {
Expand Down Expand Up @@ -973,10 +978,11 @@ class AppComponent extends React.Component {
</View>
<DropdownAlert ref={(ref: any) => this.dropdownAlert_ = ref} tapToCloseEnabled={true} />
<Animated.View pointerEvents='none' style={{ position: 'absolute', backgroundColor: 'black', opacity: this.state.sideMenuContentOpacity, width: '100%', height: '120%' }}/>
<BiometricPopup
{ this.state.sensorInfo && <BiometricPopup
dispatch={this.props.dispatch}
themeId={this.props.themeId}
sensorInfo={this.state.sensorInfo}
/>
/> }
</SafeAreaView>
</MenuContext>
</SideMenu>
Expand Down Expand Up @@ -1017,6 +1023,7 @@ const mapStateToProps = (state: any) => {
routeName: state.route.routeName,
themeId: state.settings.theme,
noteSideMenuOptions: state.noteSideMenuOptions,
biometricsDone: state.biometricsDone,
};
};

Expand Down
6 changes: 6 additions & 0 deletions packages/lib/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface State {
settings: any;
sharedData: any;
appState: string;
biometricsDone: boolean;
hasDisabledSyncItems: boolean;
hasDisabledEncryptionItems: boolean;
customCss: string;
Expand Down Expand Up @@ -134,6 +135,7 @@ export const defaultState: State = {
settings: {},
sharedData: null,
appState: 'starting',
biometricsDone: false,
hasDisabledSyncItems: false,
hasDisabledEncryptionItems: false,
customCss: '',
Expand Down Expand Up @@ -1086,6 +1088,10 @@ const reducer = produce((draft: Draft<State> = defaultState, action: any) => {
draft.appState = action.state;
break;

case 'BIOMETRICS_DONE_SET':
draft.biometricsDone = action.value;
break;

case 'SYNC_HAS_DISABLED_SYNC_ITEMS':
draft.hasDisabledSyncItems = true;
break;
Expand Down

0 comments on commit a1a10a6

Please sign in to comment.