pub struct BrowserDetector { /* private fields */ }Implementations§
Source§impl BrowserDetector
impl BrowserDetector
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/test_copilot.rs (line 5)
4async fn main() {
5 let detector = BrowserDetector::new();
6 let browsers = detector.detect_browsers();
7
8 for browser in &browsers {
9 if !browser.is_chromium_based() {
10 continue;
11 }
12 for prof in detector.list_profiles(*browser) {
13 match CookieReader::read_cookies(&prof, "github.com") {
14 Ok(cookies) => {
15 let has_user_session = cookies.iter().any(|c| {
16 c.name == "user_session" || c.name == "__Host-user_session_same_site"
17 });
18
19 if !has_user_session {
20 continue;
21 }
22
23 let dotcom_user = cookies
24 .iter()
25 .find(|c| c.name == "dotcom_user")
26 .map(|c| c.value.as_str())
27 .unwrap_or("unknown");
28 println!(
29 "Using {} - {} ({} cookies, user={})",
30 browser.name(),
31 prof.name,
32 cookies.len(),
33 dotcom_user
34 );
35
36 match seher::copilot::CopilotClient::fetch_quota(&cookies).await {
37 Ok(quota) => {
38 println!("\nSuccess! Copilot quota:");
39 println!(" chat_utilization: {:.1}%", quota.chat_utilization);
40 println!(" premium_utilization: {:.1}%", quota.premium_utilization);
41 println!(" reset_time: {:?}", quota.reset_time);
42 println!(" is_limited: {}", quota.is_limited());
43 return;
44 }
45 Err(e) => {
46 println!("\nFailed to fetch Copilot quota: {}", e);
47 }
48 }
49 }
50 Err(_) => {}
51 }
52 }
53 }
54
55 println!("No github.com session with user_session cookie found");
56}Sourcepub fn detect_browsers(&self) -> Vec<BrowserType>
pub fn detect_browsers(&self) -> Vec<BrowserType>
Examples found in repository?
examples/test_copilot.rs (line 6)
4async fn main() {
5 let detector = BrowserDetector::new();
6 let browsers = detector.detect_browsers();
7
8 for browser in &browsers {
9 if !browser.is_chromium_based() {
10 continue;
11 }
12 for prof in detector.list_profiles(*browser) {
13 match CookieReader::read_cookies(&prof, "github.com") {
14 Ok(cookies) => {
15 let has_user_session = cookies.iter().any(|c| {
16 c.name == "user_session" || c.name == "__Host-user_session_same_site"
17 });
18
19 if !has_user_session {
20 continue;
21 }
22
23 let dotcom_user = cookies
24 .iter()
25 .find(|c| c.name == "dotcom_user")
26 .map(|c| c.value.as_str())
27 .unwrap_or("unknown");
28 println!(
29 "Using {} - {} ({} cookies, user={})",
30 browser.name(),
31 prof.name,
32 cookies.len(),
33 dotcom_user
34 );
35
36 match seher::copilot::CopilotClient::fetch_quota(&cookies).await {
37 Ok(quota) => {
38 println!("\nSuccess! Copilot quota:");
39 println!(" chat_utilization: {:.1}%", quota.chat_utilization);
40 println!(" premium_utilization: {:.1}%", quota.premium_utilization);
41 println!(" reset_time: {:?}", quota.reset_time);
42 println!(" is_limited: {}", quota.is_limited());
43 return;
44 }
45 Err(e) => {
46 println!("\nFailed to fetch Copilot quota: {}", e);
47 }
48 }
49 }
50 Err(_) => {}
51 }
52 }
53 }
54
55 println!("No github.com session with user_session cookie found");
56}pub fn get_browser_base_path( &self, browser_type: BrowserType, ) -> Option<PathBuf>
Sourcepub fn list_profiles(&self, browser_type: BrowserType) -> Vec<Profile>
pub fn list_profiles(&self, browser_type: BrowserType) -> Vec<Profile>
Examples found in repository?
examples/test_copilot.rs (line 12)
4async fn main() {
5 let detector = BrowserDetector::new();
6 let browsers = detector.detect_browsers();
7
8 for browser in &browsers {
9 if !browser.is_chromium_based() {
10 continue;
11 }
12 for prof in detector.list_profiles(*browser) {
13 match CookieReader::read_cookies(&prof, "github.com") {
14 Ok(cookies) => {
15 let has_user_session = cookies.iter().any(|c| {
16 c.name == "user_session" || c.name == "__Host-user_session_same_site"
17 });
18
19 if !has_user_session {
20 continue;
21 }
22
23 let dotcom_user = cookies
24 .iter()
25 .find(|c| c.name == "dotcom_user")
26 .map(|c| c.value.as_str())
27 .unwrap_or("unknown");
28 println!(
29 "Using {} - {} ({} cookies, user={})",
30 browser.name(),
31 prof.name,
32 cookies.len(),
33 dotcom_user
34 );
35
36 match seher::copilot::CopilotClient::fetch_quota(&cookies).await {
37 Ok(quota) => {
38 println!("\nSuccess! Copilot quota:");
39 println!(" chat_utilization: {:.1}%", quota.chat_utilization);
40 println!(" premium_utilization: {:.1}%", quota.premium_utilization);
41 println!(" reset_time: {:?}", quota.reset_time);
42 println!(" is_limited: {}", quota.is_limited());
43 return;
44 }
45 Err(e) => {
46 println!("\nFailed to fetch Copilot quota: {}", e);
47 }
48 }
49 }
50 Err(_) => {}
51 }
52 }
53 }
54
55 println!("No github.com session with user_session cookie found");
56}pub fn get_profile( &self, browser_type: BrowserType, profile_name: Option<&str>, ) -> Option<Profile>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BrowserDetector
impl RefUnwindSafe for BrowserDetector
impl Send for BrowserDetector
impl Sync for BrowserDetector
impl Unpin for BrowserDetector
impl UnsafeUnpin for BrowserDetector
impl UnwindSafe for BrowserDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more