Skip to content

Commit

Permalink
chore: various cleanup in the codebase (#342)
Browse files Browse the repository at this point in the history
* random stuff

* fix stuff
  • Loading branch information
grant0417 authored Jan 9, 2025
1 parent 575c0b7 commit fcd4003
Show file tree
Hide file tree
Showing 65 changed files with 421 additions and 421 deletions.
17 changes: 0 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ objc2 = "0.5.2"
objc2-app-kit = "0.2.2"
objc2-foundation = "0.2.2"
objc2-input-method-kit = "0.2.2"
once_cell = { version = "1.18.0", features = ["parking_lot"] }
percent-encoding = "2.2.0"
portable-pty = "0.8.1"
rand = "0.8.5"
Expand Down
1 change: 0 additions & 1 deletion crates/dbus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ async_zip = { version = "0.0.17", features = ["deflate"] }
fig_os_shim.workspace = true
fig_util.workspace = true
futures-lite = "2.3.0"
once_cell.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
Expand Down
7 changes: 4 additions & 3 deletions crates/dbus/src/dbus/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::OnceLock;

use fig_os_shim::Context;
use once_cell::sync::OnceCell;
use thiserror::Error;
use tokio::sync::Mutex;
use zbus::Connection;
Expand All @@ -26,7 +27,7 @@ pub enum CrateError {
Fdo(#[from] zbus::fdo::Error),
}

static SESSION_BUS: OnceCell<Connection> = OnceCell::new();
static SESSION_BUS: OnceLock<Connection> = OnceLock::new();
static SESSION_BUS_INIT: Mutex<()> = Mutex::const_new(());

async fn session_bus() -> Result<&'static Connection, CrateError> {
Expand All @@ -47,7 +48,7 @@ async fn session_bus() -> Result<&'static Connection, CrateError> {
Ok(SESSION_BUS.get().unwrap())
}

static IBUS_BUS: OnceCell<Connection> = OnceCell::new();
static IBUS_BUS: OnceLock<Connection> = OnceLock::new();
static IBUS_BUS_INIT: Mutex<()> = Mutex::const_new(());

pub async fn ibus_bus(ctx: &Context) -> Result<&'static Connection, CrateError> {
Expand Down
1 change: 0 additions & 1 deletion crates/fig_api_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fig_request.workspace = true
fig_settings.workspace = true
fig_util.workspace = true
http = "1.1.0"
once_cell.workspace = true
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
1 change: 0 additions & 1 deletion crates/fig_auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fig_util.workspace = true
http-body-util = "0.1.1"
hyper = { version = "1.5.2", features = ["server"] }
hyper-util = { version = "0.1.5", features = ["tokio"] }
once_cell.workspace = true
percent-encoding.workspace = true
rand.workspace = true
serde.workspace = true
Expand Down
8 changes: 3 additions & 5 deletions crates/fig_aws_common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod sdk_error_display;
mod user_agent_override_interceptor;

use std::sync::OnceLock;
use std::sync::LazyLock;

use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
use aws_types::app_name::AppName;
Expand All @@ -11,10 +11,8 @@ pub use user_agent_override_interceptor::UserAgentOverrideInterceptor;
const APP_NAME_STR: &str = "AmazonQ-For-CLI";

pub fn app_name() -> AppName {
static APP_NAME: OnceLock<AppName> = OnceLock::new();
APP_NAME
.get_or_init(|| AppName::new(APP_NAME_STR).expect("invalid app name"))
.clone()
static APP_NAME: LazyLock<AppName> = LazyLock::new(|| AppName::new(APP_NAME_STR).expect("invalid app name"));
APP_NAME.clone()
}

pub fn behavior_version() -> BehaviorVersion {
Expand Down
1 change: 0 additions & 1 deletion crates/fig_desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ mime = "0.3.17"
moka = { version = "0.12.1", features = ["future"] }
muda = { version = "0.15.3", default-features = false }
notify = "7.0.0"
once_cell.workspace = true
parking_lot = { version = "0.12.1", features = ["serde"] }
paste = "1.0.11"
percent-encoding.workspace = true
Expand Down
1 change: 0 additions & 1 deletion crates/fig_desktop/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fig_util.workspace = true
tempfile.workspace = true
tokio.workspace = true
fig_proto = { workspace = true, features = ["arbitrary"] }
once_cell.workspace = true

[[bin]]
name = "local_ipc"
Expand Down
8 changes: 4 additions & 4 deletions crates/fig_desktop/fuzz/fuzz_targets/local_ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate libfuzzer_sys;

use std::ops::Deref;
use std::path::PathBuf;
use std::sync::LazyLock;

use fig_ipc::{
BufferedUnixStream,
Expand All @@ -13,12 +14,11 @@ use fig_ipc::{
};
use fig_proto::local::LocalMessage;
use libfuzzer_sys::fuzz_target;
use once_cell::sync::Lazy;
use tokio::net::UnixListener;

static RUNTIME: Lazy<tokio::runtime::Runtime> = Lazy::new(|| tokio::runtime::Runtime::new().unwrap());
static RUNTIME: LazyLock<tokio::runtime::Runtime> = LazyLock::new(|| tokio::runtime::Runtime::new().unwrap());

static DIRSOCK: Lazy<(tempfile::TempDir, PathBuf)> = Lazy::new(|| {
static DIRSOCK: LazyLock<(tempfile::TempDir, PathBuf)> = LazyLock::new(|| {
let temp_dir = tempfile::tempdir().unwrap();
let socket_path = temp_dir.path().join("test.sock");
#[cfg(unix)]
Expand All @@ -31,7 +31,7 @@ static DIRSOCK: Lazy<(tempfile::TempDir, PathBuf)> = Lazy::new(|| {
(temp_dir, socket_path)
});

static LISTENER: Lazy<UnixListener> = Lazy::new(|| UnixListener::bind(&DIRSOCK.1).unwrap());
static LISTENER: LazyLock<UnixListener> = LazyLock::new(|| UnixListener::bind(&DIRSOCK.1).unwrap());

fuzz_target!(|input: LocalMessage| {
RUNTIME.block_on(fuzz(input));
Expand Down
19 changes: 8 additions & 11 deletions crates/fig_desktop/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tao::dpi::{
Size,
};
use tao::event_loop::ControlFlow;
use tokio::sync::mpsc::UnboundedSender;
use wry::Theme;

use crate::platform::PlatformBoundEvent;
Expand Down Expand Up @@ -73,6 +74,11 @@ pub enum WindowPosition {
},
}

pub struct WindowGeometryResult {
pub is_above: bool,
pub is_clipped: bool,
}

#[derive(Debug, Clone)]
pub enum WindowEvent {
/// Sets the window to be enabled or disabled
Expand All @@ -81,15 +87,13 @@ pub enum WindowEvent {
/// [`WindowEvent::SetEnabled(true)`]
SetEnabled(bool),
/// Sets the theme of the window (light, dark, or system if None)
///
/// This is currently unimplemented blocked on <https://github.com/tauri-apps/tao/issues/582>
SetTheme(Option<Theme>),
UpdateWindowGeometry {
position: Option<WindowPosition>,
size: Option<LogicalSize<f64>>,
anchor: Option<LogicalSize<f64>>,
dry_run: bool,
tx: Option<tokio::sync::mpsc::UnboundedSender<(bool, bool)>>,
tx: Option<UnboundedSender<WindowGeometryResult>>,
},
/// Hides the window
Hide,
Expand All @@ -114,20 +118,13 @@ pub enum WindowEvent {

Reload,

/// Trigger a reload if the page is not already loaded
ReloadIfNotLoaded,

Api {
/// A base64 encoded protobuf
payload: Cow<'static, str>,
payload: String,
},
Devtools,
DebugMode(bool),

SetHtml {
html: Cow<'static, str>,
},

Drag,
Batch(Vec<WindowEvent>),
}
Expand Down
9 changes: 5 additions & 4 deletions crates/fig_desktop/src/local_ipc/commands.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Mutex;

use fig_os_shim::{
ContextArcProvider,
ContextProvider,
Expand All @@ -20,7 +22,6 @@ use fig_proto::local::{
use fig_remote_ipc::figterm::FigtermState;
use fig_settings::StateProvider;
use fig_settings::settings::SettingsProvider;
use parking_lot::Mutex;
use tao::event_loop::ControlFlow;
use tracing::error;

Expand All @@ -47,16 +48,16 @@ pub async fn debug(command: DebugModeCommand, proxy: &EventLoopProxy) -> LocalRe

let debug_mode = match command.set_debug_mode {
Some(b) => {
*DEBUG_MODE.lock() = b;
*DEBUG_MODE.lock().unwrap() = b;
b
},
None => match command.toggle_debug_mode {
Some(true) => {
let mut locked_debug = DEBUG_MODE.lock();
let mut locked_debug = DEBUG_MODE.lock().unwrap();
*locked_debug = !*locked_debug;
*locked_debug
},
_ => *DEBUG_MODE.lock(),
_ => *DEBUG_MODE.lock().unwrap(),
},
};

Expand Down
6 changes: 4 additions & 2 deletions crates/fig_desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ mod webview;

use std::path::Path;
use std::process::exit;
use std::sync::Arc;
use std::sync::{
Arc,
RwLock,
};

use clap::Parser;
use event::Event;
Expand All @@ -34,7 +37,6 @@ use fig_util::{
URL_SCHEMA,
directories,
};
use parking_lot::RwLock;
use platform::PlatformState;
use sysinfo::{
ProcessRefreshKind,
Expand Down
Loading

0 comments on commit fcd4003

Please sign in to comment.