:drunk: Werid miniapp runtime
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/modular/miniapp_loader.dart';
|
||||
import 'package:island/pods/message.dart';
|
||||
import 'package:island/pods/network.dart';
|
||||
import 'package:island/pods/plugin_registry.dart';
|
||||
import 'package:island/services/update_service.dart';
|
||||
import 'package:island/widgets/alert.dart';
|
||||
import 'package:island/widgets/content/network_status_sheet.dart';
|
||||
import 'package:island/widgets/content/sheet.dart';
|
||||
import 'package:island/widgets/miniapp_modal.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:island/pods/config.dart';
|
||||
import 'package:talker_flutter/talker_flutter.dart';
|
||||
@@ -196,9 +202,136 @@ class DebugSheet extends HookConsumerWidget {
|
||||
DefaultCacheManager().emptyCache();
|
||||
},
|
||||
),
|
||||
const Divider(height: 8),
|
||||
if (!kIsWeb &&
|
||||
(Platform.isMacOS || Platform.isWindows || Platform.isLinux))
|
||||
ListTile(
|
||||
minTileHeight: 48,
|
||||
leading: const Icon(Symbols.file_upload),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 24),
|
||||
title: Text('Load Miniapp from File'),
|
||||
onTap: () async {
|
||||
await MiniappLoader.loadMiniappFromSource(context, ref);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
minTileHeight: 48,
|
||||
leading: const Icon(Symbols.download),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 24),
|
||||
title: Text('Load Miniapp from URL'),
|
||||
onTap: () async {
|
||||
await _showLoadFromUrlDialog(context, ref);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
minTileHeight: 48,
|
||||
leading: const Icon(Symbols.play_circle),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 24),
|
||||
title: Text('Launch Miniapp'),
|
||||
onTap: () async {
|
||||
await _showMiniappSelector(context, ref);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showLoadFromUrlDialog(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
) async {
|
||||
final TextEditingController controller = TextEditingController();
|
||||
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Load Miniapp from URL'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Enter .evc file URL',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
),
|
||||
),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Load'),
|
||||
onPressed: () async {
|
||||
final url = controller.text.trim();
|
||||
if (url.isNotEmpty) {
|
||||
Navigator.of(context).pop();
|
||||
showLoadingModal(context);
|
||||
await MiniappLoader.loadMiniappFromUrl(context, ref, url);
|
||||
if (context.mounted) {
|
||||
hideLoadingModal(context);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showMiniappSelector(BuildContext context, WidgetRef ref) async {
|
||||
final registry = ref.read(pluginRegistryProvider);
|
||||
final miniapps = registry.miniApps.values.toList();
|
||||
|
||||
if (miniapps.isEmpty) {
|
||||
showErrorAlert('No miniapps loaded');
|
||||
return;
|
||||
}
|
||||
|
||||
final selectedId = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Select Miniapp'),
|
||||
content: SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: miniapps.length,
|
||||
itemBuilder: (context, index) {
|
||||
final miniapp = miniapps[index];
|
||||
return ListTile(
|
||||
title: Text(miniapp.metadata.name),
|
||||
subtitle: Text(miniapp.metadata.description),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop(miniapp.metadata.id);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (selectedId != null && context.mounted) {
|
||||
await showMiniappModal(context, ref, selectedId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user