|
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 |
@@ -106,6 +107,8 @@ pub struct DesktopQueryParams { |
106 | 107 | pub base: QueryParamsBase, |
107 | 108 | pub bid_window: String, |
108 | 109 | pub bid_afk: String, |
| 110 | + #[serde(default)] |
| 111 | + pub always_active_pattern: Option<String>, |
109 | 112 | } |
110 | 113 |
|
111 | 114 | /// Query parameters specific to Android |
@@ -182,11 +185,26 @@ pub fn build_desktop_canonical_events(params: &DesktopQueryParams) -> String { |
182 | 185 |
|
183 | 186 | // Fetch not-afk events |
184 | 187 | if params.base.filter_afk { |
185 | | - query.push(format!( |
| 188 | + let mut not_afk_query = format!( |
186 | 189 | "not_afk = flood(query_bucket(find_bucket(\"{}\"))); |
187 | 190 | not_afk = filter_keyvals(not_afk, \"status\", [\"not-afk\"])", |
188 | 191 | escape_doublequote(¶ms.bid_afk) |
189 | | - )); |
| 192 | + ); |
| 193 | + |
| 194 | + // Add treat_as_active functionality if pattern is provided |
| 195 | + if let Some(ref pattern) = params.always_active_pattern { |
| 196 | + not_afk_query.push_str(&format!( |
| 197 | + "; |
| 198 | +not_treat_as_afk = filter_keyvals_regex(events, \"app\", \"{}\"); |
| 199 | +not_afk = period_union(not_afk, not_treat_as_afk); |
| 200 | +not_treat_as_afk = filter_keyvals_regex(events, \"title\", \"{}\"); |
| 201 | +not_afk = period_union(not_afk, not_treat_as_afk)", |
| 202 | + escape_doublequote(pattern), |
| 203 | + escape_doublequote(pattern) |
| 204 | + )); |
| 205 | + } |
| 206 | + |
| 207 | + query.push(not_afk_query); |
190 | 208 | } |
191 | 209 |
|
192 | 210 | // Add browser events if any browser buckets specified |
@@ -368,6 +386,7 @@ mod tests { |
368 | 386 | }, |
369 | 387 | bid_window: "aw-watcher-window_".to_string(), |
370 | 388 | bid_afk: "aw-watcher-afk_".to_string(), |
| 389 | + always_active_pattern: None, |
371 | 390 | }; |
372 | 391 |
|
373 | 392 | let query = full_desktop_query(¶ms); |
@@ -420,6 +439,7 @@ mod tests { |
420 | 439 | }, |
421 | 440 | bid_window: "test-window".to_string(), |
422 | 441 | bid_afk: "test-afk".to_string(), |
| 442 | + always_active_pattern: None, |
423 | 443 | }; |
424 | 444 |
|
425 | 445 | let query_params = QueryParams::Desktop(params); |
@@ -451,6 +471,7 @@ mod tests { |
451 | 471 | }, |
452 | 472 | bid_window: "test-window".to_string(), |
453 | 473 | bid_afk: "test-afk".to_string(), |
| 474 | + always_active_pattern: None, |
454 | 475 | }; |
455 | 476 |
|
456 | 477 | let query_params = QueryParams::Desktop(params); |
|
0 commit comments