diff --git a/scripts/resources/Tachidesk Webview Launcher.bat b/scripts/resources/Tachidesk Webview Launcher.bat new file mode 100644 index 0000000..779af70 --- /dev/null +++ b/scripts/resources/Tachidesk Webview Launcher.bat @@ -0,0 +1 @@ +jre\bin\java -Dir.armor.tachidesk.openInWebview=true -jar Tachidesk.jar diff --git a/scripts/windows32-bundler.ps1 b/scripts/windows32-bundler.ps1 index addf297..5137deb 100644 --- a/scripts/windows32-bundler.ps1 +++ b/scripts/windows32-bundler.ps1 @@ -29,6 +29,7 @@ Copy-Item $jar.FullName "$release_name/Tachidesk.jar" Copy-Item "resources/Tachidesk Launcher-win32.exe" $release_name Copy-Item "resources/Tachidesk Launcher.bat" $release_name Copy-Item "resources/Tachidesk Debug Launcher.bat" $release_name +Copy-Item "resources/Tachidesk Webview Launcher.bat" $release_name $zip_name="$release_name.zip" Compress-Archive -CompressionLevel Optimal -DestinationPath $zip_name -Path $release_name -Force -ErrorAction SilentlyContinue diff --git a/scripts/windows32-bundler.sh b/scripts/windows32-bundler.sh index 3d96521..cd06812 100755 --- a/scripts/windows32-bundler.sh +++ b/scripts/windows32-bundler.sh @@ -32,6 +32,7 @@ cp $jar $release_name/Tachidesk.jar cp "resources/Tachidesk Launcher-win32.exe" "$release_name/Tachidesk Launcher.exe" cp "resources/Tachidesk Launcher.bat" $release_name cp "resources/Tachidesk Debug Launcher.bat" $release_name +cp "resources/Tachidesk Webview Launcher.bat" $release_name zip_name=$release_name.zip zip -9 -r $zip_name $release_name diff --git a/scripts/windows64-bundler.ps1 b/scripts/windows64-bundler.ps1 index b243c62..cd06da2 100644 --- a/scripts/windows64-bundler.ps1 +++ b/scripts/windows64-bundler.ps1 @@ -29,6 +29,7 @@ Copy-Item $jar.FullName "$release_name/Tachidesk.jar" Copy-Item "resources/Tachidesk Launcher-win64.exe" $release_name Copy-Item "resources/Tachidesk Launcher.bat" $release_name Copy-Item "resources/Tachidesk Debug Launcher.bat" $release_name +Copy-Item "resources/Tachidesk Webview Launcher.bat" $release_name $zip_name="$release_name.zip" Compress-Archive -CompressionLevel Optimal -DestinationPath $zip_name -Path $release_name -Force -ErrorAction SilentlyContinue diff --git a/scripts/windows64-bundler.sh b/scripts/windows64-bundler.sh index e3193ee..e99bf9e 100755 --- a/scripts/windows64-bundler.sh +++ b/scripts/windows64-bundler.sh @@ -32,6 +32,7 @@ cp $jar $release_name/Tachidesk.jar cp "resources/Tachidesk Launcher-win64.exe" "$release_name/Tachidesk Launcher.exe" cp "resources/Tachidesk Launcher.bat" $release_name cp "resources/Tachidesk Debug Launcher.bat" $release_name +cp "resources/Tachidesk Webview Launcher.bat" $release_name zip_name=$release_name.zip zip -9 -r $zip_name $release_name diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 23f41b6..65cfe11 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -65,6 +65,9 @@ dependencies { implementation(project(":AndroidCompat")) implementation(project(":AndroidCompat:Config")) + // webview + implementation(files("lib/WebView.jar")) + // uncomment to test extensions directly // implementation(fileTree("lib/")) diff --git a/server/lib/README.md b/server/lib/README.md new file mode 100644 index 0000000..ca8ce7f --- /dev/null +++ b/server/lib/README.md @@ -0,0 +1 @@ +WebView.jar is taken from https://github.com/shannah/webviewjar diff --git a/server/lib/WebView.jar b/server/lib/WebView.jar new file mode 100644 index 0000000..27aef45 Binary files /dev/null and b/server/lib/WebView.jar differ diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt index a532e01..080a21f 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/JavalinSetup.kt @@ -33,7 +33,7 @@ import ir.armor.tachidesk.impl.extension.Extension.uninstallExtension import ir.armor.tachidesk.impl.extension.Extension.updateExtension import ir.armor.tachidesk.impl.extension.ExtensionsList.getExtensionList import ir.armor.tachidesk.server.impl_internal.About.getAbout -import ir.armor.tachidesk.server.util.openInBrowser +import ir.armor.tachidesk.server.util.Browser.openInBrowser import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob @@ -87,8 +87,12 @@ object JavalinSetup { } ) - if (hasWebUiBundled && serverConfig.initialOpenInBrowserEnabled) { - openInBrowser() + app.events { event -> + event.serverStarted { + if (hasWebUiBundled && serverConfig.initialOpenInBrowserEnabled) { + openInBrowser() + } + } } app.exception(NullPointerException::class.java) { e, ctx -> diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt index 153e9fc..a08c4a5 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/ServerSetup.kt @@ -10,7 +10,7 @@ package ir.armor.tachidesk.server import eu.kanade.tachiyomi.App import ir.armor.tachidesk.model.database.databaseUp import ir.armor.tachidesk.server.util.AppMutex.handleAppMutex -import ir.armor.tachidesk.server.util.systemTray +import ir.armor.tachidesk.server.util.SystemTray.systemTray import mu.KotlinLogging import org.kodein.di.DI import org.kodein.di.bind diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/util/AppMutex.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/util/AppMutex.kt index 994cb59..afa6c7f 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/util/AppMutex.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/util/AppMutex.kt @@ -13,6 +13,7 @@ import ir.armor.tachidesk.server.serverConfig import ir.armor.tachidesk.server.util.AppMutex.AppMutexStat.Clear import ir.armor.tachidesk.server.util.AppMutex.AppMutexStat.OtherApplicationRunning import ir.armor.tachidesk.server.util.AppMutex.AppMutexStat.TachideskInstanceRunning +import ir.armor.tachidesk.server.util.Browser.openInBrowser import mu.KotlinLogging import okhttp3.OkHttpClient import okhttp3.Request.Builder diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/util/Browser.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/util/Browser.kt new file mode 100644 index 0000000..2e6b6a0 --- /dev/null +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/util/Browser.kt @@ -0,0 +1,49 @@ +package ir.armor.tachidesk.server.util + +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +import ca.weblite.webview.WebView +import dorkbox.util.Desktop +import ir.armor.tachidesk.server.serverConfig + +object Browser { + private val appIP = if (serverConfig.ip == "0.0.0.0") "127.0.0.1" else serverConfig.ip + private val appBaseUrl = "http://$appIP:${serverConfig.port}" + + private val webViewInstances = mutableListOf() + + private fun createWebView() = WebView() + .size(800, 600) + .title("Tachidesk") + .resizable(true) + .url(appBaseUrl) + .also { + WebView::class.java.getDeclaredField("fullscreen").setBoolean(it, true) + }.also { + webViewInstances.add(it) + } + + fun openInBrowser() { + + val openInWebView = System.getProperty("ir.armor.tachidesk.openInWebview")?.toBoolean() + + if (openInWebView == true) { + try { + createWebView().show() + } catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error + e.printStackTrace() + } + } else { + try { + Desktop.browseURL(appBaseUrl) + } catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error + e.printStackTrace() + } + } + } +} diff --git a/server/src/main/kotlin/ir/armor/tachidesk/server/util/SystemTray.kt b/server/src/main/kotlin/ir/armor/tachidesk/server/util/SystemTray.kt index 803b541..c0e8530 100644 --- a/server/src/main/kotlin/ir/armor/tachidesk/server/util/SystemTray.kt +++ b/server/src/main/kotlin/ir/armor/tachidesk/server/util/SystemTray.kt @@ -10,56 +10,49 @@ package ir.armor.tachidesk.server.util import dorkbox.systemTray.MenuItem import dorkbox.systemTray.SystemTray import dorkbox.util.CacheUtil -import dorkbox.util.Desktop import ir.armor.tachidesk.server.BuildConfig import ir.armor.tachidesk.server.ServerConfig import ir.armor.tachidesk.server.serverConfig +import ir.armor.tachidesk.server.util.Browser.openInBrowser import ir.armor.tachidesk.server.util.ExitCode.Success -fun openInBrowser() { - val appIP = if (serverConfig.ip == "0.0.0.0") "127.0.0.1" else serverConfig.ip - try { - Desktop.browseURL("http://$appIP:${serverConfig.port}") - } catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error - e.printStackTrace() - } -} - -fun systemTray(): SystemTray? { - try { - // ref: https://github.com/dorkbox/SystemTray/blob/master/test/dorkbox/TestTray.java - SystemTray.DEBUG = serverConfig.debugLogsEnabled - - CacheUtil.clear(BuildConfig.name) - - val systemTray = SystemTray.get(BuildConfig.name) ?: return null - val mainMenu = systemTray.menu - - mainMenu.add( - MenuItem( - "Open Tachidesk" - ) { - openInBrowser() - } - ) - - val icon = ServerConfig::class.java.getResource("/icon/faviconlogo.png") - - // systemTray.setTooltip("Tachidesk") - systemTray.setImage(icon) - // systemTray.status = "No Mail" - - mainMenu.add( - MenuItem("Quit") { - shutdownApp(Success) - } - ) - - systemTray.installShutdownHook() - - return systemTray - } catch (e: Exception) { - e.printStackTrace() - return null +object SystemTray { + fun systemTray(): SystemTray? { + try { + // ref: https://github.com/dorkbox/SystemTray/blob/master/test/dorkbox/TestTray.java + SystemTray.DEBUG = serverConfig.debugLogsEnabled + + CacheUtil.clear(BuildConfig.name) + + val systemTray = SystemTray.get(BuildConfig.name) ?: return null + val mainMenu = systemTray.menu + + mainMenu.add( + MenuItem( + "Open Tachidesk" + ) { + openInBrowser() + } + ) + + val icon = ServerConfig::class.java.getResource("/icon/faviconlogo.png") + + // systemTray.setTooltip("Tachidesk") + systemTray.setImage(icon) + // systemTray.status = "No Mail" + + mainMenu.add( + MenuItem("Quit") { + shutdownApp(Success) + } + ) + + systemTray.installShutdownHook() + + return systemTray + } catch (e: Exception) { + e.printStackTrace() + return null + } } }