Installable app + one-click update from forgejo
- scripts/update-app.sh: detached updater (setsid, survives app exit): git pull atitlan master -> gradle createDistributable -> only then kill app+engine and relaunch the fresh binary. Pull or build failure leaves the running app alone. Log: ~/.config/shonar-desktop/logs/update.log. - Settings → About & updates: 'Install update' button appears when the check finds a newer remote commit; hands off to the script and tells the user the app will relaunch itself. - Desktop entry (~/.local/share/applications/shonar-desktop.desktop, outside the repo): launches the packaged distributable via launch-desktop.sh; SHONAR_REPO fallback already resolves the tree, so the packaged app spawns the engine and sees the updater script. Gate: :app:compileKotlin + :app:test green; desktop-file-validate clean; launcher verified (app window from the menu path); updater fail-safe verified (dirty-tree pull refused, app survived).
This commit is contained in:
parent
b4e335d720
commit
fc5502a7cd
3 changed files with 81 additions and 0 deletions
|
|
@ -224,6 +224,42 @@ class DesktopState(private val appDir: File = defaultAppDir()) {
|
|||
}
|
||||
}
|
||||
|
||||
/** True when scripts/update-app.sh exists next to the repo the engine
|
||||
* was spawned from (dev-tree installs only; the update pulls from
|
||||
* forgejo, rebuilds the distributable, and relaunches). */
|
||||
val updateScript: File?
|
||||
get() = repoRoot()?.let { File(it, "scripts/update-app.sh") }
|
||||
?.takeIf { it.canExecute() }
|
||||
|
||||
/** Hand off to the detached updater (git pull + rebuild + relaunch).
|
||||
* The script runs via setsid so it outlives this process when the
|
||||
* updater kills the app after a good build. */
|
||||
fun installUpdate() {
|
||||
val script = updateScript
|
||||
if (script == null) {
|
||||
_updateStatus.value = UpdateStatus("result",
|
||||
"No updater script in this install — update manually " +
|
||||
"(git pull + rebuild).", url = REPO_WEB, stale = true)
|
||||
return
|
||||
}
|
||||
_updateStatus.value = UpdateStatus("result",
|
||||
"Updating: pulling from forgejo and rebuilding — the app will " +
|
||||
"relaunch itself when it's done. Log: " +
|
||||
"${appDir.absolutePath}/logs/update.log")
|
||||
scope.launch {
|
||||
runCatching {
|
||||
ProcessBuilder("setsid", "nohup", script.absolutePath)
|
||||
.directory(script.parentFile.parentFile)
|
||||
.redirectOutput(ProcessBuilder.Redirect.DISCARD)
|
||||
.start()
|
||||
}.onFailure {
|
||||
_updateStatus.value = UpdateStatus("result",
|
||||
"Could not start the updater: ${it.message}",
|
||||
url = REPO_WEB, stale = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val _detail = MutableStateFlow<DetailUi?>(null)
|
||||
val detail: StateFlow<DetailUi?> = _detail.asStateFlow()
|
||||
|
||||
|
|
|
|||
|
|
@ -1451,6 +1451,11 @@ fun SettingsScreen(state: DesktopState) {
|
|||
Text("Open repo")
|
||||
}
|
||||
}
|
||||
if (us.stale && state.updateScript != null) {
|
||||
ShonarButton({ state.installUpdate() }) {
|
||||
Text("Install update")
|
||||
}
|
||||
}
|
||||
}
|
||||
val us = state.updateStatus.collectAsState().value
|
||||
if (us.message.isNotEmpty()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue