mirror of
https://github.com/wgtunnel/desktop.git
synced 2026-06-02 00:29:09 +02:00
fix: default to gpu rendering with optional user config override
This commit is contained in:
+1
-1
@@ -109,7 +109,7 @@ val serviceModule = module {
|
||||
}
|
||||
single<DaemonService> { UdsDaemonService(get(), get(), get()) }
|
||||
single<TunnelService> { UdsTunnelService(get(), tunnelRepository = get()) }
|
||||
single<BackendService> { UdsBackendService(get(), get(), get(), get(), get()) }
|
||||
single<BackendService> { UdsBackendService(get(), get(), get(), get()) }
|
||||
|
||||
single<TunnelImportService> { DefaultTunnelImportService(get()) }
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.window.application
|
||||
import androidx.compose.ui.window.rememberWindowState
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.dokar.sonner.ToastType
|
||||
import com.dokar.sonner.Toaster
|
||||
import com.dokar.sonner.rememberToasterState
|
||||
@@ -44,6 +45,8 @@ import com.zaneschepke.wireguardautotunnel.desktop.ui.screens.tunnels.components
|
||||
import com.zaneschepke.wireguardautotunnel.desktop.ui.state.TrayBadgeState
|
||||
import com.zaneschepke.wireguardautotunnel.desktop.ui.theme.ErrorRed
|
||||
import com.zaneschepke.wireguardautotunnel.desktop.ui.theme.WGTunnelTheme
|
||||
import com.zaneschepke.wireguardautotunnel.desktop.util.FileUtils
|
||||
import com.zaneschepke.wireguardautotunnel.desktop.util.RenderingMode
|
||||
import com.zaneschepke.wireguardautotunnel.desktop.viewmodel.AppViewModel
|
||||
import io.github.kdroidfilter.nucleus.energymanager.EnergyManager
|
||||
import io.github.kdroidfilter.nucleus.hidpi.getLinuxNativeScaleFactor
|
||||
@@ -62,8 +65,17 @@ import org.orbitmvi.orbit.compose.collectAsState
|
||||
|
||||
@OptIn(ExperimentalTrayAppApi::class)
|
||||
fun main() {
|
||||
System.setProperty("skiko.renderApi", "SOFTWARE_FASTEST")
|
||||
val appConfig = FileUtils.loadAppConfig()
|
||||
|
||||
when (appConfig.renderingMode) {
|
||||
RenderingMode.SOFTWARE -> {
|
||||
System.setProperty("skiko.renderApi", "SOFTWARE_FASTEST")
|
||||
Logger.i { "Running app with SOFTWARE rendering" }
|
||||
}
|
||||
RenderingMode.HARDWARE -> {
|
||||
Logger.i { "Running app with default hardware acceleration" }
|
||||
}
|
||||
}
|
||||
// HiDPI detection for Linux
|
||||
if (System.getProperty("sun.java2d.uiScale") == null) {
|
||||
val scale = getLinuxNativeScaleFactor()
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.zaneschepke.wireguardautotunnel.desktop.util
|
||||
|
||||
import java.util.Properties
|
||||
|
||||
data class AppConfig(val renderingMode: RenderingMode = RenderingMode.HARDWARE) {
|
||||
|
||||
companion object {
|
||||
fun fromProperties(props: Properties): AppConfig {
|
||||
val rendering = props.getProperty("rendering", "hardware")
|
||||
return AppConfig(renderingMode = RenderingMode.fromString(rendering))
|
||||
}
|
||||
}
|
||||
|
||||
fun toProperties(): Properties {
|
||||
val props = Properties()
|
||||
props.setProperty("rendering", renderingMode.name.lowercase())
|
||||
return props
|
||||
}
|
||||
}
|
||||
+39
-2
@@ -1,6 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.desktop.util
|
||||
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.zaneschepke.wireguardautotunnel.core.helper.FilePathsHelper.getDatabaseDir
|
||||
import java.io.*
|
||||
import java.util.Properties
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
import java.util.zip.ZipOutputStream
|
||||
@@ -59,7 +62,41 @@ object FileUtils {
|
||||
return byteArrayOutputStream.toByteArray()
|
||||
}
|
||||
|
||||
fun getNameFromFileName(fileName: String): String {
|
||||
return fileName.substringBeforeLast(".")
|
||||
fun getConfigFile(): File {
|
||||
val configDir = getDatabaseDir()
|
||||
if (!configDir.exists()) configDir.mkdirs()
|
||||
return File(configDir, "config.properties")
|
||||
}
|
||||
|
||||
fun loadAppConfig(): AppConfig {
|
||||
val configFile = getConfigFile()
|
||||
|
||||
if (!configFile.exists()) {
|
||||
createDefaultConfigTemplate(configFile)
|
||||
}
|
||||
|
||||
return try {
|
||||
val props = Properties()
|
||||
configFile.inputStream().use { props.load(it) }
|
||||
AppConfig.fromProperties(props)
|
||||
} catch (_: Exception) {
|
||||
Logger.w { "Could not read config.properties, using defaults" }
|
||||
AppConfig()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createDefaultConfigTemplate(file: File) {
|
||||
file.writeText(
|
||||
"""
|
||||
# WireGuard Auto Tunnel - Advanced Configuration
|
||||
# Edit this file and restart the app for changes to apply.
|
||||
#
|
||||
# rendering=hardware (default, best performance, recommended)
|
||||
# rendering=software (use only if you have issues rendering the app)
|
||||
#
|
||||
rendering=hardware
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.zaneschepke.wireguardautotunnel.desktop.util
|
||||
|
||||
enum class RenderingMode {
|
||||
HARDWARE,
|
||||
SOFTWARE;
|
||||
|
||||
companion object {
|
||||
fun fromString(value: String?): RenderingMode =
|
||||
when (value?.trim()?.lowercase()) {
|
||||
"software" -> SOFTWARE
|
||||
else -> HARDWARE
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user