WIP
This commit is contained in:
parent
5d10dc7e58
commit
50bbdd5cab
5 changed files with 107 additions and 10 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -1458,7 +1458,7 @@ dependencies = [
|
||||||
"async-tungstenite",
|
"async-tungstenite",
|
||||||
"collections",
|
"collections",
|
||||||
"db",
|
"db",
|
||||||
"feature_flags",
|
"feature_flags2",
|
||||||
"futures 0.3.28",
|
"futures 0.3.28",
|
||||||
"gpui2",
|
"gpui2",
|
||||||
"image",
|
"image",
|
||||||
|
@ -2676,6 +2676,14 @@ dependencies = [
|
||||||
"gpui",
|
"gpui",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "feature_flags2"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"gpui2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "feedback"
|
name = "feedback"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -19,7 +19,7 @@ util = { path = "../util" }
|
||||||
rpc = { path = "../rpc" }
|
rpc = { path = "../rpc" }
|
||||||
text = { path = "../text" }
|
text = { path = "../text" }
|
||||||
settings2 = { path = "../settings2" }
|
settings2 = { path = "../settings2" }
|
||||||
feature_flags = { path = "../feature_flags" }
|
feature_flags2 = { path = "../feature_flags2" }
|
||||||
sum_tree = { path = "../sum_tree" }
|
sum_tree = { path = "../sum_tree" }
|
||||||
|
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
|
|
@ -193,16 +193,14 @@ impl UserStore {
|
||||||
}
|
}
|
||||||
Status::SignedOut => {
|
Status::SignedOut => {
|
||||||
current_user_tx.send(None).await.ok();
|
current_user_tx.send(None).await.ok();
|
||||||
if let Some(this) = this.upgrade(&cx) {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.update(&mut cx, |this, cx| {
|
cx.notify();
|
||||||
cx.notify();
|
this.clear_contacts()
|
||||||
this.clear_contacts()
|
})
|
||||||
})
|
.await;
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Status::ConnectionLost => {
|
Status::ConnectionLost => {
|
||||||
if let Some(this) = this.upgrade(&cx) {
|
if let Some(this) = this.upgrade() {
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
this.clear_contacts()
|
this.clear_contacts()
|
||||||
|
|
12
crates/feature_flags2/Cargo.toml
Normal file
12
crates/feature_flags2/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "feature_flags2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/feature_flags2.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
gpui2 = { path = "../gpui2" }
|
||||||
|
anyhow.workspace = true
|
79
crates/feature_flags2/src/feature_flags2.rs
Normal file
79
crates/feature_flags2/src/feature_flags2.rs
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
use gpui2::{AppContext, Subscription, ViewContext};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct FeatureFlags {
|
||||||
|
flags: Vec<String>,
|
||||||
|
staff: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FeatureFlags {
|
||||||
|
fn has_flag(&self, flag: &str) -> bool {
|
||||||
|
self.staff || self.flags.iter().find(|f| f.as_str() == flag).is_some()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FeatureFlag {
|
||||||
|
const NAME: &'static str;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ChannelsAlpha {}
|
||||||
|
|
||||||
|
impl FeatureFlag for ChannelsAlpha {
|
||||||
|
const NAME: &'static str = "channels_alpha";
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FeatureFlagViewExt<V: 'static> {
|
||||||
|
fn observe_flag<T: FeatureFlag, F>(&mut self, callback: F) -> Subscription
|
||||||
|
where
|
||||||
|
F: Fn(bool, &mut V, &mut ViewContext<V>) + 'static;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<V: 'static> FeatureFlagViewExt<V> for ViewContext<'_, '_, V> {
|
||||||
|
fn observe_flag<T: FeatureFlag, F>(&mut self, callback: F) -> Subscription
|
||||||
|
where
|
||||||
|
F: Fn(bool, &mut V, &mut ViewContext<V>) + 'static,
|
||||||
|
{
|
||||||
|
self.observe_global::<FeatureFlags, _>(move |v, cx| {
|
||||||
|
let feature_flags = cx.global::<FeatureFlags>();
|
||||||
|
callback(feature_flags.has_flag(<T as FeatureFlag>::NAME), v, cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FeatureFlagAppExt {
|
||||||
|
fn update_flags(&mut self, staff: bool, flags: Vec<String>);
|
||||||
|
fn set_staff(&mut self, staff: bool);
|
||||||
|
fn has_flag<T: FeatureFlag>(&self) -> bool;
|
||||||
|
fn is_staff(&self) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FeatureFlagAppExt for AppContext {
|
||||||
|
fn update_flags(&mut self, staff: bool, flags: Vec<String>) {
|
||||||
|
self.update_default_global::<FeatureFlags, _, _>(|feature_flags, _| {
|
||||||
|
feature_flags.staff = staff;
|
||||||
|
feature_flags.flags = flags;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_staff(&mut self, staff: bool) {
|
||||||
|
self.update_default_global::<FeatureFlags, _, _>(|feature_flags, _| {
|
||||||
|
feature_flags.staff = staff;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has_flag<T: FeatureFlag>(&self) -> bool {
|
||||||
|
if self.has_global::<FeatureFlags>() {
|
||||||
|
self.global::<FeatureFlags>().has_flag(T::NAME)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_staff(&self) -> bool {
|
||||||
|
if self.has_global::<FeatureFlags>() {
|
||||||
|
return self.global::<FeatureFlags>().staff;
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue