Skip to content

Commit

Permalink
feat(desktop): new desktop application project
Browse files Browse the repository at this point in the history
this is a thin wrapper consisting of a tray icon only
  • Loading branch information
gotson committed Sep 8, 2023
1 parent fdd6fff commit 4da12ae
Show file tree
Hide file tree
Showing 17 changed files with 786 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ updates:
schedule:
interval: "weekly"

- package-ecosystem: "gradle"
directory: "/komga-tray"
open-pull-requests-limit: 0
schedule:
interval: "weekly"

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
Expand Down
9 changes: 6 additions & 3 deletions .idea/runConfigurations/komga__bootRun__dev.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions .idea/runConfigurations/komga__bootRun__dev_demo_noclaim.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions .idea/runConfigurations/komga__bootRun__dev_noclaim.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions komga-tray/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
run {
kotlin("jvm")
kotlin("plugin.spring")
}
id("com.gorylenko.gradle-git-properties") version "2.4.1"
id("org.jetbrains.compose") version "1.4.3"
id("dev.hydraulic.conveyor") version "1.5"
application
}

group = "org.gotson"

kotlin {
jvmToolchain(19) // for NightMonkeys
}

dependencies {
implementation(project(":komga"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.1.1"))
implementation("org.springframework.boot:spring-boot-starter-web")

implementation(compose.desktop.common)

linuxAmd64(compose.desktop.linux_x64)
macAmd64(compose.desktop.macos_x64)
macAarch64(compose.desktop.macos_arm64)
windowsAmd64(compose.desktop.windows_x64)
}

application {
mainClass.set("org.gotson.komga.DesktopApplicationKt")
}

// Work around temporary Compose bugs
configurations.all {
attributes {
attribute(Attribute.of("ui", String::class.java), "awt")
}
}
12 changes: 12 additions & 0 deletions komga-tray/src/main/kotlin/org/gotson/komga/DesktopApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.gotson.komga

import org.springframework.boot.builder.SpringApplicationBuilder

fun main(args: Array<String>) {
System.setProperty("apple.awt.UIElement", "true")
System.setProperty("org.jooq.no-logo", "true")
System.setProperty("org.jooq.no-tips", "true")
val builder = SpringApplicationBuilder(Application::class.java)
builder.headless(false)
builder.run(*args)
}
11 changes: 11 additions & 0 deletions komga-tray/src/main/kotlin/org/gotson/komga/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.gotson.komga

import java.awt.Desktop
import java.net.URI

fun openUrl(url: String) {
if (Desktop.isDesktopSupported())
Desktop.getDesktop().let {
if (it.isSupported(Desktop.Action.BROWSE)) it.browse(URI.create(url))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.gotson.komga.application.gui

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.openUrl
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.ApplicationArguments
import org.springframework.boot.ApplicationRunner
import org.springframework.context.annotation.Profile
import org.springframework.core.env.Environment
import org.springframework.core.io.ClassPathResource
import org.springframework.stereotype.Component

@Profile("!test")
@Component
class TrayIconRunner(
@Value("#{servletContext.contextPath}") servletContextPath: String,
@Value("\${server.port}") serverPort: Int,
env: Environment,
) : ApplicationRunner {

val komgaUrl = "http://localhost:$serverPort$servletContextPath"
val iconFileName = if (env.activeProfiles.contains("mac")) "komga-gray-minimal.svg" else "komga-color.svg"
override fun run(args: ApplicationArguments) {
runTray()
}

private fun runTray() {
application {
Tray(
icon = loadSvgPainter(ClassPathResource("icons/$iconFileName").inputStream, LocalDensity.current),
menu = {
Item("Open Komga", onClick = { openUrl(komgaUrl) })
Item("Quit Komga", onClick = ::exitApplication)
},
)
}
}
}
5 changes: 5 additions & 0 deletions komga-tray/src/main/resources/application-mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
logging:
file:
name: ${user.home}/Library/Logs/Komga/komga.log
komga:
config-dir: ${user.home}/Library/Application Support/Komga
2 changes: 2 additions & 0 deletions komga-tray/src/main/resources/application-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
komga:
config-dir: ${LOCALAPPDATA}/Komga
113 changes: 113 additions & 0 deletions komga-tray/src/main/resources/icons/komga-color.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4da12ae

Please sign in to comment.