Desktop app: shell and library screens
This commit is contained in:
@@ -1,11 +1,33 @@
|
||||
package ru.stenfredd.sleepyowl.core.common
|
||||
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import java.time.LocalDateTime
|
||||
import java.time.LocalTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
private val TIME = DateTimeFormatter.ofPattern("HH:mm:ss.SSS")
|
||||
private val LEVELS = mapOf(Log.DEBUG to 'D', Log.INFO to 'I', Log.WARN to 'W', Log.ERROR to 'E')
|
||||
|
||||
/** The log file of this run, see [logToFile]; written next to stderr. */
|
||||
@Volatile
|
||||
private var file: PrintStream? = null
|
||||
|
||||
/**
|
||||
* Also writes the log into `dir/sleepyowl.log`; the previous run's file is kept as `sleepyowl.1.log`.
|
||||
* Called once by the desktop app at start.
|
||||
*/
|
||||
fun logToFile(dir: File) {
|
||||
runCatching {
|
||||
dir.mkdirs()
|
||||
val current = File(dir, "sleepyowl.log")
|
||||
if (current.exists()) current.renameTo(File(dir, "sleepyowl.1.log"))
|
||||
file = PrintStream(current.outputStream().buffered(), true, Charsets.UTF_8).also {
|
||||
it.println("---- ${LocalDateTime.now()}")
|
||||
}
|
||||
}.onFailure { System.err.println("Log file not opened in $dir: $it") }
|
||||
}
|
||||
|
||||
internal actual fun logEnabled() = true
|
||||
|
||||
internal actual fun platformLog(priority: Int, tag: String, t: Throwable?, message: String, args: Array<out Any?>) {
|
||||
@@ -14,5 +36,9 @@ internal actual fun platformLog(priority: Int, tag: String, t: Throwable?, messa
|
||||
synchronized(System.err) {
|
||||
System.err.println(line)
|
||||
t?.printStackTrace()
|
||||
file?.let { out ->
|
||||
out.println(line)
|
||||
t?.printStackTrace(out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,23 @@
|
||||
package ru.stenfredd.sleepyowl.core.jellyfin
|
||||
|
||||
import org.jellyfin.sdk.JellyfinOptions
|
||||
import org.jellyfin.sdk.model.DeviceInfo
|
||||
import java.io.File
|
||||
import java.util.UUID
|
||||
|
||||
class DesktopJellyfinPlatform : JellyfinPlatform {
|
||||
// /etc/hostname rather than InetAddress: that one may wait for DNS.
|
||||
override val deviceName = "SleepyOwl · " + (runCatching { File("/etc/hostname").readText().trim() }.getOrNull()?.ifEmpty { null } ?: "Linux")
|
||||
override val deviceName = "SleepyOwl · " + (readLine("/etc/hostname") ?: "Linux")
|
||||
|
||||
/**
|
||||
* The SDK's default device: on Android it comes from the system, on the desktop it has to be given — server
|
||||
* discovery and probing (`ServerLogin.find`) create their API clients with it. Signed-in clients use the
|
||||
* account's saved device id instead. The id is this machine's (`/etc/machine-id`), hashed.
|
||||
*/
|
||||
override fun configure(options: JellyfinOptions.Builder) {
|
||||
val machine = readLine("/etc/machine-id") ?: deviceName
|
||||
options.deviceInfo = DeviceInfo(id = UUID.nameUUIDFromBytes(machine.toByteArray()).toString(), name = deviceName)
|
||||
}
|
||||
|
||||
private fun readLine(path: String) = runCatching { File(path).readText().trim() }.getOrNull()?.ifEmpty { null }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user