├── .gitignore ├── commiter.yml ├── register-handler.reg ├── handler-whitelist.reg ├── Cargo.toml ├── protocol-handlers.json ├── sumatrapdf.reg ├── protocol-handler.rs └── Cargo.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | -------------------------------------------------------------------------------- /commiter.yml: -------------------------------------------------------------------------------- 1 | convention: symphony 2 | -------------------------------------------------------------------------------- /register-handler.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skyme5/protocol-handler/develop/register-handler.reg -------------------------------------------------------------------------------- /handler-whitelist.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/skyme5/protocol-handler/develop/handler-whitelist.reg -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "protocol-handler" 3 | version = "0.1.0" 4 | authors = ["Aakash Gajjar "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | json = "0.11.14" 9 | 10 | [dependencies.url] 11 | git = "https://github.com/servo/rust-url" 12 | 13 | [[bin]] 14 | name = "protocol-handler" 15 | path = "protocol-handler.rs" 16 | -------------------------------------------------------------------------------- /protocol-handlers.json: -------------------------------------------------------------------------------- 1 | { 2 | "azw": "C:/Program Files (x86)/Calibre2/ebook-viewer.exe", 3 | "azw3": "C:/Program Files (x86)/Calibre2/ebook-viewer.exe", 4 | "cbr": "C:/Program Files/SumatraPDF/SumatraPDF.exe", 5 | "djvu": "C:/Program Files/SumatraPDF/SumatraPDF.exe", 6 | "epub": "C:/Program Files/SumatraPDF/SumatraPDF.exe", 7 | "mobi": "C:/Program Files/SumatraPDF/SumatraPDF.exe", 8 | "pdf": "C:/Program Files/SumatraPDF/SumatraPDF.exe" 9 | } 10 | -------------------------------------------------------------------------------- /sumatrapdf.reg: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | 3 | [HKEY_CLASSES_ROOT\protocol-handler] 4 | "URL Protocol"="" 5 | @="URL:Rust Protocol Handler" 6 | "DefaultIcon"="\"C:\\Program Files\\SumatraPDF\\SumatraPDF.exe\",1" 7 | 8 | [HKEY_CLASSES_ROOT\protocol-handler\shell] 9 | 10 | [HKEY_CLASSES_ROOT\protocol-handler\shell\open] 11 | 12 | [HKEY_CLASSES_ROOT\protocol-handler\shell\open\command] 13 | @="\"C:\\tools\\bin\\protocol-handler.exe\" \"%1\"" 14 | 15 | [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\URLWhitelist] 16 | "1"="protocol-handler://*" -------------------------------------------------------------------------------- /protocol-handler.rs: -------------------------------------------------------------------------------- 1 | #![windows_subsystem = "windows"] 2 | 3 | use std::env; 4 | use std::fs; 5 | use std::process::Command; 6 | 7 | use std::io; 8 | use std::io::prelude::*; 9 | 10 | use json; 11 | use url::percent_encoding::percent_decode; 12 | 13 | fn pause() { 14 | let mut stdin = io::stdin(); 15 | let mut stdout = io::stdout(); 16 | 17 | // We want the cursor to stay at the end of the line, so we print without a newline and flush manually. 18 | write!(stdout, "Press any key to continue...").unwrap(); 19 | stdout.flush().unwrap(); 20 | 21 | // Read a single byte and discard 22 | let _ = stdin.read(&mut [0u8]).unwrap(); 23 | } 24 | 25 | fn main() { 26 | let protocols = fs::read_to_string("E:/projects/personal/protocol-handler/protocol-handlers.json") 27 | .expect("Something went wrong reading the file"); 28 | pause(); 29 | let parsed = json::parse(&protocols).unwrap(); 30 | let args: Vec = env::args().collect(); 31 | 32 | println!("{}", args[1]); 33 | 34 | let uri: Vec<&str> = args[1].split("://").collect(); 35 | let filepath = percent_decode(uri[1].replace("/", "\\").as_bytes()).decode_utf8().unwrap().to_string(); 36 | let handler: Vec<&str> = filepath.split(".").collect(); 37 | let program = parsed[handler.last().unwrap().to_lowercase().to_string()].to_string(); 38 | println!("{} {}", handler.last().unwrap().to_lowercase().to_string(), program); 39 | 40 | Command::new(program) 41 | .arg(filepath) 42 | .status() 43 | .expect("failed to execute process"); 44 | } 45 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "idna" 5 | version = "0.1.5" 6 | source = "git+https://github.com/servo/rust-url#c1914b3a27c657eac1def4a85aa97717460c3061" 7 | dependencies = [ 8 | "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 9 | "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 10 | "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 11 | ] 12 | 13 | [[package]] 14 | name = "json" 15 | version = "0.11.14" 16 | source = "registry+https://github.com/rust-lang/crates.io-index" 17 | 18 | [[package]] 19 | name = "matches" 20 | version = "0.1.8" 21 | source = "registry+https://github.com/rust-lang/crates.io-index" 22 | 23 | [[package]] 24 | name = "percent-encoding" 25 | version = "1.0.2" 26 | source = "git+https://github.com/servo/rust-url#c1914b3a27c657eac1def4a85aa97717460c3061" 27 | 28 | [[package]] 29 | name = "protocol-handler" 30 | version = "0.1.0" 31 | dependencies = [ 32 | "json 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)", 33 | "url 1.7.2 (git+https://github.com/servo/rust-url)", 34 | ] 35 | 36 | [[package]] 37 | name = "smallvec" 38 | version = "0.6.10" 39 | source = "registry+https://github.com/rust-lang/crates.io-index" 40 | 41 | [[package]] 42 | name = "unicode-bidi" 43 | version = "0.3.4" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | dependencies = [ 46 | "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 47 | ] 48 | 49 | [[package]] 50 | name = "unicode-normalization" 51 | version = "0.1.8" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | dependencies = [ 54 | "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", 55 | ] 56 | 57 | [[package]] 58 | name = "url" 59 | version = "1.7.2" 60 | source = "git+https://github.com/servo/rust-url#c1914b3a27c657eac1def4a85aa97717460c3061" 61 | dependencies = [ 62 | "idna 0.1.5 (git+https://github.com/servo/rust-url)", 63 | "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 64 | "percent-encoding 1.0.2 (git+https://github.com/servo/rust-url)", 65 | ] 66 | 67 | [metadata] 68 | "checksum idna 0.1.5 (git+https://github.com/servo/rust-url)" = "" 69 | "checksum json 0.11.14 (registry+https://github.com/rust-lang/crates.io-index)" = "01d7903059b22f1f09ced2fb9562507e3556a953caa2f835c64ab022bb6148c2" 70 | "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" 71 | "checksum percent-encoding 1.0.2 (git+https://github.com/servo/rust-url)" = "" 72 | "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" 73 | "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" 74 | "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" 75 | "checksum url 1.7.2 (git+https://github.com/servo/rust-url)" = "" 76 | --------------------------------------------------------------------------------