mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-16 06:36:44 +02:00
JSON import link support (#368)
This commit is contained in:
@ -34,8 +34,7 @@
|
|||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
<data android:scheme="obtainium"
|
<data android:scheme="obtainium" />
|
||||||
android:host="add" />
|
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
@ -5,6 +5,7 @@ import 'package:app_links/app_links.dart';
|
|||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:obtainium/custom_errors.dart';
|
||||||
import 'package:obtainium/pages/add_app.dart';
|
import 'package:obtainium/pages/add_app.dart';
|
||||||
import 'package:obtainium/pages/apps.dart';
|
import 'package:obtainium/pages/apps.dart';
|
||||||
import 'package:obtainium/pages/import_export.dart';
|
import 'package:obtainium/pages/import_export.dart';
|
||||||
@ -55,7 +56,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
Future<void> initDeepLinks() async {
|
Future<void> initDeepLinks() async {
|
||||||
_appLinks = AppLinks();
|
_appLinks = AppLinks();
|
||||||
|
|
||||||
goToAddApp(Uri uri) async {
|
goToAddApp(String data) async {
|
||||||
switchToPage(1);
|
switchToPage(1);
|
||||||
while (
|
while (
|
||||||
(pages[1].widget.key as GlobalKey<AddAppPageState>?)?.currentState ==
|
(pages[1].widget.key as GlobalKey<AddAppPageState>?)?.currentState ==
|
||||||
@ -64,18 +65,40 @@ class _HomePageState extends State<HomePage> {
|
|||||||
}
|
}
|
||||||
(pages[1].widget.key as GlobalKey<AddAppPageState>?)
|
(pages[1].widget.key as GlobalKey<AddAppPageState>?)
|
||||||
?.currentState
|
?.currentState
|
||||||
?.linkFn(uri.path.length > 1 ? uri.path.substring(1) : "");
|
?.linkFn(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
interpretLink(Uri uri) async {
|
||||||
|
var action = uri.host;
|
||||||
|
var data = uri.path.length > 1 ? uri.path.substring(1) : "";
|
||||||
|
try {
|
||||||
|
if (action == 'add') {
|
||||||
|
await goToAddApp(data);
|
||||||
|
} else if (action == 'app') {
|
||||||
|
await context
|
||||||
|
.read<AppsProvider>()
|
||||||
|
.importApps('[${Uri.decodeComponent(data)}]');
|
||||||
|
} else if (action == 'apps') {
|
||||||
|
await context
|
||||||
|
.read<AppsProvider>()
|
||||||
|
.importApps(Uri.decodeComponent(data));
|
||||||
|
} else {
|
||||||
|
throw ObtainiumError(tr('unknown'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
showError(e, context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check initial link if app was in cold state (terminated)
|
// Check initial link if app was in cold state (terminated)
|
||||||
final appLink = await _appLinks.getInitialAppLink();
|
final appLink = await _appLinks.getInitialAppLink();
|
||||||
if (appLink != null) {
|
if (appLink != null) {
|
||||||
await goToAddApp(appLink);
|
await interpretLink(appLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle link when app is in warm state (front or background)
|
// Handle link when app is in warm state (front or background)
|
||||||
_linkSubscription = _appLinks.uriLinkStream.listen((uri) async {
|
_linkSubscription = _appLinks.uriLinkStream.listen((uri) async {
|
||||||
await goToAddApp(uri);
|
await interpretLink(uri);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user