Refactor RealFileSystem to use WorkingDir, and ensure clean shutdown with FlushAll

This commit is contained in:
gmp
2026-06-05 11:42:39 -04:00
parent ac2e0e444d
commit 1324772215
6 changed files with 78 additions and 36 deletions
+44 -19
View File
@@ -2,6 +2,7 @@ package st.wow.git.logbook;
import java.lang.Runnable;
import java.lang.String;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.content.Context;
@@ -39,25 +40,49 @@ public class Permissions extends Fragment {
});
}
@Override public void onAttach(Context ctx) {
super.onAttach(ctx);
Log.d("gio", "onAttach()");
if (ctx instanceof Activity) {
Log.d("gio", "It's an Activity!");
}
if (ctx.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ctx.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Log.d("gio", "Requesting permissions");
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST);
}
if (!Environment.isExternalStorageManager()){
Intent intent = new Intent();
intent.setAction(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
Uri uri = Uri.fromParts("package", getActivity().getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
Log.d("gio", "Loading gio library");
System.loadLibrary("gio");
@Override
public void onAttach(Context context) {
super.onAttach(context);
Log.d("gio", "onAttach()");
if (!(context instanceof Activity)) {
Log.w("gio", "Context is not an Activity");
return;
}
Activity activity = (Activity) context;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
if (context.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
PERMISSIONS_REQUEST
);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
&& !Environment.isExternalStorageManager()) {
Log.d("gio", "Requesting all files access");
Intent intent = new Intent(
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
Uri.parse("package:" + activity.getPackageName())
);
if (intent.resolveActivity(activity.getPackageManager()) != null) {
startActivity(intent);
} else {
Intent fallback = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
if (fallback.resolveActivity(activity.getPackageManager()) != null) {
startActivity(fallback);
} else {
Log.e("gio", "No activity found for all files access settings");
}
}
}
Log.d("gio", "Loading gio library");
System.loadLibrary("gio");
}
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
+1 -1
View File
@@ -24,7 +24,7 @@ import (
type JNIEnv = C.JNIEnv
var (
startpath="/storage/emulated/0/Documents"
startpath="/storage/emulated/0/Notes"
jvm uintptr
theJVM *C.JavaVM
)
+3 -7
View File
@@ -4,7 +4,6 @@ import (
"flag"
"log"
"os"
"path/filepath"
"sync"
"gioui.org/app"
@@ -41,12 +40,8 @@ func run(w *app.Window) error {
rootDir := flag.String("root", startpath, "root directory for the filesystem")
flag.Parse()
abs, err := filepath.Abs(*rootDir)
if err != nil {
log.Fatalf("invalid root directory: %v", err)
}
fs := &real.RealFileSystem{Root: abs}
log.Printf("using filesystem at %s", abs)
fs := real.NewRealFileSystem(*rootDir)
log.Printf("using filesystem at %s", fs.WorkingDir)
logic := editor.NewLogic(fs)
renderer := ui.New(ui.Theme{FontSize: 14}, shaper, logic.State())
@@ -62,6 +57,7 @@ func run(w *app.Window) error {
for {
switch e := w.Event().(type) {
case app.DestroyEvent:
logic.Shutdown()
return e.Err
case app.ConfigEvent:
// ConfigEvent: raw pixel dimensions only.