Minimize hides only that window, Show wIRC main tray item, remember hidden main, bump to 0.1.15
- Minimizing a window hides only that window to the tray. The other windows stay on the desktop. Win+D still hides everything. - Tray left click shows every hidden window at its old position, or hides them all if none are hidden. - The tray menu has a new Show wIRC main item that brings back just wIRC main. - If wIRC main was hidden when wIRC quit, it starts hidden next time and the servers that were connected reconnect by themselves, so their channel windows open without wIRC main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
24f54574ec
commit
78bd235a48
@@ -0,0 +1,66 @@
|
||||
package data
|
||||
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.nio.file.AtomicMoveNotSupportedException
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.StandardCopyOption
|
||||
|
||||
/**
|
||||
* What wIRC looked like when it last quit: whether wIRC main was hidden to the tray, and
|
||||
* which servers were connected. If main was hidden, the next start keeps it hidden and
|
||||
* reconnects those servers so their channel windows open by themselves (see Main.kt).
|
||||
*/
|
||||
data class SessionState(
|
||||
val mainHidden: Boolean = false,
|
||||
val connectedServerIds: Set<String> = emptySet()
|
||||
)
|
||||
|
||||
/** rootDir/session_state.json, read once at startup and written once at quit. */
|
||||
class SessionStateRepository(rootDir: File) {
|
||||
|
||||
private val file = File(rootDir, "session_state.json")
|
||||
@Volatile private var saved = false
|
||||
|
||||
fun load(): SessionState = try {
|
||||
if (!file.exists()) SessionState() else {
|
||||
val obj = JSONObject(file.readText())
|
||||
val ids = obj.optJSONArray("connectedServerIds") ?: JSONArray()
|
||||
SessionState(
|
||||
mainHidden = obj.optBoolean("mainHidden", false),
|
||||
connectedServerIds = (0 until ids.length()).map { ids.getString(it) }.toSet()
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
SessionState()
|
||||
}
|
||||
|
||||
/**
|
||||
* Only the first call counts: quitting can reach this from more than one place (the
|
||||
* Exit/close handlers and the JVM shutdown hook), and a later call could come after the
|
||||
* servers were already disconnected.
|
||||
*/
|
||||
@Synchronized
|
||||
fun saveOnce(state: SessionState) {
|
||||
if (saved) return
|
||||
saved = true
|
||||
try {
|
||||
val obj = JSONObject().apply {
|
||||
put("mainHidden", state.mainHidden)
|
||||
put("connectedServerIds", JSONArray(state.connectedServerIds.toList()))
|
||||
}
|
||||
file.parentFile?.mkdirs()
|
||||
// Temp file and move, same as WindowPrefsRepository, so a crash can't truncate it
|
||||
val tmp = File(file.parentFile, "${file.name}.tmp")
|
||||
tmp.writeText(obj.toString())
|
||||
try {
|
||||
Files.move(tmp.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE)
|
||||
} catch (e: AtomicMoveNotSupportedException) {
|
||||
Files.move(tmp.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// Next start just opens normally
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user