This commit is contained in:
leedongmyung 2023-11-12 16:27:16 +09:00
parent 7f3fa0b808
commit afed7edc78

View file

@ -6,9 +6,9 @@ import 'dart:typed_data';
import 'package:yaml/yaml.dart';
import 'package:path/path.dart' as path;
late String Function() getUserPath;
late String Function() getProjectName;
late String Function() getDataPath;
late Future<String> Function() getUserPath;
late Future<String> Function() getProjectName;
late Future<String> Function() getDataPath;
void initialize() {
getUserPath = getUserPath_;
@ -115,7 +115,7 @@ Future<Uint8List?> readFileByte(String filePath) async {
return c.future;
}
String getUserPath_() {
Future<String> getUserPath_() async {
String home = '';
Map<String, String> envVars = Platform.environment;
if (Platform.isMacOS) {
@ -125,11 +125,13 @@ String getUserPath_() {
} else if (Platform.isWindows) {
home = envVars['UserProfile']!;
}
return home;
var c = Completer<String>();
c.complete(home);
return c.future;
}
String getDataPath_() {
String path = getUserPath();
Future<String> getDataPath_() async {
String path = await getUserPath();
if (Platform.isMacOS) {
path = '$path/Library/Application Support/${getProjectName()}';
} else if (Platform.isLinux) {
@ -137,15 +139,19 @@ String getDataPath_() {
} else if (Platform.isWindows) {
path = '$path/AppData/Local/${getProjectName()}';
}
return path;
var c = Completer<String>();
c.complete(path);
return c.future;
}
String getProjectName_() {
Future<String> getProjectName_() async {
var name =
path.dirname(Platform.script.toFilePath(windows: Platform.isWindows));
print(name);
if (path.basename(name) == 'bin') {
name = path.dirname(name);
}
return path.basename(name);
var c = Completer<String>();
c.complete(path.basename(name));
return c.future;
}