mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
chore(connlib): rename can_toggle to can_be_disabled (#6362)
This is made to sync this with #6299
This commit is contained in:
@@ -52,7 +52,7 @@ internal class ResourcesAdapter(private val activity: SessionActivity) : ListAda
|
||||
// Without this the item gets reset when out of view, isn't android wonderful?
|
||||
binding.enableSwitch.setOnCheckedChangeListener(null)
|
||||
binding.enableSwitch.isChecked = resource.enabled
|
||||
binding.enableSwitch.isVisible = resource.canToggle
|
||||
binding.enableSwitch.isVisible = resource.canBeDisabled
|
||||
|
||||
binding.enableSwitch.setOnCheckedChangeListener {
|
||||
_, isChecked ->
|
||||
|
||||
@@ -13,7 +13,7 @@ data class ViewResource(
|
||||
val name: String,
|
||||
val status: StatusEnum,
|
||||
var enabled: Boolean = true,
|
||||
var canToggle: Boolean = true,
|
||||
var canBeDisabled: Boolean = true,
|
||||
)
|
||||
|
||||
fun Resource.toViewResource(enabled: Boolean): ViewResource {
|
||||
@@ -25,6 +25,6 @@ fun Resource.toViewResource(enabled: Boolean): ViewResource {
|
||||
name = this.name,
|
||||
status = this.status,
|
||||
enabled = enabled,
|
||||
canToggle = this.canToggle,
|
||||
canBeDisabled = this.canBeDisabled,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ class TunnelService : VpnService() {
|
||||
// UI updates for resources
|
||||
fun resourcesUpdated() {
|
||||
val newResources = tunnelResources.associateBy { it.id }
|
||||
val currentlyDisabled = disabledResources.filter { newResources[it]?.canToggle ?: false }
|
||||
val currentlyDisabled = disabledResources.filter { newResources[it]?.canBeDisabled ?: false }
|
||||
|
||||
connlibSessionPtr?.let {
|
||||
ConnlibSession.setDisabledResources(it, Gson().toJson(currentlyDisabled))
|
||||
|
||||
@@ -17,7 +17,7 @@ data class Resource(
|
||||
val name: String,
|
||||
val status: StatusEnum,
|
||||
var enabled: Boolean = true,
|
||||
@Json(name = "can_toggle") val canToggle: Boolean,
|
||||
@Json(name = "can_disable") val canBeDisabled: Boolean,
|
||||
) : Parcelable
|
||||
|
||||
enum class TypeEnum {
|
||||
|
||||
@@ -71,11 +71,11 @@ impl ResourceDescription {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_toggle(&self) -> bool {
|
||||
pub fn can_be_disabled(&self) -> bool {
|
||||
match self {
|
||||
ResourceDescription::Dns(r) => r.can_toggle,
|
||||
ResourceDescription::Cidr(r) => r.can_toggle,
|
||||
ResourceDescription::Internet(r) => r.can_toggle,
|
||||
ResourceDescription::Dns(r) => r.can_be_disabled,
|
||||
ResourceDescription::Cidr(r) => r.can_be_disabled,
|
||||
ResourceDescription::Internet(r) => r.can_be_disabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ pub struct ResourceDescriptionDns {
|
||||
pub sites: Vec<Site>,
|
||||
|
||||
pub status: Status,
|
||||
pub can_toggle: bool,
|
||||
pub can_be_disabled: bool,
|
||||
}
|
||||
|
||||
/// Description of a resource that maps to a CIDR.
|
||||
@@ -114,7 +114,7 @@ pub struct ResourceDescriptionCidr {
|
||||
pub sites: Vec<Site>,
|
||||
|
||||
pub status: Status,
|
||||
pub can_toggle: bool,
|
||||
pub can_be_disabled: bool,
|
||||
}
|
||||
|
||||
/// Description of an Internet resource
|
||||
@@ -123,5 +123,5 @@ pub struct ResourceDescriptionInternet {
|
||||
pub id: ResourceId,
|
||||
pub sites: Vec<Site>,
|
||||
pub status: Status,
|
||||
pub can_toggle: bool,
|
||||
pub can_be_disabled: bool,
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ impl ResourceDescriptionDns {
|
||||
name: self.name,
|
||||
address_description: self.address_description,
|
||||
sites: self.sites,
|
||||
can_toggle: false,
|
||||
can_be_disabled: false,
|
||||
status,
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ impl ResourceDescriptionCidr {
|
||||
name: self.name,
|
||||
address_description: self.address_description,
|
||||
sites: self.sites,
|
||||
can_toggle: false,
|
||||
can_be_disabled: false,
|
||||
status,
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ impl ResourceDescriptionInternet {
|
||||
crate::callbacks::ResourceDescriptionInternet {
|
||||
id: self.id,
|
||||
sites: self.sites,
|
||||
can_toggle: false,
|
||||
can_be_disabled: false,
|
||||
status,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,7 +750,7 @@ impl Controller {
|
||||
|
||||
let disabled_resources = resources
|
||||
.iter()
|
||||
.filter_map(|r| r.can_toggle().then_some(r.id()))
|
||||
.filter_map(|r| r.can_be_disabled().then_some(r.id()))
|
||||
.filter(|id| self.advanced_settings.disabled_resources.contains(id))
|
||||
.collect();
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ impl<'a> SignedIn<'a> {
|
||||
submenu.add_item(item(Event::AddFavorite(res.id()), ADD_FAVORITE));
|
||||
}
|
||||
|
||||
if res.can_toggle() {
|
||||
if res.can_be_disabled() {
|
||||
submenu.add_separator();
|
||||
if self.is_enabled(res) {
|
||||
submenu.add_item(item(Event::DisableResource(res.id()), DISABLE));
|
||||
@@ -323,7 +323,7 @@ mod tests {
|
||||
"address_description": "cidr resource",
|
||||
"sites": [{"name": "test", "id": "bf56f32d-7b2c-4f5d-a784-788977d014a4"}],
|
||||
"status": "Unknown",
|
||||
"can_toggle": false
|
||||
"can_be_disabled": false
|
||||
},
|
||||
{
|
||||
"id": "03000143-e25e-45c7-aafb-144990e57dcd",
|
||||
@@ -333,7 +333,7 @@ mod tests {
|
||||
"address_description": "https://gitlab.mycorp.com",
|
||||
"sites": [{"name": "test", "id": "bf56f32d-7b2c-4f5d-a784-788977d014a4"}],
|
||||
"status": "Online",
|
||||
"can_toggle": false
|
||||
"can_be_disabled": false
|
||||
},
|
||||
{
|
||||
"id": "1106047c-cd5d-4151-b679-96b93da7383b",
|
||||
@@ -343,7 +343,7 @@ mod tests {
|
||||
"address_description": "The whole entire Internet",
|
||||
"sites": [{"name": "test", "id": "eb94482a-94f4-47cb-8127-14fb3afa5516"}],
|
||||
"status": "Offline",
|
||||
"can_toggle": false
|
||||
"can_be_disabled": false
|
||||
}
|
||||
]"#;
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ public struct Resource: Decodable, Identifiable, Equatable {
|
||||
public var status: ResourceStatus
|
||||
public var sites: [Site]
|
||||
public var type: ResourceType
|
||||
public var canToggle: Bool
|
||||
public var canBeDisabled: Bool
|
||||
|
||||
public init(id: String, name: String, address: String, addressDescription: String?, status: ResourceStatus, sites: [Site], type: ResourceType, canToggle: Bool) {
|
||||
public init(id: String, name: String, address: String, addressDescription: String?, status: ResourceStatus, sites: [Site], type: ResourceType, canBeDisabled: Bool) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.address = address
|
||||
@@ -26,7 +26,7 @@ public struct Resource: Decodable, Identifiable, Equatable {
|
||||
self.status = status
|
||||
self.sites = sites
|
||||
self.type = type
|
||||
self.canToggle = canToggle
|
||||
self.canBeDisabled = canBeDisabled
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -564,7 +564,7 @@ public final class MenuBar: NSObject, ObservableObject {
|
||||
|
||||
|
||||
// Resource enable / disable toggle
|
||||
if resource.canToggle {
|
||||
if resource.canBeDisabled {
|
||||
subMenu.addItem(NSMenuItem.separator())
|
||||
enableToggle.action = #selector(resourceToggle(_:))
|
||||
enableToggle.title = resourceTitle(resource.id)
|
||||
|
||||
@@ -77,7 +77,7 @@ struct SessionView: View {
|
||||
label: {
|
||||
HStack {
|
||||
Text(resource.name)
|
||||
if resource.canToggle {
|
||||
if resource.canBeDisabled {
|
||||
Spacer()
|
||||
Toggle("Enabled", isOn: Binding<Bool>(
|
||||
get: { model.isResourceEnabled(resource.id) },
|
||||
|
||||
@@ -217,7 +217,7 @@ class Adapter {
|
||||
let decoder = JSONDecoder()
|
||||
decoder.keyDecodingStrategy = .convertFromSnakeCase
|
||||
|
||||
canBeDisabled = Set(resources().filter({ $0.canToggle }).map({ $0.id }))
|
||||
canBeDisabled = Set(resources().filter({ $0.canBeDisabled }).map({ $0.id }))
|
||||
|
||||
let disablingResources = disabledResources.filter({ canBeDisabled.contains($0) })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user