Skip to content

Commit 02018f3

Browse files
committed
dart, windows, android: add util.workspace to get workspace dir
- windows: current exe folder - android: app data dir
1 parent d57d87e commit 02018f3

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

android/app/src/main/java/net/seven/nodebase/nodebase/MainActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
9393
case "util.arch" -> {
9494
result.success(External.getArch());
9595
}
96+
case "util.workspace" -> {
97+
result.success(workspaceBaseDir());
98+
}
9699
}
97100
}
98101
});
@@ -151,4 +154,8 @@ public boolean fileExecutablize(String fname) {
151154
File f = new File(fname);
152155
return f.setExecutable(true, true);
153156
}
157+
158+
public String workspaceBaseDir() {
159+
return getContext().getApplicationInfo().dataDir;
160+
}
154161
}

lib/util/api.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ class NodeBaseApi {
4444
}
4545
}
4646

47+
static Future<String> apiUtilGetWorkspacePath() async {
48+
try {
49+
return await api.invokeMethod("util.workspace");
50+
} catch(e) {
51+
log("NodeBase [E] utilGetWorkspacePath / ${e.toString()}");
52+
return "";
53+
}
54+
}
55+
4756
static Future<Map<String, dynamic>> apiAppStatus(String app) async {
4857
/* {
4958
state: "none" | "new" | "running" | "dead"

windows/runner/flutter_dart.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,18 @@ flutter::EncodableValue utilGetArch() {
341341
}
342342
return flutter::EncodableValue(arch);
343343
}
344+
flutter::EncodableValue utilWorkspaceBaseDir() {
345+
TCHAR buf[1024];
346+
if (!GetModuleFileName(NULL, buf, 1024)) return flutter::EncodableValue(std::string(""));
347+
buf[1023] = 0;
348+
TCHAR* last = wcsrchr(buf, L'\\');
349+
if (last == nullptr || last == buf || last == &(buf[1]) || last == &(buf[2])) {
350+
// not found, buf = "\\", buf = "\\\\", buf = "c:\\"
351+
return flutter::EncodableValue(std::string(""));
352+
}
353+
last[0] = 0;
354+
return flutter::EncodableValue(Utf8FromUtf16(buf));
355+
}
344356

345357
#define RETURN_BADARG_ERR(x) { result->Error("BAD_ARGS", "Invalid argument type for '" #x "'"); return; }
346358
void InitMethodChannel(flutter::FlutterEngine* flutter_instance) {
@@ -421,6 +433,9 @@ void InitMethodChannel(flutter::FlutterEngine* flutter_instance) {
421433
else if (call.method_name().compare("util.arch") == 0) {
422434
result->Success(utilGetArch());
423435
}
436+
else if (call.method_name().compare("util.workspace") == 0) {
437+
result->Success(utilWorkspaceBaseDir());
438+
}
424439
else {
425440
result->NotImplemented();
426441
}

0 commit comments

Comments
 (0)