no message
This commit is contained in:
parent
4c312a297e
commit
cfb9ba131c
6 changed files with 65 additions and 52 deletions
|
|
@ -1,5 +1,8 @@
|
|||
import 'package:dart_framework/core/application.dart';
|
||||
import 'package:dart_framework/core/log.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
test();
|
||||
void main() async {
|
||||
Application(() {
|
||||
test();
|
||||
}, (error, stack) {});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'log.dart';
|
||||
import 'package:dart_framework/utils/system_util.dart' as system;
|
||||
|
||||
abstract class Application {
|
||||
class Application {
|
||||
late Function(Object, StackTrace) writeLog;
|
||||
|
||||
Application(Function() func, Function(Object, StackTrace) errorListener) {
|
||||
runZonedGuarded(() async {
|
||||
system.initialize();
|
||||
writeLog = (error, stack) => logError('$error:\n$stack');
|
||||
func();
|
||||
}, (error, stack) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import 'dart:mirrors';
|
||||
import 'dart:isolate';
|
||||
import 'dart:async';
|
||||
|
||||
|
|
@ -7,7 +6,8 @@ import 'package:dart_framework/data/isolate_data.dart';
|
|||
/// ********************** Test ************************* ///
|
||||
void test() {
|
||||
var initData = {"param0": "value0"};
|
||||
IsolateManager.create<IsolateTemplate>(initData, (isoEvent, data) async {
|
||||
IsolateManager.create<IsolateTemplate>(IsolateTemplate(), initData,
|
||||
(isoEvent, data) async {
|
||||
if (isoEvent == IsolateEvent.ready) {
|
||||
int id = data as int;
|
||||
IsolateManager.sendBroadcast(IsoMessege('test1'));
|
||||
|
|
@ -73,19 +73,20 @@ class IsolateManager {
|
|||
final Map<int, Map<String, Function(Object?)>> _innerEventMap = {};
|
||||
|
||||
static void create<T extends IsolateBase>(
|
||||
T inst,
|
||||
Object? initData,
|
||||
Function(IsolateEvent, Object?) isolateEventListener,
|
||||
Function(IsoMessege) messageListener) async {
|
||||
to._create<T>(initData, isolateEventListener, messageListener);
|
||||
to._create<T>(inst, initData, isolateEventListener, messageListener);
|
||||
}
|
||||
|
||||
void _create<T extends IsolateBase>(
|
||||
T inst,
|
||||
Object? initData,
|
||||
Function(IsolateEvent, Object?) isolateEventListener,
|
||||
Function(IsoMessege) messageListener) async {
|
||||
final isoListener = ReceivePort();
|
||||
var id = nonce;
|
||||
T inst = Activator.createInstance(T, {});
|
||||
_isoMap[id] = inst;
|
||||
_addInnerEvent(id, _IsolateInnerEvent.ready, (message) {
|
||||
inst.isoListener = message as SendPort;
|
||||
|
|
@ -232,20 +233,3 @@ class IsolateBase {
|
|||
isoListener.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
class Activator {
|
||||
static createInstance(Type type, Map<Symbol, dynamic> namedArguments,
|
||||
[Symbol? constructor, List? arguments]) {
|
||||
constructor ??= const Symbol("");
|
||||
arguments ??= const [];
|
||||
|
||||
var typeMirror = reflectType(type);
|
||||
if (typeMirror is ClassMirror) {
|
||||
return typeMirror
|
||||
.newInstance(constructor, arguments, namedArguments)
|
||||
.reflectee;
|
||||
} else {
|
||||
throw ArgumentError("Cannot create the instance of the type '$type'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,9 +98,9 @@ class Log {
|
|||
initializeLog();
|
||||
}
|
||||
|
||||
void initializeLog() {
|
||||
void initializeLog() async {
|
||||
if (path == null) {
|
||||
path = getDataPath();
|
||||
path = await getDataPath();
|
||||
if (path!.isNotEmpty) {
|
||||
path = '$path/logs';
|
||||
var dir = Directory(path!);
|
||||
|
|
@ -116,7 +116,7 @@ class Log {
|
|||
if (message.type == 'request') {
|
||||
write();
|
||||
} else if (message.type == 'ready') {
|
||||
log('Log path: ${message.message}');
|
||||
appendString('Log path: ${message.message}');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -131,6 +131,10 @@ class Log {
|
|||
}
|
||||
}
|
||||
|
||||
void appendString(String message) {
|
||||
append(LogItem(message, LogType.verbose));
|
||||
}
|
||||
|
||||
void append(LogItem item) {
|
||||
logs.insert(0, item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class LogWriterIO extends IsolateBase {
|
|||
int _id = 0;
|
||||
|
||||
void startLog(String path, Function(IsoMessege) listener) {
|
||||
IsolateManager.create<LogWriterIO>(path, (event, data) {
|
||||
IsolateManager.create<LogWriterIO>(LogWriterIO(), path, (event, data) {
|
||||
if (event == IsolateEvent.ready) {
|
||||
_id = data as int;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,16 @@ import 'package:path/path.dart';
|
|||
import 'package:yaml/yaml.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
late Future<String> Function() getUserPath;
|
||||
late Future<String> Function() getProjectName;
|
||||
late Future<String> Function() getDataPath;
|
||||
|
||||
void initialize() {
|
||||
getUserPath = getUserPath_;
|
||||
getProjectName = getProjectName_;
|
||||
getDataPath = getDataPath_;
|
||||
}
|
||||
|
||||
Map<String, List<String>?> envArguments(List<String> arguments) {
|
||||
var dic = <String, List<String>?>{};
|
||||
var list = <String>[];
|
||||
|
|
@ -35,19 +45,6 @@ Map<String, List<String>?> envArguments(List<String> arguments) {
|
|||
return dic;
|
||||
}
|
||||
|
||||
String? getUserPath() {
|
||||
String? home = '';
|
||||
Map<String, String> envVars = Platform.environment;
|
||||
if (Platform.isMacOS) {
|
||||
home = envVars['HOME'];
|
||||
} else if (Platform.isLinux) {
|
||||
home = envVars['HOME'];
|
||||
} else if (Platform.isWindows) {
|
||||
home = envVars['UserProfile'];
|
||||
}
|
||||
return home;
|
||||
}
|
||||
|
||||
String? _getKey(String value) {
|
||||
String? key;
|
||||
if (value.indexOf('-') == 0) {
|
||||
|
|
@ -113,26 +110,49 @@ Future<Uint8List?> readFileByte(String filePath) async {
|
|||
bytes = Uint8List.fromList(value);
|
||||
print('reading of bytes is completed');
|
||||
}).catchError((onError) {
|
||||
print(
|
||||
'Exception Error while reading audio from path:' + onError.toString());
|
||||
print('Exception Error while reading audio from path:$onError');
|
||||
});
|
||||
c.complete(bytes);
|
||||
return c.future;
|
||||
}
|
||||
|
||||
String getProjectName() {
|
||||
return path.basename(path.dirname(
|
||||
path.dirname(Platform.script.toFilePath(windows: Platform.isWindows))));
|
||||
Future<String> getUserPath_() async {
|
||||
var c = Completer<String>();
|
||||
String home = '';
|
||||
Map<String, String> envVars = Platform.environment;
|
||||
if (Platform.isMacOS) {
|
||||
home = envVars['HOME']!;
|
||||
} else if (Platform.isLinux) {
|
||||
home = envVars['HOME']!;
|
||||
} else if (Platform.isWindows) {
|
||||
home = envVars['UserProfile']!;
|
||||
}
|
||||
c.complete(home);
|
||||
return c.future;
|
||||
}
|
||||
|
||||
String? getDataPath() {
|
||||
String? path = getUserPath();
|
||||
Future<String> getDataPath_() async {
|
||||
var c = Completer<String>();
|
||||
String path = await getUserPath();
|
||||
if (Platform.isMacOS) {
|
||||
path = '$path/Library/Application Support/${getProjectName()}';
|
||||
path = '$path/Library/Application Support/${await getProjectName()}';
|
||||
} else if (Platform.isLinux) {
|
||||
path = '$path/.config/${getProjectName()}';
|
||||
path = '$path/.config/${await getProjectName()}';
|
||||
} else if (Platform.isWindows) {
|
||||
path = '$path/AppData/Local/${getProjectName()}';
|
||||
path = '$path/AppData/Local/${await getProjectName()}';
|
||||
}
|
||||
return path;
|
||||
c.complete(path);
|
||||
return c.future;
|
||||
}
|
||||
|
||||
Future<String> getProjectName_() async {
|
||||
var c = Completer<String>();
|
||||
var name =
|
||||
path.dirname(Platform.script.toFilePath(windows: Platform.isWindows));
|
||||
print(name);
|
||||
if (path.basename(name) == 'bin') {
|
||||
name = path.dirname(name);
|
||||
}
|
||||
c.complete(path.basename(name));
|
||||
return c.future;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue