-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57e8ad1
commit 4d2893f
Showing
8 changed files
with
111 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
mod daemon; | ||
mod l10n; | ||
mod logs; | ||
mod pac; | ||
mod prefs; | ||
mod refresh_cell; | ||
mod settings; | ||
|
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,4 @@ | ||
mod windows; | ||
|
||
#[cfg(windows)] | ||
pub use windows::*; |
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,63 @@ | ||
|
||
use anyhow::Context; | ||
use std::net::SocketAddr; | ||
use winapi::um::wininet::{ | ||
InternetSetOptionA, INTERNET_OPTION_REFRESH, INTERNET_OPTION_SETTINGS_CHANGED, | ||
}; | ||
use winreg::enums::*; | ||
use winreg::types::ToRegValue; | ||
use winreg::RegKey; | ||
|
||
const HTTP_PROXY_REG_PATH: &str = r"Software\Microsoft\Windows\CurrentVersion\Internet Settings"; | ||
|
||
fn set_registry_value(key: &RegKey, name: &str, value: &impl ToRegValue) -> anyhow::Result<()> { | ||
key.set_value(name, value) | ||
.context(format!("Failed to set registry value '{}'", name)) | ||
} | ||
|
||
fn refresh_internet_options() { | ||
unsafe { | ||
InternetSetOptionA( | ||
std::ptr::null_mut(), | ||
INTERNET_OPTION_SETTINGS_CHANGED, | ||
std::ptr::null_mut(), | ||
0, | ||
); | ||
InternetSetOptionA( | ||
std::ptr::null_mut(), | ||
INTERNET_OPTION_REFRESH, | ||
std::ptr::null_mut(), | ||
0, | ||
); | ||
} | ||
} | ||
|
||
pub fn set_http_proxy(proxy: SocketAddr) -> anyhow::Result<()> { | ||
let key = RegKey::predef(HKEY_CURRENT_USER) | ||
.open_subkey_with_flags(HTTP_PROXY_REG_PATH, KEY_WRITE) | ||
.context("Failed to open registry key with write access")?; | ||
|
||
set_registry_value( | ||
&key, | ||
"ProxyServer", | ||
&format!("{}:{}", proxy.ip(), proxy.port()), | ||
)?; | ||
set_registry_value(&key, "ProxyEnable", &1u32)?; | ||
|
||
refresh_internet_options(); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn unset_http_proxy() -> anyhow::Result<()> { | ||
let key = RegKey::predef(HKEY_CURRENT_USER) | ||
.open_subkey_with_flags(HTTP_PROXY_REG_PATH, KEY_WRITE) | ||
.context("Failed to open registry key with write access")?; | ||
|
||
set_registry_value(&key, "ProxyServer", &"")?; | ||
set_registry_value(&key, "ProxyEnable", &0u32)?; | ||
|
||
refresh_internet_options(); | ||
|
||
Ok(()) | ||
} |
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