added visual settings (font/spacing/weight), imprpved linux "show file", added "share/show" to a library card

This commit is contained in:
sergeych committed 2026-05-25 10:10:01 +03:00
1 parent 3e83185e4f
commit 2fddacb7e7
9 files changed
+520 -30

No files matched your search

@@ -293,22 +293,55 @@ actual suspend fun markLibraryFavorite(fileId: String, favorite: Boolean): Boole
actual suspend fun shareLibraryBookFile(fileId: String): Boolean = false
actual suspend fun viewLibraryBookFile(fileId: String): Boolean = withContext(Dispatchers.IO) {
actual suspend fun viewLibraryBookFile(folder: String, fileName: String): Boolean = withContext(Dispatchers.IO) {
runCatching {
if (!Desktop.isDesktopSupported()) return@withContext false
val file = openLibraryDatabase().useLibrary { db ->
db.files.get(fileId)?.storageUri?.let(::File)?.takeIf { it.isFile }
} ?: return@withContext false
val desktop = Desktop.getDesktop()
if (desktop.isSupported(Desktop.Action.BROWSE_FILE_DIR)) {
desktop.browseFileDirectory(file)
} else {
desktop.open(file.parentFile ?: file)
}
true
val directory = File(folder).takeIf { it.isDirectory } ?: return@withContext false
val file = File(directory, fileName).takeIf { it.isFile } ?: return@withContext false
selectOrOpenBookFile(directory, file)
}.getOrDefault(false)
}
private fun selectOrOpenBookFile(directory: File, file: File): Boolean {
if (isLinuxDesktop() && trySelectLinuxFile(file)) return true
if (!Desktop.isDesktopSupported()) return false
val desktop = Desktop.getDesktop()
return when {
desktop.isSupported(Desktop.Action.BROWSE_FILE_DIR) -> {
desktop.browseFileDirectory(file)
true
}
desktop.isSupported(Desktop.Action.OPEN) -> {
desktop.open(directory)
true
}
else -> false
}
}
private fun isLinuxDesktop(): Boolean =
System.getProperty("os.name").orEmpty().lowercase(Locale.ROOT).contains("linux")
private fun trySelectLinuxFile(file: File): Boolean =
runCatching {
val process = ProcessBuilder(
"dbus-send",
"--session",
"--dest=org.freedesktop.FileManager1",
"--type=method_call",
"/org/freedesktop/FileManager1",
"org.freedesktop.FileManager1.ShowItems",
"array:string:${file.toURI()}",
"string:",
).start()
if (process.waitFor(2, TimeUnit.SECONDS)) {
process.exitValue() == 0
} else {
process.destroyForcibly()
false
}
}.getOrDefault(false)
actual suspend fun loadBookInfoExtras(fileId: String): BookInfoExtras = withContext(Dispatchers.IO) {
openLibraryDatabase().useLibrary { db ->
val file = db.files.get(fileId) ?: return@useLibrary BookInfoExtras()
@@ -367,6 +400,18 @@ actual suspend fun saveThemeMode(mode: ThemeMode) = withContext(Dispatchers.IO)
}
}
actual suspend fun loadReaderFontSettings(): ReaderFontSettings = withContext(Dispatchers.IO) {
openLibraryDatabase().useLibrary { db ->
readerFontSettingsFromStorageValue(db.getAppFlag(ReaderFontSettingsFlag))
}
}
actual suspend fun saveReaderFontSettings(settings: ReaderFontSettings) = withContext(Dispatchers.IO) {
openLibraryDatabase().useLibrary { db ->
db.setAppFlag(ReaderFontSettingsFlag, settings.toStorageValue())
}
}
actual suspend fun loadScanDownloadsAutomatically(): Boolean = withContext(Dispatchers.IO) {
openLibraryDatabase().useLibrary { db ->
db.getAppFlag(ScanDownloadsAutomaticallyFlag)?.toBooleanStrictOrNull() ?: true
@@ -611,6 +656,7 @@ private fun runCommand(vararg command: String): String? =
private const val ActiveReadingFileIdFlag = "active_reading_file_id"
private const val ThemeModeFlag = "theme_mode"
private const val ReaderFontSettingsFlag = "reader_font_settings"
private const val ScanDownloadsAutomaticallyFlag = "scan_downloads_automatically"
private const val AppLocaleTagFlag = "app_locale_tag"
private const val DownloadsWasScannedFlag = "downloads_was_scanned"