|
25 | 25 | //! }, |
26 | 26 | //! bid_window: "aw-watcher-window_example".to_string(), |
27 | 27 | //! bid_afk: "aw-watcher-afk_example".to_string(), |
| 28 | +//! always_active_pattern: None, |
28 | 29 | //! }; |
29 | 30 | //! |
30 | 31 | //! // Automatically fetches classes from localhost:5600 |
@@ -104,6 +105,8 @@ pub struct DesktopQueryParams { |
104 | 105 | pub base: QueryParamsBase, |
105 | 106 | pub bid_window: String, |
106 | 107 | pub bid_afk: String, |
| 108 | + #[serde(default)] |
| 109 | + pub always_active_pattern: Option<String>, |
107 | 110 | } |
108 | 111 |
|
109 | 112 | /// Query parameters specific to Android |
@@ -180,11 +183,26 @@ pub fn build_desktop_canonical_events(params: &DesktopQueryParams) -> String { |
180 | 183 |
|
181 | 184 | // Fetch not-afk events |
182 | 185 | if params.base.filter_afk { |
183 | | - query.push(format!( |
| 186 | + let mut not_afk_query = format!( |
184 | 187 | "not_afk = flood(query_bucket(find_bucket(\"{}\"))); |
185 | 188 | not_afk = filter_keyvals(not_afk, \"status\", [\"not-afk\"])", |
186 | 189 | escape_doublequote(¶ms.bid_afk) |
187 | | - )); |
| 190 | + ); |
| 191 | + |
| 192 | + // Add treat_as_active functionality if pattern is provided |
| 193 | + if let Some(ref pattern) = params.always_active_pattern { |
| 194 | + not_afk_query.push_str(&format!( |
| 195 | + "; |
| 196 | +not_treat_as_afk = filter_keyvals_regex(events, \"app\", \"{}\"); |
| 197 | +not_afk = period_union(not_afk, not_treat_as_afk); |
| 198 | +not_treat_as_afk = filter_keyvals_regex(events, \"title\", \"{}\"); |
| 199 | +not_afk = period_union(not_afk, not_treat_as_afk)", |
| 200 | + escape_doublequote(pattern), |
| 201 | + escape_doublequote(pattern) |
| 202 | + )); |
| 203 | + } |
| 204 | + |
| 205 | + query.push(not_afk_query); |
188 | 206 | } |
189 | 207 |
|
190 | 208 | // Add browser events if any browser buckets specified |
@@ -362,6 +380,7 @@ mod tests { |
362 | 380 | }, |
363 | 381 | bid_window: "aw-watcher-window_".to_string(), |
364 | 382 | bid_afk: "aw-watcher-afk_".to_string(), |
| 383 | + always_active_pattern: None, |
365 | 384 | }; |
366 | 385 |
|
367 | 386 | let query = full_desktop_query(¶ms); |
@@ -414,6 +433,7 @@ mod tests { |
414 | 433 | }, |
415 | 434 | bid_window: "test-window".to_string(), |
416 | 435 | bid_afk: "test-afk".to_string(), |
| 436 | + always_active_pattern: None, |
417 | 437 | }; |
418 | 438 |
|
419 | 439 | let query_params = QueryParams::Desktop(params); |
@@ -445,6 +465,7 @@ mod tests { |
445 | 465 | }, |
446 | 466 | bid_window: "test-window".to_string(), |
447 | 467 | bid_afk: "test-afk".to_string(), |
| 468 | + always_active_pattern: None, |
448 | 469 | }; |
449 | 470 |
|
450 | 471 | let query_params = QueryParams::Desktop(params); |
|
0 commit comments