Skip to content

Commit

Permalink
fix: optimize sysinfo usage
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Sep 6, 2024
1 parent ae38aa7 commit 837b7a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src-tauri/src/functionality/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ fn blank_activity() -> DetectableActivity {
#[tauri::command(async)]
pub fn get_windows() -> Vec<Window> {
let conn = window_titles::Connection::new().expect("Failed to connect to window titles");
let mut system = System::new_all();

system.refresh_processes();
let system =
System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::everything()));

let windows: Vec<Window> = conn
.window_titles()
Expand Down
7 changes: 4 additions & 3 deletions src-tauri/src/functionality/streamer_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use std::sync::atomic::{AtomicBool, Ordering};
use tauri::Emitter;

use crate::config::get_config;
use sysinfo::System;
use sysinfo::{ProcessRefreshKind, RefreshKind, System};

// We keep track of this A) To not spam enable and B) to allow for the user to manually disable without it being re-enabled automatically
static OBS_OPEN: AtomicBool = AtomicBool::new(false);

#[tauri::command]
pub fn start_streamer_mode_watcher(win: tauri::WebviewWindow) {
let enabled = get_config().streamer_mode_detection.unwrap_or(false);
let mut system = System::new_all();
let mut system =
System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::everything()));

if !enabled {
return;
Expand All @@ -20,7 +21,7 @@ pub fn start_streamer_mode_watcher(win: tauri::WebviewWindow) {
std::thread::spawn(move || loop {
std::thread::sleep(std::time::Duration::from_secs(2));

system.refresh_all();
system.refresh_processes();

let mut obs_running = false;

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
windows_subsystem = "windows"
)]

use std::{sync::LazyLock, env, time::Duration};
use std::{env, sync::LazyLock, time::Duration};
use tauri::{Manager, WebviewWindowBuilder};
use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt};

Expand Down

0 comments on commit 837b7a0

Please sign in to comment.