Initial commit: Hermes Android native app

Fullscreen WebView wrapper with foreground keepalive service,
configurable server URL, and JavaScript bridge for native features.
This commit is contained in:
2026-07-07 20:30:33 -04:00
commit 4d168a44bb
27 changed files with 1445 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
*.iml
.gradle
/local.properties
/.idea
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
/app/build
/hermes-release-key.jks
*.apk
*.aab
+40
View File
@@ -0,0 +1,40 @@
# Hermes Android
Native Android app for [Hermes WebUI](https://github.com/nesquena/hermes-webui) — the browser-based Hermes AI Agent interface, packaged as a native app with foreground keepalive.
## Features
- **Fullscreen WebView** — loads your Hermes WebUI server
- **Foreground Service** — persistent notification keeps the connection alive when backgrounded
- **30s Health Pings** — prevents server-side session timeout
- **Auto-Reconnect** — detects stale connection on resume and reloads
- **Configurable Server URL** — point at any Hermes WebUI instance
- **JavaScript Bridge** — exposes `HermesNative` for TTS, vibration, toasts from the web app
- **Settings UI** — gear icon FAB in top-right corner
- **Wireless ADB Install** — sideload via developer options pairing
## Building
```bash
cd hermes-android
export ANDROID_HOME=/path/to/android-sdk
./gradlew assembleRelease
# APK at app/build/outputs/apk/release/app-release.apk
```
## Requirements
- Android 8.0+ (API 26)
- Hermes WebUI server running on your network (default: http://10.0.1.49:8787)
## Install
```bash
# Wireless ADB (recommended)
adb pair <phone-ip>:<port> <code>
adb -s <transport-id> install app-release.apk
```
## License
MIT
+73
View File
@@ -0,0 +1,73 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
}
android {
namespace = "com.hermes.app"
compileSdk = 36
defaultConfig {
applicationId = "com.hermes.app"
minSdk = 26
targetSdk = 36
versionCode = 1
versionName = "1.0.0"
}
buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.create("release") {
storeFile = file("../hermes-release-key.jks")
storePassword = "hermesapp"
keyAlias = "hermes"
keyPassword = "hermesapp"
}
}
debug {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
kotlinOptions {
jvmTarget = "21"
}
buildFeatures {
compose = true
}
}
dependencies {
// Compose BOM
val composeBom = platform("androidx.compose:compose-bom:2025.03.01")
implementation(composeBom)
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.activity:activity-compose:1.10.0")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.7")
// WebView (built-in) + core
implementation("androidx.core:core-ktx:1.15.0")
implementation("androidx.webkit:webkit:1.12.1")
// For settings
implementation("androidx.datastore:datastore-preferences:1.1.2")
// Foreground service + notifications
implementation("androidx.work:work-runtime-ktx:2.10.0")
debugImplementation("androidx.compose.ui:ui-tooling")
}
+13
View File
@@ -0,0 +1,13 @@
# Hermes App ProGuard Rules
# Keep WebView JavaScript interface methods
-keepclassmembers class com.hermes.app.HermesWebAppInterface {
@android.webkit.JavascriptInterface <methods>;
}
# Keep BuildConfig fields
-keep class com.hermes.app.BuildConfig { *; }
# Keep data classes and serialization
-keepattributes *Annotation*
-keepattributes JavascriptInterface
+66
View File
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Network access for Hermes WebUI server -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- Foreground service for keepalive -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<!-- Boot receiver for auto-start (optional) -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Hermes"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config">
<activity
android:name=".MainActivity"
android:exported="true"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Deep links to open specific sessions -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="hermes.app" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:exported="false"
android:theme="@style/Theme.Hermes.Settings" />
<service
android:name=".HermesForegroundService"
android:exported="false"
android:foregroundServiceType="connectedDevice" />
<receiver
android:name=".BootReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
@@ -0,0 +1,11 @@
package com.hermes.app
object AppConstants {
const val DEFAULT_SERVER_URL = "http://10.0.1.49:8787"
const val PREFS_NAME = "hermes_settings"
const val PREFS_SERVER_URL = "server_url"
const val PREFS_KEEPALIVE = "keepalive_enabled"
const val NOTIFICATION_CHANNEL_ID = "hermes_keepalive"
const val NOTIFICATION_ID = 1001
const val HEALTH_CHECK_INTERVAL_SECONDS = 30L
}
@@ -0,0 +1,22 @@
package com.hermes.app
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
/**
* Auto-starts the foreground keepalive service after device boot.
*/
class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
val serviceIntent = Intent(context, HermesForegroundService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(serviceIntent)
} else {
context.startService(serviceIntent)
}
}
}
}
@@ -0,0 +1,168 @@
package com.hermes.app
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Build
import android.os.IBinder
import android.os.PowerManager
import androidx.core.app.NotificationCompat
import java.net.HttpURLConnection
import java.net.URL
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
/**
* Foreground service that keeps the Hermes WebView process alive and
* periodically checks the server connection. Prevents Android from
* killing the app process when backgrounded.
*/
class HermesForegroundService : Service() {
private val executor = Executors.newSingleThreadScheduledExecutor()
private var healthCheckFuture: java.util.concurrent.ScheduledFuture<*>? = null
private var isConnected = false
private var lastHealthStatus = false
private var wakeLock: PowerManager.WakeLock? = null
override fun onCreate() {
super.onCreate()
createNotificationChannel()
registerNetworkCallback()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = buildNotification()
startForeground(AppConstants.NOTIFICATION_ID, notification)
// Start periodic health checks
startHealthChecks()
// Acquire partial wake lock to prevent CPU sleep
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
wakeLock = powerManager.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK,
"Hermes:KeepaliveLock"
)
wakeLock?.acquire(10 * 60 * 1000L) // 10 minute max
return START_STICKY
}
override fun onBind(intent: Intent?): IBinder? = null
override fun onDestroy() {
healthCheckFuture?.cancel(true)
executor.shutdown()
wakeLock?.let {
if (it.isHeld) it.release()
}
super.onDestroy()
}
private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
AppConstants.NOTIFICATION_CHANNEL_ID,
"Hermes Connection",
NotificationManager.IMPORTANCE_LOW
).apply {
description = "Keeps Hermes WebUI connected"
setShowBadge(false)
}
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.createNotificationChannel(channel)
}
}
private fun buildNotification(): Notification {
val openIntent = Intent(this, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
}
val openPendingIntent = PendingIntent.getActivity(
this, 0, openIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val prefs = getSharedPreferences(AppConstants.PREFS_NAME, Context.MODE_PRIVATE)
val serverUrl = prefs.getString(
AppConstants.PREFS_SERVER_URL, AppConstants.DEFAULT_SERVER_URL
) ?: AppConstants.DEFAULT_SERVER_URL
return NotificationCompat.Builder(this, AppConstants.NOTIFICATION_CHANNEL_ID)
.setContentTitle("Hermes")
.setContentText(
if (isConnected) "Connected to $serverUrl"
else "Reconnecting..."
)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setOngoing(true)
.setContentIntent(openPendingIntent)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.build()
}
private fun startHealthChecks() {
healthCheckFuture = executor.scheduleWithFixedDelay(
{ checkServerHealth() },
5, // initial delay in seconds
AppConstants.HEALTH_CHECK_INTERVAL_SECONDS,
TimeUnit.SECONDS
)
}
private fun checkServerHealth() {
try {
val prefs = getSharedPreferences(AppConstants.PREFS_NAME, Context.MODE_PRIVATE)
val keepaliveEnabled = prefs.getBoolean(AppConstants.PREFS_KEEPALIVE, true)
if (!keepaliveEnabled) return
val serverUrl = prefs.getString(
AppConstants.PREFS_SERVER_URL, AppConstants.DEFAULT_SERVER_URL
) ?: AppConstants.DEFAULT_SERVER_URL
val healthUrl = URL("$serverUrl/health")
val connection = healthUrl.openConnection() as HttpURLConnection
connection.connectTimeout = 5000
connection.readTimeout = 5000
connection.requestMethod = "GET"
val responseCode = connection.responseCode
connection.disconnect()
isConnected = responseCode == 200
} catch (e: Exception) {
isConnected = false
}
if (isConnected != lastHealthStatus) {
lastHealthStatus = isConnected
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.notify(AppConstants.NOTIFICATION_ID, buildNotification())
}
}
private fun registerNetworkCallback() {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkRequest = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build()
connectivityManager.registerNetworkCallback(
networkRequest,
object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
checkServerHealth()
}
}
)
}
}
@@ -0,0 +1,124 @@
package com.hermes.app
import android.content.Context
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
import android.os.VibratorManager
import android.speech.tts.TextToSpeech
import android.widget.Toast
import android.webkit.JavascriptInterface
import java.util.Locale
/**
* JavaScript interface exposed to the Hermes WebUI as `HermesNative`.
* Provides native Android capabilities to the web app.
*/
class HermesWebAppInterface(private val context: Context) {
private var tts: TextToSpeech? = null
/**
* Get the device info for analytics/debugging.
*/
@JavascriptInterface
fun getDeviceInfo(): String {
return """
{
"platform": "android",
"appVersion": "1.0.0",
"sdkInt": ${Build.VERSION.SDK_INT},
"model": "${Build.MODEL}",
"manufacturer": "${Build.MANUFACTURER}"
}
""".trimIndent()
}
/**
* Speak text using TTS.
*/
@JavascriptInterface
fun speak(text: String) {
if (tts == null) {
tts = TextToSpeech(context) { status ->
if (status == TextToSpeech.SUCCESS) {
tts?.language = Locale.US
@Suppress("DEPRECATION")
tts?.speak(text, TextToSpeech.QUEUE_FLUSH, null, null)
}
}
} else {
@Suppress("DEPRECATION")
tts?.speak(text, TextToSpeech.QUEUE_FLUSH, null, null)
}
}
/**
* Vibrate the device.
*/
@JavascriptInterface
fun vibrate(durationMs: Int) {
val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val manager = context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as? VibratorManager
manager?.defaultVibrator
} else {
@Suppress("DEPRECATION")
context.getSystemService(Context.VIBRATOR_SERVICE) as? Vibrator
}
vibrator?.let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
it.vibrate(
VibrationEffect.createOneShot(
durationMs.coerceIn(50, 5000).toLong(),
VibrationEffect.DEFAULT_AMPLITUDE
)
)
} else {
@Suppress("DEPRECATION")
it.vibrate(durationMs.coerceIn(50, 5000).toLong())
}
}
}
/**
* Show a toast message.
*/
@JavascriptInterface
fun toast(message: String) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}
/**
* Set the app badge count.
*/
@JavascriptInterface
fun setBadge(count: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE)
as android.app.NotificationManager
try {
if (count > 0) {
notificationManager.notify(
9999,
android.app.Notification.Builder(context, AppConstants.NOTIFICATION_CHANNEL_ID)
.setContentTitle("Hermes")
.setContentText("$count unread messages")
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setAutoCancel(true)
.build()
)
} else {
notificationManager.cancel(9999)
}
} catch (_: Exception) {}
}
}
/**
* Clean up TTS resources.
*/
fun shutdown() {
tts?.stop()
tts?.shutdown()
}
}
@@ -0,0 +1,150 @@
package com.hermes.app
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.webkit.*
import android.widget.Toast
/**
* Manages the WebView lifecycle and configuration for Hermes WebUI.
*/
class HermesWebViewManager(private val context: Context) {
var webView: WebView? = null
var onPageTitleChanged: ((String) -> Unit)? = null
var onPageLoading: ((Boolean) -> Unit)? = null
var onConnectionLost: (() -> Unit)? = null
fun createWebView(): WebView {
return WebView(context).apply {
layoutParams = android.view.ViewGroup.LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.MATCH_PARENT
)
webView = this
settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
loadsImagesAutomatically = true
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
cacheMode = WebSettings.LOAD_DEFAULT
useWideViewPort = true
loadWithOverviewMode = true
builtInZoomControls = false
displayZoomControls = false
mediaPlaybackRequiresUserGesture = false
allowContentAccess = true
allowFileAccess = false
userAgentString = settings.userAgentString + " HermesApp/1.0"
}
addJavascriptInterface(
HermesWebAppInterface(context),
"HermesNative"
)
webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
onPageLoading?.invoke(true)
}
override fun onPageFinished(view: WebView?, url: String?) {
onPageLoading?.invoke(false)
view?.evaluateJavascript(
"""
(function() {
window.__HERMES_NATIVE__ = true;
window.__HERMES_PLATFORM__ = 'android';
if (window.HermesPWA) {
window.HermesPWA.isNativeApp = true;
}
})()
""".trimIndent(), null
)
}
override fun onReceivedHttpError(
view: WebView?,
request: WebResourceRequest?,
errorResponse: WebResourceResponse?
) {
if (errorResponse?.statusCode in 500..599) {
onConnectionLost?.invoke()
}
}
override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?
) {
onConnectionLost?.invoke()
}
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?
): Boolean {
val url = request?.url ?: return false
val host = url.host ?: return false
val serverHost = Uri.parse(getServerUrl())?.host ?: "10.0.1.49"
if (host != serverHost && !host.endsWith(".local")) {
val intent = Intent(Intent.ACTION_VIEW, url)
context.startActivity(intent)
return true
}
return false
}
}
webChromeClient = object : WebChromeClient() {
override fun onReceivedTitle(view: WebView?, title: String?) {
onPageTitleChanged?.invoke(title ?: "Hermes")
}
}
setDownloadListener { url, userAgent, contentDisposition, mimeType, contentLength ->
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
context.startActivity(intent)
} catch (e: Exception) {
Toast.makeText(context, "Cannot open download", Toast.LENGTH_SHORT).show()
}
}
loadUrl(getServerUrl())
}
}
fun reload() {
webView?.reload()
}
fun goBack(): Boolean {
return webView?.canGoBack()?.let {
if (it) {
webView?.goBack()
true
} else false
} ?: false
}
private fun getServerUrl(): String {
val prefs = context.getSharedPreferences(
AppConstants.PREFS_NAME, Context.MODE_PRIVATE
)
return prefs.getString(
AppConstants.PREFS_SERVER_URL, AppConstants.DEFAULT_SERVER_URL
) ?: AppConstants.DEFAULT_SERVER_URL
}
fun destroy() {
webView?.destroy()
webView = null
}
}
@@ -0,0 +1,133 @@
package com.hermes.app
import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import android.webkit.WebView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
class MainActivity : ComponentActivity() {
private lateinit var webViewManager: HermesWebViewManager
private var webView: WebView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
webViewManager = HermesWebViewManager(this)
// Start foreground keepalive service
val serviceIntent = Intent(this, HermesForegroundService::class.java)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
startForegroundService(serviceIntent)
} else {
startService(serviceIntent)
}
setContent {
var isLoading by remember { mutableStateOf(true) }
var showSettingsButton by remember { mutableStateOf(true) }
HermesTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Box(modifier = Modifier.fillMaxSize()) {
// WebView
AndroidView(
factory = { ctx ->
webViewManager.createWebView().also { wv ->
webView = wv
webViewManager.onPageLoading = { loading ->
isLoading = loading
}
}
},
modifier = Modifier.fillMaxSize()
)
// Top loading bar
if (isLoading) {
LinearProgressIndicator(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.TopCenter),
color = MaterialTheme.colorScheme.primary
)
}
// Settings FAB
if (showSettingsButton) {
FloatingActionButton(
onClick = {
startActivity(
Intent(this@MainActivity, SettingsActivity::class.java)
)
},
modifier = Modifier
.align(Alignment.TopEnd)
.padding(12.dp)
.padding(top = 32.dp),
containerColor = MaterialTheme.colorScheme.surface.copy(alpha = 0.85f),
contentColor = MaterialTheme.colorScheme.onSurface,
elevation = FloatingActionButtonDefaults.elevation(
defaultElevation = 4.dp
)
) {
Text(
text = "\u2699",
style = MaterialTheme.typography.titleMedium
)
}
}
}
}
}
}
}
override fun onResume() {
super.onResume()
// When returning to foreground, check if the page needs reloading
webView?.evaluateJavascript(
"""
(function() {
var hasContent = document.querySelector('#messages-list') ||
document.querySelector('.message') ||
document.querySelector('input[type="password"]');
if (!hasContent && document.body && document.body.children.length < 4) {
return 'empty';
}
return 'ok';
})()
""".trimIndent(), null
)
}
override fun onDestroy() {
webViewManager.destroy()
super.onDestroy()
}
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK && webView?.canGoBack() == true) {
webView?.goBack()
return true
}
return super.onKeyDown(keyCode, event)
}
}
@@ -0,0 +1,158 @@
package com.hermes.app
import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
class SettingsActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val prefs = getSharedPreferences(AppConstants.PREFS_NAME, Context.MODE_PRIVATE)
setContent {
HermesTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
SettingsScreen(
prefs = prefs,
onBack = { finish() }
)
}
}
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingsScreen(
prefs: SharedPreferences,
onBack: () -> Unit
) {
val context = LocalContext.current
var serverUrl by remember {
mutableStateOf(
prefs.getString(AppConstants.PREFS_SERVER_URL, AppConstants.DEFAULT_SERVER_URL)
?: AppConstants.DEFAULT_SERVER_URL
)
}
var keepaliveEnabled by remember {
mutableStateOf(prefs.getBoolean(AppConstants.PREFS_KEEPALIVE, true))
}
Scaffold(
topBar = {
TopAppBar(
title = { Text("Settings") },
navigationIcon = {
TextButton(onClick = onBack) {
Text("Back")
}
}
)
}
) { padding ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(padding)
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
// Server URL
Text(
text = "Server URL",
style = MaterialTheme.typography.titleMedium
)
OutlinedTextField(
value = serverUrl,
onValueChange = { serverUrl = it },
label = { Text("e.g. http://10.0.1.49:8787") },
modifier = Modifier.fillMaxWidth(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri),
singleLine = true
)
Text(
text = "The address of your Hermes WebUI server. " +
"Must include http:// or https://",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
HorizontalDivider()
// Keepalive toggle
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = "Background Keepalive",
style = MaterialTheme.typography.titleMedium
)
Text(
text = "Periodically checks server connection to " +
"prevent timeout disconnects",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Switch(
checked = keepaliveEnabled,
onCheckedChange = { keepaliveEnabled = it }
)
}
HorizontalDivider()
Spacer(modifier = Modifier.weight(1f))
// Save button
Button(
onClick = {
prefs.edit()
.putString(AppConstants.PREFS_SERVER_URL, serverUrl)
.putBoolean(AppConstants.PREFS_KEEPALIVE, keepaliveEnabled)
.apply()
Toast.makeText(
context,
"Settings saved. Restart app to apply server URL.",
Toast.LENGTH_SHORT
).show()
onBack()
},
modifier = Modifier.fillMaxWidth()
) {
Text("Save")
}
// App info
Text(
text = "Hermes App v1.0.0",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.align(Alignment.CenterHorizontally)
)
}
}
}
+39
View File
@@ -0,0 +1,39 @@
package com.hermes.app
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
private val DarkColorScheme = darkColorScheme(
primary = Color(0xFF8B5CF6),
secondary = Color(0xFF6366F1),
background = Color(0xFF0D0D1A),
surface = Color(0xFF141425),
onBackground = Color(0xFFE2E8F0),
onSurface = Color(0xFFE2E8F0),
surfaceVariant = Color(0xFF1E1E3A),
onSurfaceVariant = Color(0xFF94A3B8),
)
private val LightColorScheme = lightColorScheme(
primary = Color(0xFF7C3AED),
secondary = Color(0xFF4F46E5),
background = Color(0xFFFAF7F0),
surface = Color(0xFFFFFFFF),
onBackground = Color(0xFF1E293B),
onSurface = Color(0xFF1E293B),
surfaceVariant = Color(0xFFF1F5F9),
onSurfaceVariant = Color(0xFF475569),
)
@Composable
fun HermesTheme(content: @Composable () -> Unit) {
val darkTheme = isSystemInDarkTheme()
MaterialTheme(
colorScheme = if (darkTheme) DarkColorScheme else LightColorScheme,
content = content
)
}
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#0D0D1A"
android:pathData="M0,0h108v108h-108z" />
</vector>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<!-- Hermes "H" letter icon on dark background -->
<path
android:fillColor="#8B5CF6"
android:pathData="M30,30 L30,78 L42,78 L42,60 L54,60 L54,78 L66,78 L66,30 L54,30 L54,50 L42,50 L42,30 Z" />
</vector>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="hermes_purple">#8B5CF6</color>
<color name="hermes_dark">#0D0D1A</color>
<color name="hermes_surface">#141425</color>
</resources>
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Hermes</string>
<string name="app_description">Hermes AI Agent WebUI Client</string>
</resources>
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Hermes" parent="android:Theme.Material.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowBackground">#FF0D0D1A</item>
</style>
<style name="Theme.Hermes.Settings" parent="Theme.Hermes">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
</resources>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<!-- Allow cleartext HTTP to local LAN servers -->
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.1.49</domain>
<domain includeSubdomains="true">10.10.10.1</domain>
<domain includeSubdomains="true">192.168.0.0</domain>
<domain includeSubdomains="true">192.168.1.0</domain>
<domain includeSubdomains="true">192.168.2.0</domain>
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">10.42.0.0</domain>
</domain-config>
<!-- All other traffic uses default (HTTPS) -->
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
+5
View File
@@ -0,0 +1,5 @@
plugins {
id("com.android.application") version "8.9.0" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0" apply false
}
+5
View File
@@ -0,0 +1,5 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
kotlin.code.style=official
android.nonTransitiveRClass=true
android.suppressUnsupportedCompileSdk=36
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored Executable
+248
View File
@@ -0,0 +1,248 @@
#!/bin/sh
#
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# gradlew start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh gradlew
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/<unknown>/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
Vendored
+82
View File
@@ -0,0 +1,82 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem gradlew startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables, and ensure extensions are enabled
setlocal EnableExtensions
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
"%COMSPEC%" /c exit 1
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
"%COMSPEC%" /c exit 1
:execute
@rem Setup the command line
@rem Execute gradlew
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
@rem which allows us to clear the local environment before executing the java command
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
:exitWithErrorLevel
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
"%COMSPEC%" /c exit %ERRORLEVEL%
+18
View File
@@ -0,0 +1,18 @@
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "Hermes"
include(":app")