Skip to content

Commit

Permalink
update jstool
Browse files Browse the repository at this point in the history
  • Loading branch information
laiiihz committed Sep 25, 2023
1 parent 965b952 commit d9257c1
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 94 deletions.
2 changes: 1 addition & 1 deletion lib/tools/info/device_info/device_info.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FutureOr<List<Part>> deviceInfoParts(DeviceInfoPartsRef ref) async {
case TargetPlatform.linux:
return Part.fromLinux(await p.linuxInfo);
case TargetPlatform.macOS:
return Part.fromWindows(await p.windowsInfo);
return Part.fromMacos(await p.macOsInfo);
case TargetPlatform.windows:
return Part.fromWindows(await p.windowsInfo);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tools/info/device_info/device_info.provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions lib/tools/js_tools/quick_js_tool/quick_js.provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:flutter_js/flutter_js.dart';
part 'quick_js.provider.g.dart';

sealed class JsContent {
const JsContent(this.value);

final String value;
}

class InContent extends JsContent {
const InContent(super.value);
}

class OutContent extends JsContent {
const OutContent(super.value);
}

@Riverpod(keepAlive: true)
JavascriptRuntime jsEngine(JsEngineRef ref) {
return getJavascriptRuntime();
}

@riverpod
class JsContents extends _$JsContents {
@override
List<JsContent> build() => [];

void exec(String content) async {
final engine = ref.watch(jsEngineProvider);
state = [InContent(content), ...state];
final result = await engine.evaluateAsync(content);
state = [OutContent(result.stringResult), ...state];
}

clear() {
state = [];
}
}

@riverpod
TextEditingController jsInputController(JsInputControllerRef ref) {
final controller = TextEditingController();
ref.onDispose(controller.dispose);
return controller;
}
55 changes: 55 additions & 0 deletions lib/tools/js_tools/quick_js_tool/quick_js.provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions lib/tools/js_tools/quick_js_tool/quick_js_provider.dart

This file was deleted.

84 changes: 38 additions & 46 deletions lib/tools/js_tools/quick_js_tool/quick_js_view.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,48 @@
import 'package:alga/tools/js_tools/quick_js_tool/quick_js.provider.dart';
import 'package:alga/ui/widgets/scaffold/tool_scaffold.dart';
import 'package:alga/utils/constants/import_helper.dart';

part './quick_js_provider.dart';

class QuickJsView extends StatelessWidget {
class QuickJsView extends ConsumerWidget {
const QuickJsView({super.key});

@override
Widget build(BuildContext context) {
return ScrollableToolView(
title: const Text('Quick JS Tool'),
children: [
AppTitleWrapper(
title: S.of(context).input,
actions: [
// PasteButton(
// onPaste: (ref, data) {
// ref.watch(_input).text = data;
// return ref.refresh(_result);
// },
// ),
],
child: const SizedBox(),
// child: Consumer(builder: (context, ref, _) {
// return LangTextField(
// controller: ref.watch(_input),
// lang: LangHighlightType.js,
// minLines: 2,
// maxLines: 12,
// );
// }),
),
// Consumer(builder: (context, ref, _) {
// return ElevatedButton(
// onPressed: () {
// return ref.refresh(_result);
// },
// child: const Text('RUN'),
// );
// }),
AppTitleWrapper(
title: S.of(context).output,
actions: [
// CopyButton(onCopy: (ref) {
// return ref.watch(_result);
// }),
Widget build(BuildContext context, WidgetRef ref) {
final items = ref.watch(jsContentsProvider);
return ToolScaffold(
title: Text(context.tr.jsTools),
body: ListView.builder(
itemBuilder: (context, index) {
final item = items[index];
return ListTile(
title: Text(item.value),
leading: item is InContent ? const Icon(Icons.arrow_right) : null,
selected: item is InContent,
);
},
reverse: true,
itemCount: items.length,
),
bottomNavigationBar: BottomAppBar(
child: Row(
children: [
Expanded(
child: TextField(
maxLines: 3,
minLines: 1,
controller: ref.watch(jsInputControllerProvider),
)),
IconButton(
onPressed: () {
final controller = ref.read(jsInputControllerProvider);
final content = controller.text;
controller.clear();
ref.read(jsContentsProvider.notifier).exec(content);
},
icon: const Icon(Icons.rocket_launch_rounded),
),
],
child: const SizedBox(),
// child: Consumer(builder: (context, ref, _) {
// return AppTextField(text: ref.watch(_result));
// }),
),
],
),
);
}
}
8 changes: 8 additions & 0 deletions lib/ui/widgets/scaffold/tool_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ToolScaffold extends StatelessWidget {
this.options,
required this.body,
this.padding = const EdgeInsets.all(16),
this.fab,
this.bottomNavigationBar,
}) : isScroll = false;

const ToolScaffold.scroll({
Expand All @@ -18,6 +20,8 @@ class ToolScaffold extends StatelessWidget {
this.options,
required this.body,
this.padding = const EdgeInsets.all(16),
this.fab,
this.bottomNavigationBar,
}) : isScroll = true;

final Widget title;
Expand All @@ -26,6 +30,8 @@ class ToolScaffold extends StatelessWidget {
final Widget body;
final bool isScroll;
final EdgeInsetsGeometry padding;
final Widget? fab;
final Widget? bottomNavigationBar;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -85,6 +91,8 @@ class ToolScaffold extends StatelessWidget {
actions: actions,
),
body: content,
floatingActionButton: fab,
bottomNavigationBar: bottomNavigationBar,
);
}
}
13 changes: 13 additions & 0 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
PODS:
- connectivity_plus (0.0.1):
- FlutterMacOS
- ReachabilitySwift
- device_info_plus (0.0.1):
- FlutterMacOS
- dynamic_color (0.0.2):
Expand All @@ -13,6 +16,7 @@ PODS:
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- ReachabilitySwift (5.0.0)
- screen_retriever (0.0.1):
- FlutterMacOS
- url_launcher_macos (0.0.1):
Expand All @@ -21,6 +25,7 @@ PODS:
- FlutterMacOS

DEPENDENCIES:
- connectivity_plus (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus/macos`)
- device_info_plus (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos`)
- dynamic_color (from `Flutter/ephemeral/.symlinks/plugins/dynamic_color/macos`)
- file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`)
Expand All @@ -32,7 +37,13 @@ DEPENDENCIES:
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
- window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`)

SPEC REPOS:
trunk:
- ReachabilitySwift

EXTERNAL SOURCES:
connectivity_plus:
:path: Flutter/ephemeral/.symlinks/plugins/connectivity_plus/macos
device_info_plus:
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos
dynamic_color:
Expand All @@ -55,13 +66,15 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos

SPEC CHECKSUMS:
connectivity_plus: 18d3c32514c886e046de60e9c13895109866c747
device_info_plus: 5401765fde0b8d062a2f8eb65510fb17e77cf07f
dynamic_color: 2eaa27267de1ca20d879fbd6e01259773fb1670f
file_selector_macos: 468fb6b81fac7c0e88d71317f3eec34c3b008ff9
flutter_js: c664361655af1d8fc24e278c7d086e9cbe0d68bc
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
network_info_plus: f4fbc7877ab7b3294500d9441dfa53cd54972d05
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95
window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8
Expand Down
Loading

0 comments on commit d9257c1

Please sign in to comment.