mirror of
https://github.com/gotson/komga.git
synced 2026-05-08 12:35:30 +02:00
feat(desktop): add menu items to locate log file and configuration directory
This commit is contained in:
parent
029dea9410
commit
80b5a33660
2 changed files with 16 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package org.gotson.komga
|
||||
|
||||
import java.awt.Desktop
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
|
||||
fun openUrl(url: String) {
|
||||
|
|
@ -9,3 +10,10 @@ fun openUrl(url: String) {
|
|||
if (it.isSupported(Desktop.Action.BROWSE)) it.browse(URI.create(url))
|
||||
}
|
||||
}
|
||||
|
||||
fun openExplorer(file: File) {
|
||||
if (Desktop.isDesktopSupported())
|
||||
Desktop.getDesktop().let {
|
||||
if (it.isSupported(Desktop.Action.BROWSE_FILE_DIR)) it.browseFileDirectory(file)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import androidx.compose.ui.platform.LocalDensity
|
|||
import androidx.compose.ui.res.loadSvgPainter
|
||||
import androidx.compose.ui.window.Tray
|
||||
import androidx.compose.ui.window.application
|
||||
import org.gotson.komga.openExplorer
|
||||
import org.gotson.komga.openUrl
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.boot.ApplicationArguments
|
||||
|
|
@ -12,16 +13,21 @@ import org.springframework.context.annotation.Profile
|
|||
import org.springframework.core.env.Environment
|
||||
import org.springframework.core.io.ClassPathResource
|
||||
import org.springframework.stereotype.Component
|
||||
import java.io.File
|
||||
|
||||
@Profile("!test")
|
||||
@Component
|
||||
class TrayIconRunner(
|
||||
@Value("#{servletContext.contextPath}") servletContextPath: String,
|
||||
@Value("#{komgaProperties.configDir}") komgaConfigDir: String,
|
||||
@Value("\${logging.file.name}") logFileName: String,
|
||||
@Value("\${server.port}") serverPort: Int,
|
||||
env: Environment,
|
||||
) : ApplicationRunner {
|
||||
|
||||
val komgaUrl = "http://localhost:$serverPort$servletContextPath"
|
||||
val komgaConfigDir = File(komgaConfigDir)
|
||||
val logFile = File(logFileName)
|
||||
val iconFileName = if (env.activeProfiles.contains("mac")) "komga-gray-minimal.svg" else "komga-color.svg"
|
||||
override fun run(args: ApplicationArguments) {
|
||||
runTray()
|
||||
|
|
@ -33,6 +39,8 @@ class TrayIconRunner(
|
|||
icon = loadSvgPainter(ClassPathResource("icons/$iconFileName").inputStream, LocalDensity.current),
|
||||
menu = {
|
||||
Item("Open Komga", onClick = { openUrl(komgaUrl) })
|
||||
Item("Show log file", onClick = { openExplorer(logFile) })
|
||||
Item("Open configuration directory", onClick = { openExplorer(komgaConfigDir) })
|
||||
Item("Quit Komga", onClick = ::exitApplication)
|
||||
},
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue