mirror of
https://github.com/wgtunnel/android.git
synced 2026-06-02 08:33:40 +02:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5eecb11d10 | |||
| 083904638f | |||
| d07cf7a24b | |||
| 74c4efe477 | |||
| 3256da1cfa | |||
| 132728f5dd | |||
| 3eb72cd43c |
@@ -9,6 +9,7 @@ plugins {
|
||||
alias(libs.plugins.compose.compiler)
|
||||
alias(libs.plugins.grgit)
|
||||
alias(libs.plugins.licensee)
|
||||
id("kotlin-parcelize")
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -197,6 +198,7 @@ dependencies {
|
||||
|
||||
implementation(libs.zxing.android.embedded)
|
||||
|
||||
implementation(libs.material.icons.core)
|
||||
implementation(libs.material.icons.extended)
|
||||
|
||||
implementation(libs.androidx.biometric.ktx)
|
||||
@@ -228,6 +230,11 @@ dependencies {
|
||||
implementation(libs.roomdatabasebackup) {
|
||||
exclude(group = "org.reactivestreams", module = "reactive-streams")
|
||||
}
|
||||
|
||||
// state management
|
||||
implementation(libs.orbit.compose)
|
||||
implementation(libs.orbit.viewmodel)
|
||||
implementation(libs.orbit.core)
|
||||
}
|
||||
|
||||
tasks.register<Copy>("copyLicenseeJsonToAssets") {
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
-keep class com.zaneschepke.wireguardautotunnel.ui.navigation.Route { *; }
|
||||
-keep class com.zaneschepke.wireguardautotunnel.ui.navigation.Route$** { *; }
|
||||
-keepclassmembers class com.zaneschepke.wireguardautotunnel.ui.navigation.Route$** { *; }
|
||||
@@ -0,0 +1,359 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 20,
|
||||
"identityHash": "51f828868c0ea2f0f5c987410ff5c5a1",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "Settings",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT true, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER, `app_mode` INTEGER NOT NULL DEFAULT 0, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAutoTunnelEnabled",
|
||||
"columnName": "is_tunnel_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "trustedNetworkSSIDs",
|
||||
"columnName": "trusted_network_ssids",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||
"columnName": "is_always_on_vpn_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isShortcutsEnabled",
|
||||
"columnName": "is_shortcuts_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnWifiEnabled",
|
||||
"columnName": "is_tunnel_on_wifi_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isRestoreOnBootEnabled",
|
||||
"columnName": "is_restore_on_boot_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isMultiTunnelEnabled",
|
||||
"columnName": "is_multi_tunnel_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPingEnabled",
|
||||
"columnName": "is_ping_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isWildcardsEnabled",
|
||||
"columnName": "is_wildcards_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isStopOnNoInternetEnabled",
|
||||
"columnName": "is_stop_on_no_internet_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isLanOnKillSwitchEnabled",
|
||||
"columnName": "is_lan_on_kill_switch_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "debounceDelaySeconds",
|
||||
"columnName": "debounce_delay_seconds",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "3"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
||||
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "wifiDetectionMethod",
|
||||
"columnName": "wifi_detection_method",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPingMonitoringEnabled",
|
||||
"columnName": "is_ping_monitoring_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "true"
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelPingIntervalSeconds",
|
||||
"columnName": "tunnel_ping_interval_sec",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "30"
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelPingAttempts",
|
||||
"columnName": "tunnel_ping_attempts",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "3"
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelPingTimeoutSeconds",
|
||||
"columnName": "tunnel_ping_timeout_sec",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "appMode",
|
||||
"columnName": "app_mode",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "dnsProtocol",
|
||||
"columnName": "dns_protocol",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "dnsEndpoint",
|
||||
"columnName": "dns_endpoint",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "TunnelConfig",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `restart_on_ping_failure` INTEGER NOT NULL DEFAULT false, `ping_target` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0, `auto_tunnel_apps` TEXT NOT NULL DEFAULT '[]')",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wgQuick",
|
||||
"columnName": "wg_quick",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelNetworks",
|
||||
"columnName": "tunnel_networks",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isMobileDataTunnel",
|
||||
"columnName": "is_mobile_data_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPrimaryTunnel",
|
||||
"columnName": "is_primary_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "amQuick",
|
||||
"columnName": "am_quick",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isActive",
|
||||
"columnName": "is_Active",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "restartOnPingFailure",
|
||||
"columnName": "restart_on_ping_failure",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "pingTarget",
|
||||
"columnName": "ping_target",
|
||||
"affinity": "TEXT",
|
||||
"defaultValue": "null"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isEthernetTunnel",
|
||||
"columnName": "is_ethernet_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isIpv4Preferred",
|
||||
"columnName": "is_ipv4_preferred",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "true"
|
||||
},
|
||||
{
|
||||
"fieldPath": "position",
|
||||
"columnName": "position",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "autoTunnelApps",
|
||||
"columnName": "auto_tunnel_apps",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "'[]'"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_TunnelConfig_name",
|
||||
"unique": true,
|
||||
"columnNames": [
|
||||
"name"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "proxy_settings",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `socks5_proxy_enabled` INTEGER NOT NULL DEFAULT false, `socks5_proxy_bind_address` TEXT, `http_proxy_enable` INTEGER NOT NULL DEFAULT false, `http_proxy_bind_address` TEXT, `proxy_username` TEXT, `proxy_password` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "socks5ProxyEnabled",
|
||||
"columnName": "socks5_proxy_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "socks5ProxyBindAddress",
|
||||
"columnName": "socks5_proxy_bind_address",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "httpProxyEnabled",
|
||||
"columnName": "http_proxy_enable",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "httpProxyBindAddress",
|
||||
"columnName": "http_proxy_bind_address",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "proxyUsername",
|
||||
"columnName": "proxy_username",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "proxyPassword",
|
||||
"columnName": "proxy_password",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '51f828868c0ea2f0f5c987410ff5c5a1')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 21,
|
||||
"identityHash": "51f828868c0ea2f0f5c987410ff5c5a1",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "Settings",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL, `trusted_network_ssids` TEXT NOT NULL, `is_always_on_vpn_enabled` INTEGER NOT NULL, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT false, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT false, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT false, `is_ping_enabled` INTEGER NOT NULL DEFAULT false, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT false, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT false, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT false, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT false, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT false, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT true, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER, `app_mode` INTEGER NOT NULL DEFAULT 0, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAutoTunnelEnabled",
|
||||
"columnName": "is_tunnel_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "trustedNetworkSSIDs",
|
||||
"columnName": "trusted_network_ssids",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||
"columnName": "is_always_on_vpn_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isShortcutsEnabled",
|
||||
"columnName": "is_shortcuts_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnWifiEnabled",
|
||||
"columnName": "is_tunnel_on_wifi_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isRestoreOnBootEnabled",
|
||||
"columnName": "is_restore_on_boot_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isMultiTunnelEnabled",
|
||||
"columnName": "is_multi_tunnel_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPingEnabled",
|
||||
"columnName": "is_ping_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isWildcardsEnabled",
|
||||
"columnName": "is_wildcards_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isStopOnNoInternetEnabled",
|
||||
"columnName": "is_stop_on_no_internet_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isLanOnKillSwitchEnabled",
|
||||
"columnName": "is_lan_on_kill_switch_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "debounceDelaySeconds",
|
||||
"columnName": "debounce_delay_seconds",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "3"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
||||
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "wifiDetectionMethod",
|
||||
"columnName": "wifi_detection_method",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPingMonitoringEnabled",
|
||||
"columnName": "is_ping_monitoring_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "true"
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelPingIntervalSeconds",
|
||||
"columnName": "tunnel_ping_interval_sec",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "30"
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelPingAttempts",
|
||||
"columnName": "tunnel_ping_attempts",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "3"
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelPingTimeoutSeconds",
|
||||
"columnName": "tunnel_ping_timeout_sec",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "appMode",
|
||||
"columnName": "app_mode",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "dnsProtocol",
|
||||
"columnName": "dns_protocol",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "dnsEndpoint",
|
||||
"columnName": "dns_endpoint",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "TunnelConfig",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `restart_on_ping_failure` INTEGER NOT NULL DEFAULT false, `ping_target` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0, `auto_tunnel_apps` TEXT NOT NULL DEFAULT '[]')",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wgQuick",
|
||||
"columnName": "wg_quick",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelNetworks",
|
||||
"columnName": "tunnel_networks",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isMobileDataTunnel",
|
||||
"columnName": "is_mobile_data_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPrimaryTunnel",
|
||||
"columnName": "is_primary_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "amQuick",
|
||||
"columnName": "am_quick",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isActive",
|
||||
"columnName": "is_Active",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "restartOnPingFailure",
|
||||
"columnName": "restart_on_ping_failure",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "pingTarget",
|
||||
"columnName": "ping_target",
|
||||
"affinity": "TEXT",
|
||||
"defaultValue": "null"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isEthernetTunnel",
|
||||
"columnName": "is_ethernet_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isIpv4Preferred",
|
||||
"columnName": "is_ipv4_preferred",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "true"
|
||||
},
|
||||
{
|
||||
"fieldPath": "position",
|
||||
"columnName": "position",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "autoTunnelApps",
|
||||
"columnName": "auto_tunnel_apps",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "'[]'"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_TunnelConfig_name",
|
||||
"unique": true,
|
||||
"columnNames": [
|
||||
"name"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "proxy_settings",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `socks5_proxy_enabled` INTEGER NOT NULL DEFAULT false, `socks5_proxy_bind_address` TEXT, `http_proxy_enable` INTEGER NOT NULL DEFAULT false, `http_proxy_bind_address` TEXT, `proxy_username` TEXT, `proxy_password` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "socks5ProxyEnabled",
|
||||
"columnName": "socks5_proxy_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "socks5ProxyBindAddress",
|
||||
"columnName": "socks5_proxy_bind_address",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "httpProxyEnabled",
|
||||
"columnName": "http_proxy_enable",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "httpProxyBindAddress",
|
||||
"columnName": "http_proxy_bind_address",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "proxyUsername",
|
||||
"columnName": "proxy_username",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "proxyPassword",
|
||||
"columnName": "proxy_password",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '51f828868c0ea2f0f5c987410ff5c5a1')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 22,
|
||||
"identityHash": "db93d0490401ccbef25ca39f27bafa29",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "Settings",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `is_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_mobile_data_enabled` INTEGER NOT NULL DEFAULT 0, `trusted_network_ssids` TEXT NOT NULL DEFAULT '', `is_always_on_vpn_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_ethernet_enabled` INTEGER NOT NULL DEFAULT 0, `is_shortcuts_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_wifi_enabled` INTEGER NOT NULL DEFAULT 0, `is_restore_on_boot_enabled` INTEGER NOT NULL DEFAULT 0, `is_multi_tunnel_enabled` INTEGER NOT NULL DEFAULT 0, `is_ping_enabled` INTEGER NOT NULL DEFAULT 0, `is_wildcards_enabled` INTEGER NOT NULL DEFAULT 0, `is_stop_on_no_internet_enabled` INTEGER NOT NULL DEFAULT 0, `is_lan_on_kill_switch_enabled` INTEGER NOT NULL DEFAULT 0, `debounce_delay_seconds` INTEGER NOT NULL DEFAULT 3, `is_disable_kill_switch_on_trusted_enabled` INTEGER NOT NULL DEFAULT 0, `is_tunnel_on_unsecure_enabled` INTEGER NOT NULL DEFAULT 0, `wifi_detection_method` INTEGER NOT NULL DEFAULT 0, `is_ping_monitoring_enabled` INTEGER NOT NULL DEFAULT 1, `tunnel_ping_interval_sec` INTEGER NOT NULL DEFAULT 30, `tunnel_ping_attempts` INTEGER NOT NULL DEFAULT 3, `tunnel_ping_timeout_sec` INTEGER, `app_mode` INTEGER NOT NULL DEFAULT 0, `dns_protocol` INTEGER NOT NULL DEFAULT 0, `dns_endpoint` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAutoTunnelEnabled",
|
||||
"columnName": "is_tunnel_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnMobileDataEnabled",
|
||||
"columnName": "is_tunnel_on_mobile_data_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "trustedNetworkSSIDs",
|
||||
"columnName": "trusted_network_ssids",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isAlwaysOnVpnEnabled",
|
||||
"columnName": "is_always_on_vpn_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnEthernetEnabled",
|
||||
"columnName": "is_tunnel_on_ethernet_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isShortcutsEnabled",
|
||||
"columnName": "is_shortcuts_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnWifiEnabled",
|
||||
"columnName": "is_tunnel_on_wifi_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isRestoreOnBootEnabled",
|
||||
"columnName": "is_restore_on_boot_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isMultiTunnelEnabled",
|
||||
"columnName": "is_multi_tunnel_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPingEnabled",
|
||||
"columnName": "is_ping_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isWildcardsEnabled",
|
||||
"columnName": "is_wildcards_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isStopOnNoInternetEnabled",
|
||||
"columnName": "is_stop_on_no_internet_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isLanOnKillSwitchEnabled",
|
||||
"columnName": "is_lan_on_kill_switch_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "debounceDelaySeconds",
|
||||
"columnName": "debounce_delay_seconds",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "3"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isDisableKillSwitchOnTrustedEnabled",
|
||||
"columnName": "is_disable_kill_switch_on_trusted_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isTunnelOnUnsecureEnabled",
|
||||
"columnName": "is_tunnel_on_unsecure_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "wifiDetectionMethod",
|
||||
"columnName": "wifi_detection_method",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPingMonitoringEnabled",
|
||||
"columnName": "is_ping_monitoring_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "1"
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelPingIntervalSeconds",
|
||||
"columnName": "tunnel_ping_interval_sec",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "30"
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelPingAttempts",
|
||||
"columnName": "tunnel_ping_attempts",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "3"
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelPingTimeoutSeconds",
|
||||
"columnName": "tunnel_ping_timeout_sec",
|
||||
"affinity": "INTEGER"
|
||||
},
|
||||
{
|
||||
"fieldPath": "appMode",
|
||||
"columnName": "app_mode",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "dnsProtocol",
|
||||
"columnName": "dns_protocol",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "dnsEndpoint",
|
||||
"columnName": "dns_endpoint",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tableName": "TunnelConfig",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `wg_quick` TEXT NOT NULL, `tunnel_networks` TEXT NOT NULL DEFAULT '', `is_mobile_data_tunnel` INTEGER NOT NULL DEFAULT false, `is_primary_tunnel` INTEGER NOT NULL DEFAULT false, `am_quick` TEXT NOT NULL DEFAULT '', `is_Active` INTEGER NOT NULL DEFAULT false, `restart_on_ping_failure` INTEGER NOT NULL DEFAULT false, `ping_target` TEXT DEFAULT null, `is_ethernet_tunnel` INTEGER NOT NULL DEFAULT false, `is_ipv4_preferred` INTEGER NOT NULL DEFAULT true, `position` INTEGER NOT NULL DEFAULT 0, `auto_tunnel_apps` TEXT NOT NULL DEFAULT '[]')",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "wgQuick",
|
||||
"columnName": "wg_quick",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "tunnelNetworks",
|
||||
"columnName": "tunnel_networks",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isMobileDataTunnel",
|
||||
"columnName": "is_mobile_data_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isPrimaryTunnel",
|
||||
"columnName": "is_primary_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "amQuick",
|
||||
"columnName": "am_quick",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "''"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isActive",
|
||||
"columnName": "is_Active",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "restartOnPingFailure",
|
||||
"columnName": "restart_on_ping_failure",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "pingTarget",
|
||||
"columnName": "ping_target",
|
||||
"affinity": "TEXT",
|
||||
"defaultValue": "null"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isEthernetTunnel",
|
||||
"columnName": "is_ethernet_tunnel",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "false"
|
||||
},
|
||||
{
|
||||
"fieldPath": "isIpv4Preferred",
|
||||
"columnName": "is_ipv4_preferred",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "true"
|
||||
},
|
||||
{
|
||||
"fieldPath": "position",
|
||||
"columnName": "position",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "autoTunnelApps",
|
||||
"columnName": "auto_tunnel_apps",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true,
|
||||
"defaultValue": "'[]'"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_TunnelConfig_name",
|
||||
"unique": true,
|
||||
"columnNames": [
|
||||
"name"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_TunnelConfig_name` ON `${TABLE_NAME}` (`name`)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"tableName": "proxy_settings",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `socks5_proxy_enabled` INTEGER NOT NULL DEFAULT 0, `socks5_proxy_bind_address` TEXT, `http_proxy_enable` INTEGER NOT NULL DEFAULT 0, `http_proxy_bind_address` TEXT, `proxy_username` TEXT, `proxy_password` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "socks5ProxyEnabled",
|
||||
"columnName": "socks5_proxy_enabled",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "socks5ProxyBindAddress",
|
||||
"columnName": "socks5_proxy_bind_address",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "httpProxyEnabled",
|
||||
"columnName": "http_proxy_enable",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true,
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldPath": "httpProxyBindAddress",
|
||||
"columnName": "http_proxy_bind_address",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "proxyUsername",
|
||||
"columnName": "proxy_username",
|
||||
"affinity": "TEXT"
|
||||
},
|
||||
{
|
||||
"fieldPath": "proxyPassword",
|
||||
"columnName": "proxy_password",
|
||||
"affinity": "TEXT"
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'db93d0490401ccbef25ca39f27bafa29')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import androidx.room.testing.MigrationTestHelper
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
||||
import com.zaneschepke.wireguardautotunnel.data.Queries
|
||||
import java.io.IOException
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@@ -24,8 +23,6 @@ class MigrationTest {
|
||||
helper.createDatabase(dbName, 6).apply {
|
||||
// Database has schema version 1. Insert some data using SQL queries.
|
||||
// You can't use DAO classes because they expect the latest schema.
|
||||
execSQL(Queries.createDefaultSettings())
|
||||
execSQL(Queries.createTunnelConfig())
|
||||
// Prepare for the next version.
|
||||
close()
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.zaneschepke.wireguardautotunnel
|
||||
|
||||
import ProxySettingsScreen
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.net.VpnService
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
@@ -14,96 +16,84 @@ import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.zIndex
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navigation
|
||||
import androidx.navigation.toRoute
|
||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.domain.sideeffect.GlobalSideEffect
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalSharedVm
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.banner.AppAlertBanner
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.VpnDeniedDialog
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.CustomSnackBar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.BottomNavbar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.DynamicTopAppBar
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.components.currentNavBackStackEntryAsNavBarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.AutoTunnelScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.advanced.AutoTunnelAdvancedScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.detection.WifiDetectionMethodScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.LocationDisclosureScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.MainScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.autotunnel.TunnelAutoTunnelScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.config.ConfigScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.sort.SortScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.splittunnel.SplitTunnelScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.main.tunneloptions.TunnelOptionsScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.pin.PinLockScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.SettingsScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.advanced.SettingsAdvancedScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.AppearanceScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.display.DisplayScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.appearance.language.LanguageScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.killswitch.KillSwitchScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.dns.DnsSettingsScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.logs.LogsScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.monitoring.TunnelMonitoringScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.system.SystemFeaturesScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.support.license.LicenseScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.TunnelsScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.autotunnel.TunnelAutoTunnelScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.config.ConfigScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.sort.SortScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.splittunnel.SplitTunnelScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.tunnels.tunneloptions.TunnelOptionsScreen
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.AlertRed
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.OffWhite
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.restartApp
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.showToast
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.*
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import de.raphaelebner.roomdatabasebackup.core.RoomBackup
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.system.exitProcess
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.launch
|
||||
import org.amnezia.awg.backend.GoBackend.VpnService
|
||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@Inject lateinit var appStateRepository: AppStateRepository
|
||||
|
||||
@Inject lateinit var tunnelManager: TunnelManager
|
||||
|
||||
@Inject lateinit var networkMonitor: NetworkMonitor
|
||||
|
||||
@Inject @IoDispatcher lateinit var ioDispatcher: CoroutineDispatcher
|
||||
|
||||
@Inject @MainDispatcher lateinit var mainDispatcher: CoroutineDispatcher
|
||||
|
||||
@Inject lateinit var appDatabase: AppDatabase
|
||||
|
||||
private var lastLocationPermissionState: Boolean? = null
|
||||
|
||||
private lateinit var roomBackup: RoomBackup
|
||||
|
||||
val REQUEST_CODE = 123
|
||||
|
||||
@SuppressLint("BatteryLife")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
enableEdgeToEdge(
|
||||
@@ -114,32 +104,40 @@ class MainActivity : AppCompatActivity() {
|
||||
window.isNavigationBarContrastEnforced = false
|
||||
}
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
roomBackup = RoomBackup(this)
|
||||
|
||||
val viewModel by viewModels<AppViewModel>()
|
||||
val viewModel by viewModels<SharedAppViewModel>()
|
||||
|
||||
installSplashScreen().apply {
|
||||
setKeepOnScreenCondition { !viewModel.appViewState.value.isAppReady }
|
||||
setKeepOnScreenCondition { !viewModel.container.stateFlow.value.isAppLoaded }
|
||||
}
|
||||
|
||||
setContent {
|
||||
val context = LocalContext.current
|
||||
val isTv = isRunningOnTv()
|
||||
val appUiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
val appViewState by viewModel.appViewState.collectAsStateWithLifecycle()
|
||||
|
||||
val appState by viewModel.container.stateFlow.collectAsStateWithLifecycle()
|
||||
val navController = rememberNavController()
|
||||
val backStackEntry by navController.currentBackStackEntryAsState()
|
||||
val navBarState by
|
||||
currentNavBackStackEntryAsNavBarState(
|
||||
navController,
|
||||
backStackEntry,
|
||||
viewModel,
|
||||
appUiState,
|
||||
appViewState,
|
||||
)
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
var pinManagerInitialized by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(appState.isAppLoaded) {
|
||||
if (appState.isAppLoaded) {
|
||||
if (appState.pinLockEnabled && !pinManagerInitialized) {
|
||||
PinManager.initialize(this@MainActivity)
|
||||
pinManagerInitialized = true
|
||||
}
|
||||
appState.locale.let { LocaleUtil.changeLocale(it) }
|
||||
}
|
||||
}
|
||||
|
||||
val snackbar = remember { SnackbarHostState() }
|
||||
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
||||
var vpnPermissionDenied by remember { mutableStateOf(false) }
|
||||
var requestingAppMode by remember {
|
||||
mutableStateOf<Pair<AppMode?, TunnelConf?>>(Pair(null, null))
|
||||
}
|
||||
|
||||
val vpnActivity =
|
||||
rememberLauncherForActivityResult(
|
||||
@@ -151,86 +149,86 @@ class MainActivity : AppCompatActivity() {
|
||||
} else {
|
||||
vpnPermissionDenied = false
|
||||
showVpnPermissionDialog = false
|
||||
val (appMode, config) = requestingAppMode
|
||||
when (appMode) {
|
||||
AppMode.VPN -> if (config != null) viewModel.startTunnel(config)
|
||||
AppMode.LOCK_DOWN -> viewModel.setAppMode(AppMode.LOCK_DOWN)
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
requestingAppMode = Pair(null, null)
|
||||
},
|
||||
)
|
||||
|
||||
LaunchedEffect(appUiState.tunnels) {
|
||||
if (!appViewState.isAppReady) {
|
||||
viewModel.handleEvent(AppEvent.AppReadyCheck(appUiState.tunnels))
|
||||
}
|
||||
}
|
||||
|
||||
val batteryActivity =
|
||||
rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { _: ActivityResult ->
|
||||
viewModel.handleEvent(AppEvent.SetBatteryOptimizeDisableShown)
|
||||
viewModel.disableBatteryOptimizationsShown()
|
||||
}
|
||||
|
||||
with(appViewState) {
|
||||
LaunchedEffect(isConfigChanged) {
|
||||
if (isConfigChanged) {
|
||||
Intent(this@MainActivity, MainActivity::class.java).also {
|
||||
startActivity(it)
|
||||
exitProcess(0)
|
||||
}
|
||||
fun requestDisableBatteryOptimizations() {
|
||||
batteryActivity.launch(
|
||||
Intent().apply {
|
||||
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||
data = "package:${this@MainActivity.packageName}".toUri()
|
||||
}
|
||||
}
|
||||
LaunchedEffect(errorMessage) {
|
||||
errorMessage?.let {
|
||||
snackbar.showSnackbar(it.asString(this@MainActivity))
|
||||
viewModel.handleEvent(AppEvent.MessageShown)
|
||||
}
|
||||
}
|
||||
LaunchedEffect(popBackStack) {
|
||||
if (popBackStack) {
|
||||
navController.popBackStack()
|
||||
viewModel.handleEvent(AppEvent.PopBackStack(false))
|
||||
}
|
||||
}
|
||||
LaunchedEffect(requestVpnPermission) {
|
||||
if (requestVpnPermission) {
|
||||
if (!vpnPermissionDenied) {
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.globalSideEffect.collect { sideEffect ->
|
||||
when (sideEffect) {
|
||||
GlobalSideEffect.ConfigChanged -> restartApp()
|
||||
GlobalSideEffect.PopBackStack -> navController.popBackStack()
|
||||
GlobalSideEffect.RequestBatteryOptimizationDisabled ->
|
||||
requestDisableBatteryOptimizations()
|
||||
is GlobalSideEffect.RequestVpnPermission -> {
|
||||
requestingAppMode = Pair(sideEffect.requestingMode, sideEffect.config)
|
||||
vpnActivity.launch(VpnService.prepare(this@MainActivity))
|
||||
} else {
|
||||
showVpnPermissionDialog = true
|
||||
}
|
||||
viewModel.handleEvent(AppEvent.VpnPermissionRequested)
|
||||
}
|
||||
}
|
||||
LaunchedEffect(requestBatteryPermission) {
|
||||
if (requestBatteryPermission) {
|
||||
batteryActivity.launch(
|
||||
Intent().apply {
|
||||
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||
data = "package:${this@MainActivity.packageName}".toUri()
|
||||
is GlobalSideEffect.ShareFile -> context.launchShareFile(sideEffect.file)
|
||||
is GlobalSideEffect.Snackbar ->
|
||||
scope.launch {
|
||||
snackbar.showSnackbar(sideEffect.message.asString(context))
|
||||
}
|
||||
)
|
||||
is GlobalSideEffect.Toast ->
|
||||
scope.launch { context.showToast(sideEffect.message.asString(context)) }
|
||||
is GlobalSideEffect.LaunchUrl -> context.openWebUrl(sideEffect.url)
|
||||
is GlobalSideEffect.InstallApk -> context.installApk(sideEffect.apk)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CompositionLocalProvider(LocalIsAndroidTV provides isTv) {
|
||||
CompositionLocalProvider(LocalNavController provides navController) {
|
||||
WireguardAutoTunnelTheme(theme = appUiState.appState.theme) {
|
||||
VpnDeniedDialog(
|
||||
showVpnPermissionDialog,
|
||||
onDismiss = {
|
||||
showVpnPermissionDialog = false
|
||||
vpnPermissionDenied = false
|
||||
},
|
||||
)
|
||||
if (!appState.isAppLoaded) return@setContent
|
||||
|
||||
CompositionLocalProvider(
|
||||
LocalIsAndroidTV provides isTv,
|
||||
LocalSharedVm provides viewModel,
|
||||
LocalNavController provides navController,
|
||||
) {
|
||||
WireguardAutoTunnelTheme(theme = appState.theme) {
|
||||
VpnDeniedDialog(
|
||||
showVpnPermissionDialog,
|
||||
onDismiss = {
|
||||
showVpnPermissionDialog = false
|
||||
vpnPermissionDenied = false
|
||||
},
|
||||
)
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
if (appState.settings.appMode == AppMode.LOCK_DOWN) {
|
||||
AppAlertBanner(
|
||||
stringResource(R.string.locked_down).uppercase(Locale.getDefault()),
|
||||
OffWhite,
|
||||
AlertRed,
|
||||
modifier = Modifier.fillMaxWidth().zIndex(2f),
|
||||
)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier =
|
||||
Modifier.pointerInput(Unit) {
|
||||
detectTapGestures {
|
||||
viewModel.handleEvent(AppEvent.ClearSelectedTunnels)
|
||||
}
|
||||
},
|
||||
snackbarHost = {
|
||||
SnackbarHost(snackbar) { snackbarData: SnackbarData ->
|
||||
SnackbarHost(snackbar) { snackbarData ->
|
||||
CustomSnackBar(
|
||||
snackbarData.visuals.message,
|
||||
isRtl = false,
|
||||
@@ -239,15 +237,13 @@ class MainActivity : AppCompatActivity() {
|
||||
)
|
||||
}
|
||||
},
|
||||
topBar = { DynamicTopAppBar(navBarState) },
|
||||
topBar = { DynamicTopAppBar(appState.navBarState) },
|
||||
bottomBar = {
|
||||
AnimatedVisibility(
|
||||
visible = navBarState.showBottom,
|
||||
enter = slideInVertically(initialOffsetY = { it }),
|
||||
exit = slideOutVertically(targetOffsetY = { it }),
|
||||
) {
|
||||
BottomNavbar(appUiState = appUiState)
|
||||
}
|
||||
BottomNavbar(
|
||||
appState.isAutoTunnelActive,
|
||||
appState.navBarState,
|
||||
navController,
|
||||
)
|
||||
},
|
||||
) { padding ->
|
||||
Box(
|
||||
@@ -259,83 +255,131 @@ class MainActivity : AppCompatActivity() {
|
||||
.imePadding()
|
||||
) {
|
||||
NavHost(
|
||||
navController,
|
||||
navController = navController,
|
||||
startDestination =
|
||||
(if (appUiState.appState.isPinLockEnabled) Route.Lock
|
||||
else Route.Main),
|
||||
if (appState.pinLockEnabled && !appState.isAuthorized)
|
||||
Route.Lock
|
||||
else Route.TunnelsGraph,
|
||||
) {
|
||||
composable<Route.Main> {
|
||||
MainScreen(appUiState, appViewState, viewModel)
|
||||
}
|
||||
composable<Route.Settings> {
|
||||
SettingsScreen(appUiState, appViewState, viewModel)
|
||||
}
|
||||
composable<Route.SettingsAdvanced> {
|
||||
SettingsAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.LocationDisclosure> {
|
||||
LocationDisclosureScreen(viewModel)
|
||||
}
|
||||
composable<Route.AutoTunnel> {
|
||||
AutoTunnelScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Appearance> { AppearanceScreen() }
|
||||
composable<Route.Language> {
|
||||
LanguageScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Display> {
|
||||
DisplayScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Support> {
|
||||
SupportScreen(appViewModel = viewModel)
|
||||
}
|
||||
composable<Route.License> { LicenseScreen() }
|
||||
composable<Route.AutoTunnelAdvanced> {
|
||||
AutoTunnelAdvancedScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.WifiDetectionMethod> {
|
||||
WifiDetectionMethodScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.Logs> { LogsScreen(appViewState, viewModel) }
|
||||
composable<Route.Config> { backStack ->
|
||||
val args = backStack.toRoute<Route.Config>()
|
||||
val config =
|
||||
appUiState.tunnels.firstOrNull { it.id == args.id }
|
||||
ConfigScreen(config, appUiState, viewModel)
|
||||
}
|
||||
composable<Route.TunnelOptions> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let { config ->
|
||||
TunnelOptionsScreen(
|
||||
config,
|
||||
viewModel,
|
||||
appViewState,
|
||||
appUiState.appSettings,
|
||||
composable<Route.Lock> { PinLockScreen() }
|
||||
navigation<Route.TunnelsGraph>(
|
||||
startDestination = Route.Tunnels
|
||||
) {
|
||||
composable<Route.Tunnels> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<TunnelsViewModel>(navController)
|
||||
TunnelsScreen(viewModel)
|
||||
}
|
||||
composable<Route.Sort> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<TunnelsViewModel>(navController)
|
||||
SortScreen(viewModel)
|
||||
}
|
||||
composable<Route.TunnelOptions> { backStackEntry ->
|
||||
val args = backStackEntry.toRoute<Route.TunnelOptions>()
|
||||
val viewModel =
|
||||
backStackEntry.sharedViewModel<TunnelsViewModel>(
|
||||
navController
|
||||
)
|
||||
}
|
||||
}
|
||||
composable<Route.Lock> { PinLockScreen(viewModel) }
|
||||
composable<Route.KillSwitch> {
|
||||
KillSwitchScreen(appUiState, viewModel)
|
||||
}
|
||||
composable<Route.SplitTunnel> { SplitTunnelScreen(viewModel) }
|
||||
composable<Route.TunnelAutoTunnel> { backStack ->
|
||||
val args = backStack.toRoute<Route.TunnelOptions>()
|
||||
appUiState.tunnels
|
||||
.firstOrNull { it.id == args.id }
|
||||
?.let {
|
||||
TunnelAutoTunnelScreen(
|
||||
it,
|
||||
appUiState.appSettings,
|
||||
viewModel,
|
||||
TunnelOptionsScreen(args.id, viewModel)
|
||||
}
|
||||
composable<Route.SplitTunnel> { backStackEntry ->
|
||||
val args = backStackEntry.toRoute<Route.SplitTunnel>()
|
||||
SplitTunnelScreen(args.id)
|
||||
}
|
||||
composable<Route.TunnelAutoTunnel> { backStackEntry ->
|
||||
val args =
|
||||
backStackEntry.toRoute<Route.TunnelAutoTunnel>()
|
||||
val viewModel =
|
||||
backStackEntry.sharedViewModel<TunnelsViewModel>(
|
||||
navController
|
||||
)
|
||||
}
|
||||
TunnelAutoTunnelScreen(args.id, viewModel)
|
||||
}
|
||||
composable<Route.Config> { backStackEntry ->
|
||||
val args = backStackEntry.toRoute<Route.Config>()
|
||||
val viewModel =
|
||||
backStackEntry.sharedViewModel<TunnelsViewModel>(
|
||||
navController
|
||||
)
|
||||
ConfigScreen(args.id, viewModel)
|
||||
}
|
||||
}
|
||||
composable<Route.Sort> { SortScreen(appUiState, viewModel) }
|
||||
composable<Route.TunnelMonitoring> {
|
||||
TunnelMonitoringScreen(appUiState, viewModel)
|
||||
|
||||
navigation<Route.AutoTunnelGraph>(
|
||||
startDestination =
|
||||
if (appState.isLocationDisclosureShown) Route.AutoTunnel
|
||||
else Route.LocationDisclosure
|
||||
) {
|
||||
composable<Route.LocationDisclosure> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<AutoTunnelViewModel>(
|
||||
navController
|
||||
)
|
||||
LocationDisclosureScreen(viewModel)
|
||||
}
|
||||
composable<Route.AutoTunnel> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<AutoTunnelViewModel>(
|
||||
navController
|
||||
)
|
||||
AutoTunnelScreen(viewModel)
|
||||
}
|
||||
composable<Route.AdvancedAutoTunnel> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<AutoTunnelViewModel>(
|
||||
navController
|
||||
)
|
||||
AutoTunnelAdvancedScreen(viewModel)
|
||||
}
|
||||
composable<Route.WifiDetectionMethod> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<AutoTunnelViewModel>(
|
||||
navController
|
||||
)
|
||||
WifiDetectionMethodScreen(viewModel)
|
||||
}
|
||||
}
|
||||
|
||||
navigation<Route.SettingsGraph>(
|
||||
startDestination = Route.Settings
|
||||
) {
|
||||
composable<Route.Settings> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<SettingsViewModel>(navController)
|
||||
SettingsScreen(viewModel)
|
||||
}
|
||||
composable<Route.TunnelMonitoring> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<SettingsViewModel>(navController)
|
||||
TunnelMonitoringScreen(viewModel)
|
||||
}
|
||||
composable<Route.SystemFeatures> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<SettingsViewModel>(navController)
|
||||
SystemFeaturesScreen(viewModel)
|
||||
}
|
||||
composable<Route.Dns> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<SettingsViewModel>(navController)
|
||||
DnsSettingsScreen(viewModel)
|
||||
}
|
||||
composable<Route.ProxySettings> { ProxySettingsScreen() }
|
||||
composable<Route.Appearance> { AppearanceScreen() }
|
||||
composable<Route.Language> { LanguageScreen() }
|
||||
composable<Route.Display> { DisplayScreen() }
|
||||
composable<Route.Logs> { LogsScreen() }
|
||||
}
|
||||
|
||||
navigation<Route.SupportGraph>(
|
||||
startDestination = Route.Support
|
||||
) {
|
||||
composable<Route.Support> {
|
||||
val viewModel =
|
||||
it.sharedViewModel<SupportViewModel>(navController)
|
||||
SupportScreen(viewModel)
|
||||
}
|
||||
composable<Route.License> { LicenseScreen() }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -358,15 +402,15 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
fun performBackup() =
|
||||
lifecycleScope.launch(ioDispatcher) {
|
||||
lifecycleScope.launch {
|
||||
roomBackup
|
||||
.database(appDatabase)
|
||||
.backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_DIALOG)
|
||||
.enableLogDebug(true)
|
||||
.maxFileCount(5)
|
||||
.apply {
|
||||
onCompleteListener { success, message, exitCode ->
|
||||
lifecycleScope.launch(mainDispatcher) {
|
||||
onCompleteListener { success, _, _ ->
|
||||
lifecycleScope.launch {
|
||||
if (success) {
|
||||
showToast(
|
||||
getString(
|
||||
@@ -375,7 +419,9 @@ class MainActivity : AppCompatActivity() {
|
||||
)
|
||||
)
|
||||
restartApp()
|
||||
} else showToast(R.string.backup_failed)
|
||||
} else {
|
||||
showToast(R.string.backup_failed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -389,8 +435,8 @@ class MainActivity : AppCompatActivity() {
|
||||
.enableLogDebug(true)
|
||||
.backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_DIALOG)
|
||||
.apply {
|
||||
onCompleteListener { success, message, exitCode ->
|
||||
lifecycleScope.launch(mainDispatcher) {
|
||||
onCompleteListener { success, _, _ ->
|
||||
lifecycleScope.launch {
|
||||
if (success) {
|
||||
showToast(
|
||||
getString(
|
||||
@@ -399,7 +445,9 @@ class MainActivity : AppCompatActivity() {
|
||||
)
|
||||
)
|
||||
restartApp()
|
||||
} else showToast(R.string.restore_failed)
|
||||
} else {
|
||||
showToast(R.string.restore_failed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,18 @@ import com.zaneschepke.wireguardautotunnel.core.worker.ServiceWorker
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.di.MainDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
||||
import com.zaneschepke.wireguardautotunnel.util.ReleaseTree
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
@HiltAndroidApp
|
||||
@@ -64,6 +66,11 @@ class WireGuardAutoTunnel : Application(), Configuration.Provider {
|
||||
Timber.plant(ReleaseTree())
|
||||
}
|
||||
|
||||
applicationScope.launch(ioDispatcher) {
|
||||
launch { if (appDataRepository.appState.isLocalLogsEnabled()) logReader.start() }
|
||||
launch { notificationMonitor.handleApplicationNotifications() }
|
||||
}
|
||||
|
||||
GoBackend.setAlwaysOnCallback {
|
||||
applicationScope.launch {
|
||||
val settings = appDataRepository.settings.get()
|
||||
@@ -77,21 +84,11 @@ class WireGuardAutoTunnel : Application(), Configuration.Provider {
|
||||
}
|
||||
|
||||
ServiceWorker.start(this)
|
||||
|
||||
applicationScope.launch {
|
||||
launch { notificationMonitor.handleApplicationNotifications() }
|
||||
appDataRepository.appState.getLocale()?.let {
|
||||
withContext(mainDispatcher) { LocaleUtil.changeLocale(it) }
|
||||
}
|
||||
appDataRepository.appState.isLocalLogsEnabled().let { enabled ->
|
||||
if (enabled) logReader.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTerminate() {
|
||||
applicationScope.cancel()
|
||||
tunnelManager.setBackendStatus(BackendStatus.Inactive)
|
||||
tunnelManager.setBackendMode(BackendMode.Inactive)
|
||||
super.onTerminate()
|
||||
}
|
||||
|
||||
|
||||
+3
-17
@@ -24,6 +24,7 @@ class RestartReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var serviceManager: ServiceManager
|
||||
|
||||
// injecting this should let tunnelManger handle clean startup
|
||||
@Inject lateinit var tunnelManager: TunnelManager
|
||||
|
||||
@Inject lateinit var logReader: LogReader
|
||||
@@ -34,22 +35,7 @@ class RestartReceiver : BroadcastReceiver() {
|
||||
Timber.d("RestartReceiver triggered with action: ${intent.action}")
|
||||
serviceManager.updateTunnelTile()
|
||||
serviceManager.updateAutoTunnelTile()
|
||||
applicationScope.launch(ioDispatcher) {
|
||||
val settings = appDataRepository.settings.get()
|
||||
if (settings.isRestoreOnBootEnabled) {
|
||||
if (
|
||||
settings.isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null
|
||||
) {
|
||||
Timber.d("Starting auto-tunnel on boot/update")
|
||||
serviceManager.startAutoTunnel()
|
||||
} else {
|
||||
Timber.d("Restoring previous tunnel state")
|
||||
tunnelManager.restorePreviousState()
|
||||
}
|
||||
} else {
|
||||
Timber.d("Restore on boot disabled, skipping")
|
||||
}
|
||||
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) logReader.deleteAndClearLogs()
|
||||
}
|
||||
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED)
|
||||
applicationScope.launch(ioDispatcher) { logReader.deleteAndClearLogs() }
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,9 +16,9 @@ interface NotificationManager {
|
||||
title: String = "",
|
||||
actions: Collection<NotificationCompat.Action> = emptyList(),
|
||||
description: String = "",
|
||||
showTimestamp: Boolean = false,
|
||||
showTimestamp: Boolean = true,
|
||||
importance: Int = NotificationManager.IMPORTANCE_HIGH,
|
||||
onGoing: Boolean = true,
|
||||
onGoing: Boolean = false,
|
||||
onlyAlertOnce: Boolean = true,
|
||||
): Notification
|
||||
|
||||
@@ -27,9 +27,9 @@ interface NotificationManager {
|
||||
title: StringValue,
|
||||
actions: Collection<NotificationCompat.Action> = emptyList(),
|
||||
description: StringValue,
|
||||
showTimestamp: Boolean = false,
|
||||
showTimestamp: Boolean = true,
|
||||
importance: Int = NotificationManager.IMPORTANCE_HIGH,
|
||||
onGoing: Boolean = true,
|
||||
onGoing: Boolean = false,
|
||||
onlyAlertOnce: Boolean = true,
|
||||
): Notification
|
||||
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ package com.zaneschepke.wireguardautotunnel.core.notification
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.WireGuardAutoTunnel
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||
import jakarta.inject.Inject
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
@@ -30,7 +30,7 @@ constructor(
|
||||
title = StringValue.DynamicString(tunnelConf.name),
|
||||
description =
|
||||
when (error) {
|
||||
is BackendError.BounceFailed -> error.toStringValue()
|
||||
is BackendCoreException.BounceFailed -> error.toStringValue()
|
||||
else ->
|
||||
StringValue.StringResource(
|
||||
R.string.tunnel_error_template,
|
||||
|
||||
+1
@@ -131,6 +131,7 @@ class TunnelForegroundService : LifecycleService() {
|
||||
tunnelConf.id,
|
||||
)
|
||||
),
|
||||
onGoing = true,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+6
-29
@@ -16,17 +16,17 @@ import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelMonitor
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.NotificationAction
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus.StopReason.Ping
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.AutoTunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.NetworkState
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.Tunnels
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.to
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toMillis
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
@@ -100,26 +100,10 @@ class AutoTunnelService : LifecycleService() {
|
||||
|
||||
override fun onDestroy() {
|
||||
serviceManager.handleAutoTunnelServiceDestroy()
|
||||
restoreVpnKillSwitch()
|
||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun restoreVpnKillSwitch() {
|
||||
with(autoTunnelStateFlow.value) {
|
||||
if (
|
||||
settings.isVpnKillSwitchEnabled &&
|
||||
tunnelManager.getBackendStatus() !is BackendStatus.KillSwitch
|
||||
) {
|
||||
eventHandlerJob?.cancel()
|
||||
val allowedIps =
|
||||
if (settings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
|
||||
else emptyList()
|
||||
tunnelManager.setBackendStatus(BackendStatus.KillSwitch(allowedIps))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchWatcherNotification(
|
||||
description: String = getString(R.string.monitoring_state_changes)
|
||||
) {
|
||||
@@ -134,6 +118,7 @@ class AutoTunnelService : LifecycleService() {
|
||||
NotificationAction.AUTO_TUNNEL_OFF
|
||||
)
|
||||
),
|
||||
onGoing = true,
|
||||
)
|
||||
ServiceCompat.startForeground(
|
||||
this,
|
||||
@@ -257,7 +242,7 @@ class AutoTunnelService : LifecycleService() {
|
||||
}
|
||||
|
||||
// all relevant settings to auto tunnel
|
||||
private fun areAutoTunnelSettingsTheSame(old: AppSettings, new: AppSettings): Boolean {
|
||||
private fun areAutoTunnelSettingsTheSame(old: GeneralSettings, new: GeneralSettings): Boolean {
|
||||
return (old.isTunnelOnWifiEnabled == new.isTunnelOnWifiEnabled &&
|
||||
old.isTunnelOnMobileDataEnabled == new.isTunnelOnMobileDataEnabled &&
|
||||
old.isTunnelOnEthernetEnabled == new.isTunnelOnEthernetEnabled &&
|
||||
@@ -271,7 +256,7 @@ class AutoTunnelService : LifecycleService() {
|
||||
old.isStopOnNoInternetEnabled == new.isStopOnNoInternetEnabled)
|
||||
}
|
||||
|
||||
private fun combineSettings(): Flow<Pair<AppSettings, Tunnels>> {
|
||||
private fun combineSettings(): Flow<Pair<GeneralSettings, Tunnels>> {
|
||||
return combine(
|
||||
appDataRepository
|
||||
.get()
|
||||
@@ -319,7 +304,7 @@ class AutoTunnelService : LifecycleService() {
|
||||
.distinctUntilChanged(::areAutoTunnelPermissionsRequiredTheSame)
|
||||
.map {
|
||||
NetworkPermissionState(
|
||||
it.settings.wifiDetectionMethod,
|
||||
it.settings.wifiDetectionMethod.to(),
|
||||
it.networkState.locationServicesEnabled == true,
|
||||
it.networkState.locationPermissionGranted == true,
|
||||
(it.tunnels.any { tunnel -> tunnel.tunnelNetworks.isNotEmpty() } ||
|
||||
@@ -400,14 +385,6 @@ class AutoTunnelService : LifecycleService() {
|
||||
AutoTunnelEvent.DoNothing -> Timber.i("Auto-tunneling: nothing to do")
|
||||
is AutoTunnelEvent.Bounce ->
|
||||
handleBounceWithBackoff(event.configsPeerKeyResolvedMap)
|
||||
is AutoTunnelEvent.StartKillSwitch -> {
|
||||
Timber.d("Starting kill switch")
|
||||
tunnelManager.setBackendStatus(BackendStatus.KillSwitch(event.allowedIps))
|
||||
}
|
||||
AutoTunnelEvent.StopKillSwitch -> {
|
||||
Timber.d("Stopping kill switch")
|
||||
tunnelManager.setBackendStatus(BackendStatus.Active)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.service.autotunnel
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.NetworkState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
||||
@@ -11,7 +11,7 @@ import org.amnezia.awg.crypto.Key
|
||||
sealed class StateChange {
|
||||
data class NetworkChange(val networkState: NetworkState) : StateChange()
|
||||
|
||||
data class SettingsChange(val settings: AppSettings, val tunnels: Tunnels) : StateChange()
|
||||
data class SettingsChange(val settings: GeneralSettings, val tunnels: Tunnels) : StateChange()
|
||||
|
||||
data class ActiveTunnelsChange(val activeTunnels: Map<TunnelConf, TunnelState>) : StateChange()
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
import com.wireguard.android.backend.Tunnel
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
@@ -30,7 +30,7 @@ abstract class BaseTunnel(
|
||||
private val serviceManager: ServiceManager,
|
||||
) : TunnelProvider {
|
||||
|
||||
private val _errorEvents = MutableSharedFlow<Pair<TunnelConf, BackendError>>()
|
||||
private val _errorEvents = MutableSharedFlow<Pair<TunnelConf, BackendCoreException>>()
|
||||
override val errorEvents = _errorEvents.asSharedFlow()
|
||||
|
||||
private val _messageEvents = MutableSharedFlow<Pair<TunnelConf, BackendMessage>>()
|
||||
@@ -154,7 +154,7 @@ abstract class BaseTunnel(
|
||||
|
||||
var currentConf = tunnelConf
|
||||
var restoreAttempted = false
|
||||
var originalError: BackendError? = null
|
||||
var originalError: BackendCoreException? = null
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
@@ -169,7 +169,7 @@ abstract class BaseTunnel(
|
||||
_messageEvents.emit(tunnelConf to BackendMessage.BounceSuccess)
|
||||
}
|
||||
return // Success, return
|
||||
} catch (e: BackendError) {
|
||||
} catch (e: BackendCoreException) {
|
||||
originalError = originalError ?: e
|
||||
val bounceReason = bouncingTunnelIds[currentConf.id]
|
||||
if (!restoreAttempted && bounceReason is TunnelStatus.StopReason.Ping) {
|
||||
@@ -192,7 +192,7 @@ abstract class BaseTunnel(
|
||||
val (wg, amnezia) = updatedConfigProxy.buildConfigs()
|
||||
currentConf =
|
||||
currentConf.copyWithCallback(
|
||||
amQuick = amnezia.toAwgQuickString(true),
|
||||
amQuick = amnezia.toAwgQuickString(true, false),
|
||||
wgQuick = wg.toWgQuickString(true),
|
||||
)
|
||||
bouncingTunnelIds.remove(currentConf.id)
|
||||
@@ -209,7 +209,7 @@ abstract class BaseTunnel(
|
||||
}
|
||||
Timber.e(e, "Failed to start backend for ${currentConf.name}")
|
||||
val emitError =
|
||||
if (restoreAttempted) BackendError.BounceFailed(originalError) else e
|
||||
if (restoreAttempted) BackendCoreException.BounceFailed(originalError) else e
|
||||
_errorEvents.emit(currentConf to emitError)
|
||||
updateTunnelStatus(currentConf, TunnelStatus.Down)
|
||||
return
|
||||
@@ -238,7 +238,7 @@ abstract class BaseTunnel(
|
||||
stopBackend(tunnel)
|
||||
saveTunnelActiveState(tunnelConf, false)
|
||||
removeActiveTunnel(tunnel)
|
||||
} catch (e: BackendError) {
|
||||
} catch (e: BackendCoreException) {
|
||||
Timber.e(e, "Failed to stop tunnel ${tunnelConf.id}")
|
||||
_errorEvents.emit(tunnelConf to e)
|
||||
updateTunnelStatus(tunnelConf, TunnelStatus.Down)
|
||||
|
||||
@@ -5,14 +5,15 @@ import com.wireguard.android.backend.BackendException
|
||||
import com.wireguard.android.backend.Tunnel
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||
import com.zaneschepke.wireguardautotunnel.di.Kernel
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.WireGuardStatistics
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendCoreException
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import timber.log.Timber
|
||||
@@ -23,7 +24,7 @@ constructor(
|
||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
||||
serviceManager: ServiceManager,
|
||||
appDataRepository: AppDataRepository,
|
||||
private val backend: Backend,
|
||||
@Kernel private val backend: Backend,
|
||||
) : BaseTunnel(applicationScope, appDataRepository, serviceManager) {
|
||||
|
||||
override fun getStatistics(tunnelConf: TunnelConf): TunnelStatistics? {
|
||||
@@ -37,16 +38,16 @@ constructor(
|
||||
|
||||
override suspend fun startBackend(tunnel: TunnelConf) {
|
||||
// name too long for kernel mode
|
||||
if (!tunnel.isNameKernelCompatible) throw BackendError.TunnelNameTooLong
|
||||
if (!tunnel.isNameKernelCompatible) throw BackendCoreException.TunnelNameTooLong
|
||||
try {
|
||||
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
||||
backend.setState(tunnel, Tunnel.State.UP, tunnel.toWgConfig())
|
||||
} catch (e: BackendException) {
|
||||
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
||||
throw e.toBackendError()
|
||||
throw e.toBackendCoreException()
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
||||
throw BackendError.Config
|
||||
throw BackendCoreException.Config
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,16 +56,16 @@ constructor(
|
||||
try {
|
||||
backend.setState(tunnel, Tunnel.State.DOWN, tunnel.toWgConfig())
|
||||
} catch (e: BackendException) {
|
||||
throw e.toBackendError()
|
||||
throw e.toBackendCoreException()
|
||||
}
|
||||
}
|
||||
|
||||
override fun setBackendStatus(backendStatus: BackendStatus) {
|
||||
override fun setBackendMode(backendMode: BackendMode) {
|
||||
Timber.w("Not yet implemented for kernel")
|
||||
}
|
||||
|
||||
override fun getBackendStatus(): BackendStatus {
|
||||
return BackendStatus.Inactive
|
||||
override fun getBackendMode(): BackendMode {
|
||||
return BackendMode.Inactive
|
||||
}
|
||||
|
||||
override suspend fun runningTunnelNames(): Set<String> {
|
||||
|
||||
+95
-33
@@ -1,9 +1,13 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||
import com.zaneschepke.wireguardautotunnel.di.*
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
||||
@@ -11,43 +15,117 @@ import com.zaneschepke.wireguardautotunnel.domain.state.TunnelState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.inject.Inject
|
||||
import kotlin.concurrent.atomics.AtomicBoolean
|
||||
import kotlin.concurrent.atomics.AtomicReference
|
||||
import kotlin.concurrent.atomics.ExperimentalAtomicApi
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.plus
|
||||
import org.amnezia.awg.crypto.Key
|
||||
import timber.log.Timber
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class TunnelManager
|
||||
@Inject
|
||||
constructor(
|
||||
private val kernelTunnel: TunnelProvider,
|
||||
private val userspaceTunnel: TunnelProvider,
|
||||
@Kernel private val kernelTunnel: TunnelProvider,
|
||||
@Userspace private val userspaceTunnel: TunnelProvider,
|
||||
@ProxyUserspace private val proxyUserspaceTunnel: TunnelProvider,
|
||||
private val serviceManager: ServiceManager,
|
||||
private val appDataRepository: AppDataRepository,
|
||||
applicationScope: CoroutineScope,
|
||||
ioDispatcher: CoroutineDispatcher,
|
||||
@ApplicationScope applicationScope: CoroutineScope,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
) : TunnelProvider {
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
private val tunnelProviderFlow =
|
||||
@OptIn(ExperimentalAtomicApi::class)
|
||||
private val tunnelProviderFlow: StateFlow<TunnelProvider> = run {
|
||||
val currentBackend = AtomicReference(userspaceTunnel)
|
||||
val currentSettings = AtomicReference(GeneralSettings())
|
||||
val initialEmit = AtomicBoolean(true)
|
||||
|
||||
appDataRepository.settings.flow
|
||||
.filterNotNull()
|
||||
.flatMapLatest { settings ->
|
||||
val backend = if (settings.isKernelEnabled) kernelTunnel else userspaceTunnel
|
||||
MutableStateFlow(backend)
|
||||
// ignore default state
|
||||
.filterNot { it == GeneralSettings() }
|
||||
.distinctUntilChanged { old, new ->
|
||||
old.appMode == new.appMode &&
|
||||
old.isLanOnKillSwitchEnabled == new.isLanOnKillSwitchEnabled
|
||||
}
|
||||
.map { settings ->
|
||||
Timber.d("App mode changes with ${settings.appMode}")
|
||||
val backend =
|
||||
when (settings.appMode) {
|
||||
AppMode.VPN -> userspaceTunnel
|
||||
AppMode.PROXY -> proxyUserspaceTunnel
|
||||
AppMode.LOCK_DOWN -> proxyUserspaceTunnel
|
||||
AppMode.KERNEL -> kernelTunnel
|
||||
}
|
||||
settings to backend
|
||||
}
|
||||
.onEach { (settings, newBackend) ->
|
||||
val isInitialEmit = initialEmit.exchange(false)
|
||||
val oldBackend = currentBackend.exchange(newBackend)
|
||||
val oldSettings = currentSettings.exchange(settings)
|
||||
|
||||
if ((oldSettings.appMode != settings.appMode) && !isInitialEmit) {
|
||||
oldBackend.stopTunnel()
|
||||
if (oldSettings.appMode == AppMode.LOCK_DOWN)
|
||||
proxyUserspaceTunnel.setBackendMode(BackendMode.Inactive)
|
||||
}
|
||||
if (settings.appMode == AppMode.LOCK_DOWN) {
|
||||
// kill switch will always catch all ipv6, just add ipv4 networks for allowsIps
|
||||
val allowedIps =
|
||||
if (settings.isLanOnKillSwitchEnabled) TunnelConf.IPV4_PUBLIC_NETWORKS
|
||||
else emptySet()
|
||||
try {
|
||||
// TODO handle situation where they don't have vpn permission, request it
|
||||
if (hasVpnPermission()) {
|
||||
proxyUserspaceTunnel.setBackendMode(BackendMode.KillSwitch(allowedIps))
|
||||
}
|
||||
} catch (e: BackendCoreException) {
|
||||
// TODO expose this error to user
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
// restore state if configured
|
||||
if (isInitialEmit && settings.isRestoreOnBootEnabled) {
|
||||
Timber.d("Restoring previous state")
|
||||
if (
|
||||
settings.isAutoTunnelEnabled &&
|
||||
serviceManager.autoTunnelService.value == null
|
||||
) {
|
||||
serviceManager.startAutoTunnel()
|
||||
} else {
|
||||
val previouslyActiveTuns = appDataRepository.tunnels.getActive()
|
||||
val tunsToStart =
|
||||
previouslyActiveTuns.filterNot { tun ->
|
||||
activeTunnels.value.any { tun.id == it.key.id }
|
||||
}
|
||||
tunsToStart.forEach { startTunnel(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
.map { (_, backend) -> backend }
|
||||
.stateIn(
|
||||
scope = applicationScope.plus(ioDispatcher),
|
||||
started = SharingStarted.Eagerly,
|
||||
initialValue = userspaceTunnel,
|
||||
)
|
||||
}
|
||||
|
||||
override val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>> =
|
||||
tunnelProviderFlow.value.activeTunnels
|
||||
tunnelProviderFlow
|
||||
.flatMapLatest { it.activeTunnels }
|
||||
.stateIn(
|
||||
scope = applicationScope.plus(ioDispatcher),
|
||||
started = SharingStarted.Eagerly,
|
||||
initialValue = emptyMap(),
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>> =
|
||||
override val errorEvents: SharedFlow<Pair<TunnelConf, BackendCoreException>> =
|
||||
tunnelProviderFlow
|
||||
.flatMapLatest { it.errorEvents }
|
||||
.shareIn(
|
||||
@@ -90,12 +168,12 @@ constructor(
|
||||
tunnelProviderFlow.value.bounceTunnel(tunnelConf, reason)
|
||||
}
|
||||
|
||||
override fun setBackendStatus(backendStatus: BackendStatus) {
|
||||
tunnelProviderFlow.value.setBackendStatus(backendStatus)
|
||||
override fun setBackendMode(backendMode: BackendMode) {
|
||||
tunnelProviderFlow.value.setBackendMode(backendMode)
|
||||
}
|
||||
|
||||
override fun getBackendStatus(): BackendStatus {
|
||||
return tunnelProviderFlow.value.getBackendStatus()
|
||||
override fun getBackendMode(): BackendMode {
|
||||
return tunnelProviderFlow.value.getBackendMode()
|
||||
}
|
||||
|
||||
override suspend fun runningTunnelNames(): Set<String> {
|
||||
@@ -117,20 +195,4 @@ constructor(
|
||||
handshakeSuccessLogs,
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun restorePreviousState() {
|
||||
val settings = appDataRepository.settings.get()
|
||||
if (settings.isRestoreOnBootEnabled) {
|
||||
val previouslyActiveTuns = appDataRepository.tunnels.getActive()
|
||||
val tunsToStart =
|
||||
previouslyActiveTuns.filterNot { tun ->
|
||||
activeTunnels.value.any { tun.id == it.key.id }
|
||||
}
|
||||
if (settings.isKernelEnabled) {
|
||||
return tunsToStart.forEach { startTunnel(it) }
|
||||
} else {
|
||||
tunsToStart.firstOrNull()?.let { startTunnel(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendMessage
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.PingState
|
||||
@@ -41,9 +41,9 @@ interface TunnelProvider {
|
||||
reason: TunnelStatus.StopReason = TunnelStatus.StopReason.User,
|
||||
)
|
||||
|
||||
fun setBackendStatus(backendStatus: BackendStatus)
|
||||
fun setBackendMode(backendMode: BackendMode)
|
||||
|
||||
fun getBackendStatus(): BackendStatus
|
||||
fun getBackendMode(): BackendMode
|
||||
|
||||
suspend fun runningTunnelNames(): Set<String>
|
||||
|
||||
@@ -51,7 +51,7 @@ interface TunnelProvider {
|
||||
|
||||
val activeTunnels: StateFlow<Map<TunnelConf, TunnelState>>
|
||||
|
||||
val errorEvents: SharedFlow<Pair<TunnelConf, BackendError>>
|
||||
val errorEvents: SharedFlow<Pair<TunnelConf, BackendCoreException>>
|
||||
|
||||
val messageEvents: SharedFlow<Pair<TunnelConf, BackendMessage>>
|
||||
|
||||
|
||||
+75
-27
@@ -1,22 +1,31 @@
|
||||
package com.zaneschepke.wireguardautotunnel.core.tunnel
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendError
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.BackendCoreException
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppProxySettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.AmneziaStatistics
|
||||
import com.zaneschepke.wireguardautotunnel.domain.state.TunnelStatistics
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendStatus
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendStatus
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendError
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asAmBackendMode
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asBackendMode
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.toBackendCoreException
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.amnezia.awg.backend.Backend
|
||||
import org.amnezia.awg.backend.BackendException
|
||||
import org.amnezia.awg.backend.ProxyGoBackend
|
||||
import org.amnezia.awg.backend.Tunnel
|
||||
import org.amnezia.awg.config.Config
|
||||
import org.amnezia.awg.config.DnsSettings
|
||||
import org.amnezia.awg.config.proxy.HttpProxy
|
||||
import org.amnezia.awg.config.proxy.Proxy
|
||||
import org.amnezia.awg.config.proxy.Socks5Proxy
|
||||
import timber.log.Timber
|
||||
|
||||
class UserspaceTunnel
|
||||
@@ -31,24 +40,60 @@ constructor(
|
||||
override suspend fun startBackend(tunnel: TunnelConf) {
|
||||
try {
|
||||
updateTunnelStatus(tunnel, TunnelStatus.Starting)
|
||||
val amConfig = tunnel.toAmConfig()
|
||||
var previousKillSwitch: Backend.BackendStatus? = null
|
||||
// prevent dns failures from bringing tuns up when vpn kill switch active
|
||||
if (
|
||||
amConfig.peers.any { it.endpoint.getOrNull()?.toString()?.isUrl() == true } &&
|
||||
backend.backendStatus is Backend.BackendStatus.KillSwitchActive
|
||||
) {
|
||||
previousKillSwitch = backend.backendStatus
|
||||
setBackendStatus(BackendStatus.Active)
|
||||
}
|
||||
backend.setState(tunnel, Tunnel.State.UP, amConfig)
|
||||
previousKillSwitch?.let { backend.backendStatus = it }
|
||||
|
||||
val proxies: List<Proxy> =
|
||||
when (backend) {
|
||||
is ProxyGoBackend -> {
|
||||
val proxySettings = appDataRepository.proxySettings.get()
|
||||
Timber.d("Adding proxy configs")
|
||||
buildList {
|
||||
if (proxySettings.socks5ProxyEnabled) {
|
||||
add(
|
||||
Socks5Proxy(
|
||||
proxySettings.socks5ProxyBindAddress
|
||||
?: AppProxySettings.DEFAULT_SOCKS_BIND_ADDRESS,
|
||||
proxySettings.proxyUsername,
|
||||
proxySettings.proxyPassword,
|
||||
)
|
||||
)
|
||||
}
|
||||
if (proxySettings.httpProxyEnabled) {
|
||||
add(
|
||||
HttpProxy(
|
||||
proxySettings.httpProxyBindAddress
|
||||
?: AppProxySettings.DEFAULT_HTTP_BIND_ADDRESS,
|
||||
proxySettings.proxyUsername,
|
||||
proxySettings.proxyPassword,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> emptyList()
|
||||
}
|
||||
val setting = appDataRepository.settings.get()
|
||||
val config = tunnel.toAmConfig()
|
||||
val updatedConfig =
|
||||
Config.Builder()
|
||||
.apply {
|
||||
setInterface(config.`interface`)
|
||||
addPeers(config.peers)
|
||||
addProxies(proxies)
|
||||
setDnsSettings(
|
||||
DnsSettings(
|
||||
setting.dnsProtocol == DnsProtocol.DOH,
|
||||
Optional.ofNullable(setting.dnsEndpoint),
|
||||
)
|
||||
)
|
||||
}
|
||||
.build()
|
||||
backend.setState(tunnel, Tunnel.State.UP, updatedConfig)
|
||||
} catch (e: BackendException) {
|
||||
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
||||
throw e.toBackendError()
|
||||
throw e.toBackendCoreException()
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Timber.e(e, "Failed to start up backend for tunnel ${tunnel.name}")
|
||||
throw BackendError.Config
|
||||
throw BackendCoreException.Config
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,21 +103,24 @@ constructor(
|
||||
backend.setState(tunnel, Tunnel.State.DOWN, tunnel.toAmConfig())
|
||||
} catch (e: BackendException) {
|
||||
Timber.e(e, "Failed to stop tunnel ${tunnel.id}")
|
||||
throw e.toBackendError()
|
||||
throw e.toBackendCoreException()
|
||||
}
|
||||
}
|
||||
|
||||
override fun setBackendStatus(backendStatus: BackendStatus) {
|
||||
Timber.d("Setting backend state: $backendStatus")
|
||||
override fun setBackendMode(backendMode: BackendMode) {
|
||||
Timber.d("Setting backend mode: $backendMode")
|
||||
try {
|
||||
backend.backendStatus = backendStatus.asAmBackendStatus()
|
||||
backend.backendMode = backendMode.asAmBackendMode()
|
||||
} catch (e: BackendException) {
|
||||
throw e.toBackendError()
|
||||
throw e.toBackendCoreException()
|
||||
// TODO this should be mapped to BackendException in the lib
|
||||
} catch (e: IOException) {
|
||||
throw BackendCoreException.NotAuthorized
|
||||
}
|
||||
}
|
||||
|
||||
override fun getBackendStatus(): BackendStatus {
|
||||
return backend.backendStatus.asBackendStatus()
|
||||
override fun getBackendMode(): BackendMode {
|
||||
return backend.backendMode.asBackendMode()
|
||||
}
|
||||
|
||||
override suspend fun runningTunnelNames(): Set<String> {
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.Context
|
||||
import androidx.hilt.work.HiltWorker
|
||||
import androidx.work.*
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.TunnelManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import dagger.assisted.Assisted
|
||||
@@ -23,7 +22,6 @@ constructor(
|
||||
private val serviceManager: ServiceManager,
|
||||
private val appDataRepository: AppDataRepository,
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
private val tunnelManager: TunnelManager,
|
||||
) : CoroutineWorker(context, params) {
|
||||
|
||||
companion object {
|
||||
@@ -53,10 +51,11 @@ constructor(
|
||||
withContext(ioDispatcher) {
|
||||
Timber.i("Service worker started")
|
||||
with(appDataRepository.settings.get()) {
|
||||
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null)
|
||||
return@with serviceManager.startAutoTunnel()
|
||||
if (tunnelManager.activeTunnels.value.isEmpty())
|
||||
tunnelManager.restorePreviousState()
|
||||
Timber.i("Checking to see if auto-tunnel has been killed by system")
|
||||
if (isAutoTunnelEnabled && serviceManager.autoTunnelService.value == null) {
|
||||
Timber.i("Service has been killed by system, restoring.")
|
||||
serviceManager.startAutoTunnel()
|
||||
}
|
||||
}
|
||||
Result.success()
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@ package com.zaneschepke.wireguardautotunnel.data
|
||||
|
||||
import androidx.room.*
|
||||
import androidx.room.migration.AutoMigrationSpec
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.ProxySettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||
|
||||
@Database(
|
||||
entities = [Settings::class, TunnelConfig::class],
|
||||
version = 19,
|
||||
entities = [Settings::class, TunnelConfig::class, ProxySettings::class],
|
||||
version = 22,
|
||||
autoMigrations =
|
||||
[
|
||||
AutoMigration(from = 1, to = 2),
|
||||
@@ -30,6 +33,9 @@ import com.zaneschepke.wireguardautotunnel.data.entity.TunnelConfig
|
||||
AutoMigration(from = 16, to = 17, spec = WifiDetectionMigration::class),
|
||||
AutoMigration(from = 17, to = 18),
|
||||
AutoMigration(from = 18, to = 19, spec = PingMigration::class),
|
||||
AutoMigration(from = 19, to = 20, spec = ProxyMigration::class),
|
||||
AutoMigration(from = 20, to = 21, spec = FixProxySettingsMigration::class),
|
||||
AutoMigration(from = 21, to = 22),
|
||||
],
|
||||
exportSchema = true,
|
||||
)
|
||||
@@ -38,6 +44,8 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun settingDao(): SettingsDao
|
||||
|
||||
abstract fun tunnelConfigDoa(): TunnelConfigDao
|
||||
|
||||
abstract fun proxySettingsDoa(): ProxySettingsDao
|
||||
}
|
||||
|
||||
@DeleteColumn(tableName = "Settings", columnName = "default_tunnel")
|
||||
@@ -68,3 +76,27 @@ class WifiDetectionMigration : AutoMigrationSpec
|
||||
),
|
||||
)
|
||||
class PingMigration : AutoMigrationSpec
|
||||
|
||||
@DeleteColumn.Entries(
|
||||
DeleteColumn(tableName = "Settings", columnName = "is_amnezia_enabled"),
|
||||
DeleteColumn(tableName = "Settings", columnName = "is_vpn_kill_switch_enabled"),
|
||||
DeleteColumn(tableName = "Settings", columnName = "is_kernel_kill_switch_enabled"),
|
||||
DeleteColumn(tableName = "Settings", columnName = "is_kernel_enabled"),
|
||||
)
|
||||
class ProxyMigration : AutoMigrationSpec {
|
||||
override fun onPostMigrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("INSERT INTO proxy_settings DEFAULT VALUES")
|
||||
}
|
||||
}
|
||||
|
||||
class FixProxySettingsMigration : AutoMigrationSpec {
|
||||
override fun onPostMigrate(db: SupportSQLiteDatabase) {
|
||||
val cursor = db.query("SELECT COUNT(*) FROM proxy_settings")
|
||||
val count = if (cursor.moveToFirst()) cursor.getInt(0) else 0
|
||||
cursor.close()
|
||||
|
||||
if (count == 0) {
|
||||
db.execSQL("INSERT INTO proxy_settings DEFAULT VALUES")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
|
||||
@@ -85,9 +84,5 @@ class DataStoreManager(
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> getFromStoreBlocking(key: Preferences.Key<T>) = runBlocking {
|
||||
context.dataStore.data.map { it[key] }.first()
|
||||
}
|
||||
|
||||
val preferencesFlow: Flow<Preferences?> = context.dataStore.data.flowOn(ioDispatcher)
|
||||
}
|
||||
|
||||
@@ -2,20 +2,15 @@ package com.zaneschepke.wireguardautotunnel.data
|
||||
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
|
||||
class DatabaseCallback : RoomDatabase.Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) =
|
||||
db.run {
|
||||
beginTransaction()
|
||||
try {
|
||||
execSQL(Queries.createDefaultSettings())
|
||||
Timber.i("Bootstrapping settings data")
|
||||
setTransactionSuccessful()
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
} finally {
|
||||
endTransaction()
|
||||
}
|
||||
}
|
||||
class DatabaseCallback @Inject constructor(private val databaseProvider: Provider<AppDatabase>) :
|
||||
RoomDatabase.Callback() {
|
||||
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
super.onCreate(db)
|
||||
db.execSQL("INSERT INTO proxy_settings DEFAULT VALUES")
|
||||
db.execSQL("INSERT INTO Settings DEFAULT VALUES")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.WifiDetectionMethod
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class DatabaseConverters {
|
||||
@@ -22,9 +24,26 @@ class DatabaseConverters {
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter fun fromStatus(status: Settings.WifiDetectionMethod): Int = status.value
|
||||
@TypeConverter
|
||||
fun setToString(value: Set<String>): String {
|
||||
return listToString(value.toList())
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toStatus(value: Int): Settings.WifiDetectionMethod =
|
||||
Settings.WifiDetectionMethod.fromValue(value)
|
||||
fun stringToSet(value: String): Set<String> {
|
||||
return stringToList(value).toSet()
|
||||
}
|
||||
|
||||
@TypeConverter fun fromStatus(status: WifiDetectionMethod): Int = status.value
|
||||
|
||||
@TypeConverter
|
||||
fun toStatus(value: Int): WifiDetectionMethod = WifiDetectionMethod.fromValue(value)
|
||||
|
||||
@TypeConverter fun toMode(value: Int): AppMode = AppMode.fromValue(value)
|
||||
|
||||
@TypeConverter fun fromMode(mode: AppMode): Int = mode.value
|
||||
|
||||
@TypeConverter fun toDnsProtocol(value: Int): DnsProtocol = DnsProtocol.fromValue(value)
|
||||
|
||||
@TypeConverter fun fromDnsProtocol(mode: DnsProtocol): Int = mode.value
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data
|
||||
|
||||
object Queries {
|
||||
fun createDefaultSettings(): String {
|
||||
return """
|
||||
INSERT INTO Settings (is_tunnel_enabled,
|
||||
is_tunnel_on_mobile_data_enabled,
|
||||
trusted_network_ssids,
|
||||
is_always_on_vpn_enabled,
|
||||
is_tunnel_on_ethernet_enabled,
|
||||
is_shortcuts_enabled,
|
||||
is_tunnel_on_wifi_enabled,
|
||||
is_kernel_enabled,
|
||||
is_restore_on_boot_enabled,
|
||||
is_multi_tunnel_enabled)
|
||||
VALUES
|
||||
('false',
|
||||
'false',
|
||||
'',
|
||||
'false',
|
||||
'false',
|
||||
'false',
|
||||
'false',
|
||||
'false',
|
||||
'false',
|
||||
'false')
|
||||
"""
|
||||
.trimIndent()
|
||||
}
|
||||
|
||||
fun createTunnelConfig(): String {
|
||||
return """
|
||||
INSERT INTO TunnelConfig (name, wg_quick) VALUES ('test', 'test')
|
||||
"""
|
||||
.trimIndent()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.dao
|
||||
|
||||
import androidx.room.*
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface ProxySettingsDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun save(t: ProxySettings)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun saveAll(t: List<ProxySettings>)
|
||||
|
||||
@Query("SELECT * FROM proxy_settings WHERE id=:id")
|
||||
suspend fun getById(id: Long): ProxySettings?
|
||||
|
||||
@Query("SELECT * FROM proxy_settings") suspend fun getAll(): List<ProxySettings>
|
||||
|
||||
@Query("SELECT * FROM proxy_settings LIMIT 1") fun getSettingsFlow(): Flow<ProxySettings>
|
||||
|
||||
@Query("SELECT * FROM proxy_settings") fun getAllFlow(): Flow<List<ProxySettings>>
|
||||
|
||||
@Delete suspend fun delete(t: ProxySettings)
|
||||
|
||||
@Query("SELECT COUNT('id') FROM proxy_settings") suspend fun count(): Long
|
||||
}
|
||||
@@ -16,7 +16,7 @@ interface SettingsDao {
|
||||
|
||||
@Query("SELECT * FROM settings LIMIT 1") fun getSettingsFlow(): Flow<Settings>
|
||||
|
||||
@Query("SELECT * FROM settings") fun getAllFlow(): Flow<MutableList<Settings>>
|
||||
@Query("SELECT * FROM settings") fun getAllFlow(): Flow<List<Settings>>
|
||||
|
||||
@Delete suspend fun delete(t: Settings)
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ interface TunnelConfigDao {
|
||||
|
||||
@Delete suspend fun delete(t: TunnelConfig)
|
||||
|
||||
@Delete suspend fun delete(t: TunnelConfigs)
|
||||
|
||||
@Query("SELECT COUNT('id') FROM TunnelConfig") suspend fun count(): Long
|
||||
|
||||
@Query("SELECT * FROM TunnelConfig WHERE tunnel_networks LIKE '%' || :name || '%'")
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.entity
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "proxy_settings")
|
||||
data class ProxySettings(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||
@ColumnInfo(name = "socks5_proxy_enabled", defaultValue = "0")
|
||||
val socks5ProxyEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "socks5_proxy_bind_address") val socks5ProxyBindAddress: String? = null,
|
||||
@ColumnInfo(name = "http_proxy_enable", defaultValue = "0")
|
||||
val httpProxyEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "http_proxy_bind_address") val httpProxyBindAddress: String? = null,
|
||||
@ColumnInfo(name = "proxy_username") val proxyUsername: String? = null,
|
||||
@ColumnInfo(name = "proxy_password") val proxyPassword: String? = null,
|
||||
)
|
||||
@@ -3,65 +3,54 @@ package com.zaneschepke.wireguardautotunnel.data.entity
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.WifiDetectionMethod
|
||||
|
||||
@Entity
|
||||
data class Settings(
|
||||
@PrimaryKey(autoGenerate = true) val id: Int = 0,
|
||||
@ColumnInfo(name = "is_tunnel_enabled") val isAutoTunnelEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_tunnel_on_mobile_data_enabled")
|
||||
@ColumnInfo(name = "is_tunnel_enabled", defaultValue = "0")
|
||||
val isAutoTunnelEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_tunnel_on_mobile_data_enabled", defaultValue = "0")
|
||||
val isTunnelOnMobileDataEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "trusted_network_ssids") val trustedNetworkSSIDs: List<String> = emptyList(),
|
||||
@ColumnInfo(name = "is_always_on_vpn_enabled") val isAlwaysOnVpnEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_tunnel_on_ethernet_enabled")
|
||||
@ColumnInfo(name = "trusted_network_ssids", defaultValue = "")
|
||||
val trustedNetworkSSIDs: Set<String> = emptySet(),
|
||||
@ColumnInfo(name = "is_always_on_vpn_enabled", defaultValue = "0")
|
||||
val isAlwaysOnVpnEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_tunnel_on_ethernet_enabled", defaultValue = "0")
|
||||
val isTunnelOnEthernetEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_shortcuts_enabled", defaultValue = "false")
|
||||
@ColumnInfo(name = "is_shortcuts_enabled", defaultValue = "0")
|
||||
val isShortcutsEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_tunnel_on_wifi_enabled", defaultValue = "false")
|
||||
@ColumnInfo(name = "is_tunnel_on_wifi_enabled", defaultValue = "0")
|
||||
val isTunnelOnWifiEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_kernel_enabled", defaultValue = "false")
|
||||
val isKernelEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_restore_on_boot_enabled", defaultValue = "false")
|
||||
@ColumnInfo(name = "is_restore_on_boot_enabled", defaultValue = "0")
|
||||
val isRestoreOnBootEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_multi_tunnel_enabled", defaultValue = "false")
|
||||
@ColumnInfo(name = "is_multi_tunnel_enabled", defaultValue = "0")
|
||||
val isMultiTunnelEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_ping_enabled", defaultValue = "false")
|
||||
val isPingEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_amnezia_enabled", defaultValue = "false")
|
||||
val isAmneziaEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_wildcards_enabled", defaultValue = "false")
|
||||
@ColumnInfo(name = "is_ping_enabled", defaultValue = "0") val isPingEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_wildcards_enabled", defaultValue = "0")
|
||||
val isWildcardsEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_stop_on_no_internet_enabled", defaultValue = "false")
|
||||
@ColumnInfo(name = "is_stop_on_no_internet_enabled", defaultValue = "0")
|
||||
val isStopOnNoInternetEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_vpn_kill_switch_enabled", defaultValue = "false")
|
||||
val isVpnKillSwitchEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_kernel_kill_switch_enabled", defaultValue = "false")
|
||||
val isKernelKillSwitchEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_lan_on_kill_switch_enabled", defaultValue = "false")
|
||||
@ColumnInfo(name = "is_lan_on_kill_switch_enabled", defaultValue = "0")
|
||||
val isLanOnKillSwitchEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "debounce_delay_seconds", defaultValue = "3")
|
||||
val debounceDelaySeconds: Int = 3,
|
||||
@ColumnInfo(name = "is_disable_kill_switch_on_trusted_enabled", defaultValue = "false")
|
||||
@ColumnInfo(name = "is_disable_kill_switch_on_trusted_enabled", defaultValue = "0")
|
||||
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "is_tunnel_on_unsecure_enabled", defaultValue = "false")
|
||||
@ColumnInfo(name = "is_tunnel_on_unsecure_enabled", defaultValue = "0")
|
||||
val isTunnelOnUnsecureEnabled: Boolean = false,
|
||||
@ColumnInfo(name = "wifi_detection_method", defaultValue = "0")
|
||||
val wifiDetectionMethod: WifiDetectionMethod = WifiDetectionMethod.fromValue(0),
|
||||
@ColumnInfo(name = "is_ping_monitoring_enabled", defaultValue = "true")
|
||||
@ColumnInfo(name = "is_ping_monitoring_enabled", defaultValue = "1")
|
||||
val isPingMonitoringEnabled: Boolean = true,
|
||||
@ColumnInfo(name = "tunnel_ping_interval_sec", defaultValue = "30")
|
||||
val tunnelPingIntervalSeconds: Int = 30,
|
||||
@ColumnInfo(name = "tunnel_ping_attempts", defaultValue = "3") val tunnelPingAttempts: Int = 3,
|
||||
@ColumnInfo(name = "tunnel_ping_timeout_sec") val tunnelPingTimeoutSeconds: Int? = null,
|
||||
) {
|
||||
enum class WifiDetectionMethod(val value: Int) {
|
||||
DEFAULT(0),
|
||||
LEGACY(1),
|
||||
ROOT(2),
|
||||
SHIZUKU(3);
|
||||
|
||||
companion object {
|
||||
fun fromValue(value: Int): WifiDetectionMethod =
|
||||
entries.find { it.value == value } ?: DEFAULT
|
||||
}
|
||||
}
|
||||
}
|
||||
@ColumnInfo(name = "app_mode", defaultValue = "0") val appMode: AppMode = AppMode.fromValue(0),
|
||||
@ColumnInfo(name = "dns_protocol", defaultValue = "0")
|
||||
val dnsProtocol: DnsProtocol = DnsProtocol.fromValue(0),
|
||||
@ColumnInfo(name = "dns_endpoint") val dnsEndpoint: String? = null,
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ data class TunnelConfig(
|
||||
@ColumnInfo(name = "name") val name: String,
|
||||
@ColumnInfo(name = "wg_quick") val wgQuick: String,
|
||||
@ColumnInfo(name = "tunnel_networks", defaultValue = "")
|
||||
val tunnelNetworks: List<String> = listOf(),
|
||||
val tunnelNetworks: Set<String> = setOf(),
|
||||
@ColumnInfo(name = "is_mobile_data_tunnel", defaultValue = "false")
|
||||
val isMobileDataTunnel: Boolean = false,
|
||||
@ColumnInfo(name = "is_primary_tunnel", defaultValue = "false")
|
||||
@@ -27,7 +27,7 @@ data class TunnelConfig(
|
||||
val isIpv4Preferred: Boolean = true,
|
||||
@ColumnInfo(name = "position", defaultValue = "0") val position: Int = 0,
|
||||
@ColumnInfo(name = "auto_tunnel_apps", defaultValue = "[]")
|
||||
val autoTunnelApps: List<String> = listOf(),
|
||||
val autoTunnelApps: Set<String> = setOf(),
|
||||
) {
|
||||
|
||||
companion object {
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppProxySettings
|
||||
|
||||
object ProxySettingsMapper {
|
||||
fun to(proxySettings: ProxySettings): AppProxySettings =
|
||||
with(proxySettings) {
|
||||
AppProxySettings(
|
||||
id,
|
||||
socks5ProxyEnabled,
|
||||
socks5ProxyBindAddress,
|
||||
httpProxyEnabled,
|
||||
httpProxyBindAddress,
|
||||
proxyUsername,
|
||||
proxyPassword,
|
||||
)
|
||||
}
|
||||
|
||||
fun to(proxySettings: AppProxySettings): ProxySettings =
|
||||
with(proxySettings) {
|
||||
ProxySettings(
|
||||
id,
|
||||
socks5ProxyEnabled,
|
||||
socks5ProxyBindAddress,
|
||||
httpProxyEnabled,
|
||||
httpProxyBindAddress,
|
||||
proxyUsername,
|
||||
proxyPassword,
|
||||
)
|
||||
}
|
||||
}
|
||||
+72
-66
@@ -1,71 +1,77 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.mapper
|
||||
|
||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsSettings
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.WifiDetectionMethod
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||
|
||||
object SettingsMapper {
|
||||
fun toAppSettings(settings: Settings): AppSettings {
|
||||
return AppSettings(
|
||||
id = settings.id,
|
||||
isAutoTunnelEnabled = settings.isAutoTunnelEnabled,
|
||||
isTunnelOnMobileDataEnabled = settings.isTunnelOnMobileDataEnabled,
|
||||
trustedNetworkSSIDs = settings.trustedNetworkSSIDs,
|
||||
isAlwaysOnVpnEnabled = settings.isAlwaysOnVpnEnabled,
|
||||
isTunnelOnEthernetEnabled = settings.isTunnelOnEthernetEnabled,
|
||||
isShortcutsEnabled = settings.isShortcutsEnabled,
|
||||
isTunnelOnWifiEnabled = settings.isTunnelOnWifiEnabled,
|
||||
isKernelEnabled = settings.isKernelEnabled,
|
||||
isRestoreOnBootEnabled = settings.isRestoreOnBootEnabled,
|
||||
isMultiTunnelEnabled = settings.isMultiTunnelEnabled,
|
||||
isPingEnabled = settings.isPingEnabled,
|
||||
isAmneziaEnabled = settings.isAmneziaEnabled,
|
||||
isWildcardsEnabled = settings.isWildcardsEnabled,
|
||||
isStopOnNoInternetEnabled = settings.isStopOnNoInternetEnabled,
|
||||
isVpnKillSwitchEnabled = settings.isVpnKillSwitchEnabled,
|
||||
isKernelKillSwitchEnabled = settings.isKernelKillSwitchEnabled,
|
||||
isLanOnKillSwitchEnabled = settings.isLanOnKillSwitchEnabled,
|
||||
debounceDelaySeconds = settings.debounceDelaySeconds,
|
||||
isDisableKillSwitchOnTrustedEnabled = settings.isDisableKillSwitchOnTrustedEnabled,
|
||||
isTunnelOnUnsecureEnabled = settings.isTunnelOnUnsecureEnabled,
|
||||
wifiDetectionMethod =
|
||||
AndroidNetworkMonitor.WifiDetectionMethod.fromValue(
|
||||
settings.wifiDetectionMethod.value
|
||||
),
|
||||
tunnelPingIntervalSeconds = settings.tunnelPingIntervalSeconds,
|
||||
tunnelPingAttempts = settings.tunnelPingAttempts,
|
||||
tunnelPingTimeoutSeconds = settings.tunnelPingTimeoutSeconds,
|
||||
)
|
||||
}
|
||||
|
||||
fun toSettings(appSettings: AppSettings): Settings {
|
||||
return Settings(
|
||||
id = appSettings.id,
|
||||
isAutoTunnelEnabled = appSettings.isAutoTunnelEnabled,
|
||||
isTunnelOnMobileDataEnabled = appSettings.isTunnelOnMobileDataEnabled,
|
||||
trustedNetworkSSIDs = appSettings.trustedNetworkSSIDs,
|
||||
isAlwaysOnVpnEnabled = appSettings.isAlwaysOnVpnEnabled,
|
||||
isTunnelOnEthernetEnabled = appSettings.isTunnelOnEthernetEnabled,
|
||||
isShortcutsEnabled = appSettings.isShortcutsEnabled,
|
||||
isTunnelOnWifiEnabled = appSettings.isTunnelOnWifiEnabled,
|
||||
isKernelEnabled = appSettings.isKernelEnabled,
|
||||
isRestoreOnBootEnabled = appSettings.isRestoreOnBootEnabled,
|
||||
isMultiTunnelEnabled = appSettings.isMultiTunnelEnabled,
|
||||
isPingEnabled = appSettings.isPingEnabled,
|
||||
isAmneziaEnabled = appSettings.isAmneziaEnabled,
|
||||
isWildcardsEnabled = appSettings.isWildcardsEnabled,
|
||||
isStopOnNoInternetEnabled = appSettings.isStopOnNoInternetEnabled,
|
||||
isVpnKillSwitchEnabled = appSettings.isVpnKillSwitchEnabled,
|
||||
isKernelKillSwitchEnabled = appSettings.isKernelKillSwitchEnabled,
|
||||
isLanOnKillSwitchEnabled = appSettings.isLanOnKillSwitchEnabled,
|
||||
debounceDelaySeconds = appSettings.debounceDelaySeconds,
|
||||
isDisableKillSwitchOnTrustedEnabled = appSettings.isDisableKillSwitchOnTrustedEnabled,
|
||||
isTunnelOnUnsecureEnabled = appSettings.isTunnelOnUnsecureEnabled,
|
||||
wifiDetectionMethod =
|
||||
Settings.WifiDetectionMethod.fromValue(appSettings.wifiDetectionMethod.value),
|
||||
tunnelPingIntervalSeconds = appSettings.tunnelPingIntervalSeconds,
|
||||
tunnelPingAttempts = appSettings.tunnelPingAttempts,
|
||||
tunnelPingTimeoutSeconds = appSettings.tunnelPingTimeoutSeconds,
|
||||
)
|
||||
}
|
||||
fun Settings.toAppSettings(): GeneralSettings {
|
||||
return GeneralSettings(
|
||||
id = id,
|
||||
isAutoTunnelEnabled = isAutoTunnelEnabled,
|
||||
isTunnelOnMobileDataEnabled = isTunnelOnMobileDataEnabled,
|
||||
trustedNetworkSSIDs = trustedNetworkSSIDs,
|
||||
isAlwaysOnVpnEnabled = isAlwaysOnVpnEnabled,
|
||||
isTunnelOnEthernetEnabled = isTunnelOnEthernetEnabled,
|
||||
isShortcutsEnabled = isShortcutsEnabled,
|
||||
isTunnelOnWifiEnabled = isTunnelOnWifiEnabled,
|
||||
isRestoreOnBootEnabled = isRestoreOnBootEnabled,
|
||||
isMultiTunnelEnabled = isMultiTunnelEnabled,
|
||||
isPingEnabled = isPingEnabled,
|
||||
isWildcardsEnabled = isWildcardsEnabled,
|
||||
isStopOnNoInternetEnabled = isStopOnNoInternetEnabled,
|
||||
isLanOnKillSwitchEnabled = isLanOnKillSwitchEnabled,
|
||||
debounceDelaySeconds = debounceDelaySeconds,
|
||||
isDisableKillSwitchOnTrustedEnabled = isDisableKillSwitchOnTrustedEnabled,
|
||||
isTunnelOnUnsecureEnabled = isTunnelOnUnsecureEnabled,
|
||||
wifiDetectionMethod = WifiDetectionMethod.fromValue(wifiDetectionMethod.value),
|
||||
tunnelPingIntervalSeconds = tunnelPingIntervalSeconds,
|
||||
tunnelPingAttempts = tunnelPingAttempts,
|
||||
tunnelPingTimeoutSeconds = tunnelPingTimeoutSeconds,
|
||||
appMode = appMode,
|
||||
dnsProtocol = dnsProtocol,
|
||||
dnsEndpoint = dnsEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
fun GeneralSettings.toSettings(): Settings {
|
||||
return Settings(
|
||||
id = id,
|
||||
isAutoTunnelEnabled = isAutoTunnelEnabled,
|
||||
isTunnelOnMobileDataEnabled = isTunnelOnMobileDataEnabled,
|
||||
trustedNetworkSSIDs = trustedNetworkSSIDs,
|
||||
isAlwaysOnVpnEnabled = isAlwaysOnVpnEnabled,
|
||||
isTunnelOnEthernetEnabled = isTunnelOnEthernetEnabled,
|
||||
isShortcutsEnabled = isShortcutsEnabled,
|
||||
isTunnelOnWifiEnabled = isTunnelOnWifiEnabled,
|
||||
isRestoreOnBootEnabled = isRestoreOnBootEnabled,
|
||||
isMultiTunnelEnabled = isMultiTunnelEnabled,
|
||||
isPingEnabled = isPingEnabled,
|
||||
isWildcardsEnabled = isWildcardsEnabled,
|
||||
isStopOnNoInternetEnabled = isStopOnNoInternetEnabled,
|
||||
isLanOnKillSwitchEnabled = isLanOnKillSwitchEnabled,
|
||||
debounceDelaySeconds = debounceDelaySeconds,
|
||||
isDisableKillSwitchOnTrustedEnabled = isDisableKillSwitchOnTrustedEnabled,
|
||||
isTunnelOnUnsecureEnabled = isTunnelOnUnsecureEnabled,
|
||||
wifiDetectionMethod = WifiDetectionMethod.fromValue(wifiDetectionMethod.value),
|
||||
tunnelPingIntervalSeconds = tunnelPingIntervalSeconds,
|
||||
tunnelPingAttempts = tunnelPingAttempts,
|
||||
tunnelPingTimeoutSeconds = tunnelPingTimeoutSeconds,
|
||||
appMode = appMode,
|
||||
dnsProtocol = dnsProtocol,
|
||||
dnsEndpoint = dnsEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
fun GeneralSettings.toDomain(): DnsSettings {
|
||||
return DnsSettings(
|
||||
protocol =
|
||||
DnsProtocol.entries.toTypedArray().getOrElse(dnsProtocol.value) { DnsProtocol.SYSTEM },
|
||||
endpoint = dnsEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
fun DnsSettings.toAppSettings(existing: GeneralSettings): GeneralSettings {
|
||||
return existing.copy(dnsProtocol = protocol, dnsEndpoint = endpoint)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.model
|
||||
|
||||
enum class AppMode(val value: Int) {
|
||||
VPN(0),
|
||||
PROXY(1),
|
||||
LOCK_DOWN(2),
|
||||
KERNEL(3);
|
||||
|
||||
companion object {
|
||||
fun fromValue(value: Int): AppMode = entries.find { it.value == value } ?: VPN
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.model
|
||||
|
||||
import android.content.Context
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
|
||||
enum class DnsProtocol(val value: Int) {
|
||||
SYSTEM(0),
|
||||
DOH(1);
|
||||
|
||||
fun asString(context: Context): String {
|
||||
return when (this) {
|
||||
SYSTEM -> context.getString(R.string.system)
|
||||
DOH -> context.getString(R.string.doh)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromValue(value: Int): DnsProtocol =
|
||||
DnsProtocol.entries.find { it.value == value } ?: SYSTEM
|
||||
}
|
||||
}
|
||||
|
||||
data class DnsSettings(
|
||||
val protocol: DnsProtocol = DnsProtocol.SYSTEM,
|
||||
val endpoint: String? = null,
|
||||
)
|
||||
|
||||
enum class DnsProvider(private val systemAddress: String, private val dohAddress: String) {
|
||||
CLOUDFLARE("1.1.1.1", "https://1.1.1.1/dns-query"),
|
||||
ADGUARD("94.140.14.14", "https://94.140.14.14/dns-query");
|
||||
|
||||
fun asAddress(protocol: DnsProtocol): String {
|
||||
return when (protocol) {
|
||||
DnsProtocol.SYSTEM -> systemAddress
|
||||
DnsProtocol.DOH -> dohAddress
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromAddress(address: String): DnsProvider {
|
||||
return entries.find { it.systemAddress == address || it.dohAddress == address }
|
||||
?: CLOUDFLARE
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.model
|
||||
|
||||
enum class WifiDetectionMethod(val value: Int) {
|
||||
DEFAULT(0),
|
||||
LEGACY(1),
|
||||
ROOT(2),
|
||||
SHIZUKU(3);
|
||||
|
||||
fun needsLocationPermissions(): Boolean {
|
||||
return this == LEGACY || this == DEFAULT
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromValue(value: Int): WifiDetectionMethod =
|
||||
entries.find { it.value == value } ?: DEFAULT
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -1,18 +1,16 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.TunnelRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class AppDataRoomRepository
|
||||
@Inject
|
||||
constructor(
|
||||
override val settings: AppSettingRepository,
|
||||
override val settings: GeneralSettingRepository,
|
||||
override val tunnels: TunnelRepository,
|
||||
override val appState: AppStateRepository,
|
||||
override val proxySettings: ProxySettingsRepository,
|
||||
) : AppDataRepository {
|
||||
|
||||
override suspend fun getPrimaryOrFirstTunnel(): TunnelConf? {
|
||||
|
||||
+17
-2
@@ -3,15 +3,25 @@ package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.GeneralState
|
||||
import com.zaneschepke.wireguardautotunnel.data.mapper.GeneralStateMapper
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppState
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppStateRepository
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.plus
|
||||
import timber.log.Timber
|
||||
|
||||
class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager) :
|
||||
AppStateRepository {
|
||||
class DataStoreAppStateRepository(
|
||||
private val dataStoreManager: DataStoreManager,
|
||||
@ApplicationScope private val applicationScope: CoroutineScope,
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
) : AppStateRepository {
|
||||
override suspend fun isLocationDisclosureShown(): Boolean {
|
||||
return dataStoreManager.getFromStore(DataStoreManager.locationDisclosureShown)
|
||||
?: GeneralState.LOCATION_DISCLOSURE_SHOWN_DEFAULT
|
||||
@@ -167,4 +177,9 @@ class DataStoreAppStateRepository(private val dataStoreManager: DataStoreManager
|
||||
} ?: GeneralState()
|
||||
}
|
||||
.map(GeneralStateMapper::toAppState)
|
||||
.stateIn(
|
||||
scope = applicationScope + ioDispatcher,
|
||||
started = SharingStarted.Eagerly,
|
||||
initialValue = AppState(),
|
||||
)
|
||||
}
|
||||
|
||||
+6
-5
@@ -41,7 +41,7 @@ class GitHubUpdateRepository(
|
||||
val standaloneApkAsset =
|
||||
release.assets.find { asset ->
|
||||
asset.name.startsWith("wgtunnel-${Constants.STANDALONE_FLAVOR}-v") &&
|
||||
asset.name.endsWith(".apk")
|
||||
asset.name.endsWith(".apk")
|
||||
}
|
||||
val newVersion =
|
||||
standaloneApkAsset
|
||||
@@ -53,9 +53,10 @@ class GitHubUpdateRepository(
|
||||
if (isNightly && newVersion != currentVersion)
|
||||
return@map GitHubReleaseMapper.toAppUpdate(release, newVersion)
|
||||
if (NumberUtils.compareVersions(newVersion, currentVersion) > 0) {
|
||||
GitHubReleaseMapper.toAppUpdate(release.copy(
|
||||
assets = listOf(standaloneApkAsset)
|
||||
), newVersion)
|
||||
GitHubReleaseMapper.toAppUpdate(
|
||||
release.copy(assets = listOf(standaloneApkAsset)),
|
||||
newVersion,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -103,4 +104,4 @@ class GitHubUpdateRepository(
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import com.zaneschepke.wireguardautotunnel.di.ApplicationScope
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.InstalledPackage
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.InstalledPackageRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getAllInternetCapablePackages
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.getFriendlyAppName
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
|
||||
@Singleton
|
||||
class InstalledAndroidPackageRepository(
|
||||
private val context: Context,
|
||||
@ApplicationScope val applicationScope: CoroutineScope,
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
) : InstalledPackageRepository {
|
||||
|
||||
private var cachedPackages: List<InstalledPackage>? = null
|
||||
|
||||
init {
|
||||
val receiver =
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
when (intent.action) {
|
||||
Intent.ACTION_PACKAGE_ADDED,
|
||||
Intent.ACTION_PACKAGE_REMOVED,
|
||||
Intent.ACTION_PACKAGE_CHANGED -> {
|
||||
// don't update if we have nothing cached
|
||||
if (cachedPackages == null) return
|
||||
Timber.d("Updating installed packages cache")
|
||||
applicationScope.launch { refreshInstalledPackages() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val filter =
|
||||
IntentFilter().apply {
|
||||
addAction(Intent.ACTION_PACKAGE_ADDED)
|
||||
addAction(Intent.ACTION_PACKAGE_REMOVED)
|
||||
addAction(Intent.ACTION_PACKAGE_CHANGED)
|
||||
addDataScheme("package")
|
||||
}
|
||||
context.registerReceiver(receiver, filter)
|
||||
}
|
||||
|
||||
override suspend fun getInstalledPackages(): List<InstalledPackage> =
|
||||
withContext(ioDispatcher) {
|
||||
cachedPackages?.let {
|
||||
return@withContext it
|
||||
}
|
||||
refreshInstalledPackages()
|
||||
}
|
||||
|
||||
override suspend fun refreshInstalledPackages(): List<InstalledPackage> =
|
||||
withContext(ioDispatcher) {
|
||||
val packages = context.getAllInternetCapablePackages()
|
||||
|
||||
val installedPackages =
|
||||
packages.mapNotNull { packageInfo ->
|
||||
try {
|
||||
val appInfo =
|
||||
context.packageManager.getApplicationInfo(packageInfo.packageName, 0)
|
||||
InstalledPackage(
|
||||
name =
|
||||
context.packageManager.getFriendlyAppName(
|
||||
packageInfo.packageName,
|
||||
appInfo,
|
||||
),
|
||||
packageName = packageInfo.packageName,
|
||||
uId = appInfo.uid,
|
||||
)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
Timber.e(e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
cachedPackages = installedPackages
|
||||
|
||||
installedPackages
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.ProxySettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.ProxySettings
|
||||
import com.zaneschepke.wireguardautotunnel.data.mapper.ProxySettingsMapper
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppProxySettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.ProxySettingsRepository
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class RoomProxySettingsRepository(
|
||||
private val proxySettingsDao: ProxySettingsDao,
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
) : ProxySettingsRepository {
|
||||
override suspend fun save(proxySettings: AppProxySettings) {
|
||||
withContext(ioDispatcher) { proxySettingsDao.save(ProxySettingsMapper.to(proxySettings)) }
|
||||
}
|
||||
|
||||
override val flow =
|
||||
proxySettingsDao.getSettingsFlow().flowOn(ioDispatcher).map(ProxySettingsMapper::to)
|
||||
|
||||
override suspend fun get(): AppProxySettings {
|
||||
return withContext(ioDispatcher) {
|
||||
ProxySettingsMapper.to(proxySettingsDao.getAll().firstOrNull() ?: ProxySettings())
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-9
@@ -2,10 +2,11 @@ package com.zaneschepke.wireguardautotunnel.data.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.entity.Settings
|
||||
import com.zaneschepke.wireguardautotunnel.data.mapper.SettingsMapper
|
||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toAppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.data.mapper.toSettings
|
||||
import com.zaneschepke.wireguardautotunnel.di.IoDispatcher
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
@@ -14,18 +15,18 @@ import kotlinx.coroutines.withContext
|
||||
class RoomSettingsRepository(
|
||||
private val settingsDoa: SettingsDao,
|
||||
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
) : AppSettingRepository {
|
||||
) : GeneralSettingRepository {
|
||||
|
||||
override suspend fun save(appSettings: AppSettings) {
|
||||
withContext(ioDispatcher) { settingsDoa.save(SettingsMapper.toSettings(appSettings)) }
|
||||
override suspend fun save(generalSettings: GeneralSettings) {
|
||||
withContext(ioDispatcher) { settingsDoa.save(generalSettings.toSettings()) }
|
||||
}
|
||||
|
||||
override val flow =
|
||||
settingsDoa.getSettingsFlow().flowOn(ioDispatcher).map(SettingsMapper::toAppSettings)
|
||||
settingsDoa.getSettingsFlow().flowOn(ioDispatcher).map { it.toAppSettings() }
|
||||
|
||||
override suspend fun get(): AppSettings {
|
||||
override suspend fun get(): GeneralSettings {
|
||||
return withContext(ioDispatcher) {
|
||||
SettingsMapper.toAppSettings(settingsDoa.getAll().firstOrNull() ?: Settings())
|
||||
(settingsDoa.getAll().firstOrNull() ?: Settings()).toAppSettings()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -105,4 +105,10 @@ class RoomTunnelRepository(
|
||||
tunnelConfigDao.findByPrimary().map(TunnelConfigMapper::toTunnelConf)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun delete(tunnels: List<TunnelConf>) {
|
||||
withContext(ioDispatcher) {
|
||||
tunnelConfigDao.delete(tunnels.map { TunnelConfigMapper.toTunnelConfig(it) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import kotlinx.coroutines.SupervisorJob
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class AppModule {
|
||||
|
||||
@Singleton
|
||||
@ApplicationScope
|
||||
@Provides
|
||||
|
||||
@@ -9,3 +9,5 @@ import javax.inject.Qualifier
|
||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class Kernel
|
||||
|
||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class Userspace
|
||||
|
||||
@Qualifier @Retention(AnnotationRetention.BINARY) annotation class ProxyUserspace
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.data.AppDatabase
|
||||
import com.zaneschepke.wireguardautotunnel.data.DataStoreManager
|
||||
import com.zaneschepke.wireguardautotunnel.data.DatabaseCallback
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.ProxySettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.SettingsDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.dao.TunnelConfigDao
|
||||
import com.zaneschepke.wireguardautotunnel.data.network.GitHubApi
|
||||
@@ -21,20 +22,41 @@ import dagger.hilt.components.SingletonComponent
|
||||
import io.ktor.client.*
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class RepositoryModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideDatabase(@ApplicationContext context: Context): AppDatabase {
|
||||
fun provideGlobalEffectRepository(): GlobalEffectRepository {
|
||||
return GlobalEffectRepository()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideInstalledPackageRepository(
|
||||
@ApplicationContext context: Context,
|
||||
@ApplicationScope applicationScope: CoroutineScope,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): InstalledPackageRepository {
|
||||
return InstalledAndroidPackageRepository(context, applicationScope, ioDispatcher)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideDatabase(
|
||||
@ApplicationContext context: Context,
|
||||
callback: DatabaseCallback,
|
||||
): AppDatabase {
|
||||
return Room.databaseBuilder(
|
||||
context,
|
||||
AppDatabase::class.java,
|
||||
context.getString(R.string.db_name),
|
||||
)
|
||||
.fallbackToDestructiveMigration(true)
|
||||
.addCallback(DatabaseCallback())
|
||||
.addCallback(callback)
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -44,6 +66,12 @@ class RepositoryModule {
|
||||
return appDatabase.settingDao()
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideProxyDoa(appDatabase: AppDatabase): ProxySettingsDao {
|
||||
return appDatabase.proxySettingsDoa()
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideTunnelConfigDoa(appDatabase: AppDatabase): TunnelConfigDao {
|
||||
@@ -64,10 +92,19 @@ class RepositoryModule {
|
||||
fun provideSettingsRepository(
|
||||
settingsDao: SettingsDao,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): AppSettingRepository {
|
||||
): GeneralSettingRepository {
|
||||
return RoomSettingsRepository(settingsDao, ioDispatcher)
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideProxySettingsRepository(
|
||||
proxySettingsDao: ProxySettingsDao,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): ProxySettingsRepository {
|
||||
return RoomProxySettingsRepository(proxySettingsDao, ioDispatcher)
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun providePreferencesDataStore(
|
||||
@@ -79,18 +116,28 @@ class RepositoryModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideGeneralStateRepository(dataStoreManager: DataStoreManager): AppStateRepository {
|
||||
return DataStoreAppStateRepository(dataStoreManager)
|
||||
fun provideGeneralStateRepository(
|
||||
dataStoreManager: DataStoreManager,
|
||||
@ApplicationScope applicationScope: CoroutineScope,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): AppStateRepository {
|
||||
return DataStoreAppStateRepository(dataStoreManager, applicationScope, ioDispatcher)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAppDataRepository(
|
||||
settingsRepository: AppSettingRepository,
|
||||
settingsRepository: GeneralSettingRepository,
|
||||
tunnelRepository: TunnelRepository,
|
||||
appStateRepository: AppStateRepository,
|
||||
proxySettingsRepository: ProxySettingsRepository,
|
||||
): AppDataRepository {
|
||||
return AppDataRoomRepository(settingsRepository, tunnelRepository, appStateRepository)
|
||||
return AppDataRoomRepository(
|
||||
settingsRepository,
|
||||
tunnelRepository,
|
||||
appStateRepository,
|
||||
proxySettingsRepository,
|
||||
)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -7,11 +7,11 @@ import com.wireguard.android.util.ToolsInstaller
|
||||
import com.zaneschepke.logcatter.LogReader
|
||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||
import com.zaneschepke.networkmonitor.NetworkMonitor
|
||||
import com.zaneschepke.wireguardautotunnel.core.notification.NotificationManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.ServiceManager
|
||||
import com.zaneschepke.wireguardautotunnel.core.tunnel.*
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppDataRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.AppSettingRepository
|
||||
import com.zaneschepke.wireguardautotunnel.domain.repository.GeneralSettingRepository
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.to
|
||||
import com.zaneschepke.wireguardautotunnel.util.network.NetworkUtils
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
@@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||
import kotlinx.coroutines.flow.map
|
||||
import org.amnezia.awg.backend.Backend
|
||||
import org.amnezia.awg.backend.GoBackend
|
||||
import org.amnezia.awg.backend.ProxyGoBackend
|
||||
import org.amnezia.awg.backend.RootTunnelActionHandler
|
||||
|
||||
@Module
|
||||
@@ -48,10 +49,21 @@ class TunnelModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Userspace
|
||||
fun provideAmneziaBackend(@ApplicationContext context: Context): Backend {
|
||||
return GoBackend(context, RootTunnelActionHandler(org.amnezia.awg.util.RootShell(context)))
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@ProxyUserspace
|
||||
fun provideAmneziaProxyBackend(@ApplicationContext context: Context): Backend {
|
||||
return ProxyGoBackend(
|
||||
context,
|
||||
RootTunnelActionHandler(org.amnezia.awg.util.RootShell(context)),
|
||||
)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideKernelBackend(
|
||||
@@ -86,7 +98,19 @@ class TunnelModule {
|
||||
@ApplicationScope applicationScope: CoroutineScope,
|
||||
serviceManager: ServiceManager,
|
||||
appDataRepository: AppDataRepository,
|
||||
backend: Backend,
|
||||
@Userspace backend: Backend,
|
||||
): TunnelProvider {
|
||||
return UserspaceTunnel(applicationScope, serviceManager, appDataRepository, backend)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@ProxyUserspace
|
||||
fun provideProxyUserspaceProvider(
|
||||
@ApplicationScope applicationScope: CoroutineScope,
|
||||
serviceManager: ServiceManager,
|
||||
appDataRepository: AppDataRepository,
|
||||
@ProxyUserspace backend: Backend,
|
||||
): TunnelProvider {
|
||||
return UserspaceTunnel(applicationScope, serviceManager, appDataRepository, backend)
|
||||
}
|
||||
@@ -96,14 +120,17 @@ class TunnelModule {
|
||||
fun provideTunnelManager(
|
||||
@Kernel kernelTunnel: TunnelProvider,
|
||||
@Userspace userspaceTunnel: TunnelProvider,
|
||||
@ProxyUserspace proxyTunnel: TunnelProvider,
|
||||
serviceManager: ServiceManager,
|
||||
appDataRepository: AppDataRepository,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
@ApplicationScope applicationScope: CoroutineScope,
|
||||
notificationManager: NotificationManager,
|
||||
): TunnelManager {
|
||||
return TunnelManager(
|
||||
kernelTunnel,
|
||||
userspaceTunnel,
|
||||
proxyTunnel,
|
||||
serviceManager,
|
||||
appDataRepository,
|
||||
applicationScope,
|
||||
ioDispatcher,
|
||||
@@ -114,7 +141,7 @@ class TunnelModule {
|
||||
@Singleton
|
||||
fun provideNetworkMonitor(
|
||||
@ApplicationContext context: Context,
|
||||
settingsRepository: AppSettingRepository,
|
||||
settingsRepository: GeneralSettingRepository,
|
||||
@ApplicationScope applicationScope: CoroutineScope,
|
||||
@AppShell appShell: RootShell,
|
||||
): NetworkMonitor {
|
||||
@@ -125,7 +152,7 @@ class TunnelModule {
|
||||
get() =
|
||||
settingsRepository.flow
|
||||
.distinctUntilChangedBy { it.wifiDetectionMethod }
|
||||
.map { it.wifiDetectionMethod }
|
||||
.map { it.wifiDetectionMethod.to() }
|
||||
|
||||
override val rootShell: RootShell
|
||||
get() = appShell
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||
|
||||
sealed class BackendMode {
|
||||
data object Inactive : BackendMode()
|
||||
|
||||
data class KillSwitch(val allowedIps: Set<String>) : BackendMode()
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.enums
|
||||
|
||||
sealed class BackendStatus {
|
||||
data object Inactive : BackendStatus()
|
||||
|
||||
data object Active : BackendStatus()
|
||||
|
||||
data class KillSwitch(val allowedIps: List<String>) : BackendStatus()
|
||||
}
|
||||
@@ -11,8 +11,4 @@ sealed class AutoTunnelEvent {
|
||||
data object Stop : AutoTunnelEvent()
|
||||
|
||||
data object DoNothing : AutoTunnelEvent()
|
||||
|
||||
data class StartKillSwitch(val allowedIps: List<String>) : AutoTunnelEvent()
|
||||
|
||||
data object StopKillSwitch : AutoTunnelEvent()
|
||||
}
|
||||
|
||||
+10
-10
@@ -3,24 +3,24 @@ package com.zaneschepke.wireguardautotunnel.domain.events
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||
|
||||
sealed class BackendError : Exception() {
|
||||
data object DNS : BackendError()
|
||||
sealed class BackendCoreException : Exception() {
|
||||
data object DNS : BackendCoreException()
|
||||
|
||||
data object Unauthorized : BackendError()
|
||||
data object Unauthorized : BackendCoreException()
|
||||
|
||||
data object Config : BackendError()
|
||||
data object Config : BackendCoreException()
|
||||
|
||||
data object KernelModuleName : BackendError()
|
||||
data object KernelModuleName : BackendCoreException()
|
||||
|
||||
data object NotAuthorized : BackendError()
|
||||
data object NotAuthorized : BackendCoreException()
|
||||
|
||||
data object ServiceNotRunning : BackendError()
|
||||
data object ServiceNotRunning : BackendCoreException()
|
||||
|
||||
data object Unknown : BackendError()
|
||||
data object Unknown : BackendCoreException()
|
||||
|
||||
data object TunnelNameTooLong : BackendError()
|
||||
data object TunnelNameTooLong : BackendCoreException()
|
||||
|
||||
data class BounceFailed(val error: BackendError) : BackendError()
|
||||
data class BounceFailed(val error: BackendCoreException) : BackendCoreException()
|
||||
|
||||
fun toStringRes() =
|
||||
when (this) {
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||
|
||||
data class AppProxySettings(
|
||||
val id: Long = 0,
|
||||
val socks5ProxyEnabled: Boolean = false,
|
||||
val socks5ProxyBindAddress: String? = null,
|
||||
val httpProxyEnabled: Boolean = false,
|
||||
val httpProxyBindAddress: String? = null,
|
||||
val proxyUsername: String? = null,
|
||||
val proxyPassword: String? = null,
|
||||
) {
|
||||
companion object {
|
||||
const val DEFAULT_SOCKS_BIND_ADDRESS = "127.0.0.1:25344"
|
||||
const val DEFAULT_HTTP_BIND_ADDRESS = "127.0.0.1:25345"
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,14 @@ package com.zaneschepke.wireguardautotunnel.domain.model
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.Theme
|
||||
|
||||
data class AppState(
|
||||
val isLocationDisclosureShown: Boolean,
|
||||
val isBatteryOptimizationDisableShown: Boolean,
|
||||
val isPinLockEnabled: Boolean,
|
||||
val expandedTunnelIds: List<Int>,
|
||||
val isLocalLogsEnabled: Boolean,
|
||||
val isRemoteControlEnabled: Boolean,
|
||||
val showDetailedPingStats: Boolean,
|
||||
val remoteKey: String?,
|
||||
val locale: String?,
|
||||
val theme: Theme,
|
||||
val isLocationDisclosureShown: Boolean = false,
|
||||
val isBatteryOptimizationDisableShown: Boolean = false,
|
||||
val isPinLockEnabled: Boolean = false,
|
||||
val expandedTunnelIds: List<Int> = emptyList(),
|
||||
val isLocalLogsEnabled: Boolean = false,
|
||||
val isRemoteControlEnabled: Boolean = false,
|
||||
val showDetailedPingStats: Boolean = false,
|
||||
val remoteKey: String? = null,
|
||||
val locale: String? = null,
|
||||
val theme: Theme = Theme.AUTOMATIC,
|
||||
)
|
||||
|
||||
+16
-9
@@ -1,21 +1,21 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||
|
||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.DnsProtocol
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.WifiDetectionMethod
|
||||
|
||||
data class AppSettings(
|
||||
data class GeneralSettings(
|
||||
val id: Int = 0,
|
||||
val isAutoTunnelEnabled: Boolean = false,
|
||||
val isTunnelOnMobileDataEnabled: Boolean = false,
|
||||
val trustedNetworkSSIDs: List<String> = emptyList(),
|
||||
val trustedNetworkSSIDs: Set<String> = emptySet(),
|
||||
val isAlwaysOnVpnEnabled: Boolean = false,
|
||||
val isTunnelOnEthernetEnabled: Boolean = false,
|
||||
val isShortcutsEnabled: Boolean = false,
|
||||
val isTunnelOnWifiEnabled: Boolean = false,
|
||||
val isKernelEnabled: Boolean = false,
|
||||
val isRestoreOnBootEnabled: Boolean = false,
|
||||
val isMultiTunnelEnabled: Boolean = false,
|
||||
val isPingEnabled: Boolean = false,
|
||||
val isAmneziaEnabled: Boolean = false,
|
||||
val isWildcardsEnabled: Boolean = false,
|
||||
val isStopOnNoInternetEnabled: Boolean = false,
|
||||
val isVpnKillSwitchEnabled: Boolean = false,
|
||||
@@ -24,11 +24,13 @@ data class AppSettings(
|
||||
val debounceDelaySeconds: Int = 3,
|
||||
val isDisableKillSwitchOnTrustedEnabled: Boolean = false,
|
||||
val isTunnelOnUnsecureEnabled: Boolean = false,
|
||||
val wifiDetectionMethod: AndroidNetworkMonitor.WifiDetectionMethod =
|
||||
AndroidNetworkMonitor.WifiDetectionMethod.DEFAULT,
|
||||
val tunnelPingIntervalSeconds: Int = 30,
|
||||
val tunnelPingAttempts: Int = 3,
|
||||
val wifiDetectionMethod: WifiDetectionMethod = WifiDetectionMethod.DEFAULT,
|
||||
val tunnelPingIntervalSeconds: Int = PING_INTERVAL_DEFAULT,
|
||||
val tunnelPingAttempts: Int = PING_ATTEMPTS_DEFAULT,
|
||||
val tunnelPingTimeoutSeconds: Int? = null,
|
||||
val appMode: AppMode = AppMode.VPN,
|
||||
val dnsProtocol: DnsProtocol = DnsProtocol.SYSTEM,
|
||||
val dnsEndpoint: String? = null,
|
||||
) {
|
||||
fun toAutoTunnelStateString(): String {
|
||||
return """
|
||||
@@ -41,4 +43,9 @@ data class AppSettings(
|
||||
"""
|
||||
.trimIndent()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PING_INTERVAL_DEFAULT = 30
|
||||
const val PING_ATTEMPTS_DEFAULT = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||
|
||||
data class InstalledPackage(val name: String, val packageName: String, val uId: Int)
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.wireguard.android.backend.Tunnel
|
||||
import com.wireguard.config.Config
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.*
|
||||
import java.io.InputStream
|
||||
import java.nio.charset.StandardCharsets
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class TunnelConf(
|
||||
val id: Int = 0,
|
||||
val tunName: String,
|
||||
val wgQuick: String,
|
||||
val tunnelNetworks: List<String> = emptyList(),
|
||||
val tunnelNetworks: Set<String> = emptySet(),
|
||||
val isMobileDataTunnel: Boolean = false,
|
||||
val isPrimaryTunnel: Boolean = false,
|
||||
val amQuick: String,
|
||||
@@ -21,7 +24,7 @@ data class TunnelConf(
|
||||
val isIpv4Preferred: Boolean = true,
|
||||
val position: Int = 0,
|
||||
@Transient private var stateChangeCallback: ((Any) -> Unit)? = null,
|
||||
) : Tunnel, org.amnezia.awg.backend.Tunnel {
|
||||
) : Tunnel, org.amnezia.awg.backend.Tunnel, Parcelable {
|
||||
|
||||
val isNameKernelCompatible: Boolean = (name.length <= 15)
|
||||
|
||||
@@ -61,7 +64,7 @@ data class TunnelConf(
|
||||
id: Int = this.id,
|
||||
tunName: String = this.tunName,
|
||||
wgQuick: String = this.wgQuick,
|
||||
tunnelNetworks: List<String> = this.tunnelNetworks,
|
||||
tunnelNetworks: Set<String> = this.tunnelNetworks,
|
||||
isMobileDataTunnel: Boolean = this.isMobileDataTunnel,
|
||||
isPrimaryTunnel: Boolean = this.isPrimaryTunnel,
|
||||
amQuick: String = this.amQuick,
|
||||
@@ -99,8 +102,6 @@ data class TunnelConf(
|
||||
|
||||
override fun getName(): String = tunName
|
||||
|
||||
override fun isIpv4ResolutionPreferred(): Boolean = isIpv4Preferred
|
||||
|
||||
override fun onStateChange(newState: org.amnezia.awg.backend.Tunnel.State) {
|
||||
stateChangeCallback?.invoke(newState)
|
||||
}
|
||||
@@ -109,6 +110,10 @@ data class TunnelConf(
|
||||
stateChangeCallback?.invoke(newState)
|
||||
}
|
||||
|
||||
override fun isIpv4ResolutionPreferred(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
fun generateUniqueName(tunnelNames: List<String>): String {
|
||||
var tunnelName = this.tunName
|
||||
var num = 1
|
||||
@@ -138,11 +143,21 @@ data class TunnelConf(
|
||||
}
|
||||
}
|
||||
|
||||
fun tunnelConfigFromAmConfig(
|
||||
fun tunnelConfFromQuick(amQuick: String, name: String? = null): TunnelConf {
|
||||
val config = configFromAmQuick(amQuick)
|
||||
val wgQuick = config.toWgQuickString()
|
||||
return TunnelConf(
|
||||
tunName = name ?: config.defaultName(),
|
||||
wgQuick = wgQuick,
|
||||
amQuick = amQuick,
|
||||
)
|
||||
}
|
||||
|
||||
private fun tunnelConfFromAmConfig(
|
||||
config: org.amnezia.awg.config.Config,
|
||||
name: String? = null,
|
||||
): TunnelConf {
|
||||
val amQuick = config.toAwgQuickString(true)
|
||||
val amQuick = config.toAwgQuickString(true, false)
|
||||
val wgQuick = config.toWgQuickString()
|
||||
return TunnelConf(
|
||||
tunName = name ?: config.defaultName(),
|
||||
@@ -154,8 +169,8 @@ data class TunnelConf(
|
||||
private const val IPV6_ALL_NETWORKS = "::/0"
|
||||
private const val IPV4_ALL_NETWORKS = "0.0.0.0/0"
|
||||
val ALL_IPS = listOf(IPV4_ALL_NETWORKS, IPV6_ALL_NETWORKS)
|
||||
private val IPV4_PUBLIC_NETWORKS =
|
||||
listOf(
|
||||
val IPV4_PUBLIC_NETWORKS =
|
||||
setOf(
|
||||
"0.0.0.0/5",
|
||||
"8.0.0.0/7",
|
||||
"11.0.0.0/8",
|
||||
@@ -187,6 +202,6 @@ data class TunnelConf(
|
||||
"200.0.0.0/5",
|
||||
"208.0.0.0/4",
|
||||
)
|
||||
val LAN_BYPASS_ALLOWED_IPS = listOf(IPV6_ALL_NETWORKS) + IPV4_PUBLIC_NETWORKS
|
||||
val LAN_BYPASS_ALLOWED_IPS = setOf(IPV6_ALL_NETWORKS) + IPV4_PUBLIC_NETWORKS
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -7,7 +7,9 @@ interface AppDataRepository {
|
||||
|
||||
suspend fun getStartTunnelConfig(): TunnelConf?
|
||||
|
||||
val settings: AppSettingRepository
|
||||
val settings: GeneralSettingRepository
|
||||
val tunnels: TunnelRepository
|
||||
val appState: AppStateRepository
|
||||
|
||||
val proxySettings: ProxySettingsRepository
|
||||
}
|
||||
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface AppSettingRepository {
|
||||
suspend fun save(appSettings: AppSettings)
|
||||
|
||||
val flow: Flow<AppSettings>
|
||||
|
||||
suspend fun get(): AppSettings
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.sideeffect.GlobalSideEffect
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
|
||||
@Singleton
|
||||
class GlobalEffectRepository {
|
||||
|
||||
private val _globalEffectFlow =
|
||||
MutableSharedFlow<GlobalSideEffect>(replay = 0, extraBufferCapacity = 1)
|
||||
val flow = _globalEffectFlow.asSharedFlow()
|
||||
|
||||
suspend fun post(effect: GlobalSideEffect) {
|
||||
_globalEffectFlow.emit(effect)
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface GeneralSettingRepository {
|
||||
suspend fun save(generalSettings: GeneralSettings)
|
||||
|
||||
val flow: Flow<GeneralSettings>
|
||||
|
||||
suspend fun get(): GeneralSettings
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.InstalledPackage
|
||||
|
||||
interface InstalledPackageRepository {
|
||||
|
||||
// gets packages from cache or queries and updates cache if empty
|
||||
suspend fun getInstalledPackages(): List<InstalledPackage>
|
||||
|
||||
// updates the cache and returns the results
|
||||
suspend fun refreshInstalledPackages(): List<InstalledPackage>
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.repository
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppProxySettings
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface ProxySettingsRepository {
|
||||
suspend fun save(proxySettings: AppProxySettings)
|
||||
|
||||
val flow: Flow<AppProxySettings>
|
||||
|
||||
suspend fun get(): AppProxySettings
|
||||
}
|
||||
+2
@@ -34,4 +34,6 @@ interface TunnelRepository {
|
||||
suspend fun findByMobileDataTunnel(): Tunnels
|
||||
|
||||
suspend fun findPrimary(): Tunnels
|
||||
|
||||
suspend fun delete(tunnels: List<TunnelConf>)
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.sideeffect
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.AppMode
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||
import java.io.File
|
||||
|
||||
sealed class GlobalSideEffect {
|
||||
data object RequestBatteryOptimizationDisabled : GlobalSideEffect()
|
||||
|
||||
data class Snackbar(val message: StringValue) : GlobalSideEffect()
|
||||
|
||||
data class Toast(val message: StringValue) : GlobalSideEffect()
|
||||
|
||||
data object PopBackStack : GlobalSideEffect()
|
||||
|
||||
data class ShareFile(val file: File) : GlobalSideEffect()
|
||||
|
||||
data class LaunchUrl(val url: String) : GlobalSideEffect()
|
||||
|
||||
data object ConfigChanged : GlobalSideEffect()
|
||||
|
||||
data class RequestVpnPermission(val requestingMode: AppMode, val config: TunnelConf?) :
|
||||
GlobalSideEffect()
|
||||
|
||||
data class InstallApk(val apk: File) : GlobalSideEffect()
|
||||
}
|
||||
+3
-13
@@ -3,14 +3,14 @@ package com.zaneschepke.wireguardautotunnel.domain.state
|
||||
import com.zaneschepke.wireguardautotunnel.core.service.autotunnel.StateChange
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent
|
||||
import com.zaneschepke.wireguardautotunnel.domain.events.AutoTunnelEvent.*
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.AppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.GeneralSettings
|
||||
import com.zaneschepke.wireguardautotunnel.domain.model.TunnelConf
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.isMatchingToWildcardList
|
||||
|
||||
data class AutoTunnelState(
|
||||
val activeTunnels: Map<TunnelConf, TunnelState> = emptyMap(),
|
||||
val networkState: NetworkState = NetworkState(),
|
||||
val settings: AppSettings = AppSettings(),
|
||||
val settings: GeneralSettings = GeneralSettings(),
|
||||
val tunnels: List<TunnelConf> = emptyList(),
|
||||
) {
|
||||
|
||||
@@ -53,16 +53,6 @@ data class AutoTunnelState(
|
||||
return AutoTunnelEvent.Stop
|
||||
}
|
||||
}
|
||||
// Handle kill switch only if no user tunnel is or will be active
|
||||
if (stopKillSwitchOnTrusted()) {
|
||||
return AutoTunnelEvent.StopKillSwitch
|
||||
}
|
||||
if (startKillSwitch()) {
|
||||
val allowedIps =
|
||||
if (settings.isLanOnKillSwitchEnabled) TunnelConf.LAN_BYPASS_ALLOWED_IPS
|
||||
else emptyList()
|
||||
return StartKillSwitch(allowedIps)
|
||||
}
|
||||
}
|
||||
is StateChange.MonitoringChange -> {
|
||||
val bounceTunnels = bounceOnPingFailed()
|
||||
@@ -147,7 +137,7 @@ data class AutoTunnelState(
|
||||
|
||||
private fun hasTrustedWifiName(
|
||||
wifiName: String,
|
||||
wifiNames: List<String> = settings.trustedNetworkSSIDs,
|
||||
wifiNames: Set<String> = settings.trustedNetworkSSIDs,
|
||||
): Boolean {
|
||||
return if (settings.isWildcardsEnabled) {
|
||||
wifiNames.isMatchingToWildcardList(wifiName)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.zaneschepke.wireguardautotunnel.domain.state
|
||||
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendStatus
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.BackendMode
|
||||
import com.zaneschepke.wireguardautotunnel.domain.enums.TunnelStatus
|
||||
import org.amnezia.awg.crypto.Key
|
||||
|
||||
data class TunnelState(
|
||||
val status: TunnelStatus = TunnelStatus.Down,
|
||||
val backendState: BackendStatus = BackendStatus.Inactive,
|
||||
val backendState: BackendMode = BackendMode.Inactive,
|
||||
val statistics: TunnelStatistics? = null,
|
||||
val pingStates: Map<Key, PingState>? = null,
|
||||
val handshakeSuccessLogs: Boolean? = null,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui
|
||||
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.navigation.NavHostController
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.SharedAppViewModel
|
||||
|
||||
val LocalNavController =
|
||||
compositionLocalOf<NavHostController> { error("NavController was not provided") }
|
||||
|
||||
val LocalIsAndroidTV = staticCompositionLocalOf { false }
|
||||
|
||||
val LocalSharedVm = staticCompositionLocalOf<SharedAppViewModel> { error("No SharedVm") }
|
||||
+1
-1
@@ -22,7 +22,7 @@ fun ExpandingRowListItem(
|
||||
text: String,
|
||||
trailing: @Composable () -> Unit,
|
||||
isSelected: Boolean,
|
||||
expanded: @Composable () -> Unit,
|
||||
expanded: (@Composable () -> Unit),
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Box(
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common
|
||||
|
||||
import android.view.WindowManager
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import com.zaneschepke.wireguardautotunnel.MainActivity
|
||||
|
||||
@Composable
|
||||
fun SecureScreenFromRecording() {
|
||||
val context = LocalContext.current
|
||||
|
||||
val activity = context as? MainActivity
|
||||
|
||||
// Secure screen due to sensitive information
|
||||
DisposableEffect(Unit) {
|
||||
activity
|
||||
?.window
|
||||
?.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_SECURE,
|
||||
WindowManager.LayoutParams.FLAG_SECURE,
|
||||
)
|
||||
onDispose { activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) }
|
||||
}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.animation
|
||||
|
||||
import androidx.compose.animation.core.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
@Composable
|
||||
fun ShimmerEffect(modifier: Modifier = Modifier): Brush {
|
||||
val shimmerColors =
|
||||
listOf(
|
||||
Color.LightGray.copy(alpha = 0.9f),
|
||||
Color.LightGray.copy(alpha = 0.3f),
|
||||
Color.LightGray.copy(alpha = 0.9f),
|
||||
)
|
||||
|
||||
val transition = rememberInfiniteTransition()
|
||||
val translateAnim by
|
||||
transition.animateFloat(
|
||||
initialValue = 0f,
|
||||
targetValue = 1000f,
|
||||
animationSpec =
|
||||
infiniteRepeatable(animation = tween(durationMillis = 1200, easing = LinearEasing)),
|
||||
)
|
||||
|
||||
return Brush.linearGradient(
|
||||
colors = shimmerColors,
|
||||
start = Offset(0f, 0f),
|
||||
end = Offset(translateAnim, translateAnim),
|
||||
)
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.banner
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
@Composable
|
||||
fun AppAlertBanner(
|
||||
message: String,
|
||||
textColor: Color,
|
||||
containerColor: Color,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Box(
|
||||
modifier =
|
||||
modifier
|
||||
.fillMaxWidth()
|
||||
.height(IntrinsicSize.Min)
|
||||
.background(
|
||||
color = containerColor,
|
||||
shape = RoundedCornerShape(bottomStart = 8.dp, bottomEnd = 8.dp),
|
||||
)
|
||||
.clip(RoundedCornerShape(bottomStart = 8.dp, bottomEnd = 8.dp))
|
||||
.statusBarsPadding()
|
||||
) {
|
||||
Text(
|
||||
text = message,
|
||||
color = textColor,
|
||||
style = MaterialTheme.typography.labelSmall.copy(fontSize = 8.sp),
|
||||
modifier = Modifier.align(Alignment.Center).padding(bottom = 5.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.button
|
||||
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
|
||||
@Composable
|
||||
fun ActionIconButton(icon: ImageVector, labelRes: Int, onClick: () -> Unit) {
|
||||
IconButton(onClick = onClick) {
|
||||
Icon(
|
||||
icon,
|
||||
contentDescription = stringResource(labelRes),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -12,8 +12,10 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItemLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionLabelType
|
||||
|
||||
@androidx.compose.runtime.Composable
|
||||
@Composable
|
||||
fun IconSurfaceButton(
|
||||
title: String,
|
||||
onClick: () -> Unit,
|
||||
@@ -55,7 +57,7 @@ fun IconSurfaceButton(
|
||||
) {
|
||||
leading?.invoke()
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Text(title, style = MaterialTheme.typography.titleMedium)
|
||||
SelectionItemLabel(title, SelectionLabelType.TITLE)
|
||||
description?.let {
|
||||
Text(
|
||||
description,
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.button
|
||||
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.OpenInNew
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
|
||||
@Composable
|
||||
fun LinkIconButton(modifier: Modifier = Modifier.focusable(), onClick: () -> Unit) {
|
||||
IconButton(modifier = modifier, onClick = onClick) {
|
||||
val icon = Icons.AutoMirrored.Outlined.OpenInNew
|
||||
Icon(icon, icon.name, Modifier.size(iconSize))
|
||||
}
|
||||
}
|
||||
+36
-16
@@ -4,24 +4,28 @@ import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.ripple
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItemLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionLabelType
|
||||
|
||||
@Composable
|
||||
fun SelectionItemButton(
|
||||
leading: (@Composable () -> Unit)? = null,
|
||||
buttonText: String,
|
||||
trailing: (@Composable () -> Unit)? = null,
|
||||
description: String? = null,
|
||||
onClick: () -> Unit,
|
||||
ripple: Boolean = true,
|
||||
modifier: Modifier = Modifier,
|
||||
leading: (@Composable () -> Unit)? = null,
|
||||
trailing: (@Composable () -> Unit)? = null,
|
||||
ripple: Boolean = true,
|
||||
) {
|
||||
Card(
|
||||
modifier =
|
||||
@@ -32,23 +36,39 @@ fun SelectionItemButton(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
onClick = { onClick() },
|
||||
)
|
||||
.height(56.dp),
|
||||
.height(IntrinsicSize.Min)
|
||||
.padding(horizontal = 12.dp)
|
||||
.padding(end = 12.dp),
|
||||
colors = CardDefaults.cardColors(containerColor = Color.Transparent),
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
modifier = Modifier.fillMaxSize().padding(horizontal = 12.dp),
|
||||
) {
|
||||
leading?.let { it() }
|
||||
Text(
|
||||
buttonText,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = Modifier.fillMaxWidth(3 / 4f),
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(24.dp),
|
||||
) {
|
||||
leading?.let { it() }
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
modifier = Modifier.weight(1f).padding(end = 12.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
SelectionItemLabel(
|
||||
buttonText,
|
||||
SelectionLabelType.TITLE,
|
||||
modifier = Modifier.weight(1f).padding(end = 24.dp),
|
||||
)
|
||||
description?.let {
|
||||
SelectionItemLabel(
|
||||
it,
|
||||
SelectionLabelType.DESCRIPTION,
|
||||
modifier = Modifier.weight(1f).padding(end = 24.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
trailing?.let { it() }
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -22,6 +22,7 @@ fun SelectionItemLabel(text: String, labelType: SelectionLabelType, modifier: Mo
|
||||
}
|
||||
|
||||
enum class SelectionLabelType {
|
||||
|
||||
DESCRIPTION,
|
||||
TITLE,
|
||||
}
|
||||
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.config
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
|
||||
@Composable
|
||||
fun ConfigurationToggle(
|
||||
label: String,
|
||||
enabled: Boolean = true,
|
||||
checked: Boolean,
|
||||
onCheckChanged: (checked: Boolean) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Text(
|
||||
label,
|
||||
textAlign = TextAlign.Start,
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
modifier = Modifier.weight(weight = 1.0f, fill = false),
|
||||
softWrap = true,
|
||||
)
|
||||
ScaledSwitch(
|
||||
modifier = modifier,
|
||||
enabled = enabled,
|
||||
checked = checked,
|
||||
onClick = { onCheckChanged(it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
+8
-16
@@ -2,7 +2,7 @@ package com.zaneschepke.wireguardautotunnel.ui.common.dropdown
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
@@ -23,37 +23,29 @@ fun <T> DropdownSelector(
|
||||
label: @Composable (() -> Unit)? = null,
|
||||
isExpanded: Boolean = false,
|
||||
onDismiss: () -> Unit = {},
|
||||
optionToString: @Composable (T?) -> String = {
|
||||
it?.toString() ?: stringResource(R.string._default)
|
||||
},
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(5.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
if (label != null) label()
|
||||
Text(
|
||||
text = currentValue?.toString() ?: stringResource(R.string._default),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
Text(text = optionToString(currentValue), style = MaterialTheme.typography.bodyMedium)
|
||||
Icon(Icons.Default.ArrowDropDown, contentDescription = stringResource(R.string.dropdown))
|
||||
}
|
||||
|
||||
DropdownMenu(
|
||||
modifier = modifier.height(250.dp),
|
||||
modifier = modifier.heightIn(max = 250.dp),
|
||||
scrollState = rememberScrollState(),
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
expanded = isExpanded,
|
||||
onDismissRequest = onDismiss,
|
||||
) {
|
||||
options.forEach { option ->
|
||||
if (option == null) {
|
||||
return@forEach DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string._default)) },
|
||||
onClick = {
|
||||
onValueSelected(null)
|
||||
onDismiss()
|
||||
},
|
||||
)
|
||||
}
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = option.toString()) },
|
||||
text = { Text(optionToString(option)) },
|
||||
onClick = {
|
||||
onValueSelected(option)
|
||||
onDismiss()
|
||||
|
||||
+8
-5
@@ -5,15 +5,17 @@ import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionIte
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
|
||||
@Composable
|
||||
fun LabelledNumberDropdown(
|
||||
fun <T> LabelledDropdown(
|
||||
title: @Composable () -> Unit,
|
||||
description: (@Composable () -> Unit)? = null,
|
||||
leading: @Composable () -> Unit,
|
||||
onSelected: (Int?) -> Unit,
|
||||
options: List<Int?>,
|
||||
currentValue: Int?,
|
||||
onSelected: (T?) -> Unit,
|
||||
options: List<T?>,
|
||||
currentValue: T?,
|
||||
optionToString: @Composable (T?) -> String,
|
||||
) {
|
||||
var isDropDownExpanded by remember { mutableStateOf(false) }
|
||||
|
||||
SurfaceSelectionGroupButton(
|
||||
listOf(
|
||||
SelectionItem(
|
||||
@@ -25,9 +27,10 @@ fun LabelledNumberDropdown(
|
||||
DropdownSelector(
|
||||
currentValue = currentValue,
|
||||
options = options,
|
||||
onValueSelected = { num -> onSelected(num) },
|
||||
onValueSelected = { selected -> onSelected(selected) },
|
||||
isExpanded = isDropDownExpanded,
|
||||
onDismiss = { isDropDownExpanded = false },
|
||||
optionToString = optionToString,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
+8
-8
@@ -9,8 +9,8 @@ import androidx.activity.compose.ManagedActivityResultLauncher
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.runtime.Composable
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.util.Constants
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.util.FileUtils
|
||||
import timber.log.Timber
|
||||
|
||||
@Composable
|
||||
@@ -26,9 +26,9 @@ fun rememberFileImportLauncherForResult(
|
||||
super.createIntent(context, input).apply {
|
||||
type =
|
||||
if (isTv) {
|
||||
Constants.ALLOWED_TV_FILE_TYPES
|
||||
FileUtils.ALLOWED_TV_FILE_TYPES
|
||||
} else {
|
||||
Constants.ALL_FILE_TYPES
|
||||
FileUtils.ALL_FILE_TYPES
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ fun rememberFileImportLauncherForResult(
|
||||
if (
|
||||
activitiesToResolveIntent.all {
|
||||
val name = it.activityInfo.packageName
|
||||
name.startsWith(Constants.GOOGLE_TV_EXPLORER_STUB) ||
|
||||
name.startsWith(Constants.ANDROID_TV_EXPLORER_STUB)
|
||||
name.startsWith(FileUtils.GOOGLE_TV_EXPLORER_STUB) ||
|
||||
name.startsWith(FileUtils.ANDROID_TV_EXPLORER_STUB)
|
||||
}
|
||||
) {
|
||||
onNoFileExplorer()
|
||||
@@ -68,7 +68,7 @@ fun rememberFileImportLauncherForResult(
|
||||
|
||||
@Composable
|
||||
fun rememberFileExportLauncherForResult(
|
||||
mimeType: String = Constants.ZIP_FILE_MIME_TYPE,
|
||||
mimeType: String = FileUtils.ZIP_FILE_MIME_TYPE,
|
||||
onResult: (Uri?) -> Unit,
|
||||
): ManagedActivityResultLauncher<String, Uri?> {
|
||||
val isTv = LocalIsAndroidTV.current
|
||||
@@ -82,7 +82,7 @@ fun rememberFileExportLauncherForResult(
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type =
|
||||
if (isTv) {
|
||||
Constants.ALLOWED_TV_FILE_TYPES
|
||||
FileUtils.ALLOWED_TV_FILE_TYPES
|
||||
} else {
|
||||
mimeType
|
||||
}
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.sheet
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Check
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
|
||||
@Composable
|
||||
fun SheetOption(
|
||||
label: String,
|
||||
leadingIcon: ImageVector? = null,
|
||||
onClick: () -> Unit,
|
||||
selected: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier.fillMaxWidth().clickable(onClick = onClick).padding(10.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
Row {
|
||||
leadingIcon?.let {
|
||||
Icon(
|
||||
imageVector = it,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
}
|
||||
Text(text = label, modifier = Modifier.padding(10.dp))
|
||||
}
|
||||
if (selected) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Check,
|
||||
contentDescription = stringResource(R.string.selected),
|
||||
modifier = Modifier.padding(10.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun CustomBottomSheet(options: List<SheetOption>, onDismiss: () -> Unit) {
|
||||
ModalBottomSheet(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
onDismissRequest = onDismiss,
|
||||
) {
|
||||
options.forEachIndexed { index, option ->
|
||||
SheetOption(option.label, option.leadingIcon, option.onClick, option.selected)
|
||||
if (index != options.size - 1) HorizontalDivider()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class SheetOption(
|
||||
val leadingIcon: ImageVector,
|
||||
val label: String,
|
||||
val onClick: () -> Unit,
|
||||
val selected: Boolean = false,
|
||||
)
|
||||
+1
-1
@@ -16,7 +16,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalIsAndroidTV
|
||||
|
||||
@Composable
|
||||
fun CustomSnackBar(
|
||||
|
||||
+28
-13
@@ -1,55 +1,70 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.config
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.textbox
|
||||
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun ConfigurationTextBox(
|
||||
value: String,
|
||||
label: String,
|
||||
hint: String,
|
||||
onValueChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
keyboardActions: KeyboardActions = KeyboardActions(),
|
||||
label: String,
|
||||
modifier: Modifier,
|
||||
isError: Boolean = false,
|
||||
keyboardOptions: KeyboardOptions =
|
||||
KeyboardOptions(capitalization = KeyboardCapitalization.None, imeAction = ImeAction.Done),
|
||||
leading: (@Composable () -> Unit)? = null,
|
||||
trailing: (@Composable () -> Unit)? = null,
|
||||
interactionSource: MutableInteractionSource? = null,
|
||||
supportingText: (@Composable () -> Unit)? = null,
|
||||
interactionSource: MutableInteractionSource = MutableInteractionSource(),
|
||||
visualTransformation: VisualTransformation = VisualTransformation.None,
|
||||
enabled: Boolean = true,
|
||||
readOnly: Boolean = false,
|
||||
singleLine: Boolean = true,
|
||||
) {
|
||||
OutlinedTextField(
|
||||
CustomTextField(
|
||||
isError = isError,
|
||||
textStyle = MaterialTheme.typography.labelLarge,
|
||||
modifier = modifier,
|
||||
textStyle =
|
||||
MaterialTheme.typography.bodySmall.copy(color = MaterialTheme.colorScheme.onSurface),
|
||||
modifier = modifier.fillMaxWidth().height(48.dp),
|
||||
value = value,
|
||||
singleLine = true,
|
||||
visualTransformation = visualTransformation,
|
||||
singleLine = singleLine,
|
||||
interactionSource = interactionSource,
|
||||
onValueChange = { onValueChange(it) },
|
||||
label = {
|
||||
Text(
|
||||
label,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
)
|
||||
},
|
||||
maxLines = 1,
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
placeholder = {
|
||||
Text(
|
||||
hint,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
},
|
||||
keyboardOptions = keyboardOptions,
|
||||
keyboardActions = keyboardActions,
|
||||
trailingIcon = trailing,
|
||||
trailing = trailing,
|
||||
supportingText = supportingText,
|
||||
leading = leading,
|
||||
readOnly = readOnly,
|
||||
enabled = enabled,
|
||||
)
|
||||
}
|
||||
+8
-6
@@ -27,7 +27,7 @@ fun CustomTextField(
|
||||
label: @Composable () -> Unit,
|
||||
containerColor: Color,
|
||||
onValueChange: (value: String) -> Unit = {},
|
||||
singleLine: Boolean = false,
|
||||
singleLine: Boolean = true,
|
||||
placeholder: @Composable (() -> Unit)? = null,
|
||||
keyboardOptions: KeyboardOptions = KeyboardOptions(),
|
||||
keyboardActions: KeyboardActions = KeyboardActions(),
|
||||
@@ -37,7 +37,8 @@ fun CustomTextField(
|
||||
isError: Boolean = false,
|
||||
readOnly: Boolean = false,
|
||||
enabled: Boolean = true,
|
||||
interactionSource: MutableInteractionSource,
|
||||
visualTransformation: VisualTransformation = VisualTransformation.None,
|
||||
interactionSource: MutableInteractionSource = MutableInteractionSource(),
|
||||
) {
|
||||
val space = " "
|
||||
BasicTextField(
|
||||
@@ -52,6 +53,7 @@ fun CustomTextField(
|
||||
interactionSource = interactionSource,
|
||||
enabled = enabled,
|
||||
singleLine = singleLine,
|
||||
visualTransformation = visualTransformation,
|
||||
) {
|
||||
OutlinedTextFieldDefaults.DecorationBox(
|
||||
value = space + value,
|
||||
@@ -81,14 +83,14 @@ fun CustomTextField(
|
||||
),
|
||||
enabled = enabled,
|
||||
label = label,
|
||||
visualTransformation = VisualTransformation.None,
|
||||
visualTransformation = visualTransformation,
|
||||
interactionSource = interactionSource,
|
||||
placeholder = placeholder,
|
||||
container = {
|
||||
OutlinedTextFieldDefaults.ContainerBox(
|
||||
enabled,
|
||||
OutlinedTextFieldDefaults.Container(
|
||||
enabled = enabled,
|
||||
isError = isError,
|
||||
interactionSource,
|
||||
interactionSource = interactionSource,
|
||||
colors =
|
||||
TextFieldDefaults.colors()
|
||||
.copy(
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.config
|
||||
package com.zaneschepke.wireguardautotunnel.ui.common.textbox
|
||||
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
@@ -19,13 +19,13 @@ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.textbox.CustomTextField
|
||||
|
||||
@Composable
|
||||
fun SubmitConfigurationTextBox(
|
||||
value: String?,
|
||||
label: String,
|
||||
hint: String,
|
||||
modifier: Modifier = Modifier,
|
||||
isErrorValue: (value: String?) -> Boolean,
|
||||
onSubmit: (value: String) -> Unit,
|
||||
supportingText: @Composable (() -> Unit)? = null,
|
||||
@@ -62,7 +62,7 @@ fun SubmitConfigurationTextBox(
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
)
|
||||
},
|
||||
modifier = Modifier.padding(top = 5.dp, bottom = 10.dp).fillMaxWidth().padding(end = 16.dp),
|
||||
modifier = modifier.fillMaxWidth().height(48.dp),
|
||||
singleLine = true,
|
||||
keyboardOptions = keyboardOptions,
|
||||
keyboardActions =
|
||||
+1
-2
@@ -1,12 +1,11 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
|
||||
data class BottomNavItem(
|
||||
val name: String,
|
||||
val route: Route,
|
||||
val icon: ImageVector,
|
||||
val onClick: () -> Unit,
|
||||
val active: Boolean = false,
|
||||
val route: Route,
|
||||
)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavHostController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
fun <T : Route> NavBackStackEntry?.isCurrentRoute(cls: KClass<T>): Boolean {
|
||||
return this?.destination?.hierarchy?.any { it.hasRoute(route = cls) } == true
|
||||
}
|
||||
|
||||
val LocalNavController =
|
||||
compositionLocalOf<NavHostController> { error("NavController was not provided") }
|
||||
val LocalIsAndroidTV = staticCompositionLocalOf { false }
|
||||
+40
-34
@@ -1,52 +1,58 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
sealed class Route {
|
||||
@Serializable data object TunnelsGraph : Route()
|
||||
|
||||
@Serializable data object AutoTunnelGraph : Route()
|
||||
|
||||
@Serializable data object SettingsGraph : Route()
|
||||
|
||||
@Serializable data object SupportGraph : Route()
|
||||
|
||||
@Serializable data object Support : Route()
|
||||
|
||||
@Serializable data object Settings : Route()
|
||||
|
||||
@Serializable data object SettingsAdvanced : Route()
|
||||
|
||||
@Serializable data object AutoTunnel : Route()
|
||||
|
||||
@Serializable data object AutoTunnelAdvanced : Route()
|
||||
|
||||
@Serializable data object WifiDetectionMethod : Route()
|
||||
|
||||
@Serializable data object LocationDisclosure : Route()
|
||||
|
||||
@Serializable data object Appearance : Route()
|
||||
|
||||
@Serializable data object Display : Route()
|
||||
|
||||
@Serializable data object KillSwitch : Route()
|
||||
|
||||
@Serializable data object Language : Route()
|
||||
|
||||
@Serializable data object Main : Route()
|
||||
|
||||
@Serializable data class TunnelOptions(val id: Int) : Route()
|
||||
|
||||
@Serializable data object Lock : Route()
|
||||
|
||||
@Serializable data object License : Route()
|
||||
|
||||
@Serializable data class Config(val id: Int) : Route()
|
||||
@Serializable data object Logs : Route()
|
||||
|
||||
@Serializable
|
||||
data class SplitTunnel(val id: Int) : Route() {
|
||||
companion object {
|
||||
const val KEY_ID = "id"
|
||||
}
|
||||
}
|
||||
@Serializable data object Appearance : Route()
|
||||
|
||||
@Serializable data object Language : Route()
|
||||
|
||||
@Serializable data object Display : Route()
|
||||
|
||||
@Serializable data object Tunnels : Route()
|
||||
|
||||
@Serializable data class TunnelOptions(val id: Int) : Route()
|
||||
|
||||
@Serializable data class Config(val id: Int?) : Route()
|
||||
|
||||
@Serializable data class SplitTunnel(val id: Int) : Route()
|
||||
|
||||
@Serializable data class TunnelAutoTunnel(val id: Int) : Route()
|
||||
|
||||
@Serializable data object Logs : Route()
|
||||
|
||||
@Serializable data object Sort : Route()
|
||||
|
||||
@Serializable data object Settings : Route()
|
||||
|
||||
@Serializable data object TunnelMonitoring : Route()
|
||||
|
||||
@Serializable data object SystemFeatures : Route()
|
||||
|
||||
@Serializable data object Dns : Route()
|
||||
|
||||
@Serializable data object ProxySettings : Route()
|
||||
|
||||
@Serializable data object AutoTunnel : Route()
|
||||
|
||||
@Serializable data object AdvancedAutoTunnel : Route()
|
||||
|
||||
@Serializable data object WifiDetectionMethod : Route()
|
||||
|
||||
@Serializable data object LocationDisclosure : Route()
|
||||
}
|
||||
+108
-62
@@ -1,107 +1,153 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Bolt
|
||||
import androidx.compose.material.icons.rounded.Home
|
||||
import androidx.compose.material.icons.rounded.QuestionMark
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.BottomNavItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavbarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.SilverTree
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.debounce
|
||||
|
||||
@Composable
|
||||
fun NavHostController.getCurrentGraph(): State<Route?> {
|
||||
val navBackStackEntry by currentBackStackEntryAsState()
|
||||
|
||||
return remember(navBackStackEntry) {
|
||||
derivedStateOf {
|
||||
val parentRouteString = navBackStackEntry?.destination?.parent?.route
|
||||
when (parentRouteString) {
|
||||
Route.TunnelsGraph::class.qualifiedName -> Route.TunnelsGraph
|
||||
Route.AutoTunnelGraph::class.qualifiedName -> Route.AutoTunnelGraph
|
||||
Route.SettingsGraph::class.qualifiedName -> Route.SettingsGraph
|
||||
Route.SupportGraph::class.qualifiedName -> Route.SupportGraph
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun BottomNavbar(appUiState: AppUiState) {
|
||||
val navController = LocalNavController.current
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
fun BottomNavbar(
|
||||
isAutoTunnelActive: Boolean,
|
||||
navbarState: NavbarState,
|
||||
navController: NavHostController,
|
||||
) {
|
||||
|
||||
val currentGraph by navController.getCurrentGraph()
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
val navigateToDebounced =
|
||||
remember<(Route) -> Unit> {
|
||||
debounce(scope = coroutineScope, 150L) { route ->
|
||||
navController.navigate(route) {
|
||||
popUpTo(navController.graph.findStartDestination().id) { saveState = true }
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val items =
|
||||
listOf(
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.tunnels),
|
||||
route = Route.Main,
|
||||
icon = Icons.Rounded.Home,
|
||||
onClick = { navController.goFromRoot(Route.Main) },
|
||||
onClick = { navigateToDebounced(Route.TunnelsGraph) },
|
||||
route = Route.TunnelsGraph,
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.auto_tunnel),
|
||||
route = Route.AutoTunnel,
|
||||
icon = Icons.Rounded.Bolt,
|
||||
onClick = {
|
||||
val route =
|
||||
if (appUiState.appState.isLocationDisclosureShown) {
|
||||
Route.AutoTunnel
|
||||
} else Route.LocationDisclosure
|
||||
navController.goFromRoot(route)
|
||||
},
|
||||
active = appUiState.isAutoTunnelActive,
|
||||
onClick = { navigateToDebounced(Route.AutoTunnelGraph) },
|
||||
route = Route.AutoTunnelGraph,
|
||||
active = isAutoTunnelActive,
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.settings),
|
||||
route = Route.Settings,
|
||||
icon = Icons.Rounded.Settings,
|
||||
onClick = { navController.goFromRoot(Route.Settings) },
|
||||
onClick = { navigateToDebounced(Route.SettingsGraph) },
|
||||
route = Route.SettingsGraph,
|
||||
),
|
||||
BottomNavItem(
|
||||
name = stringResource(R.string.support),
|
||||
route = Route.Support,
|
||||
icon = Icons.Rounded.QuestionMark,
|
||||
onClick = { navController.goFromRoot(Route.Support) },
|
||||
onClick = { navigateToDebounced(Route.SupportGraph) },
|
||||
route = Route.SupportGraph,
|
||||
),
|
||||
)
|
||||
|
||||
NavigationBar(containerColor = MaterialTheme.colorScheme.surface) {
|
||||
items.forEach { item ->
|
||||
val isSelected = navBackStackEntry.isCurrentRoute(item.route::class)
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
|
||||
NavigationBarItem(
|
||||
icon = {
|
||||
if (item.active) {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
Badge(
|
||||
modifier = Modifier.offset(x = 8.dp, y = (-8).dp).size(6.dp),
|
||||
containerColor = SilverTree,
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(imageVector = item.icon, contentDescription = item.name)
|
||||
}
|
||||
} else {
|
||||
Icon(imageVector = item.icon, contentDescription = item.name)
|
||||
if (!navbarState.removeBottom) {
|
||||
NavigationBar(containerColor = MaterialTheme.colorScheme.surface) {
|
||||
AnimatedVisibility(
|
||||
visible = navbarState.showBottomItems,
|
||||
enter = slideInVertically(initialOffsetY = { it }),
|
||||
exit = slideOutVertically(targetOffsetY = { it }),
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(0.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
items.forEach { item ->
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
NavigationBarItem(
|
||||
icon = {
|
||||
if (item.active) {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
Badge(
|
||||
modifier =
|
||||
Modifier.offset(x = 8.dp, y = (-8).dp)
|
||||
.size(6.dp),
|
||||
containerColor = SilverTree,
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
imageVector = item.icon,
|
||||
contentDescription = item.name,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Icon(imageVector = item.icon, contentDescription = item.name)
|
||||
}
|
||||
},
|
||||
onClick = item.onClick,
|
||||
selected = currentGraph == item.route,
|
||||
enabled = true,
|
||||
label = null,
|
||||
alwaysShowLabel = false,
|
||||
colors =
|
||||
NavigationBarItemDefaults.colors(
|
||||
selectedIconColor = MaterialTheme.colorScheme.primary,
|
||||
unselectedIconColor = MaterialTheme.colorScheme.onBackground,
|
||||
indicatorColor = Color.Transparent,
|
||||
),
|
||||
interactionSource = interactionSource,
|
||||
)
|
||||
}
|
||||
},
|
||||
onClick = item.onClick,
|
||||
selected = isSelected,
|
||||
enabled = true,
|
||||
label = null,
|
||||
alwaysShowLabel = false,
|
||||
colors =
|
||||
NavigationBarItemDefaults.colors(
|
||||
selectedIconColor = MaterialTheme.colorScheme.primary,
|
||||
unselectedIconColor = MaterialTheme.colorScheme.onBackground,
|
||||
indicatorColor = Color.Transparent,
|
||||
),
|
||||
interactionSource = interactionSource,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-18
@@ -1,6 +1,5 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation.components
|
||||
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
@@ -10,31 +9,20 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavBarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavbarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.LockedDownBannerHeight
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DynamicTopAppBar(navBarState: NavBarState, modifier: Modifier = Modifier) {
|
||||
fun DynamicTopAppBar(navBarState: NavbarState, modifier: Modifier = Modifier) {
|
||||
TopAppBar(
|
||||
modifier = modifier,
|
||||
modifier = modifier.padding(top = LockedDownBannerHeight),
|
||||
colors = TopAppBarDefaults.topAppBarColors().copy(Color.Transparent),
|
||||
title = {
|
||||
AnimatedVisibility(
|
||||
visible = navBarState.showTop,
|
||||
enter = slideInVertically() + fadeIn(),
|
||||
exit = slideOutVertically() + fadeOut(),
|
||||
) {
|
||||
Box(modifier = Modifier.padding(start = 10.dp)) { navBarState.topTitle?.invoke() }
|
||||
}
|
||||
Box(modifier = Modifier.padding(start = 10.dp)) { navBarState.topTitle?.invoke() }
|
||||
},
|
||||
actions = {
|
||||
AnimatedVisibility(
|
||||
visible = navBarState.showTop,
|
||||
enter = slideInVertically() + fadeIn(),
|
||||
exit = slideOutVertically() + fadeOut(),
|
||||
) {
|
||||
Box(modifier = Modifier.padding(end = 10.dp)) { navBarState.topTrailing?.invoke() }
|
||||
}
|
||||
Box(modifier = Modifier.padding(end = 10.dp)) { navBarState.topTrailing?.invoke() }
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
-311
@@ -1,311 +0,0 @@
|
||||
package com.zaneschepke.wireguardautotunnel.ui.navigation.components
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.Sort
|
||||
import androidx.compose.material.icons.rounded.*
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.toRoute
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.isCurrentRoute
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppViewState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavBarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.UiEvent
|
||||
|
||||
@Composable
|
||||
fun currentNavBackStackEntryAsNavBarState(
|
||||
navController: NavController,
|
||||
backStackEntry: NavBackStackEntry?,
|
||||
viewModel: AppViewModel,
|
||||
uiState: AppUiState,
|
||||
appViewState: AppViewState,
|
||||
): State<NavBarState> {
|
||||
fun isActiveSelected() =
|
||||
uiState.activeTunnels.any { active ->
|
||||
appViewState.selectedTunnels.any { it.id == active.key.id }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ActionIconButton(icon: ImageVector, labelRes: Int, onClick: () -> Unit) {
|
||||
IconButton(onClick = onClick) {
|
||||
Icon(
|
||||
icon,
|
||||
contentDescription = stringResource(labelRes),
|
||||
modifier = Modifier.size(iconSize),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TunnelActionBar() {
|
||||
val selectedCount = appViewState.selectedTunnels.size
|
||||
val showDelete = !isActiveSelected()
|
||||
|
||||
Row {
|
||||
if (selectedCount == 0) {
|
||||
val showSort = remember(uiState.tunnels) { uiState.tunnels.size > 1 }
|
||||
if (showSort)
|
||||
ActionIconButton(Icons.AutoMirrored.Rounded.Sort, R.string.sort) {
|
||||
navController.navigate(Route.Sort)
|
||||
}
|
||||
ActionIconButton(Icons.Rounded.Add, R.string.add_tunnel) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.IMPORT_TUNNELS)
|
||||
)
|
||||
}
|
||||
return@Row
|
||||
}
|
||||
ActionIconButton(Icons.Rounded.SelectAll, R.string.select_all) {
|
||||
viewModel.handleEvent(AppEvent.ToggleSelectAllTunnels)
|
||||
}
|
||||
// due to permissions, and SAF issues on TV, not support less than Android 10 on
|
||||
// Android TV for file exports
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
ActionIconButton(Icons.Rounded.Download, R.string.download) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.EXPORT_TUNNELS)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedCount == 1) {
|
||||
ActionIconButton(Icons.Rounded.CopyAll, R.string.copy) {
|
||||
viewModel.handleEvent(AppEvent.CopySelectedTunnel)
|
||||
}
|
||||
}
|
||||
|
||||
if (showDelete) {
|
||||
ActionIconButton(Icons.Rounded.Delete, R.string.delete_tunnel) {
|
||||
viewModel.handleEvent(AppEvent.SetShowModal(AppViewState.ModalType.DELETE))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return produceState(
|
||||
initialValue = NavBarState(),
|
||||
key1 = backStackEntry,
|
||||
key2 = uiState,
|
||||
key3 = appViewState,
|
||||
) {
|
||||
value =
|
||||
when {
|
||||
backStackEntry.isCurrentRoute(Route.Main::class) -> {
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.tunnels)) },
|
||||
topTrailing = { TunnelActionBar() },
|
||||
route = Route.Main,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.AutoTunnel::class) -> {
|
||||
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.auto_tunnel)) },
|
||||
route = Route.AutoTunnel,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Logs::class) -> {
|
||||
NavBarState(
|
||||
showBottom = false,
|
||||
topTitle = { Text(stringResource(R.string.logs)) },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Menu, R.string.quick_actions) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(AppViewState.BottomSheet.LOGS)
|
||||
)
|
||||
}
|
||||
},
|
||||
route = Route.Logs,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Settings::class) ->
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.settings)) },
|
||||
route = Route.Settings,
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Menu, R.string.quick_actions) {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetBottomSheet(
|
||||
AppViewState.BottomSheet.BACKUP_AND_RESTORE
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Appearance::class) ->
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.appearance)) },
|
||||
route = Route.Appearance,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Language::class) ->
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.language)) },
|
||||
route = Route.Language,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Display::class) ->
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.display_theme)) },
|
||||
route = Route.Display,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.TunnelMonitoring::class) ->
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.tunnel_monitoring)) },
|
||||
route = Route.TunnelMonitoring,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.WifiDetectionMethod::class) ->
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.wifi_detection_method)) },
|
||||
route = Route.WifiDetectionMethod,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.KillSwitch::class) ->
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.kill_switch)) },
|
||||
route = Route.KillSwitch,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Support::class) ->
|
||||
NavBarState(
|
||||
topTitle = { Text(stringResource(R.string.support)) },
|
||||
route = Route.Support,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Sort::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.sort)) },
|
||||
topTrailing = {
|
||||
Row {
|
||||
ActionIconButton(Icons.Rounded.SortByAlpha, R.string.sort) {
|
||||
viewModel.handleUiEvent(UiEvent.SortTunnels)
|
||||
}
|
||||
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||
}
|
||||
}
|
||||
},
|
||||
route = Route.Sort,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.License::class) -> {
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.licenses)) },
|
||||
route = Route.License,
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.AutoTunnelAdvanced::class) ||
|
||||
backStackEntry.isCurrentRoute(Route.SettingsAdvanced::class) ->
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { Text(stringResource(R.string.advanced_settings)) },
|
||||
route = Route.AutoTunnelAdvanced,
|
||||
)
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.TunnelOptions::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.TunnelOptions>()
|
||||
val tunnel = uiState.tunnels.find { it.id == args?.id }
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { tunnel?.name?.let { Text(it) } },
|
||||
topTrailing = {
|
||||
Row {
|
||||
ActionIconButton(Icons.Rounded.QrCode2, R.string.show_qr) {
|
||||
tunnel?.id?.let {
|
||||
viewModel.handleEvent(
|
||||
AppEvent.SetShowModal(AppViewState.ModalType.QR)
|
||||
)
|
||||
}
|
||||
}
|
||||
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
||||
tunnel?.id?.let { navController.navigate(Route.Config(it)) }
|
||||
}
|
||||
}
|
||||
},
|
||||
route = args?.let { Route.TunnelOptions(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.SplitTunnel::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.SplitTunnel>()
|
||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { name?.let { Text(it) } },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||
}
|
||||
},
|
||||
route = args?.let { Route.SplitTunnel(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.Config::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.Config>()
|
||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { name?.let { Text(it) } },
|
||||
topTrailing = {
|
||||
ActionIconButton(Icons.Rounded.Save, R.string.save) {
|
||||
viewModel.handleEvent(AppEvent.InvokeScreenAction)
|
||||
}
|
||||
},
|
||||
route = args?.let { Route.Config(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
backStackEntry.isCurrentRoute(Route.TunnelAutoTunnel::class) -> {
|
||||
val args = backStackEntry?.toRoute<Route.TunnelAutoTunnel>()
|
||||
val name = uiState.tunnels.find { it.id == args?.id }?.name
|
||||
|
||||
NavBarState(
|
||||
showTop = true,
|
||||
showBottom = true,
|
||||
topTitle = { name?.let { Text(it) } },
|
||||
route = args?.let { Route.TunnelAutoTunnel(it.id) },
|
||||
)
|
||||
}
|
||||
|
||||
else -> NavBarState(showTop = false, showBottom = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
+52
-31
@@ -17,61 +17,75 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalSharedVm
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.SectionDivider
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.banner.WarningBanner
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dialog.InfoDialog
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.AdvancedSettingsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.NetworkTunnelingItems
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.WifiTunnelingItems
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.networkTunnelingItems
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components.wifiTunnelingItems
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavbarState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.launchAppSettings
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.launchLocationServicesSettings
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AutoTunnelViewModel
|
||||
|
||||
@OptIn(ExperimentalPermissionsApi::class)
|
||||
@Composable
|
||||
fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
val navController = LocalNavController.current
|
||||
fun AutoTunnelScreen(viewModel: AutoTunnelViewModel = hiltViewModel()) {
|
||||
val context = LocalContext.current
|
||||
val sharedViewModel = LocalSharedVm.current
|
||||
val navController = LocalNavController.current
|
||||
val autoTunnelState by viewModel.container.stateFlow.collectAsStateWithLifecycle()
|
||||
|
||||
if (!autoTunnelState.stateInitialized) return
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
sharedViewModel.updateNavbarState(
|
||||
NavbarState(
|
||||
showBottomItems = true,
|
||||
topTitle = { Text(stringResource(R.string.auto_tunnel)) },
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
var currentText by remember { mutableStateOf("") }
|
||||
var showLocationDialog by remember { mutableStateOf(false) }
|
||||
|
||||
val showLocationServicesWarning by
|
||||
remember(
|
||||
uiState.connectivityState?.wifiState,
|
||||
uiState.appSettings.trustedNetworkSSIDs,
|
||||
uiState.appSettings.wifiDetectionMethod,
|
||||
autoTunnelState.connectivityState?.wifiState,
|
||||
autoTunnelState.generalSettings.trustedNetworkSSIDs,
|
||||
autoTunnelState.generalSettings.wifiDetectionMethod,
|
||||
) {
|
||||
derivedStateOf {
|
||||
uiState.connectivityState?.wifiState?.locationServicesEnabled == false &&
|
||||
uiState.appSettings.wifiDetectionMethod.needsLocationPermissions() &&
|
||||
uiState.appSettings.trustedNetworkSSIDs.isNotEmpty()
|
||||
autoTunnelState.connectivityState?.wifiState?.locationServicesEnabled == false &&
|
||||
autoTunnelState.generalSettings.wifiDetectionMethod
|
||||
.needsLocationPermissions() &&
|
||||
autoTunnelState.generalSettings.trustedNetworkSSIDs.isNotEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
val showLocationPermissionsWarning by
|
||||
remember(
|
||||
uiState.connectivityState?.wifiState,
|
||||
uiState.appSettings.trustedNetworkSSIDs,
|
||||
uiState.appSettings.wifiDetectionMethod,
|
||||
autoTunnelState.connectivityState?.wifiState,
|
||||
autoTunnelState.generalSettings.trustedNetworkSSIDs,
|
||||
autoTunnelState.generalSettings.wifiDetectionMethod,
|
||||
) {
|
||||
derivedStateOf {
|
||||
uiState.connectivityState?.wifiState?.locationPermissionsGranted == false &&
|
||||
uiState.appSettings.wifiDetectionMethod.needsLocationPermissions() &&
|
||||
uiState.appSettings.trustedNetworkSSIDs.isNotEmpty()
|
||||
autoTunnelState.connectivityState?.wifiState?.locationPermissionsGranted == false &&
|
||||
autoTunnelState.generalSettings.wifiDetectionMethod
|
||||
.needsLocationPermissions() &&
|
||||
autoTunnelState.generalSettings.trustedNetworkSSIDs.isNotEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(uiState.appSettings.trustedNetworkSSIDs) { currentText = "" }
|
||||
|
||||
if (showLocationDialog) {
|
||||
InfoDialog(
|
||||
onAttest = {
|
||||
@@ -121,8 +135,8 @@ fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
},
|
||||
)
|
||||
val (title, buttonText, icon) =
|
||||
remember(uiState.isAutoTunnelActive) {
|
||||
when (uiState.isAutoTunnelActive) {
|
||||
remember(autoTunnelState.autoTunnelActive) {
|
||||
when (autoTunnelState.autoTunnelActive) {
|
||||
true ->
|
||||
Triple(
|
||||
context.getString(R.string.auto_tunnel_running),
|
||||
@@ -144,24 +158,31 @@ fun AutoTunnelScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
leading = { Icon(icon, null) },
|
||||
title = { Text(title) },
|
||||
trailing = {
|
||||
Button({ viewModel.handleEvent(AppEvent.ToggleAutoTunnel) }) {
|
||||
Text(buttonText, fontWeight = FontWeight.Bold)
|
||||
Button({ viewModel.toggleAutoTunnel() }) {
|
||||
Text(
|
||||
buttonText,
|
||||
fontWeight = FontWeight.Bold,
|
||||
style =
|
||||
MaterialTheme.typography.bodyMedium.copy(
|
||||
color = MaterialTheme.colorScheme.surface
|
||||
),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
)
|
||||
)
|
||||
SurfaceSelectionGroupButton(
|
||||
items = WifiTunnelingItems(uiState, viewModel, currentText) { currentText = it }
|
||||
items = wifiTunnelingItems(autoTunnelState, viewModel, navController)
|
||||
)
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(items = NetworkTunnelingItems(uiState, viewModel))
|
||||
SurfaceSelectionGroupButton(items = networkTunnelingItems(autoTunnelState, viewModel))
|
||||
SectionDivider()
|
||||
SurfaceSelectionGroupButton(
|
||||
items =
|
||||
listOf(
|
||||
AdvancedSettingsItem(
|
||||
onClick = { navController.navigate(Route.AutoTunnelAdvanced) }
|
||||
onClick = { navController.navigate(Route.AdvancedAutoTunnel) }
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
+24
-10
@@ -12,18 +12,33 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dropdown.LabelledNumberDropdown
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalSharedVm
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.dropdown.LabelledDropdown
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavbarState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AutoTunnelViewModel
|
||||
|
||||
@Composable
|
||||
fun AutoTunnelAdvancedScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
||||
fun AutoTunnelAdvancedScreen(viewModel: AutoTunnelViewModel) {
|
||||
val sharedViewModel = LocalSharedVm.current
|
||||
val autoTunnelState by viewModel.container.stateFlow.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
sharedViewModel.updateNavbarState(
|
||||
NavbarState(
|
||||
showBottomItems = true,
|
||||
topTitle = { Text(stringResource(R.string.advanced_settings)) },
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.Top),
|
||||
@@ -33,7 +48,7 @@ fun AutoTunnelAdvancedScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
||||
.padding(vertical = 24.dp)
|
||||
.padding(horizontal = 12.dp),
|
||||
) {
|
||||
LabelledNumberDropdown(
|
||||
LabelledDropdown(
|
||||
title = {
|
||||
Text(
|
||||
stringResource(R.string.debounce_delay),
|
||||
@@ -44,11 +59,10 @@ fun AutoTunnelAdvancedScreen(appUiState: AppUiState, viewModel: AppViewModel) {
|
||||
)
|
||||
},
|
||||
leading = { Icon(Icons.Outlined.PauseCircle, null) },
|
||||
onSelected = { selected ->
|
||||
viewModel.handleEvent(AppEvent.SetDebounceDelay(selected!!))
|
||||
},
|
||||
onSelected = { selected -> viewModel.setDebounceDelay(selected!!) },
|
||||
options = (0..10).toList(),
|
||||
currentValue = appUiState.appSettings.debounceDelaySeconds,
|
||||
currentValue = autoTunnelState.generalSettings.debounceDelaySeconds,
|
||||
optionToString = { it?.toString() ?: stringResource(R.string._default) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+33
-19
@@ -14,12 +14,14 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AutoTunnelUiState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AutoTunnelViewModel
|
||||
|
||||
@Composable
|
||||
fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<SelectionItem> {
|
||||
fun networkTunnelingItems(
|
||||
autoTunnelState: AutoTunnelUiState,
|
||||
viewModel: AutoTunnelViewModel,
|
||||
): List<SelectionItem> {
|
||||
return listOf(
|
||||
SelectionItem(
|
||||
leading = { Icon(Icons.Outlined.SignalCellular4Bar, contentDescription = null) },
|
||||
@@ -34,15 +36,15 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
||||
},
|
||||
trailing = {
|
||||
ScaledSwitch(
|
||||
enabled = !uiState.appSettings.isAlwaysOnVpnEnabled,
|
||||
checked = uiState.appSettings.isTunnelOnMobileDataEnabled,
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnCellular) },
|
||||
enabled = !autoTunnelState.generalSettings.isAlwaysOnVpnEnabled,
|
||||
checked = autoTunnelState.generalSettings.isTunnelOnMobileDataEnabled,
|
||||
onClick = { viewModel.setTunnelOnCellular(it) },
|
||||
)
|
||||
},
|
||||
description = {
|
||||
val cellularActive =
|
||||
remember(uiState.connectivityState) {
|
||||
uiState.connectivityState?.cellularConnected ?: false
|
||||
remember(autoTunnelState.connectivityState) {
|
||||
autoTunnelState.connectivityState?.cellularConnected ?: false
|
||||
}
|
||||
Text(
|
||||
text =
|
||||
@@ -56,7 +58,11 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
},
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnCellular) },
|
||||
onClick = {
|
||||
viewModel.setTunnelOnCellular(
|
||||
!autoTunnelState.generalSettings.isTunnelOnMobileDataEnabled
|
||||
)
|
||||
},
|
||||
),
|
||||
SelectionItem(
|
||||
leading = { Icon(Icons.Outlined.SettingsEthernet, contentDescription = null) },
|
||||
@@ -71,15 +77,15 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
||||
},
|
||||
trailing = {
|
||||
ScaledSwitch(
|
||||
enabled = !uiState.appSettings.isAlwaysOnVpnEnabled,
|
||||
checked = uiState.appSettings.isTunnelOnEthernetEnabled,
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
||||
enabled = !autoTunnelState.generalSettings.isAlwaysOnVpnEnabled,
|
||||
checked = autoTunnelState.generalSettings.isTunnelOnEthernetEnabled,
|
||||
onClick = { viewModel.setTunnelOnEthernet(it) },
|
||||
)
|
||||
},
|
||||
description = {
|
||||
val ethernetActive =
|
||||
remember(uiState.connectivityState) {
|
||||
uiState.connectivityState?.ethernetConnected ?: false
|
||||
remember(autoTunnelState.connectivityState) {
|
||||
autoTunnelState.connectivityState?.ethernetConnected ?: false
|
||||
}
|
||||
Text(
|
||||
text =
|
||||
@@ -93,7 +99,11 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
},
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnEthernet) },
|
||||
onClick = {
|
||||
viewModel.setTunnelOnEthernet(
|
||||
!autoTunnelState.generalSettings.isTunnelOnEthernetEnabled
|
||||
)
|
||||
},
|
||||
),
|
||||
SelectionItem(
|
||||
leading = { Icon(Icons.Outlined.PublicOff, contentDescription = null) },
|
||||
@@ -115,11 +125,15 @@ fun NetworkTunnelingItems(uiState: AppUiState, viewModel: AppViewModel): List<Se
|
||||
},
|
||||
trailing = {
|
||||
ScaledSwitch(
|
||||
checked = uiState.appSettings.isStopOnNoInternetEnabled,
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleStopTunnelOnNoInternet) },
|
||||
checked = autoTunnelState.generalSettings.isStopOnNoInternetEnabled,
|
||||
onClick = { viewModel.setStopOnNoInternetEnabled(it) },
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
viewModel.setStopOnNoInternetEnabled(
|
||||
!autoTunnelState.generalSettings.isStopOnNoInternetEnabled
|
||||
)
|
||||
},
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleStopTunnelOnNoInternet) },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,14 +20,14 @@ import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalIsAndroidTV
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ClickableIconButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.textbox.CustomTextField
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalIsAndroidTV
|
||||
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
fun TrustedNetworkTextBox(
|
||||
trustedNetworks: List<String>,
|
||||
trustedNetworks: Set<String>,
|
||||
onDelete: (ssid: String) -> Unit,
|
||||
currentText: String,
|
||||
onSave: (ssid: String) -> Unit,
|
||||
|
||||
+46
-57
@@ -3,46 +3,48 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.components
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.*
|
||||
import androidx.compose.material.icons.outlined.Filter1
|
||||
import androidx.compose.material.icons.outlined.Security
|
||||
import androidx.compose.material.icons.outlined.Wifi
|
||||
import androidx.compose.material.icons.outlined.WifiFind
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavController
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.functions.rememberClipboardHelper
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.LearnMoreLinkLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AutoTunnelUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.theme.iconSize
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asString
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTitleString
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AutoTunnelViewModel
|
||||
|
||||
@Composable
|
||||
fun WifiTunnelingItems(
|
||||
uiState: AppUiState,
|
||||
viewModel: AppViewModel,
|
||||
currentText: String,
|
||||
onTextChange: (String) -> Unit,
|
||||
fun wifiTunnelingItems(
|
||||
autoTunnelState: AutoTunnelUiState,
|
||||
viewModel: AutoTunnelViewModel,
|
||||
navController: NavController,
|
||||
): List<SelectionItem> {
|
||||
val context = LocalContext.current
|
||||
val navController = LocalNavController.current
|
||||
val clipboardHelper = rememberClipboardHelper()
|
||||
|
||||
var currentText by rememberSaveable { mutableStateOf("") }
|
||||
|
||||
LaunchedEffect(autoTunnelState.generalSettings.trustedNetworkSSIDs) { currentText = "" }
|
||||
|
||||
val baseItems =
|
||||
listOf(
|
||||
SelectionItem(
|
||||
@@ -58,16 +60,16 @@ fun WifiTunnelingItems(
|
||||
},
|
||||
trailing = {
|
||||
ScaledSwitch(
|
||||
enabled = !uiState.appSettings.isAlwaysOnVpnEnabled,
|
||||
checked = uiState.appSettings.isTunnelOnWifiEnabled,
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnWifi) },
|
||||
enabled = !autoTunnelState.generalSettings.isAlwaysOnVpnEnabled,
|
||||
checked = autoTunnelState.generalSettings.isTunnelOnWifiEnabled,
|
||||
onClick = { viewModel.setAutoTunnelOnWifiEnabled(it) },
|
||||
)
|
||||
},
|
||||
description = {
|
||||
val wifiInfo by
|
||||
remember(uiState.connectivityState) {
|
||||
remember(autoTunnelState.connectivityState) {
|
||||
derivedStateOf {
|
||||
uiState.connectivityState
|
||||
autoTunnelState.connectivityState
|
||||
?.wifiState
|
||||
?.takeIf { it.connected }
|
||||
.let { Pair(it?.ssid, it?.securityType) }
|
||||
@@ -101,11 +103,15 @@ fun WifiTunnelingItems(
|
||||
}
|
||||
}
|
||||
},
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelOnWifi) },
|
||||
onClick = {
|
||||
viewModel.setAutoTunnelOnWifiEnabled(
|
||||
!autoTunnelState.generalSettings.isTunnelOnWifiEnabled
|
||||
)
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
return if (uiState.appSettings.isTunnelOnWifiEnabled) {
|
||||
return if (autoTunnelState.generalSettings.isTunnelOnWifiEnabled) {
|
||||
baseItems +
|
||||
listOf(
|
||||
SelectionItem(
|
||||
@@ -123,7 +129,9 @@ fun WifiTunnelingItems(
|
||||
Text(
|
||||
stringResource(
|
||||
R.string.current_template,
|
||||
uiState.appSettings.wifiDetectionMethod.asString(context),
|
||||
autoTunnelState.generalSettings.wifiDetectionMethod.asTitleString(
|
||||
context
|
||||
),
|
||||
),
|
||||
style =
|
||||
MaterialTheme.typography.bodySmall.copy(
|
||||
@@ -155,11 +163,15 @@ fun WifiTunnelingItems(
|
||||
},
|
||||
trailing = {
|
||||
ScaledSwitch(
|
||||
checked = uiState.appSettings.isWildcardsEnabled,
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelWildcards) },
|
||||
checked = autoTunnelState.generalSettings.isWildcardsEnabled,
|
||||
onClick = { viewModel.setWildcardsEnabled(it) },
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
viewModel.setWildcardsEnabled(
|
||||
!autoTunnelState.generalSettings.isWildcardsEnabled
|
||||
)
|
||||
},
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleAutoTunnelWildcards) },
|
||||
),
|
||||
SelectionItem(
|
||||
title = {
|
||||
@@ -195,41 +207,18 @@ fun WifiTunnelingItems(
|
||||
},
|
||||
description = {
|
||||
TrustedNetworkTextBox(
|
||||
uiState.appSettings.trustedNetworkSSIDs,
|
||||
onDelete = { viewModel.handleEvent(AppEvent.DeleteTrustedSSID(it)) },
|
||||
autoTunnelState.generalSettings.trustedNetworkSSIDs,
|
||||
onDelete = { viewModel.removeTrustedNetworkName(it) },
|
||||
currentText = currentText,
|
||||
onSave = { ssid ->
|
||||
viewModel.handleEvent(AppEvent.SaveTrustedSSID(ssid))
|
||||
},
|
||||
onValueChange = onTextChange,
|
||||
onSave = { ssid -> viewModel.saveTrustedNetworkName(ssid) },
|
||||
onValueChange = { currentText = it },
|
||||
supporting = {
|
||||
if (uiState.appSettings.isWildcardsEnabled) WildcardsLabel()
|
||||
if (autoTunnelState.generalSettings.isWildcardsEnabled)
|
||||
WildcardsLabel()
|
||||
},
|
||||
)
|
||||
},
|
||||
),
|
||||
SelectionItem(
|
||||
leading = { Icon(Icons.Outlined.VpnKeyOff, contentDescription = null) },
|
||||
title = {
|
||||
Text(
|
||||
stringResource(R.string.kill_switch_off),
|
||||
style =
|
||||
MaterialTheme.typography.bodyMedium.copy(
|
||||
MaterialTheme.colorScheme.onSurface
|
||||
),
|
||||
)
|
||||
},
|
||||
trailing = {
|
||||
ScaledSwitch(
|
||||
enabled = uiState.appSettings.isVpnKillSwitchEnabled,
|
||||
checked = uiState.appSettings.isDisableKillSwitchOnTrustedEnabled,
|
||||
onClick = {
|
||||
viewModel.handleEvent(AppEvent.ToggleStopKillSwitchOnTrusted)
|
||||
},
|
||||
)
|
||||
},
|
||||
onClick = { viewModel.handleEvent(AppEvent.ToggleStopKillSwitchOnTrusted) },
|
||||
),
|
||||
)
|
||||
} else {
|
||||
baseItems
|
||||
|
||||
+29
-10
@@ -4,34 +4,53 @@ import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.networkmonitor.AndroidNetworkMonitor
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.data.model.WifiDetectionMethod
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalSharedVm
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.IconSurfaceButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.AppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavbarState
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asDescriptionString
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asString
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.asTitleString
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AutoTunnelViewModel
|
||||
|
||||
@Composable
|
||||
fun WifiDetectionMethodScreen(uiState: AppUiState, viewModel: AppViewModel) {
|
||||
fun WifiDetectionMethodScreen(viewModel: AutoTunnelViewModel) {
|
||||
val context = LocalContext.current
|
||||
val sharedViewModel = LocalSharedVm.current
|
||||
|
||||
val autoTunnelState by viewModel.container.stateFlow.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
sharedViewModel.updateNavbarState(
|
||||
NavbarState(
|
||||
topTitle = { Text(stringResource(R.string.wifi_detection_method)) },
|
||||
showBottomItems = true,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.Top),
|
||||
modifier = Modifier.fillMaxSize().padding(top = 24.dp).padding(horizontal = 24.dp),
|
||||
) {
|
||||
enumValues<AndroidNetworkMonitor.WifiDetectionMethod>().forEach {
|
||||
val title = it.asString(context)
|
||||
enumValues<WifiDetectionMethod>().forEach {
|
||||
val title = it.asTitleString(context)
|
||||
val description = it.asDescriptionString(context)
|
||||
IconSurfaceButton(
|
||||
title = title,
|
||||
onClick = { viewModel.handleEvent(AppEvent.SetDetectionMethod(it)) },
|
||||
selected = uiState.appSettings.wifiDetectionMethod == it,
|
||||
onClick = { sharedViewModel.setWifiDetectionMethod(it) },
|
||||
selected = autoTunnelState.generalSettings.wifiDetectionMethod == it,
|
||||
description = description,
|
||||
)
|
||||
}
|
||||
|
||||
+11
-5
@@ -9,17 +9,23 @@ import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalNavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.LocalSharedVm
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.LocationDisclosureHeader
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.appSettingsItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.components.skipItem
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AppViewModel
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.event.AppEvent
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavbarState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.AutoTunnelViewModel
|
||||
|
||||
@Composable
|
||||
fun LocationDisclosureScreen(viewModel: AppViewModel) {
|
||||
fun LocationDisclosureScreen(viewModel: AutoTunnelViewModel) {
|
||||
val navController = LocalNavController.current
|
||||
val sharedViewModel = LocalSharedVm.current
|
||||
|
||||
LaunchedEffect(Unit) { viewModel.handleEvent(AppEvent.SetLocationDisclosureShown) }
|
||||
LaunchedEffect(Unit) { sharedViewModel.updateNavbarState(NavbarState(showBottomItems = true)) }
|
||||
|
||||
LaunchedEffect(Unit) { viewModel.setLocationDisclosureShown() }
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
@@ -28,6 +34,6 @@ fun LocationDisclosureScreen(viewModel: AppViewModel) {
|
||||
) {
|
||||
LocationDisclosureHeader()
|
||||
SurfaceSelectionGroupButton(items = listOf(appSettingsItem()))
|
||||
SurfaceSelectionGroupButton(items = listOf(skipItem()))
|
||||
SurfaceSelectionGroupButton(items = listOf(skipItem(navController)))
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -3,14 +3,14 @@ package com.zaneschepke.wireguardautotunnel.ui.screens.autotunnel.disclosure.com
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.LocationOn
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ForwardButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItem
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionItemLabel
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionLabelType
|
||||
import com.zaneschepke.wireguardautotunnel.util.extensions.launchAppSettings
|
||||
|
||||
@Composable
|
||||
@@ -20,9 +20,9 @@ fun appSettingsItem(): SelectionItem {
|
||||
return SelectionItem(
|
||||
leading = { Icon(Icons.Outlined.LocationOn, contentDescription = null) },
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(R.string.launch_app_settings),
|
||||
style = MaterialTheme.typography.bodyLarge.copy(MaterialTheme.colorScheme.onSurface),
|
||||
SelectionItemLabel(
|
||||
stringResource(R.string.launch_app_settings),
|
||||
labelType = SelectionLabelType.TITLE,
|
||||
)
|
||||
},
|
||||
trailing = { ForwardButton { context.launchAppSettings() } },
|
||||
|
||||
+3
-3
@@ -20,14 +20,14 @@ fun LocationDisclosureHeader() {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = icon.name,
|
||||
modifier = Modifier.padding(30.dp).size(128.dp),
|
||||
modifier = Modifier.padding(24.dp).size(100.dp),
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.prominent_background_location_title),
|
||||
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Bold),
|
||||
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold),
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.prominent_background_location_message),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
)
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user