Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dev/tools/src/bin/browser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! List out browser information

use clap::Parser;
use platform::web;
use platform::browser;
use tools::filters::{
ProcessDetails, ProcessFilter, WindowDetails, WindowFilter, match_running_windows,
};
Expand Down Expand Up @@ -61,7 +61,7 @@ async fn main() -> Result<()> {
},
)?;

let detect = web::Detect::new()?;
let detect = browser::Detect::new()?;

let mut browsers = vec![];
for window_group in window_group {
Expand All @@ -74,10 +74,10 @@ async fn main() -> Result<()> {
let url = detect.chromium_url(&element)?;
let incognito = detect.chromium_incognito(&element)?;
let (name, description) = if let Some(url) = &url {
let base_url = web::WebsiteInfo::url_to_base_url(url);
let website_info = web::WebsiteInfo::from_base_url(base_url.clone())
let base_url = browser::WebsiteInfo::url_to_base_url(url);
let website_info = browser::WebsiteInfo::from_base_url(base_url.clone())
.await
.unwrap_or(web::WebsiteInfo::default_from_url(base_url));
.unwrap_or(browser::WebsiteInfo::default_from_url(base_url));
(Some(website_info.name), Some(website_info.description))
} else {
(None, None)
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/src/bin/close_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use clap::Parser;
use dialoguer::Select;
use dialoguer::theme::ColorfulTheme;
use platform::web;
use platform::browser;
use tools::filters::{
ProcessFilter, ProcessWindowGroup, WindowDetails, WindowFilter, match_running_windows,
};
Expand Down Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<()> {
},
)?;

let detect = web::Detect::new()?;
let detect = browser::Detect::new()?;
if let Some(details) = select_window(&matches)? {
let element = detect.get_chromium_element(&details.window)?;
detect.close_current_tab(&element)?;
Expand Down
14 changes: 7 additions & 7 deletions dev/tools/src/bin/driver_web_state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Driver to poll the [web::State] as the engine is runningand save it to a file
//! Driver to poll the [browser::State] as the engine is runningand save it to a file

use std::fs::File;
use std::io::Write;
Expand All @@ -7,8 +7,8 @@ use std::time::{Duration, UNIX_EPOCH};

use clap::Parser;
use engine::desktop;
use platform::browser;
use platform::objects::Window;
use platform::web;
use serde::Serialize;
use util::ds::SmallHashMap;
use util::error::Result;
Expand Down Expand Up @@ -42,7 +42,7 @@ fn main() -> Result<()> {

let args = Args::parse();

let web_state = web::default_state();
let web_state = browser::default_state();
let desktop_state = desktop::new_desktop_state(web_state.clone());

let _web_state = web_state.clone();
Expand All @@ -62,11 +62,11 @@ fn main() -> Result<()> {

struct Driver {
current_state: WebStateSnapshot,
state: web::State,
state: browser::State,
}

impl Driver {
fn new(state: web::State) -> Self {
fn new(state: browser::State) -> Self {
let current_state = WebStateSnapshot::from(&*state.blocking_read());
Self {
state,
Expand Down Expand Up @@ -105,8 +105,8 @@ struct WebStateSnapshot {
// pub browser_processes: SmallHashSet<ProcessId>,
}

impl From<&web::StateInner> for WebStateSnapshot {
fn from(state: &web::StateInner) -> Self {
impl From<&browser::StateInner> for WebStateSnapshot {
fn from(state: &browser::StateInner) -> Self {
Self {
browser_windows: state
.browser_windows
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/src/bin/tab_switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use std::io::stdin;

use platform::browser;
use platform::objects::Window;
use platform::web;
use tools::filters::{ProcessFilter, WindowFilter, match_running_windows};
use util::error::Result;
use util::tracing::info;
Expand Down Expand Up @@ -41,7 +41,7 @@ mod tab_track_handler {
_sender: windows_core::Ref<'_, IUIAutomationElement>,
_eventid: UIA_EVENT_ID,
) -> windows::core::Result<()> {
let detect = web::Detect::new().expect("Failed to create browser detector");
let detect = browser::Detect::new().expect("Failed to create browser detector");
let element = detect
.get_chromium_element(&self.window)
.expect("Failed to get Chromium element");
Expand Down
6 changes: 3 additions & 3 deletions dev/tools/src/bin/tab_track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use std::sync::Mutex;

use platform::browser;
use platform::events::WindowTitleWatcher;
use platform::objects::{EventLoop, Target, Window};
use platform::web;
use tools::filters::{ProcessFilter, WindowFilter, match_running_windows};
use util::error::Result;
// use util::tracing::info;
Expand All @@ -18,12 +18,12 @@ use util::{Target as UtilTarget, config, future as tokio};
// }

struct UnsafeSyncSendBrowserDetect {
detect: web::Detect,
detect: browser::Detect,
}

impl UnsafeSyncSendBrowserDetect {
fn new() -> Result<Self> {
let detect = web::Detect::new()?;
let detect = browser::Detect::new()?;
Ok(Self { detect })
}

Expand Down
23 changes: 13 additions & 10 deletions src/engine/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::future::Future;
use std::sync::Arc;

use data::entities::{Alert, App, AppIdentity, Duration, Ref, Session, Timestamp};
use platform::browser;
use platform::events::{ForegroundWindowSessionInfo, WindowSession};
use platform::objects::{ProcessId, ProcessThreadId, Window};
use platform::web;
use scoped_futures::ScopedBoxFuture;
use util::ds::{SmallHashMap, SmallHashSet};
use util::error::Result;
Expand All @@ -31,7 +31,7 @@ pub struct DesktopStateInner {
pub type DesktopState = Arc<RwLock<DesktopStateInner>>;

/// Create a new [DesktopState]
pub fn new_desktop_state(web_state: web::State) -> DesktopState {
pub fn new_desktop_state(web_state: browser::State) -> DesktopState {
Arc::new(RwLock::new(DesktopStateInner::new(web_state)))
}

Expand All @@ -50,11 +50,11 @@ pub struct Store {
#[derive(Debug)]
pub struct WebsiteCache {
// This never gets cleared, but it's ok since it's a small set of urls?
websites: HashMap<web::BaseWebsiteUrl, AppDetails>,
websites: HashMap<browser::BaseWebsiteUrl, AppDetails>,
// This never gets cleared, but it's ok since it's a small set of apps?
apps: HashMap<Ref<App>, web::BaseWebsiteUrl>,
apps: HashMap<Ref<App>, browser::BaseWebsiteUrl>,
// Web state
state: web::State,
state: browser::State,
}

/// Cache for storing information about windows and processes
Expand Down Expand Up @@ -187,7 +187,7 @@ pub enum KillableProcessId {

impl DesktopStateInner {
/// Create a new [Cache].
pub fn new(web_state: web::State) -> Self {
pub fn new(web_state: browser::State) -> Self {
Self {
store: Store {
sessions: HashMap::new(),
Expand Down Expand Up @@ -250,7 +250,10 @@ impl DesktopStateInner {
}

/// Get the websites for an [App]. If the app is not a website, will return nothing.
pub fn websites_for_app(&self, app: &Ref<App>) -> impl Iterator<Item = &web::BaseWebsiteUrl> {
pub fn websites_for_app(
&self,
app: &Ref<App>,
) -> impl Iterator<Item = &browser::BaseWebsiteUrl> {
self.web.apps.get(app).into_iter()
}

Expand Down Expand Up @@ -333,11 +336,11 @@ impl DesktopStateInner {
Ok(self.store.apps.entry(ptid).or_insert(created))
}

/// Get or insert a [AppDetails] for a [web::BaseWebsiteUrl], using the create callback
/// Get or insert a [AppDetails] for a [browser::BaseWebsiteUrl], using the create callback
/// to make a new [AppDetails] if not found.
pub async fn get_or_insert_website_for_base_url<F: Future<Output = Result<AppDetails>>>(
&mut self,
base_url: web::BaseWebsiteUrl,
base_url: browser::BaseWebsiteUrl,
create: impl FnOnce(&mut Self) -> F,
) -> Result<&mut AppDetails> {
if self.web.websites.contains_key(&base_url) {
Expand Down Expand Up @@ -477,7 +480,7 @@ async fn inner_mut_compiles() {

let window: Window = Window::foreground().unwrap();
let process = ProcessThreadId { pid: 1, tid: 1 };
let web_state = web::default_state();
let web_state = browser::default_state();
let mut desktop = DesktopStateInner::new(web_state);

desktop
Expand Down
6 changes: 3 additions & 3 deletions src/engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use data::db::{DatabasePool, FoundOrInserted, UsageWriter};
use data::entities::{
AppIdentity, InteractionPeriod, Ref, Session, SystemEvent as DataSystemEvent, Usage,
};
use platform::browser::{self, BaseWebsiteUrl, WebsiteInfo};
use platform::events::{
ForegroundChangedEvent, ForegroundWindowSessionInfo, InteractionChangedEvent, SystemStateEvent,
};
use platform::objects::{Process, ProcessThreadId, SquirrelExe, Timestamp, Window};
use platform::web::{self, BaseWebsiteUrl, WebsiteInfo};
use scoped_futures::ScopedFutureExt;
use util::config::Config;
use util::error::{Context, Result};
Expand All @@ -22,7 +22,7 @@ use crate::resolver::AppInfoResolver;
pub struct Engine {
desktop_state: DesktopState,
config: Config,
web_state: web::State,
web_state: browser::State,
current_usage: Usage,
db_pool: DatabasePool,
inserter: UsageWriter,
Expand Down Expand Up @@ -55,7 +55,7 @@ pub struct EngineArgs {
/// Desktop State
pub desktop_state: DesktopState,
/// Web State
pub web_state: web::State,
pub web_state: browser::State,

/// Config
pub config: Config,
Expand Down
28 changes: 14 additions & 14 deletions src/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use std::thread;

use data::db::{AppUpdater, DatabasePool};
use engine::{Engine, Event};
use platform::browser;
use platform::events::{
ForegroundEventWatcher, ForegroundWindowSessionInfo, InteractionWatcher,
InteractionWatcherHooks, SystemEventWatcher,
};
use platform::objects::{
Duration, EventLoop, MessageWindow, SingleInstance, Timer, Timestamp, User,
};
use platform::web;
use resolver::AppInfoResolver;
use sentry::Sentry;
use util::channels::{self, Receiver, Sender};
Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn main() {

let _instance = single_instance().expect("setup single instance");

let web_state = web::default_state();
let web_state = browser::default_state();
let desktop_state = desktop::new_desktop_state(web_state.clone());

if let Err(report) = run(&config, rt.handle().clone(), web_state, desktop_state) {
Expand Down Expand Up @@ -98,7 +98,7 @@ fn setup() -> Result<(Config, Runtime)> {
pub fn run(
config: &Config,
rt: Handle,
web_state: web::State,
web_state: browser::State,
desktop_state: desktop::DesktopState,
) -> Result<()> {
let (event_tx, event_rx) = channels::unbounded();
Expand Down Expand Up @@ -151,13 +151,13 @@ pub fn run(
}

struct EventLoopArgs {
web_state: web::State,
web_state: browser::State,

config: Config,

event_tx: Sender<Event>,
alert_tx: Sender<Timestamp>,
web_change_tx: Sender<web::Changed>,
web_change_tx: Sender<browser::Changed>,

session: ForegroundWindowSessionInfo,
start: Timestamp,
Expand Down Expand Up @@ -227,7 +227,7 @@ fn event_loop(args: EventLoopArgs) -> Result<()> {
}),
)?;

let mut web_watcher = web::Watcher::new(args.web_change_tx, args.web_state)?;
let mut web_watcher = browser::Watcher::new(args.web_change_tx, args.web_state)?;

let dim_tick = Duration::from_millis(1000);
let _web_tick_timer = Timer::new(
Expand Down Expand Up @@ -258,10 +258,10 @@ async fn sentry_loop(
config: Config,
db_pool: DatabasePool,
desktop_state: desktop::DesktopState,
web_state: web::State,
web_state: browser::State,
spawner: Handle,
alert_rx: Receiver<Timestamp>,
web_change_rx: Receiver<web::Changed>,
web_change_rx: Receiver<browser::Changed>,
) -> Result<()> {
let db = db_pool.get_db().await?;
let sentry = Arc::new(Mutex::new(Sentry::new(
Expand Down Expand Up @@ -307,14 +307,14 @@ async fn sentry_loop(

struct ProcessorArgs {
desktop_state: desktop::DesktopState,
web_state: web::State,
web_state: browser::State,

config: Config,
rt: Handle,

event_rx: Receiver<Event>,
alert_rx: Receiver<Timestamp>,
web_change_rx: Receiver<web::Changed>,
web_change_rx: Receiver<browser::Changed>,

session: ForegroundWindowSessionInfo,
start: Timestamp,
Expand Down Expand Up @@ -448,9 +448,9 @@ async fn update_app_infos(db_pool: DatabasePool, handle: Handle) -> Result<()> {
/// Get the foreground [Window], and makes it into a [WindowSession] blocking until one is present.
fn foreground_window_session(
config: &Config,
web_state: web::State,
web_state: browser::State,
) -> Result<ForegroundWindowSessionInfo> {
let detect = web::Detect::new()?;
let detect = browser::Detect::new()?;
loop {
let session = ForegroundEventWatcher::foreground_window_session(
&detect,
Expand All @@ -470,9 +470,9 @@ fn foreground_window_session(
/// Get the foreground [Window], and makes it into a [WindowSession] blocking until one is present.
async fn foreground_window_session_async(
config: &Config,
web_state: web::State,
web_state: browser::State,
) -> Result<ForegroundWindowSessionInfo> {
let detect = web::Detect::new()?;
let detect = browser::Detect::new()?;
loop {
let session = ForegroundEventWatcher::foreground_window_session(
&detect,
Expand Down
2 changes: 1 addition & 1 deletion src/engine/src/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use data::db::{AppUpdater, DatabasePool};
use data::entities::{App, AppIdentity, Ref};
use platform::browser::WebsiteInfo;
use platform::objects::AppInfo;
use platform::web::WebsiteInfo;
use util::error::Result;
use util::time::{TimeSystem, ToTicks};
use util::tracing::{info, warn};
Expand Down
Loading