diff --git a/AGENTS.md b/AGENTS.md index 47b044b..88c9c17 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -160,7 +160,7 @@ Keep the format `major.minor.micro`: the Makefile splits it on the dots and `mak - Conflict resolution calls `SyncUi::resolveConflict(localPath, sides)` with the names of the sides that changed (`LOCAL_SIDE`, "3DS", first when it is one), which on the 3DS is `frontend::WorkerSyncUi` and returns a `ConflictChoice`: `keep(index)`, `skip()` (X) or `cancel()` (START). The prompt lists the sides however many there are (two included): the highlighted side is the A button, and tapping another row, R (wrapping) or D-pad ↑/↓ move the highlight. It starts on the first side, so A alone still keeps the 3DS's version whenever that is one of them; there is no B. Four rows fit; beyond that the list window follows the highlight (`conflictListFirst()`), with a small arrow at a scrolled-off end. L toggles "for all": a skip then skips every later conflict, a kept side is kept in every later conflict it is part of, and one it is not part of is asked again. - The main menu (`frontend::waitForMenu()`) returns a `frontend::MenuChoice`: A runs a sync, B a review-first sync (`MENU_REVIEW`, see next point), Y runs the same sync in debug mode, X (or tapping the card's PATHS line) opens the path picker, START exits. `main()` calls `setDebugEnabled()` and `debugLogReset()` from that choice *before* `frontend::runWorker()`, because the providers read the flag when they construct their `Curl` handle. START also cancels a running sync, and the flag stays set only for that run. - **Review first** (B). `syncFile()` is split in two: `decideFile()` does everything up to and including the conflict prompt (and the byte comparison before it) and returns a `FilePlan` — the sides, the source, the new generation and one `SideAction` per side (source, same, read-only, renumber, upload) — and `applyFile()` carries it out: transfers, then the manifest. A normal sync (`syncEntry()`) applies each plan at once, so it behaves as before; a review-first one runs `planEntry()` for every entry (no transfer, no manifest write), prints `planLines()`, asks `frontend::askStartTransfers()` (`SCREEN_REVIEW`), and only then `applyEntryPlan()` for each (`transferPlanned()` in `main.cpp`). A plan owns its comparison copies (`FilePlan`'s destructor removes unused ones) and points into its participants and their listings, which `PlannedEntry` (a `std::list`) keeps alive in between. `applyFile()` re-stats the 3DS's copy and leaves it alone, as a `problems` entry, if it changed since it was decided. Drive's `legacyUpload()` transfers as it goes, so `SyncProvider::hasLegacyUpload()` tells the review to hold it back for the second pass. - - **Unattended transfers.** `frontend::setUnattended(true)` for the second pass only: `aptSetSleepAllowed(false)`, so closing the lid does not sleep the console (which drops Wi-Fi and the SMB session), and `frame()` polls `PTMU_GetShellState()` and turns the backlights off (`GSPLCD_PowerOffBacklight()`) while the lid is closed. Off again restores sleep and the backlight. `ptmuInit()`/`gspLcdInit()` are in `componentsInit()`. Never leave sleep refused outside that pass: a console that does not sleep with the lid shut drains its battery. + - **Unattended transfers.** `frontend::setUnattended(true)` for the second pass only: `aptSetSleepAllowed(false)`, so closing the lid does not sleep the console (which drops Wi-Fi and the SMB session), and `frame()` polls `PTMU_GetShellState()` and turns the backlights off (`GSPLCD_PowerOffBacklight()`) while the lid is closed. Off again restores sleep and the backlight. **Neither service is held open:** `ptm:u` is opened by `watchLid()` for the unattended pass only, and `gsp::Lcd` by `setBacklights()` for each call. v0.9.0 opened both in `componentsInit()` for the app's lifetime, and the whole console froze after a while at the menu, HOME included (no crash dump): the system needs those sessions itself. Never leave sleep refused outside that pass: a console that does not sleep with the lid shut drains its battery. - **The path picker** (`frontend::choosePaths()`, `SCREEN_PATHS`) ticks which configured paths the next syncs take. `main()` owns the choice — one `bool` per `configuredPaths()` entry, all ticked at startup — and hands it to `runSync()` through `SyncRequest`. It lasts for the session only: 3DSync.ini is never rewritten for it. `runSync()` neither walks nor syncs an unticked path, and lists the ones left out at the top of the log. **A remote that takes part in none of the chosen entries is not connected at all** — not built, no login, no SMB/FTP timeout — and says so in one line; `RemoteConfig::takesPart()` is that rule (its `Only=`, and never an upload-only entry for a `Role=source` remote), shared with `syncAllEntries()` so the two cannot disagree. - The manifest (`/3ds/3DSync/manifest.json`) is a hand-parsed JSON file. Use `Manifest::set/get/has/remove` — never write JSON by hand elsewhere. - `svcSleepThread(nanoseconds)` is the 3DS sleep call (from `<3ds.h>`). Use it for rate-limit back-offs. diff --git a/source/main.cpp b/source/main.cpp index 0443bf2..e8df073 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -582,10 +582,6 @@ bool componentsInit() initStep("pxiDevInit", pxiDevInit()); initStep("amInit", amInit()); initStep("acInit", acInit()); - // A review-first sync keeps running with the lid closed: these watch the - // lid and switch the screens off meanwhile. - initStep("ptmuInit", ptmuInit()); - initStep("gspLcdInit", gspLcdInit()); u32 *socketBuffer = (u32 *)memalign(0x1000, 0x100000); if (socketBuffer == NULL) @@ -612,8 +608,6 @@ void componentsExit() sslcExit(); httpcExit(); socExit(); - gspLcdExit(); - ptmuExit(); acExit(); pxiDevExit(); romfsExit(); diff --git a/source/ui/frontend.cpp b/source/ui/frontend.cpp index 9539440..e612913 100644 --- a/source/ui/frontend.cpp +++ b/source/ui/frontend.cpp @@ -47,6 +47,7 @@ static volatile bool g_workerDone; static u64 g_runStarted; static bool g_unattended; // setUnattended(): sleep refused, lid watched static bool g_lidClosed; // as last seen while unattended +static bool g_ptmuOpen; // ptm:u, open only while unattended static Canvas *g_top; static Canvas *g_bottom; @@ -344,6 +345,9 @@ bool init() void exit() { + if (g_ptmuOpen) + ptmuExit(); + g_ptmuOpen = false; delete g_top; delete g_bottom; g_top = g_bottom = NULL; @@ -712,12 +716,44 @@ void setUnattended(bool on) LightLock_Unlock(&g_stateLock); } +// gsp::Lcd is opened for the one call and closed again. The system needs +// that service itself, to dim the screens after a while without input among +// other things: an app that kept a session open from start to exit froze the +// whole console at the menu, HOME included. +static void setBacklights(bool on) +{ + Result res = gspLcdInit(); + if (R_FAILED(res)) + { + debugf("gspLcdInit failed (0x%08lx), backlights left as they are\n", (unsigned long)res); + return; + } + if (on) + GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTH); + else + GSPLCD_PowerOffBacklight(GSPLCD_SCREEN_BOTH); + gspLcdExit(); +} + // Called from frame(): dark screens while the lid is closed during an -// unattended run, lit again when it opens or the run ends. +// unattended run, lit again when it opens or the run ends. ptm:u, which +// reads the lid, is held only for that run, for the same reason as gsp::Lcd. static void watchLid(bool unattended) { + if (unattended && !g_ptmuOpen) + { + Result res = ptmuInit(); + g_ptmuOpen = R_SUCCEEDED(res); + if (!g_ptmuOpen) + debugf("ptmuInit failed (0x%08lx), the lid is not watched\n", (unsigned long)res); + } + else if (!unattended && g_ptmuOpen) + { + ptmuExit(); + g_ptmuOpen = false; + } bool closed = false; - if (unattended) + if (g_ptmuOpen) { u8 open = 1; if (R_SUCCEEDED(PTMU_GetShellState(&open))) @@ -726,10 +762,7 @@ static void watchLid(bool unattended) if (closed == g_lidClosed) return; g_lidClosed = closed; - if (closed) - GSPLCD_PowerOffBacklight(GSPLCD_SCREEN_BOTH); - else - GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTH); + setBacklights(!closed); } // --------------------------------------------------------------------------- diff --git a/source/version.h b/source/version.h index e9706f0..d3ff628 100644 --- a/source/version.h +++ b/source/version.h @@ -16,6 +16,6 @@ // the format "major.minor.micro" — the Makefile splits it on the dots. // --------------------------------------------------------------------------- -#define APP_VERSION "0.9.0" +#define APP_VERSION "0.9.1" #endif