add webview

This commit is contained in:
Aria Moradi 2021-05-23 22:10:04 +04:30
parent 6ddb5db57b
commit 75786a91b0
13 changed files with 106 additions and 50 deletions

View File

@ -0,0 +1 @@
jre\bin\java -Dir.armor.tachidesk.openInWebview=true -jar Tachidesk.jar

View File

@ -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-win32.exe" $release_name
Copy-Item "resources/Tachidesk Launcher.bat" $release_name Copy-Item "resources/Tachidesk Launcher.bat" $release_name
Copy-Item "resources/Tachidesk Debug 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" $zip_name="$release_name.zip"
Compress-Archive -CompressionLevel Optimal -DestinationPath $zip_name -Path $release_name -Force -ErrorAction SilentlyContinue Compress-Archive -CompressionLevel Optimal -DestinationPath $zip_name -Path $release_name -Force -ErrorAction SilentlyContinue

View File

@ -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-win32.exe" "$release_name/Tachidesk Launcher.exe"
cp "resources/Tachidesk Launcher.bat" $release_name cp "resources/Tachidesk Launcher.bat" $release_name
cp "resources/Tachidesk Debug 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_name=$release_name.zip
zip -9 -r $zip_name $release_name zip -9 -r $zip_name $release_name

View File

@ -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-win64.exe" $release_name
Copy-Item "resources/Tachidesk Launcher.bat" $release_name Copy-Item "resources/Tachidesk Launcher.bat" $release_name
Copy-Item "resources/Tachidesk Debug 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" $zip_name="$release_name.zip"
Compress-Archive -CompressionLevel Optimal -DestinationPath $zip_name -Path $release_name -Force -ErrorAction SilentlyContinue Compress-Archive -CompressionLevel Optimal -DestinationPath $zip_name -Path $release_name -Force -ErrorAction SilentlyContinue

View File

@ -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-win64.exe" "$release_name/Tachidesk Launcher.exe"
cp "resources/Tachidesk Launcher.bat" $release_name cp "resources/Tachidesk Launcher.bat" $release_name
cp "resources/Tachidesk Debug 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_name=$release_name.zip
zip -9 -r $zip_name $release_name zip -9 -r $zip_name $release_name

View File

@ -65,6 +65,9 @@ dependencies {
implementation(project(":AndroidCompat")) implementation(project(":AndroidCompat"))
implementation(project(":AndroidCompat:Config")) implementation(project(":AndroidCompat:Config"))
// webview
implementation(files("lib/WebView.jar"))
// uncomment to test extensions directly // uncomment to test extensions directly
// implementation(fileTree("lib/")) // implementation(fileTree("lib/"))

1
server/lib/README.md Normal file
View File

@ -0,0 +1 @@
WebView.jar is taken from https://github.com/shannah/webviewjar

BIN
server/lib/WebView.jar Normal file

Binary file not shown.

View File

@ -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.Extension.updateExtension
import ir.armor.tachidesk.impl.extension.ExtensionsList.getExtensionList import ir.armor.tachidesk.impl.extension.ExtensionsList.getExtensionList
import ir.armor.tachidesk.server.impl_internal.About.getAbout 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.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
@ -87,8 +87,12 @@ object JavalinSetup {
} }
) )
if (hasWebUiBundled && serverConfig.initialOpenInBrowserEnabled) { app.events { event ->
openInBrowser() event.serverStarted {
if (hasWebUiBundled && serverConfig.initialOpenInBrowserEnabled) {
openInBrowser()
}
}
} }
app.exception(NullPointerException::class.java) { e, ctx -> app.exception(NullPointerException::class.java) { e, ctx ->

View File

@ -10,7 +10,7 @@ package ir.armor.tachidesk.server
import eu.kanade.tachiyomi.App import eu.kanade.tachiyomi.App
import ir.armor.tachidesk.model.database.databaseUp import ir.armor.tachidesk.model.database.databaseUp
import ir.armor.tachidesk.server.util.AppMutex.handleAppMutex 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 mu.KotlinLogging
import org.kodein.di.DI import org.kodein.di.DI
import org.kodein.di.bind import org.kodein.di.bind

View File

@ -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.Clear
import ir.armor.tachidesk.server.util.AppMutex.AppMutexStat.OtherApplicationRunning import ir.armor.tachidesk.server.util.AppMutex.AppMutexStat.OtherApplicationRunning
import ir.armor.tachidesk.server.util.AppMutex.AppMutexStat.TachideskInstanceRunning import ir.armor.tachidesk.server.util.AppMutex.AppMutexStat.TachideskInstanceRunning
import ir.armor.tachidesk.server.util.Browser.openInBrowser
import mu.KotlinLogging import mu.KotlinLogging
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request.Builder import okhttp3.Request.Builder

View File

@ -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<WebView>()
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()
}
}
}
}

View File

@ -10,56 +10,49 @@ package ir.armor.tachidesk.server.util
import dorkbox.systemTray.MenuItem import dorkbox.systemTray.MenuItem
import dorkbox.systemTray.SystemTray import dorkbox.systemTray.SystemTray
import dorkbox.util.CacheUtil import dorkbox.util.CacheUtil
import dorkbox.util.Desktop
import ir.armor.tachidesk.server.BuildConfig import ir.armor.tachidesk.server.BuildConfig
import ir.armor.tachidesk.server.ServerConfig import ir.armor.tachidesk.server.ServerConfig
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 import ir.armor.tachidesk.server.util.ExitCode.Success
fun openInBrowser() { object SystemTray {
val appIP = if (serverConfig.ip == "0.0.0.0") "127.0.0.1" else serverConfig.ip fun systemTray(): SystemTray? {
try { try {
Desktop.browseURL("http://$appIP:${serverConfig.port}") // ref: https://github.com/dorkbox/SystemTray/blob/master/test/dorkbox/TestTray.java
} catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error SystemTray.DEBUG = serverConfig.debugLogsEnabled
e.printStackTrace()
} CacheUtil.clear(BuildConfig.name)
}
val systemTray = SystemTray.get(BuildConfig.name) ?: return null
fun systemTray(): SystemTray? { val mainMenu = systemTray.menu
try {
// ref: https://github.com/dorkbox/SystemTray/blob/master/test/dorkbox/TestTray.java mainMenu.add(
SystemTray.DEBUG = serverConfig.debugLogsEnabled MenuItem(
"Open Tachidesk"
CacheUtil.clear(BuildConfig.name) ) {
openInBrowser()
val systemTray = SystemTray.get(BuildConfig.name) ?: return null }
val mainMenu = systemTray.menu )
mainMenu.add( val icon = ServerConfig::class.java.getResource("/icon/faviconlogo.png")
MenuItem(
"Open Tachidesk" // systemTray.setTooltip("Tachidesk")
) { systemTray.setImage(icon)
openInBrowser() // systemTray.status = "No Mail"
}
) mainMenu.add(
MenuItem("Quit") {
val icon = ServerConfig::class.java.getResource("/icon/faviconlogo.png") shutdownApp(Success)
}
// systemTray.setTooltip("Tachidesk") )
systemTray.setImage(icon)
// systemTray.status = "No Mail" systemTray.installShutdownHook()
mainMenu.add( return systemTray
MenuItem("Quit") { } catch (e: Exception) {
shutdownApp(Success) e.printStackTrace()
} return null
) }
systemTray.installShutdownHook()
return systemTray
} catch (e: Exception) {
e.printStackTrace()
return null
} }
} }