Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ windows = { version = "0.58", features = [
"Win32_UI_Shell",
"Win32_System_LibraryLoader",
"Win32_System_Threading",
"Win32_Media"
"Win32_Media",
"Win32_Networking_WinHttp"
] }
tiny-skia = "0.11"
rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Settings are saved automatically to `%APPDATA%\Snowfall\settings.txt` and restor

## Privacy

Snowfall makes no network connections and collects no data. It only reads window positions and titles locally to find where snow can land.
Snowfall collects no data and makes no network connections on its own. It only reads window positions and titles locally to find where snow can land. The one exception is the **Check for updates** button in the settings window: when you press it, Snowfall sends a single request to the GitHub API (api.github.com) to read the version number of the latest release. Nothing else is sent.

## License

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod settings_ui;
mod snow;
mod tracker;
mod tray;
mod update;

use overlay::Overlay;
use snow::{bgra, Snow};
Expand Down
151 changes: 149 additions & 2 deletions src/settings_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ const SWITCH_HEIGHT: i32 = 22;

const FPS_TOP: i32 = 410;
const BUTTON_TOP: i32 = 465;
const UPDATE_TOP: i32 = 515;
const CLIENT_WIDTH: i32 = 340;
const CLIENT_HEIGHT: i32 = 520;
const CLIENT_HEIGHT: i32 = 570;

#[derive(Clone, Copy, PartialEq)]
enum SliderKind {
Expand Down Expand Up @@ -338,6 +339,15 @@ fn clear_btn_rect() -> RECT {
}
}

fn update_btn_rect() -> RECT {
RECT {
left: 180,
top: UPDATE_TOP,
right: 320,
bottom: UPDATE_TOP + 34,
}
}

fn hit_test_slider(x: i32, y: i32) -> Option<SliderKind> {
if (MARGIN_X..=MARGIN_X + TRACK_WIDTH).contains(&x) {
if (SLIDER1_TOP..SLIDER1_TOP + ROW_HEIGHT).contains(&y) {
Expand Down Expand Up @@ -884,12 +894,98 @@ unsafe fn draw_content(hdc: windows::Win32::Graphics::Gdi::HDC, state: &AppState
DT_CENTER | DT_VCENTER | DT_SINGLELINE,
);

// Update row
let hfont_small = CreateFontW(
12,
0,
0,
0,
FW_NORMAL.0 as i32,
0,
0,
0,
DEFAULT_CHARSET.0 as u32,
OUT_DEFAULT_PRECIS.0 as u32,
CLIP_DEFAULT_PRECIS.0 as u32,
DEFAULT_QUALITY.0 as u32,
DEFAULT_PITCH.0 as u32,
windows::core::w!("Segoe UI"),
);

let mut ver_rc = RECT {
left: MARGIN_X,
top: UPDATE_TOP,
right: 170,
bottom: UPDATE_TOP + 17,
};
let _ = SetTextColor(hdc, COLORREF(0x008A8482));
SelectObject(hdc, hfont_normal);
let ver_str = format!("Snowfall v{}", env!("CARGO_PKG_VERSION"));
draw_text_str(
hdc,
&ver_str,
&mut ver_rc,
DT_LEFT | DT_VCENTER | DT_SINGLELINE,
);

let mut status_rc = RECT {
left: MARGIN_X,
top: UPDATE_TOP + 18,
right: 170,
bottom: UPDATE_TOP + 34,
};
let update_state_val = state.update_state.load(Ordering::Relaxed);
let status_str = match update_state_val {
1 => "Checking...".to_string(),
2 => "You have the latest version".to_string(),
3 => {
let tag = state
.update_tag
.lock()
.map(|l| l.clone())
.unwrap_or_default();
format!("Update available: {}", tag)
}
4 => "Check failed".to_string(),
_ => "".to_string(),
};
if !status_str.is_empty() {
SelectObject(hdc, hfont_small);
draw_text_str(
hdc,
&status_str,
&mut status_rc,
DT_LEFT | DT_VCENTER | DT_SINGLELINE,
);
}

let update_r = update_btn_rect();
let u_brush = CreateSolidBrush(COLORREF(0x003A3D41));
let mut u_sys = update_r;
FillRect(hdc, &u_sys, u_brush);
let _ = DeleteObject(HGDIOBJ(u_brush.0));
let _ = SetTextColor(hdc, COLORREF(0x00FFFFFF));
let update_btn_str = if update_state_val == 3 {
"Download update"
} else {
"Check for updates"
};
SelectObject(hdc, hfont_normal);
draw_text_str(
hdc,
update_btn_str,
&mut u_sys,
DT_CENTER | DT_VCENTER | DT_SINGLELINE,
);

let _ = DeleteObject(HGDIOBJ(hfont_small.0));

SelectObject(hdc, old_font);
let _ = DeleteObject(HGDIOBJ(hfont_normal.0));
let _ = DeleteObject(HGDIOBJ(hfont_bold.0));
}

fn handle_click(state: &AppState, x: i32, y: i32) -> bool {
fn handle_click(state: &Arc<AppState>, x: i32, y: i32) -> bool {
// Check accumulate tiles
let t0_l = MARGIN_X;
let t0_r = t0_l + TILE_WIDTH;
Expand Down Expand Up @@ -954,5 +1050,56 @@ fn handle_click(state: &AppState, x: i32, y: i32) -> bool {
return true;
}

// Check update button
let ur = update_btn_rect();
if x >= ur.left && x <= ur.right && y >= ur.top && y <= ur.bottom {
let update_state = state.update_state.load(Ordering::Relaxed);
if update_state == 3 {
unsafe {
let _ = windows::Win32::UI::Shell::ShellExecuteW(
HWND(std::ptr::null_mut()),
windows::core::w!("open"),
windows::core::w!("https://github.com/Tomjerri1/Snowfall/releases/latest"),
windows::core::PCWSTR::null(),
windows::core::PCWSTR::null(),
windows::Win32::UI::WindowsAndMessaging::SW_SHOW,
);
}
} else if update_state != 1 {
state.update_state.store(1, Ordering::Release);
let state_clone = state.clone();
std::thread::spawn(move || {
match crate::update::fetch_latest_tag() {
Ok(tag) => {
if crate::update::parse_version(&tag).is_none() {
state_clone.update_state.store(4, Ordering::Release);
} else {
let newer = crate::update::is_newer(env!("CARGO_PKG_VERSION"), &tag);
if newer {
if let Ok(mut lock) = state_clone.update_tag.lock() {
*lock = tag;
}
state_clone.update_state.store(3, Ordering::Release);
} else {
state_clone.update_state.store(2, Ordering::Release);
}
}
}
Err(_) => {
state_clone.update_state.store(4, Ordering::Release);
}
}
let hwnd_val = state_clone.settings_hwnd.load(Ordering::Acquire);
if hwnd_val != 0 {
let hwnd = HWND(hwnd_val as *mut std::ffi::c_void);
unsafe {
let _ = InvalidateRect(hwnd, None, false);
}
}
});
}
return true;
}

false
}
4 changes: 4 additions & 0 deletions src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub struct AppState {
pub acc_dock: AtomicBool,
pub acc_ground: AtomicBool,
pub mouse_flakes: AtomicBool,
pub update_state: AtomicUsize,
pub update_tag: std::sync::Mutex<String>,
}

impl AppState {
Expand All @@ -59,6 +61,8 @@ impl AppState {
acc_dock: AtomicBool::new(true),
acc_ground: AtomicBool::new(false),
mouse_flakes: AtomicBool::new(true),
update_state: AtomicUsize::new(0),
update_tag: std::sync::Mutex::new(String::new()),
}
}
}
Expand Down
Loading
Loading