-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add global state and parse url
- Loading branch information
Showing
5 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use headless_chrome::Browser; | ||
use tokio::sync::mpsc::Sender; | ||
|
||
use crate::model::task::TaskConfig; | ||
|
||
pub struct GlobalState { | ||
pub domain: String, | ||
pub browser: Browser, | ||
pub config: TaskConfig, | ||
|
||
pub sender: Option<Sender<String>>, | ||
} | ||
|
||
impl GlobalState { | ||
pub fn new(tx: Sender<String>, domain: String, browser: Browser, config: TaskConfig) -> Self { | ||
GlobalState { | ||
domain, | ||
browser, | ||
config, | ||
sender: Some(tx), | ||
} | ||
} | ||
|
||
pub fn send_message(&self, message: &str) { | ||
if let Some(ref sender) = self.sender { | ||
if sender.blocking_send(message.to_owned()).is_err() { | ||
log::error!("Failed to send URL through channel"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod channel; | ||
pub mod cli; | ||
pub mod common; | ||
pub mod handler; | ||
|