Move StaffMode declaration out of paths

This commit is contained in:
Mikayla Maki 2023-01-27 15:37:36 -08:00
parent 2d889f59bf
commit 57781fd7aa
6 changed files with 28 additions and 33 deletions

View File

@ -7,7 +7,7 @@ use postage::{sink::Sink, watch};
use rpc::proto::{RequestMessage, UsersResponse}; use rpc::proto::{RequestMessage, UsersResponse};
use settings::Settings; use settings::Settings;
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
use util::{paths::StaffMode, TryFutureExt as _}; use util::{StaffMode, TryFutureExt as _};
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct User { pub struct User {
@ -149,11 +149,16 @@ impl UserStore {
); );
cx.update(|cx| { cx.update(|cx| {
cx.set_global( cx.update_default_global(|staff_mode: &mut StaffMode, _| {
if !staff_mode.0 {
*staff_mode = StaffMode(
info.as_ref() info.as_ref()
.map(|info| StaffMode(info.staff)) .map(|info| info.staff)
.unwrap_or(StaffMode(false)), .unwrap_or_default(),
); )
}
()
});
}); });
current_user_tx.send(user).await.ok(); current_user_tx.send(user).await.ok();

View File

@ -7,7 +7,7 @@ use picker::{Picker, PickerDelegate};
use settings::{settings_file::SettingsFile, Settings}; use settings::{settings_file::SettingsFile, Settings};
use std::sync::Arc; use std::sync::Arc;
use theme::{Theme, ThemeMeta, ThemeRegistry}; use theme::{Theme, ThemeMeta, ThemeRegistry};
use util::paths::StaffMode; use util::StaffMode;
use workspace::{AppState, Workspace}; use workspace::{AppState, Workspace};
pub struct ThemeSelector { pub struct ThemeSelector {
@ -45,7 +45,7 @@ impl ThemeSelector {
let original_theme = settings.theme.clone(); let original_theme = settings.theme.clone();
let mut theme_names = registry let mut theme_names = registry
.list(**cx.try_global::<StaffMode>().unwrap_or(&StaffMode(false))) .list(**cx.default_global::<StaffMode>())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
theme_names.sort_unstable_by(|a, b| { theme_names.sort_unstable_by(|a, b| {
a.is_light a.is_light

View File

@ -13,6 +13,17 @@ use std::{
task::{Context, Poll}, task::{Context, Poll},
}; };
#[derive(Debug, Default)]
pub struct StaffMode(pub bool);
impl std::ops::Deref for StaffMode {
type Target = bool;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[macro_export] #[macro_export]
macro_rules! debug_panic { macro_rules! debug_panic {
( $($fmt_arg:tt)* ) => { ( $($fmt_arg:tt)* ) => {

View File

@ -1,15 +1,4 @@
use std::{ops::Deref, path::PathBuf}; use std::path::PathBuf;
#[derive(Debug)]
pub struct StaffMode(pub bool);
impl Deref for StaffMode {
type Target = bool;
fn deref(&self) -> &Self::Target {
&self.0
}
}
lazy_static::lazy_static! { lazy_static::lazy_static! {
pub static ref HOME: PathBuf = dirs::home_dir().expect("failed to determine home directory"); pub static ref HOME: PathBuf = dirs::home_dir().expect("failed to determine home directory");

View File

@ -39,11 +39,7 @@ use terminal_view::{get_working_directory, TerminalView};
use fs::RealFs; use fs::RealFs;
use settings::watched_json::{watch_keymap_file, watch_settings_file, WatchedJsonFile}; use settings::watched_json::{watch_keymap_file, watch_settings_file, WatchedJsonFile};
use theme::ThemeRegistry; use theme::ThemeRegistry;
use util::{ use util::{channel::RELEASE_CHANNEL, paths, ResultExt, StaffMode, TryFutureExt};
channel::RELEASE_CHANNEL,
paths::{self, StaffMode},
ResultExt, TryFutureExt,
};
use workspace::{ use workspace::{
self, item::ItemHandle, notifications::NotifyResultExt, AppState, NewFile, OpenPaths, Workspace, self, item::ItemHandle, notifications::NotifyResultExt, AppState, NewFile, OpenPaths, Workspace,
}; };
@ -109,8 +105,6 @@ fn main() {
app.run(move |cx| { app.run(move |cx| {
cx.set_global(*RELEASE_CHANNEL); cx.set_global(*RELEASE_CHANNEL);
#[cfg(not(debug_assertions))]
cx.set_global(StaffMode(false));
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
cx.set_global(StaffMode(true)); cx.set_global(StaffMode(true));

View File

@ -32,11 +32,7 @@ use serde::Deserialize;
use serde_json::to_string_pretty; use serde_json::to_string_pretty;
use settings::{keymap_file_json_schema, settings_file_json_schema, Settings}; use settings::{keymap_file_json_schema, settings_file_json_schema, Settings};
use std::{borrow::Cow, env, path::Path, str, sync::Arc}; use std::{borrow::Cow, env, path::Path, str, sync::Arc};
use util::{ use util::{channel::ReleaseChannel, paths, ResultExt, StaffMode};
channel::ReleaseChannel,
paths::{self, StaffMode},
ResultExt,
};
use uuid::Uuid; use uuid::Uuid;
pub use workspace; pub use workspace;
use workspace::{sidebar::SidebarSide, AppState, Workspace}; use workspace::{sidebar::SidebarSide, AppState, Workspace};
@ -303,7 +299,7 @@ pub fn initialize_workspace(
let theme_names = app_state let theme_names = app_state
.themes .themes
.list(**cx.try_global::<StaffMode>().unwrap_or(&StaffMode(false))) .list(**cx.default_global::<StaffMode>())
.map(|meta| meta.name) .map(|meta| meta.name)
.collect(); .collect();
let language_names = app_state.languages.language_names(); let language_names = app_state.languages.language_names();