mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-12-24 23:09:25 -05:00
flutter work
This commit is contained in:
parent
8c96373cfd
commit
a44794ab98
186
veilid-flutter/example/lib/app.dart
Normal file
186
veilid-flutter/example/lib/app.dart
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:veilid/veilid.dart';
|
||||||
|
import 'package:loggy/loggy.dart';
|
||||||
|
|
||||||
|
import 'log_terminal.dart';
|
||||||
|
import 'config.dart';
|
||||||
|
import 'log.dart';
|
||||||
|
|
||||||
|
// Main App
|
||||||
|
class MyApp extends StatefulWidget {
|
||||||
|
const MyApp({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MyApp> createState() => _MyAppState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MyAppState extends State<MyApp> with UiLoggy {
|
||||||
|
String _veilidVersion = 'Unknown';
|
||||||
|
Stream<VeilidUpdate>? _updateStream;
|
||||||
|
Future<void>? _updateProcessor;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
initPlatformState();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Platform messages are asynchronous, so we initialize in an async method.
|
||||||
|
Future<void> initPlatformState() async {
|
||||||
|
String veilidVersion;
|
||||||
|
// Platform messages may fail, so we use a try/catch PlatformException.
|
||||||
|
// We also handle the message potentially returning null.
|
||||||
|
try {
|
||||||
|
veilidVersion = Veilid.instance.veilidVersionString();
|
||||||
|
} on Exception {
|
||||||
|
veilidVersion = 'Failed to get veilid version.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case of hot restart shut down first
|
||||||
|
try {
|
||||||
|
await Veilid.instance.shutdownVeilidCore();
|
||||||
|
} on Exception {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the widget was removed from the tree while the asynchronous platform
|
||||||
|
// message was in flight, we want to discard the reply rather than calling
|
||||||
|
// setState to update our non-existent appearance.
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_veilidVersion = veilidVersion;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> processLog(VeilidLog log) async {
|
||||||
|
StackTrace? stackTrace;
|
||||||
|
Object? error;
|
||||||
|
final backtrace = log.backtrace;
|
||||||
|
if (backtrace != null) {
|
||||||
|
stackTrace =
|
||||||
|
StackTrace.fromString("$backtrace\n${StackTrace.current.toString()}");
|
||||||
|
error = 'embedded stack trace for ${log.logLevel} ${log.message}';
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (log.logLevel) {
|
||||||
|
case VeilidLogLevel.error:
|
||||||
|
loggy.error(log.message, error, stackTrace);
|
||||||
|
break;
|
||||||
|
case VeilidLogLevel.warn:
|
||||||
|
loggy.warning(log.message, error, stackTrace);
|
||||||
|
break;
|
||||||
|
case VeilidLogLevel.info:
|
||||||
|
loggy.info(log.message, error, stackTrace);
|
||||||
|
break;
|
||||||
|
case VeilidLogLevel.debug:
|
||||||
|
loggy.debug(log.message, error, stackTrace);
|
||||||
|
break;
|
||||||
|
case VeilidLogLevel.trace:
|
||||||
|
loggy.trace(log.message, error, stackTrace);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> processUpdates() async {
|
||||||
|
var stream = _updateStream;
|
||||||
|
if (stream != null) {
|
||||||
|
await for (final update in stream) {
|
||||||
|
if (update is VeilidLog) {
|
||||||
|
await processLog(update);
|
||||||
|
} else if (update is VeilidAppMessage) {
|
||||||
|
loggy.info("AppMessage: ${update.json}");
|
||||||
|
} else if (update is VeilidAppCall) {
|
||||||
|
loggy.info("AppCall: ${update.json}");
|
||||||
|
} else {
|
||||||
|
loggy.trace("Update: ${update.json}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final ButtonStyle buttonStyle =
|
||||||
|
ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text('Veilid Plugin Version $_veilidVersion'),
|
||||||
|
),
|
||||||
|
body: Column(children: [
|
||||||
|
const Expanded(child: LogTerminal()),
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.fromLTRB(8, 8, 8, 12),
|
||||||
|
child: Row(children: [
|
||||||
|
ElevatedButton(
|
||||||
|
style: buttonStyle,
|
||||||
|
onPressed: _updateStream != null
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
var updateStream = await Veilid.instance
|
||||||
|
.startupVeilidCore(
|
||||||
|
await getDefaultVeilidConfig());
|
||||||
|
setState(() {
|
||||||
|
_updateStream = updateStream;
|
||||||
|
_updateProcessor = processUpdates();
|
||||||
|
});
|
||||||
|
await Veilid.instance.attach();
|
||||||
|
},
|
||||||
|
child: const Text('Startup'),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
style: buttonStyle,
|
||||||
|
onPressed: _updateStream == null
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
await Veilid.instance.shutdownVeilidCore();
|
||||||
|
if (_updateProcessor != null) {
|
||||||
|
await _updateProcessor;
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
_updateProcessor = null;
|
||||||
|
_updateStream = null;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Text('Shutdown'),
|
||||||
|
),
|
||||||
|
])),
|
||||||
|
Row(children: [
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
labelText: 'Debug Command'),
|
||||||
|
textInputAction: TextInputAction.send,
|
||||||
|
onSubmitted: (String v) async {
|
||||||
|
loggy.info(await Veilid.instance.debug(v));
|
||||||
|
})),
|
||||||
|
DropdownButton<LogLevel>(
|
||||||
|
value: loggy.level.logLevel,
|
||||||
|
onChanged: (LogLevel? newLevel) {
|
||||||
|
setState(() {
|
||||||
|
setRootLogLevel(newLevel);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
items: const [
|
||||||
|
DropdownMenuItem<LogLevel>(
|
||||||
|
value: LogLevel.error, child: Text("Error")),
|
||||||
|
DropdownMenuItem<LogLevel>(
|
||||||
|
value: LogLevel.warning, child: Text("Warning")),
|
||||||
|
DropdownMenuItem<LogLevel>(
|
||||||
|
value: LogLevel.info, child: Text("Info")),
|
||||||
|
DropdownMenuItem<LogLevel>(
|
||||||
|
value: LogLevel.debug, child: Text("Debug")),
|
||||||
|
DropdownMenuItem<LogLevel>(
|
||||||
|
value: traceLevel, child: Text("Trace")),
|
||||||
|
DropdownMenuItem<LogLevel>(
|
||||||
|
value: LogLevel.all, child: Text("All")),
|
||||||
|
])
|
||||||
|
]),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
115
veilid-flutter/example/lib/log.dart
Normal file
115
veilid-flutter/example/lib/log.dart
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:veilid/veilid.dart';
|
||||||
|
import 'package:loggy/loggy.dart';
|
||||||
|
import 'package:ansicolor/ansicolor.dart';
|
||||||
|
|
||||||
|
// Loggy tools
|
||||||
|
const LogLevel traceLevel = LogLevel('Trace', 1);
|
||||||
|
|
||||||
|
VeilidConfigLogLevel convertToVeilidConfigLogLevel(LogLevel? level) {
|
||||||
|
if (level == null) {
|
||||||
|
return VeilidConfigLogLevel.off;
|
||||||
|
}
|
||||||
|
switch (level) {
|
||||||
|
case LogLevel.error:
|
||||||
|
return VeilidConfigLogLevel.error;
|
||||||
|
case LogLevel.warning:
|
||||||
|
return VeilidConfigLogLevel.warn;
|
||||||
|
case LogLevel.info:
|
||||||
|
return VeilidConfigLogLevel.info;
|
||||||
|
case LogLevel.debug:
|
||||||
|
return VeilidConfigLogLevel.debug;
|
||||||
|
case traceLevel:
|
||||||
|
return VeilidConfigLogLevel.trace;
|
||||||
|
}
|
||||||
|
return VeilidConfigLogLevel.off;
|
||||||
|
}
|
||||||
|
|
||||||
|
String wrapWithLogColor(LogLevel? level, String text) {
|
||||||
|
if (level == null) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
final pen = AnsiPen();
|
||||||
|
ansiColorDisabled = false;
|
||||||
|
switch (level) {
|
||||||
|
case LogLevel.error:
|
||||||
|
pen
|
||||||
|
..reset()
|
||||||
|
..red(bold: true);
|
||||||
|
return pen(text);
|
||||||
|
case LogLevel.warning:
|
||||||
|
pen
|
||||||
|
..reset()
|
||||||
|
..yellow(bold: true);
|
||||||
|
return pen(text);
|
||||||
|
case LogLevel.info:
|
||||||
|
pen
|
||||||
|
..reset()
|
||||||
|
..white(bold: true);
|
||||||
|
return pen(text);
|
||||||
|
case LogLevel.debug:
|
||||||
|
pen
|
||||||
|
..reset()
|
||||||
|
..green(bold: true);
|
||||||
|
return pen(text);
|
||||||
|
case traceLevel:
|
||||||
|
pen
|
||||||
|
..reset()
|
||||||
|
..blue(bold: true);
|
||||||
|
return pen(text);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setRootLogLevel(LogLevel? level) {
|
||||||
|
Loggy('').level = getLogOptions(level);
|
||||||
|
Veilid.instance.changeLogLevel("all", convertToVeilidConfigLogLevel(level));
|
||||||
|
}
|
||||||
|
|
||||||
|
extension PrettyPrintLogRecord on LogRecord {
|
||||||
|
String pretty() {
|
||||||
|
final lstr =
|
||||||
|
wrapWithLogColor(level, '[${level.toString().substring(0, 1)}]');
|
||||||
|
return '$lstr $message';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CallbackPrinter extends LoggyPrinter {
|
||||||
|
CallbackPrinter() : super();
|
||||||
|
|
||||||
|
void Function(LogRecord)? callback;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onLog(LogRecord record) {
|
||||||
|
debugPrint(record.pretty());
|
||||||
|
callback?.call(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCallback(Function(LogRecord)? cb) {
|
||||||
|
callback = cb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var globalTerminalPrinter = CallbackPrinter();
|
||||||
|
|
||||||
|
extension TraceLoggy on Loggy {
|
||||||
|
void trace(dynamic message, [Object? error, StackTrace? stackTrace]) =>
|
||||||
|
log(traceLevel, message, error, stackTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
LogOptions getLogOptions(LogLevel? level) {
|
||||||
|
return LogOptions(
|
||||||
|
level ?? LogLevel.all,
|
||||||
|
stackTraceLevel: LogLevel.error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void initLoggy() {
|
||||||
|
Loggy.initLoggy(
|
||||||
|
logPrinter: globalTerminalPrinter,
|
||||||
|
logOptions: getLogOptions(null),
|
||||||
|
);
|
||||||
|
|
||||||
|
setRootLogLevel(LogLevel.info);
|
||||||
|
}
|
@ -3,60 +3,30 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_pty/flutter_pty.dart';
|
|
||||||
import 'package:xterm/xterm.dart';
|
import 'package:xterm/xterm.dart';
|
||||||
|
import 'log.dart';
|
||||||
|
|
||||||
class Home extends StatefulWidget {
|
class LogTerminal extends StatefulWidget {
|
||||||
Home({Key? key}) : super(key: key);
|
const LogTerminal({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// ignore: library_private_types_in_public_api
|
// ignore: library_private_types_in_public_api
|
||||||
_HomeState createState() => _HomeState();
|
_LogTerminalState createState() => _LogTerminalState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeState extends State<Home> {
|
class _LogTerminalState extends State<LogTerminal> {
|
||||||
final terminal = Terminal(
|
final terminal = Terminal(
|
||||||
maxLines: 10000,
|
maxLines: 10000,
|
||||||
);
|
);
|
||||||
|
|
||||||
final terminalController = TerminalController();
|
final terminalController = TerminalController();
|
||||||
|
|
||||||
late final Pty pty;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
terminal.setLineFeedMode(true);
|
||||||
WidgetsBinding.instance.endOfFrame.then(
|
globalTerminalPrinter
|
||||||
(_) {
|
.setCallback((log) => {terminal.write("${log.pretty()}\n")});
|
||||||
if (mounted) _startPty();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _startPty() {
|
|
||||||
pty = Pty.start(
|
|
||||||
shell,
|
|
||||||
columns: terminal.viewWidth,
|
|
||||||
rows: terminal.viewHeight,
|
|
||||||
);
|
|
||||||
|
|
||||||
pty.output
|
|
||||||
.cast<List<int>>()
|
|
||||||
.transform(Utf8Decoder())
|
|
||||||
.listen(terminal.write);
|
|
||||||
|
|
||||||
pty.exitCode.then((code) {
|
|
||||||
terminal.write('the process exited with exit code $code');
|
|
||||||
});
|
|
||||||
|
|
||||||
terminal.onOutput = (data) {
|
|
||||||
pty.write(const Utf8Encoder().convert(data));
|
|
||||||
};
|
|
||||||
|
|
||||||
terminal.onResize = (w, h, pw, ph) {
|
|
||||||
pty.resize(h, w);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -88,15 +58,3 @@ class _HomeState extends State<Home> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String get shell {
|
|
||||||
if (Platform.isMacOS || Platform.isLinux) {
|
|
||||||
return Platform.environment['SHELL'] ?? 'bash';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Platform.isWindows) {
|
|
||||||
return 'cmd.exe';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'sh';
|
|
||||||
}
|
|
@ -1,82 +1,14 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:veilid/veilid.dart';
|
import 'package:veilid/veilid.dart';
|
||||||
//import 'package:flutter_loggy/flutter_loggy.dart';
|
|
||||||
import 'package:loggy/loggy.dart';
|
|
||||||
import 'platform_menu.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter_acrylic/flutter_acrylic.dart';
|
import 'package:flutter_acrylic/flutter_acrylic.dart';
|
||||||
import 'package:xterm/xterm.dart';
|
|
||||||
import 'home.dart';
|
|
||||||
|
|
||||||
import 'config.dart';
|
import 'veilid_color.dart';
|
||||||
|
import 'log.dart';
|
||||||
// Loggy tools
|
import 'app.dart';
|
||||||
const LogLevel traceLevel = LogLevel('Trace', 1);
|
import 'veilid_init.dart';
|
||||||
|
|
||||||
class ConsolePrinter extends LoggyPrinter {
|
|
||||||
ConsolePrinter(this.childPrinter) : super();
|
|
||||||
|
|
||||||
final LoggyPrinter childPrinter;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void onLog(LogRecord record) {
|
|
||||||
debugPrint(record.toString());
|
|
||||||
childPrinter.onLog(record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension TraceLoggy on Loggy {
|
|
||||||
void trace(dynamic message, [Object? error, StackTrace? stackTrace]) =>
|
|
||||||
log(traceLevel, message, error, stackTrace);
|
|
||||||
}
|
|
||||||
|
|
||||||
LogOptions getLogOptions(LogLevel? level) {
|
|
||||||
return LogOptions(
|
|
||||||
level ?? LogLevel.all,
|
|
||||||
stackTraceLevel: LogLevel.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
VeilidConfigLogLevel convertToVeilidConfigLogLevel(LogLevel? level) {
|
|
||||||
if (level == null) {
|
|
||||||
return VeilidConfigLogLevel.off;
|
|
||||||
}
|
|
||||||
switch (level) {
|
|
||||||
case LogLevel.error:
|
|
||||||
return VeilidConfigLogLevel.error;
|
|
||||||
case LogLevel.warning:
|
|
||||||
return VeilidConfigLogLevel.warn;
|
|
||||||
case LogLevel.info:
|
|
||||||
return VeilidConfigLogLevel.info;
|
|
||||||
case LogLevel.debug:
|
|
||||||
return VeilidConfigLogLevel.debug;
|
|
||||||
case traceLevel:
|
|
||||||
return VeilidConfigLogLevel.trace;
|
|
||||||
}
|
|
||||||
return VeilidConfigLogLevel.off;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRootLogLevel(LogLevel? level) {
|
|
||||||
Loggy('').level = getLogOptions(level);
|
|
||||||
Veilid.instance.changeLogLevel("all", convertToVeilidConfigLogLevel(level));
|
|
||||||
}
|
|
||||||
|
|
||||||
void initLoggy() {
|
|
||||||
// Loggy.initLoggy(
|
|
||||||
// logPrinter: StreamPrinter(ConsolePrinter(
|
|
||||||
// const PrettyDeveloperPrinter(),
|
|
||||||
// )),
|
|
||||||
// logOptions: getLogOptions(null),
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////// Acrylic
|
/////////////////////////////// Acrylic
|
||||||
|
|
||||||
@ -92,7 +24,8 @@ bool get isDesktop {
|
|||||||
Future<void> setupAcrylic() async {
|
Future<void> setupAcrylic() async {
|
||||||
await Window.initialize();
|
await Window.initialize();
|
||||||
await Window.makeTitlebarTransparent();
|
await Window.makeTitlebarTransparent();
|
||||||
await Window.setEffect(effect: WindowEffect.aero, color: Color(0xFFFFFFFF));
|
await Window.setEffect(
|
||||||
|
effect: WindowEffect.aero, color: const Color(0xFFFFFFFF));
|
||||||
await Window.setBlurViewState(MacOSBlurViewState.active);
|
await Window.setBlurViewState(MacOSBlurViewState.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,243 +33,15 @@ Future<void> setupAcrylic() async {
|
|||||||
void main() {
|
void main() {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
// Initialize Log
|
||||||
initLoggy();
|
initLoggy();
|
||||||
if (kIsWeb) {
|
|
||||||
var platformConfig = VeilidWASMConfig(
|
|
||||||
logging: VeilidWASMConfigLogging(
|
|
||||||
performance: VeilidWASMConfigLoggingPerformance(
|
|
||||||
enabled: true,
|
|
||||||
level: VeilidConfigLogLevel.debug,
|
|
||||||
logsInTimings: true,
|
|
||||||
logsInConsole: true),
|
|
||||||
api: VeilidWASMConfigLoggingApi(
|
|
||||||
enabled: true, level: VeilidConfigLogLevel.info)));
|
|
||||||
Veilid.instance.initializeVeilidCore(platformConfig.json);
|
|
||||||
} else {
|
|
||||||
var platformConfig = VeilidFFIConfig(
|
|
||||||
logging: VeilidFFIConfigLogging(
|
|
||||||
terminal: VeilidFFIConfigLoggingTerminal(
|
|
||||||
enabled: false,
|
|
||||||
level: VeilidConfigLogLevel.debug,
|
|
||||||
),
|
|
||||||
otlp: VeilidFFIConfigLoggingOtlp(
|
|
||||||
enabled: false,
|
|
||||||
level: VeilidConfigLogLevel.trace,
|
|
||||||
grpcEndpoint: "localhost:4317",
|
|
||||||
serviceName: "VeilidExample"),
|
|
||||||
api: VeilidFFIConfigLoggingApi(
|
|
||||||
enabled: true, level: VeilidConfigLogLevel.info)));
|
|
||||||
Veilid.instance.initializeVeilidCore(platformConfig.json);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Initialize Veilid
|
||||||
|
veilidInit();
|
||||||
|
|
||||||
|
// Run the app
|
||||||
runApp(MaterialApp(
|
runApp(MaterialApp(
|
||||||
title: 'Veilid Plugin Demo',
|
title: 'Veilid Plugin Demo',
|
||||||
theme: ThemeData(
|
theme: newVeilidTheme(),
|
||||||
primarySwatch: '#6667AB',
|
|
||||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
|
||||||
),
|
|
||||||
home: const MyApp()));
|
home: const MyApp()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main App
|
|
||||||
class MyApp extends StatefulWidget {
|
|
||||||
const MyApp({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MyApp> createState() => _MyAppState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MyAppState extends State<MyApp> with UiLoggy {
|
|
||||||
String _veilidVersion = 'Unknown';
|
|
||||||
Stream<VeilidUpdate>? _updateStream;
|
|
||||||
Future<void>? _updateProcessor;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
setRootLogLevel(LogLevel.info);
|
|
||||||
initPlatformState();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Platform messages are asynchronous, so we initialize in an async method.
|
|
||||||
Future<void> initPlatformState() async {
|
|
||||||
String veilidVersion;
|
|
||||||
// Platform messages may fail, so we use a try/catch PlatformException.
|
|
||||||
// We also handle the message potentially returning null.
|
|
||||||
try {
|
|
||||||
veilidVersion = Veilid.instance.veilidVersionString();
|
|
||||||
} on Exception {
|
|
||||||
veilidVersion = 'Failed to get veilid version.';
|
|
||||||
}
|
|
||||||
|
|
||||||
// In case of hot restart shut down first
|
|
||||||
try {
|
|
||||||
await Veilid.instance.shutdownVeilidCore();
|
|
||||||
} on Exception {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the widget was removed from the tree while the asynchronous platform
|
|
||||||
// message was in flight, we want to discard the reply rather than calling
|
|
||||||
// setState to update our non-existent appearance.
|
|
||||||
if (!mounted) return;
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
_veilidVersion = veilidVersion;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> processLog(VeilidLog log) async {
|
|
||||||
StackTrace? stackTrace;
|
|
||||||
Object? error;
|
|
||||||
final backtrace = log.backtrace;
|
|
||||||
if (backtrace != null) {
|
|
||||||
stackTrace =
|
|
||||||
StackTrace.fromString("$backtrace\n${StackTrace.current.toString()}");
|
|
||||||
error = 'embedded stack trace for ${log.logLevel} ${log.message}';
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (log.logLevel) {
|
|
||||||
case VeilidLogLevel.error:
|
|
||||||
loggy.error(log.message, error, stackTrace);
|
|
||||||
break;
|
|
||||||
case VeilidLogLevel.warn:
|
|
||||||
loggy.warning(log.message, error, stackTrace);
|
|
||||||
break;
|
|
||||||
case VeilidLogLevel.info:
|
|
||||||
loggy.info(log.message, error, stackTrace);
|
|
||||||
break;
|
|
||||||
case VeilidLogLevel.debug:
|
|
||||||
loggy.debug(log.message, error, stackTrace);
|
|
||||||
break;
|
|
||||||
case VeilidLogLevel.trace:
|
|
||||||
loggy.trace(log.message, error, stackTrace);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> processUpdates() async {
|
|
||||||
var stream = _updateStream;
|
|
||||||
if (stream != null) {
|
|
||||||
await for (final update in stream) {
|
|
||||||
if (update is VeilidLog) {
|
|
||||||
await processLog(update);
|
|
||||||
} else if (update is VeilidAppMessage) {
|
|
||||||
loggy.info("AppMessage: ${update.json}");
|
|
||||||
} else if (update is VeilidAppCall) {
|
|
||||||
loggy.info("AppCall: ${update.json}");
|
|
||||||
} else {
|
|
||||||
loggy.trace("Update: ${update.json}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final ButtonStyle buttonStyle =
|
|
||||||
ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text('Veilid Plugin Version $_veilidVersion'),
|
|
||||||
),
|
|
||||||
body: Column(children: [
|
|
||||||
Expanded(
|
|
||||||
child: Container(
|
|
||||||
color: ThemeData.dark().scaffoldBackgroundColor,
|
|
||||||
height: MediaQuery.of(context).size.height * 0.4,
|
|
||||||
child: SafeArea(
|
|
||||||
child: TerminalView(
|
|
||||||
terminal,
|
|
||||||
controller: terminalController,
|
|
||||||
autofocus: true,
|
|
||||||
backgroundOpacity: 0.7,
|
|
||||||
onSecondaryTapDown: (details, offset) async {
|
|
||||||
final selection = terminalController.selection;
|
|
||||||
if (selection != null) {
|
|
||||||
final text = terminal.buffer.getText(selection);
|
|
||||||
terminalController.clearSelection();
|
|
||||||
await Clipboard.setData(ClipboardData(text: text));
|
|
||||||
} else {
|
|
||||||
final data = await Clipboard.getData('text/plain');
|
|
||||||
final text = data?.text;
|
|
||||||
if (text != null) {
|
|
||||||
terminal.paste(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 12),
|
|
||||||
child: Row(children: [
|
|
||||||
ElevatedButton(
|
|
||||||
style: buttonStyle,
|
|
||||||
onPressed: _updateStream != null
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
var updateStream = await Veilid.instance
|
|
||||||
.startupVeilidCore(
|
|
||||||
await getDefaultVeilidConfig());
|
|
||||||
setState(() {
|
|
||||||
_updateStream = updateStream;
|
|
||||||
_updateProcessor = processUpdates();
|
|
||||||
});
|
|
||||||
await Veilid.instance.attach();
|
|
||||||
},
|
|
||||||
child: const Text('Startup'),
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
|
||||||
style: buttonStyle,
|
|
||||||
onPressed: _updateStream == null
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
await Veilid.instance.shutdownVeilidCore();
|
|
||||||
if (_updateProcessor != null) {
|
|
||||||
await _updateProcessor;
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
_updateProcessor = null;
|
|
||||||
_updateStream = null;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: const Text('Shutdown'),
|
|
||||||
),
|
|
||||||
])),
|
|
||||||
Row(children: [
|
|
||||||
Expanded(
|
|
||||||
child: TextField(
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
labelText: 'Debug Command'),
|
|
||||||
textInputAction: TextInputAction.send,
|
|
||||||
onSubmitted: (String v) async {
|
|
||||||
loggy.info(await Veilid.instance.debug(v));
|
|
||||||
})),
|
|
||||||
DropdownButton<LogLevel>(
|
|
||||||
value: loggy.level.logLevel,
|
|
||||||
onChanged: (LogLevel? newLevel) {
|
|
||||||
setState(() {
|
|
||||||
setRootLogLevel(newLevel);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
items: const [
|
|
||||||
DropdownMenuItem<LogLevel>(
|
|
||||||
value: LogLevel.error, child: Text("Error")),
|
|
||||||
DropdownMenuItem<LogLevel>(
|
|
||||||
value: LogLevel.warning, child: Text("Warning")),
|
|
||||||
DropdownMenuItem<LogLevel>(
|
|
||||||
value: LogLevel.info, child: Text("Info")),
|
|
||||||
DropdownMenuItem<LogLevel>(
|
|
||||||
value: LogLevel.debug, child: Text("Debug")),
|
|
||||||
DropdownMenuItem<LogLevel>(
|
|
||||||
value: traceLevel, child: Text("Trace")),
|
|
||||||
DropdownMenuItem<LogLevel>(
|
|
||||||
value: LogLevel.all, child: Text("All")),
|
|
||||||
])
|
|
||||||
]),
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -232,3 +232,11 @@ const Map<int, Color> popComplentaryColorSwatch = {
|
|||||||
|
|
||||||
const MaterialColor materialPopComplementaryColor =
|
const MaterialColor materialPopComplementaryColor =
|
||||||
MaterialColor(0xff59f282, popComplentaryColorSwatch);
|
MaterialColor(0xff59f282, popComplentaryColorSwatch);
|
||||||
|
|
||||||
|
ThemeData newVeilidTheme() {
|
||||||
|
return ThemeData(
|
||||||
|
primarySwatch: materialPrimaryColor,
|
||||||
|
secondaryHeaderColor: materialSecondaryColor,
|
||||||
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
34
veilid-flutter/example/lib/veilid_init.dart
Normal file
34
veilid-flutter/example/lib/veilid_init.dart
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:veilid/veilid.dart';
|
||||||
|
|
||||||
|
// Initialize Veilid
|
||||||
|
// Call only once.
|
||||||
|
void veilidInit() {
|
||||||
|
if (kIsWeb) {
|
||||||
|
var platformConfig = VeilidWASMConfig(
|
||||||
|
logging: VeilidWASMConfigLogging(
|
||||||
|
performance: VeilidWASMConfigLoggingPerformance(
|
||||||
|
enabled: true,
|
||||||
|
level: VeilidConfigLogLevel.debug,
|
||||||
|
logsInTimings: true,
|
||||||
|
logsInConsole: true),
|
||||||
|
api: VeilidWASMConfigLoggingApi(
|
||||||
|
enabled: true, level: VeilidConfigLogLevel.info)));
|
||||||
|
Veilid.instance.initializeVeilidCore(platformConfig.json);
|
||||||
|
} else {
|
||||||
|
var platformConfig = VeilidFFIConfig(
|
||||||
|
logging: VeilidFFIConfigLogging(
|
||||||
|
terminal: VeilidFFIConfigLoggingTerminal(
|
||||||
|
enabled: false,
|
||||||
|
level: VeilidConfigLogLevel.debug,
|
||||||
|
),
|
||||||
|
otlp: VeilidFFIConfigLoggingOtlp(
|
||||||
|
enabled: false,
|
||||||
|
level: VeilidConfigLogLevel.trace,
|
||||||
|
grpcEndpoint: "localhost:4317",
|
||||||
|
serviceName: "VeilidExample"),
|
||||||
|
api: VeilidFFIConfigLoggingApi(
|
||||||
|
enabled: true, level: VeilidConfigLogLevel.info)));
|
||||||
|
Veilid.instance.initializeVeilidCore(platformConfig.json);
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,6 @@ class VirtualKeyboardView extends StatelessWidget {
|
|||||||
return AnimatedBuilder(
|
return AnimatedBuilder(
|
||||||
animation: keyboard,
|
animation: keyboard,
|
||||||
builder: (context, child) => ToggleButtons(
|
builder: (context, child) => ToggleButtons(
|
||||||
children: [Text('Ctrl'), Text('Alt'), Text('Shift')],
|
|
||||||
isSelected: [keyboard.ctrl, keyboard.alt, keyboard.shift],
|
isSelected: [keyboard.ctrl, keyboard.alt, keyboard.shift],
|
||||||
onPressed: (index) {
|
onPressed: (index) {
|
||||||
switch (index) {
|
switch (index) {
|
||||||
@ -26,6 +25,7 @@ class VirtualKeyboardView extends StatelessWidget {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
children: const [Text('Ctrl'), Text('Alt'), Text('Shift')],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
PODS:
|
PODS:
|
||||||
|
- flutter_acrylic (0.1.0):
|
||||||
|
- FlutterMacOS
|
||||||
|
- flutter_pty (0.0.1):
|
||||||
|
- FlutterMacOS
|
||||||
- FlutterMacOS (1.0.0)
|
- FlutterMacOS (1.0.0)
|
||||||
- path_provider_macos (0.0.1):
|
- path_provider_macos (0.0.1):
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
@ -6,11 +10,17 @@ PODS:
|
|||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
|
- flutter_acrylic (from `Flutter/ephemeral/.symlinks/plugins/flutter_acrylic/macos`)
|
||||||
|
- flutter_pty (from `Flutter/ephemeral/.symlinks/plugins/flutter_pty/macos`)
|
||||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||||
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
|
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
|
||||||
- veilid (from `Flutter/ephemeral/.symlinks/plugins/veilid/macos`)
|
- veilid (from `Flutter/ephemeral/.symlinks/plugins/veilid/macos`)
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
|
flutter_acrylic:
|
||||||
|
:path: Flutter/ephemeral/.symlinks/plugins/flutter_acrylic/macos
|
||||||
|
flutter_pty:
|
||||||
|
:path: Flutter/ephemeral/.symlinks/plugins/flutter_pty/macos
|
||||||
FlutterMacOS:
|
FlutterMacOS:
|
||||||
:path: Flutter/ephemeral
|
:path: Flutter/ephemeral
|
||||||
path_provider_macos:
|
path_provider_macos:
|
||||||
@ -19,6 +29,8 @@ EXTERNAL SOURCES:
|
|||||||
:path: Flutter/ephemeral/.symlinks/plugins/veilid/macos
|
:path: Flutter/ephemeral/.symlinks/plugins/veilid/macos
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
|
flutter_acrylic: c3df24ae52ab6597197837ce59ef2a8542640c17
|
||||||
|
flutter_pty: 41b6f848ade294be726a6b94cdd4a67c3bc52f59
|
||||||
FlutterMacOS: ae6af50a8ea7d6103d888583d46bd8328a7e9811
|
FlutterMacOS: ae6af50a8ea7d6103d888583d46bd8328a7e9811
|
||||||
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
|
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
|
||||||
veilid: f2b3b5b3ac8cd93fc5443ab830d5153575dacf36
|
veilid: f2b3b5b3ac8cd93fc5443ab830d5153575dacf36
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
# Generated by pub
|
# Generated by pub
|
||||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||||
packages:
|
packages:
|
||||||
|
ansicolor:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: ansicolor
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
async:
|
async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -39,6 +39,7 @@ dependencies:
|
|||||||
xterm: ^3.4.0
|
xterm: ^3.4.0
|
||||||
flutter_pty: ^0.3.1
|
flutter_pty: ^0.3.1
|
||||||
flutter_acrylic: ^1.0.0+2
|
flutter_acrylic: ^1.0.0+2
|
||||||
|
ansicolor: ^2.0.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
import 'package:veilid_example/main.dart';
|
import 'package:veilid_example/app.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Verify Platform version', (WidgetTester tester) async {
|
testWidgets('Verify Platform version', (WidgetTester tester) async {
|
||||||
@ -18,8 +18,8 @@ void main() {
|
|||||||
// Verify that platform version is retrieved.
|
// Verify that platform version is retrieved.
|
||||||
expect(
|
expect(
|
||||||
find.byWidgetPredicate(
|
find.byWidgetPredicate(
|
||||||
(Widget widget) => widget is Text &&
|
(Widget widget) =>
|
||||||
widget.data!.startsWith('Running on:'),
|
widget is Text && widget.data!.startsWith('Running on:'),
|
||||||
),
|
),
|
||||||
findsOneWidget,
|
findsOneWidget,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user