Skip to content

Commit

Permalink
Removes deep link logic, moves widget updating to 'itemChange' events
Browse files Browse the repository at this point in the history
  • Loading branch information
fstanis committed Nov 20, 2021
1 parent a90e029 commit d1ebb36
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ packages/app-mobile/utils/shareHandler.js
packages/app-mobile/utils/shareHandler.js.map
packages/app-mobile/utils/RecentsWidget.js
packages/app-mobile/utils/RecentsWidget.js.map
packages/app-mobile/utils/updateRecentsWidget.js
packages/app-mobile/utils/updateRecentsWidget.js.map
packages/app-mobile/utils/WidgetUtils.js
packages/app-mobile/utils/WidgetUtils.js.map
packages/fork-htmlparser2/src/CollectingHandler.d.ts
packages/fork-htmlparser2/src/CollectingHandler.js
packages/fork-htmlparser2/src/CollectingHandler.js.map
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,8 @@ packages/app-mobile/utils/shareHandler.js
packages/app-mobile/utils/shareHandler.js.map
packages/app-mobile/utils/RecentsWidget.js
packages/app-mobile/utils/RecentsWidget.js.map
packages/app-mobile/utils/updateRecentsWidget.js
packages/app-mobile/utils/updateRecentsWidget.js.map
packages/app-mobile/utils/WidgetUtils.js
packages/app-mobile/utils/WidgetUtils.js.map
packages/fork-htmlparser2/src/CollectingHandler.d.ts
packages/fork-htmlparser2/src/CollectingHandler.js
packages/fork-htmlparser2/src/CollectingHandler.js.map
Expand Down
6 changes: 0 additions & 6 deletions packages/app-mobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="joplin" />
</intent-filter>
</activity>

<receiver android:name=".widgets.recents.RecentsWidgetProvider">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RecentsWidgetProvider extends AppWidgetProvider {
private static final int listViewId = R.id.list_view;

private void handleClick(Context context, String noteId) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("joplin://notes/" + noteId));
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("joplin://x-callback-url/openNote?id=" + noteId));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
Expand Down
51 changes: 12 additions & 39 deletions packages/app-mobile/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import setupQuickActions from './setupQuickActions';
import PluginAssetsLoader from './PluginAssetsLoader';
import AlarmService from '@joplin/lib/services/AlarmService';
import Alarm from '@joplin/lib/models/Alarm';
import eventManager from '@joplin/lib/eventManager';
import time from '@joplin/lib/time';
import Logger, { TargetType } from '@joplin/lib/Logger';
import BaseModel from '@joplin/lib/BaseModel';
import BaseModel, { ModelType } from '@joplin/lib/BaseModel';
import BaseService from '@joplin/lib/services/BaseService';
import ResourceService from '@joplin/lib/services/ResourceService';
import KvStore from '@joplin/lib/services/KvStore';
Expand All @@ -20,7 +21,7 @@ import PoorManIntervals from '@joplin/lib/PoorManIntervals';
import reducer from '@joplin/lib/reducer';
import ShareExtension from './utils/ShareExtension';
import handleShared from './utils/shareHandler';
import updateRecentsWidget from './utils/updateRecentsWidget';
import { updateRecentsWidgetWithDebounce } from './utils/WidgetUtils';
import uuid from '@joplin/lib/uuid';
import { loadKeychainServiceAndSettings } from '@joplin/lib/services/SettingUtils';
import KeychainServiceDriverMobile from '@joplin/lib/services/keychain/KeychainServiceDriver.mobile';
Expand Down Expand Up @@ -699,8 +700,6 @@ class AppComponent extends React.Component {
this.handleOpenURL_ = (event: any) => {
if (event.url == ShareExtension.shareURL) {
void this.handleShareData();
} else {
void this.navigate(event.url);
}
};
}
Expand Down Expand Up @@ -755,10 +754,10 @@ class AppComponent extends React.Component {
});
}

Linking.getInitialURL().then((url: string) => this.navigate(url));

Linking.addEventListener('url', this.handleOpenURL_);

eventManager.on('itemChange', this.onItemChange_);

BackButtonService.initialize(this.backButtonHandler_);

AlarmService.setInAppNotificationHandler(async (alarmId: string) => {
Expand All @@ -775,8 +774,6 @@ class AppComponent extends React.Component {

await setupNotifications(this.props.dispatch);

await updateRecentsWidget();

// Setting.setValue('encryption.masterPassword', 'WRONG');
// setTimeout(() => NavService.go('EncryptionConfig'), 2000);
}
Expand Down Expand Up @@ -817,6 +814,13 @@ class AppComponent extends React.Component {
return false;
}

private onItemChange_({ itemType }: {itemType: ModelType}) {
if (itemType !== ModelType.Note) {
return;
}
updateRecentsWidgetWithDebounce();
}

private async handleShareData() {
const sharedData = await ShareExtension.data();
if (sharedData) {
Expand Down Expand Up @@ -903,37 +907,6 @@ class AppComponent extends React.Component {
</View>
);
}

private async navigate(url: string) {
if (!url) return;
let parsedUrl;
try {
parsedUrl = new URL(url);
} catch (_) {
// invalid URL
return;
}
reg.logger().info(`navigate to ${url}`);

await this.props.dispatch({ type: 'NAV_BACK' });
await this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
const { pathname } = parsedUrl;
if (pathname.startsWith('//notes/')) {
const noteId = pathname.replace('//notes/', '');
await this.props.dispatch({
type: 'NAV_GO',
noteId,
routeName: 'Note',
});
} else if (pathname.startsWith('//folder/')) {
const folderId = pathname.replace('//folder/', '');
await this.props.dispatch({
type: 'NAV_GO',
folderId,
routeName: 'Folder',
});
}
}
}

const mapStateToProps = (state: any) => {
Expand Down
32 changes: 32 additions & 0 deletions packages/app-mobile/utils/WidgetUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { RecentsWidget } from './RecentsWidget';
import Note from '@joplin/lib/models/Note';
import { reg } from '@joplin/lib/registry';
import shim from '@joplin/lib/shim';

const MAX_COUNT = 10;
const DEBOUNCE_TIMEOUT = 5000;

export async function updateRecentsWidget() {
reg.logger().info('updating recents widget');
const recents = await Note.all({
fields: ['id', 'title'],
order: [{ by: 'updated_time', dir: 'DESC' }],
limit: MAX_COUNT,
});
return RecentsWidget.write({
notes: recents,
});
}

let hasUpdateScheduled = false;

export function updateRecentsWidgetWithDebounce() {
if (hasUpdateScheduled) {
return;
}
hasUpdateScheduled = true;
shim.setTimeout(async () => {
await updateRecentsWidget();
hasUpdateScheduled = false;
}, DEBOUNCE_TIMEOUT);
}
15 changes: 0 additions & 15 deletions packages/app-mobile/utils/updateRecentsWidget.ts

This file was deleted.

0 comments on commit d1ebb36

Please sign in to comment.