move open url into bottom sheet
This commit is contained in:
@@ -211,7 +211,7 @@ class OpenSharedContentRoute extends GoRouteData with $OpenSharedContentRoute {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Page<void> buildPage(BuildContext context, GoRouterState state) {
|
Page<void> buildPage(BuildContext context, GoRouterState state) {
|
||||||
return DialogPage(
|
return BottomSheetPage(
|
||||||
builder: (_) => OpenSharedContent(
|
builder: (_) => OpenSharedContent(
|
||||||
sharedUrl: Uri.tryParse(sharedUrl) ?? Uri.parse('about:blank'),
|
sharedUrl: Uri.tryParse(sharedUrl) ?? Uri.parse('about:blank'),
|
||||||
),
|
),
|
||||||
|
|||||||
+86
-28
@@ -17,16 +17,18 @@
|
|||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart' hide Column;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
|
||||||
|
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart'
|
||||||
|
show GeckoBrowserService;
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:weblibre/core/design/app_colors.dart';
|
||||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
|
import 'package:weblibre/features/geckoview/features/tabs/data/models/container_data.dart';
|
||||||
import 'package:weblibre/features/geckoview/features/tabs/presentation/widgets/container_chips.dart';
|
import 'package:weblibre/features/geckoview/features/tabs/presentation/widgets/container_chips.dart';
|
||||||
import 'package:weblibre/presentation/icons/weblibre_icons.dart';
|
|
||||||
import 'package:weblibre/utils/form_validators.dart';
|
import 'package:weblibre/utils/form_validators.dart';
|
||||||
|
|
||||||
class OpenSharedContent extends HookConsumerWidget {
|
class OpenSharedContent extends HookConsumerWidget {
|
||||||
@@ -38,6 +40,7 @@ class OpenSharedContent extends HookConsumerWidget {
|
|||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final formKey = useMemoized(() => GlobalKey<FormState>());
|
final formKey = useMemoized(() => GlobalKey<FormState>());
|
||||||
final textController = useTextEditingController(text: sharedUrl.toString());
|
final textController = useTextEditingController(text: sharedUrl.toString());
|
||||||
|
final appColors = AppColors.of(context);
|
||||||
|
|
||||||
final selectedContainer = useState<ContainerData?>(null);
|
final selectedContainer = useState<ContainerData?>(null);
|
||||||
|
|
||||||
@@ -59,16 +62,32 @@ class OpenSharedContent extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Form(
|
Future<void> openCustomTab(bool isPrivate) async {
|
||||||
|
if (formKey.currentState?.validate() == true) {
|
||||||
|
await GeckoBrowserService().openInCustomTab(
|
||||||
|
url: Uri.parse(textController.text),
|
||||||
|
private: isPrivate,
|
||||||
|
contextId: selectedContainer.value?.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
context.pop(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SafeArea(
|
||||||
|
child: Form(
|
||||||
key: formKey,
|
key: formKey,
|
||||||
child: SimpleDialog(
|
child: Padding(
|
||||||
title: const Text('Open URL'),
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Text('Open link', style: Theme.of(context).textTheme.titleLarge),
|
||||||
padding: const EdgeInsetsDirectional.symmetric(horizontal: 16.0),
|
const SizedBox(height: 16),
|
||||||
child: SizedBox(
|
ContainerChips(
|
||||||
width: double.maxFinite,
|
|
||||||
child: ContainerChips(
|
|
||||||
displayMenu: false,
|
displayMenu: false,
|
||||||
selectedContainer: selectedContainer.value,
|
selectedContainer: selectedContainer.value,
|
||||||
onSelected: (container) {
|
onSelected: (container) {
|
||||||
@@ -78,11 +97,7 @@ class OpenSharedContent extends HookConsumerWidget {
|
|||||||
selectedContainer.value = null;
|
selectedContainer.value = null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
TextFormField(
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsetsDirectional.symmetric(horizontal: 16.0),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: textController,
|
controller: textController,
|
||||||
keyboardType: TextInputType.url,
|
keyboardType: TextInputType.url,
|
||||||
minLines: 1,
|
minLines: 1,
|
||||||
@@ -91,23 +106,66 @@ class OpenSharedContent extends HookConsumerWidget {
|
|||||||
return validateUrl(value, eagerParsing: false);
|
return validateUrl(value, eagerParsing: false);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_OpenActionTile(
|
||||||
|
title: 'Open in new tab',
|
||||||
|
subtitle: 'Add to your browser tabs',
|
||||||
|
icon: MdiIcons.tab,
|
||||||
|
privateColor: appColors.privateTabPurple,
|
||||||
|
onTap: () => openTab(false),
|
||||||
|
onPrivateTap: () => openTab(true),
|
||||||
),
|
),
|
||||||
ListTile(
|
_OpenActionTile(
|
||||||
title: const Text('Open Regular Tab'),
|
title: 'Open in custom tab',
|
||||||
leading: const Icon(MdiIcons.tab),
|
subtitle: 'Open in a separate window',
|
||||||
onTap: () async {
|
icon: MdiIcons.applicationOutline,
|
||||||
await openTab(false);
|
privateColor: appColors.privateTabPurple,
|
||||||
},
|
onTap: () => openCustomTab(false),
|
||||||
),
|
onPrivateTap: () => openCustomTab(true),
|
||||||
ListTile(
|
|
||||||
title: const Text('Open Private Tab'),
|
|
||||||
leading: const Icon(WebLibreIcons.privateTab),
|
|
||||||
onTap: () async {
|
|
||||||
await openTab(true);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _OpenActionTile extends StatelessWidget {
|
||||||
|
final String title;
|
||||||
|
final String? subtitle;
|
||||||
|
final IconData icon;
|
||||||
|
final Color privateColor;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
final VoidCallback onPrivateTap;
|
||||||
|
|
||||||
|
const _OpenActionTile({
|
||||||
|
required this.title,
|
||||||
|
this.subtitle,
|
||||||
|
required this.icon,
|
||||||
|
required this.privateColor,
|
||||||
|
required this.onTap,
|
||||||
|
required this.onPrivateTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(title),
|
||||||
|
subtitle: subtitle != null ? Text(subtitle!) : null,
|
||||||
|
leading: Icon(icon),
|
||||||
|
trailing: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 24, child: VerticalDivider(width: 16)),
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(MdiIcons.dominoMask, color: privateColor, size: 24),
|
||||||
|
tooltip: 'Private',
|
||||||
|
onPressed: onPrivateTap,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: onTap,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ final class UserBackupServiceProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _$userBackupServiceHash() => r'a0bcf458e6b0a982f1fc90fce99e60cc3418f4d9';
|
String _$userBackupServiceHash() => r'fb0b29075da3b32135d6309ef1bb7a7f119a3e25';
|
||||||
|
|
||||||
abstract class _$UserBackupService extends $Notifier<void> {
|
abstract class _$UserBackupService extends $Notifier<void> {
|
||||||
void build();
|
void build();
|
||||||
|
|||||||
+33
@@ -14,6 +14,7 @@ import eu.weblibre.flutter_mozilla_components.BrowserFragment
|
|||||||
import eu.weblibre.flutter_mozilla_components.GeckoViewFactory
|
import eu.weblibre.flutter_mozilla_components.GeckoViewFactory
|
||||||
import eu.weblibre.flutter_mozilla_components.GlobalComponents
|
import eu.weblibre.flutter_mozilla_components.GlobalComponents
|
||||||
import eu.weblibre.flutter_mozilla_components.ProfileContext
|
import eu.weblibre.flutter_mozilla_components.ProfileContext
|
||||||
|
import eu.weblibre.flutter_mozilla_components.activities.ExternalAppBrowserActivity
|
||||||
import eu.weblibre.flutter_mozilla_components.activities.NotificationActivity
|
import eu.weblibre.flutter_mozilla_components.activities.NotificationActivity
|
||||||
import eu.weblibre.flutter_mozilla_components.feature.DefaultSelectionActionDelegate
|
import eu.weblibre.flutter_mozilla_components.feature.DefaultSelectionActionDelegate
|
||||||
import eu.weblibre.flutter_mozilla_components.pigeons.AddonCollection
|
import eu.weblibre.flutter_mozilla_components.pigeons.AddonCollection
|
||||||
@@ -58,7 +59,11 @@ import eu.weblibre.flutter_mozilla_components.pigeons.ReaderViewController
|
|||||||
import eu.weblibre.flutter_mozilla_components.pigeons.ReaderViewEvents
|
import eu.weblibre.flutter_mozilla_components.pigeons.ReaderViewEvents
|
||||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||||
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding
|
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding
|
||||||
|
import mozilla.components.browser.state.action.CustomTabListAction
|
||||||
import mozilla.components.browser.state.action.SystemAction
|
import mozilla.components.browser.state.action.SystemAction
|
||||||
|
import mozilla.components.browser.state.state.CustomTabConfig
|
||||||
|
import mozilla.components.browser.state.state.SessionState
|
||||||
|
import mozilla.components.browser.state.state.createCustomTab
|
||||||
import mozilla.components.feature.addons.logger
|
import mozilla.components.feature.addons.logger
|
||||||
import mozilla.components.support.base.ext.getStacktraceAsString
|
import mozilla.components.support.base.ext.getStacktraceAsString
|
||||||
import mozilla.components.support.base.log.Log
|
import mozilla.components.support.base.log.Log
|
||||||
@@ -386,4 +391,32 @@ class GeckoBrowserApiImpl : GeckoBrowserApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun openInCustomTab(url: String, `private`: Boolean, contextId: String?) {
|
||||||
|
val currentActivity = requireNotNull(activity) { "Activity not attached" }
|
||||||
|
|
||||||
|
val customTabConfig = CustomTabConfig()
|
||||||
|
|
||||||
|
val tab = createCustomTab(
|
||||||
|
url = url,
|
||||||
|
contextId = contextId,
|
||||||
|
config = customTabConfig,
|
||||||
|
source = SessionState.Source.Internal.CustomTab,
|
||||||
|
private = `private`,
|
||||||
|
)
|
||||||
|
|
||||||
|
components.core.store.dispatch(
|
||||||
|
CustomTabListAction.AddCustomTabAction(tab)
|
||||||
|
)
|
||||||
|
|
||||||
|
components.useCases.sessionUseCases.loadUrl(url, tab.id)
|
||||||
|
|
||||||
|
val intent = ExternalAppBrowserActivity.createIntent(
|
||||||
|
context = currentActivity,
|
||||||
|
customTabSessionId = tab.id,
|
||||||
|
)
|
||||||
|
currentActivity.startActivity(intent)
|
||||||
|
|
||||||
|
logger.debug("$TAG: Opened custom tab ${tab.id} for $url (private=$`private`)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
@@ -4394,6 +4394,7 @@ interface GeckoBrowserApi {
|
|||||||
fun initialize(profileFolder: String, logLevel: LogLevel, contentBlocking: ContentBlocking, addonCollection: AddonCollection?, fxaServerOverride: String?, syncTokenServerOverride: String?)
|
fun initialize(profileFolder: String, logLevel: LogLevel, contentBlocking: ContentBlocking, addonCollection: AddonCollection?, fxaServerOverride: String?, syncTokenServerOverride: String?)
|
||||||
fun showNativeFragment(): Boolean
|
fun showNativeFragment(): Boolean
|
||||||
fun onTrimMemory(level: Long)
|
fun onTrimMemory(level: Long)
|
||||||
|
fun openInCustomTab(url: String, private: Boolean, contextId: String?)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/** The codec used by GeckoBrowserApi. */
|
/** The codec used by GeckoBrowserApi. */
|
||||||
@@ -4475,6 +4476,26 @@ interface GeckoBrowserApi {
|
|||||||
channel.setMessageHandler(null)
|
channel.setMessageHandler(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
run {
|
||||||
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_mozilla_components.GeckoBrowserApi.openInCustomTab$separatedMessageChannelSuffix", codec)
|
||||||
|
if (api != null) {
|
||||||
|
channel.setMessageHandler { message, reply ->
|
||||||
|
val args = message as List<Any?>
|
||||||
|
val urlArg = args[0] as String
|
||||||
|
val privateArg = args[1] as Boolean
|
||||||
|
val contextIdArg = args[2] as String?
|
||||||
|
val wrapped: List<Any?> = try {
|
||||||
|
api.openInCustomTab(urlArg, privateArg, contextIdArg)
|
||||||
|
listOf(null)
|
||||||
|
} catch (exception: Throwable) {
|
||||||
|
GeckoPigeonUtils.wrapError(exception)
|
||||||
|
}
|
||||||
|
reply.reply(wrapped)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
channel.setMessageHandler(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,4 +42,16 @@ class GeckoBrowserService {
|
|||||||
Future<void> onTrimMemory(int level) {
|
Future<void> onTrimMemory(int level) {
|
||||||
return _api.onTrimMemory(level);
|
return _api.onTrimMemory(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> openInCustomTab({
|
||||||
|
required Uri url,
|
||||||
|
required bool private,
|
||||||
|
String? contextId,
|
||||||
|
}) {
|
||||||
|
return _api.openInCustomTab(
|
||||||
|
url: url.toString(),
|
||||||
|
private: private,
|
||||||
|
contextId: contextId,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5160,6 +5160,28 @@ class GeckoBrowserApi {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> openInCustomTab({required String url, required bool private, required String? contextId, }) async {
|
||||||
|
final pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoBrowserApi.openInCustomTab$pigeonVar_messageChannelSuffix';
|
||||||
|
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||||
|
pigeonVar_channelName,
|
||||||
|
pigeonChannelCodec,
|
||||||
|
binaryMessenger: pigeonVar_binaryMessenger,
|
||||||
|
);
|
||||||
|
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[url, private, contextId]);
|
||||||
|
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||||
|
if (pigeonVar_replyList == null) {
|
||||||
|
throw _createConnectionError(pigeonVar_channelName);
|
||||||
|
} else if (pigeonVar_replyList.length > 1) {
|
||||||
|
throw PlatformException(
|
||||||
|
code: pigeonVar_replyList[0]! as String,
|
||||||
|
message: pigeonVar_replyList[1] as String?,
|
||||||
|
details: pigeonVar_replyList[2],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GeckoSyncApi {
|
class GeckoSyncApi {
|
||||||
|
|||||||
@@ -1003,6 +1003,11 @@ abstract class GeckoBrowserApi {
|
|||||||
);
|
);
|
||||||
bool showNativeFragment();
|
bool showNativeFragment();
|
||||||
void onTrimMemory(int level);
|
void onTrimMemory(int level);
|
||||||
|
void openInCustomTab({
|
||||||
|
required String url,
|
||||||
|
required bool private,
|
||||||
|
required String? contextId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SyncEngineValue { history, bookmarks, tabs }
|
enum SyncEngineValue { history, bookmarks, tabs }
|
||||||
|
|||||||
Reference in New Issue
Block a user