Repository navigation
Store app and Edge removal fixes; a cleaner Hunter target #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,7 +104,7 @@ impl HunterView { | |
| let (mut hunted, mut close, mut open_main, mut hide) = (false, false, false, false); | ||
| let builder = egui::ViewportBuilder::default() | ||
| .with_title("CleanCore Hunter") | ||
| .with_inner_size([128.0, 132.0]) | ||
| .with_inner_size([132.0, 150.0]) | ||
| .with_resizable(false) | ||
| .with_decorations(false) | ||
| .with_always_on_top() | ||
|
|
@@ -113,37 +113,42 @@ impl HunterView { | |
| if ui.input(|i| i.viewport().close_requested()) { | ||
| close = true; | ||
| } | ||
| egui::CentralPanel::default().frame(egui::Frame::new().fill(p.surface).stroke(egui::Stroke::new(1.0, p.border)).inner_margin(6)).show(ui, |ui| { | ||
| crate::gui::style::row(ui, |ui| { | ||
| // Grip: drag the window around. Its buttons sit at the far end. | ||
| ui.spacing_mut().item_spacing.x = 0.0; | ||
| let (grip, r) = ui.allocate_exact_size(egui::vec2(24.0, 30.0), egui::Sense::drag()); | ||
| ui.painter().text(grip.center(), egui::Align2::CENTER_CENTER, style::vstr(icon::DOTS), egui::FontId::proportional(14.0), p.faint); | ||
| if r.hovered() { | ||
| ui.ctx().set_cursor_icon(egui::CursorIcon::Grab); | ||
| } | ||
| if r.drag_started() { | ||
| ui.ctx().send_viewport_cmd(egui::ViewportCommand::StartDrag); | ||
| } | ||
| r.on_hover_text(style::vis(tr("Move"))); | ||
| ui.with_layout(crate::gui::style::far_layout(egui::Align::Center), |ui| { | ||
| close = style::icon_button(ui, icon::X, "Exit Hunter Mode").clicked() || close; | ||
| hide = style::icon_button(ui, icon::APP_WINDOW, "Open CleanCore").clicked(); | ||
| }); | ||
| }); | ||
| let frame = egui::Frame::new().fill(p.surface).stroke(egui::Stroke::new(1.0, p.border)).inner_margin(egui::Margin::symmetric(6, 4)); | ||
| egui::CentralPanel::default().frame(frame).show(ui, |ui| { | ||
| // Title bar: all of it moves the window, except its two small buttons at the far end. | ||
| let (bar, r) = ui.allocate_exact_size(egui::vec2(ui.available_width(), 26.0), egui::Sense::drag()); | ||
| if r.hovered() { | ||
| ui.ctx().set_cursor_icon(egui::CursorIcon::Grab); | ||
| } | ||
| if r.drag_started() { | ||
| ui.ctx().send_viewport_cmd(egui::ViewportCommand::StartDrag); | ||
| } | ||
| r.on_hover_text(style::vis(tr("Move"))); | ||
| let mut buttons = ui.new_child(egui::UiBuilder::new().max_rect(bar).layout(style::far_layout(egui::Align::Center))); | ||
| buttons.spacing_mut().item_spacing.x = 2.0; | ||
| close = bar_button(&mut buttons, icon::X, "Exit Hunter Mode", p).clicked() || close; | ||
| hide = bar_button(&mut buttons, icon::APP_WINDOW, "Open CleanCore", p).clicked(); | ||
|
|
||
| ui.add_space(4.0); | ||
| ui.vertical_centered(|ui| { | ||
| let (rect, r) = ui.allocate_exact_size(egui::vec2(64.0, 64.0), egui::Sense::drag()); | ||
| // The target: a round button with a ring that answers hover, red while hunting. | ||
| let (rect, r) = ui.allocate_exact_size(egui::vec2(72.0, 72.0), egui::Sense::drag()); | ||
| r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, tr("Floating hunter target"))); | ||
| let hover = ui.ctx().animate_bool(r.id, r.hovered() || r.dragged()); | ||
| let col = if r.dragged() { p.danger } else { p.accent }; | ||
| ui.painter().rect_filled(rect, 16.0, col.gamma_multiply(if p.dark { 0.25 } else { 0.14 })); | ||
| ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, style::vstr(icon::CROSSHAIR), egui::FontId::proportional(38.0), col); | ||
| let painter = ui.painter(); | ||
| let radius = 30.0 + 2.0 * hover; | ||
| painter.circle_filled(rect.center(), radius, col.gamma_multiply(if p.dark { 0.22 } else { 0.12 } + 0.08 * hover)); | ||
| painter.circle_stroke(rect.center(), radius, egui::Stroke::new(1.5, col.gamma_multiply(0.35 + 0.65 * hover))); | ||
| painter.text(rect.center(), egui::Align2::CENTER_CENTER, style::vstr(icon::CROSSHAIR), egui::FontId::proportional(34.0 + 2.0 * hover), col); | ||
| if r.hovered() || r.dragged() { | ||
| ui.ctx().set_cursor_icon(egui::CursorIcon::Crosshair); | ||
| } | ||
| if r.drag_stopped() { | ||
| hunted = true; | ||
| } | ||
| ui.add(style::Label::new(style::rich(tr("Drag me")).size(11.0).color(p.muted))); | ||
| ui.add_space(2.0); | ||
| ui.add(style::Label::new(style::rich(tr("Drag me")).size(12.0).color(if r.dragged() { p.danger } else { p.muted }))); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
@@ -526,6 +531,22 @@ fn program_row(ui: &mut Ui, pr: &Proc, selected: bool, p: Palette) -> egui::Resp | |
| } | ||
|
|
||
| /// Bring the main window back from the taskbar. | ||
| /// A small icon button for the floating target's title bar (the usual ones would crowd it). | ||
| fn bar_button(ui: &mut Ui, glyph: &str, tip: &str, p: Palette) -> egui::Response { | ||
| let tip = tr(tip); | ||
| let (rect, r) = ui.allocate_exact_size(egui::vec2(24.0, 24.0), egui::Sense::click()); | ||
| let t = ui.ctx().animate_bool(r.id, r.hovered()); | ||
| if t > 0.0 { | ||
| ui.painter().rect_filled(rect, 6.0, p.surface_alt.lerp_to_gamma(p.border, 0.5).gamma_multiply(t)); | ||
| } | ||
| ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, style::vstr(glyph), egui::FontId::proportional(14.0), p.faint.lerp_to_gamma(p.text, t)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Increase the idle icon contrast. In the light palette,
|
||
| if r.hovered() { | ||
| ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand); | ||
| } | ||
| r.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, tip)); | ||
| r.on_hover_text(style::vis(tip)) | ||
| } | ||
|
|
||
| fn show_main(ctx: &egui::Context) { | ||
| ctx.send_viewport_cmd_to(egui::ViewportId::ROOT, egui::ViewportCommand::Minimized(false)); | ||
| ctx.send_viewport_cmd_to(egui::ViewportId::ROOT, egui::ViewportCommand::Focus); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,17 +120,30 @@ function Remove-Autostart($like) { | |
| } | ||
| "#; | ||
|
|
||
| /// Put before a script that calls `Invoke-Uninstaller $exe $arguments`: it runs the uninstaller | ||
| /// and waits for it, and for the copies of it named `$name` it hands over to, 5 minutes at most. | ||
| /// `Start-Process -Wait` waits for every process the uninstaller starts too, so an uninstaller | ||
| /// that leaves Edge Update or a helper running held the removal until PowerShell was stopped. | ||
| const RUN: &str = r#" | ||
| function Invoke-Uninstaller($exe, $arguments, $name) { | ||
| $until = (Get-Date).AddMinutes(5) | ||
| $p = Start-Process $exe $arguments -PassThru | ||
| if ($p) { [void]$p.WaitForExit(300000) } | ||
| while ($name -and (Get-Date) -lt $until -and @(Get-Process -Name $name -ErrorAction SilentlyContinue).Count) { Start-Sleep -Milliseconds 500 } | ||
|
Comment on lines
+131
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stop removal when the wait expires.
Report a timeout and stop cleanup when a required uninstaller is still running.
|
||
| } | ||
| "#; | ||
|
|
||
| /// OneDrive: its own uninstallers (this user's copy, then the machine-wide one). | ||
| const ONEDRIVE_REMOVE: &str = r#" | ||
| $ErrorActionPreference = 'SilentlyContinue' | ||
| Stop-Process -Name OneDrive, OneDriveSetup -Force | ||
| Start-Sleep -Seconds 1 | ||
| Get-ChildItem "$env:LOCALAPPDATA\Microsoft\OneDrive\*\OneDriveSetup.exe" | ForEach-Object { Start-Process $_.FullName '/uninstall' -Wait } | ||
| Get-ChildItem "$env:LOCALAPPDATA\Microsoft\OneDrive\*\OneDriveSetup.exe" | ForEach-Object { Invoke-Uninstaller $_.FullName '/uninstall' 'OneDriveSetup' } | ||
| foreach ($d in $env:ProgramFiles, ${env:ProgramFiles(x86)}) { | ||
| Get-ChildItem "$d\Microsoft OneDrive\*\OneDriveSetup.exe" | ForEach-Object { Start-Process $_.FullName '/uninstall /allusers' -Wait } | ||
| Get-ChildItem "$d\Microsoft OneDrive\*\OneDriveSetup.exe" | ForEach-Object { Invoke-Uninstaller $_.FullName '/uninstall /allusers' 'OneDriveSetup' } | ||
| } | ||
| foreach ($s in "$env:SystemRoot\System32\OneDriveSetup.exe", "$env:SystemRoot\SysWOW64\OneDriveSetup.exe") { | ||
| if (Test-Path $s) { Start-Process $s '/uninstall' -Wait } | ||
| if (Test-Path $s) { Invoke-Uninstaller $s '/uninstall' 'OneDriveSetup' } | ||
| } | ||
| "#; | ||
|
|
||
|
|
@@ -139,7 +152,7 @@ const ONEDRIVE_BLOCK: &str = r#" | |
| $ErrorActionPreference = 'SilentlyContinue' | ||
| # The policy "Prevent the usage of OneDrive for file storage": OneDrive won't run for anyone. | ||
| $pol = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive' | ||
| New-Item $pol -Force | Out-Null | ||
| if (-not (Test-Path $pol)) { New-Item $pol -Force | Out-Null } | ||
| Set-ItemProperty $pol -Name DisableFileSyncNGSC -Value 1 -Type DWord | ||
| # New accounts: the default profile installs it at first sign-in. | ||
| $hive = "$env:SystemDrive\Users\Default\NTUSER.DAT" | ||
|
|
@@ -156,7 +169,7 @@ Remove-Autostart 'OneDrive*' | |
| Get-ScheduledTask -TaskName 'OneDrive*' | Unregister-ScheduledTask -Confirm:$false | ||
| # Explorer's sidebar entry. | ||
| foreach ($c in 'HKCU:\Software\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}', 'HKCU:\Software\Classes\WOW6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}') { | ||
| New-Item $c -Force | Out-Null | ||
| if (-not (Test-Path $c)) { New-Item $c -Force | Out-Null } | ||
| Set-ItemProperty $c -Name 'System.IsPinnedToNameSpaceTree' -Value 0 -Type DWord | ||
| } | ||
| Write-Output $old | ||
|
|
@@ -172,8 +185,9 @@ foreach ($c in 'HKCU:\Software\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1F | |
| $hive = "$env:SystemDrive\Users\Default\NTUSER.DAT" | ||
| if ($old -and (Test-Path $hive)) { | ||
| reg.exe load 'HKU\CleanCoreDefault' $hive | Out-Null | ||
| New-Item 'Registry::HKEY_USERS\CleanCoreDefault\Software\Microsoft\Windows\CurrentVersion\Run' -Force | Out-Null | ||
| Set-ItemProperty 'Registry::HKEY_USERS\CleanCoreDefault\Software\Microsoft\Windows\CurrentVersion\Run' -Name OneDriveSetup -Value $old | ||
| $run = 'Registry::HKEY_USERS\CleanCoreDefault\Software\Microsoft\Windows\CurrentVersion\Run' | ||
| if (-not (Test-Path $run)) { New-Item $run -Force | Out-Null } | ||
| Set-ItemProperty $run -Name OneDriveSetup -Value $old | ||
| [gc]::Collect() | ||
| reg.exe unload 'HKU\CleanCoreDefault' | Out-Null | ||
| } | ||
|
|
@@ -208,24 +222,27 @@ function Stop-Edge { | |
| Stop-Edge | ||
|
|
||
| $dev = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdateDev' | ||
| New-Item $dev -Force | Out-Null | ||
| if (-not (Test-Path $dev)) { New-Item $dev -Force | Out-Null } | ||
| Set-ItemProperty $dev -Name AllowUninstall -Value 1 -Type DWord | ||
| $legacy = "$env:SystemRoot\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe" | ||
| $made = -not (Test-Path "$legacy\MicrosoftEdge.exe") | ||
| if ($made) { New-Item $legacy -ItemType Directory -Force | Out-Null; New-Item "$legacy\MicrosoftEdge.exe" -ItemType File -Force | Out-Null } | ||
| foreach ($r in $roots) { | ||
| Get-ChildItem "$r\Application\*\Installer\setup.exe" | ForEach-Object { | ||
| Start-Process $_.FullName '--uninstall --msedge --system-level --verbose-logging --force-uninstall' -Wait | ||
| Invoke-Uninstaller $_.FullName '--uninstall --msedge --system-level --verbose-logging --force-uninstall' | ||
| } | ||
| } | ||
| # A copy of Edge's setup it handed over to (setup.exe is a common name: only Edge's counts). | ||
| # Only waited for, never stopped. | ||
| $until = (Get-Date).AddMinutes(2) | ||
| while ((Get-Date) -lt $until -and @(Get-Process setup | Where-Object { $_.Product -like '*Edge*' }).Count) { Start-Sleep -Milliseconds 500 } | ||
| if ($made) { Remove-Item "$legacy\MicrosoftEdge.exe" -Force } | ||
| Remove-ItemProperty $dev -Name AllowUninstall | ||
|
|
||
| # What the uninstaller left of the program folder. | ||
| Stop-Edge | ||
| $svc = Get-CimInstance Win32_Service -Filter "Name='MicrosoftEdgeElevationService'" | ||
| if ($svc -and @($roots | Where-Object { $svc.PathName.Trim('"').StartsWith("$_\", 'OrdinalIgnoreCase') }).Count) { sc.exe delete MicrosoftEdgeElevationService | Out-Null } | ||
| Add-Type -Namespace CleanCore -Name Kernel32 -MemberDefinition '[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern bool MoveFileEx(string from, string to, int flags);' | ||
| foreach ($r in $roots) { | ||
| if (-not (Test-Path -LiteralPath $r)) { continue } | ||
| # Ownership to Administrators, then full control for them. takeown's prompt (for folders it | ||
|
|
@@ -237,6 +254,10 @@ foreach ($r in $roots) { | |
| Remove-Item -LiteralPath $r -Recurse -Force | ||
| if (Test-Path -LiteralPath $r) { | ||
| # Still in use: deleted when Windows restarts, deepest first so each folder is empty by then. | ||
| # (Compiling MoveFileEx's wrapper takes a few seconds: only when it is needed.) | ||
| if (-not ('CleanCore.Kernel32' -as [type])) { | ||
| Add-Type -Namespace CleanCore -Name Kernel32 -MemberDefinition '[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern bool MoveFileEx(string from, string to, int flags);' | ||
| } | ||
| @(Get-ChildItem -LiteralPath $r -Recurse -Force) + @(Get-Item -LiteralPath $r) | Sort-Object { $_.FullName.Length } -Descending | ForEach-Object { [CleanCore.Kernel32]::MoveFileEx($_.FullName, [NullString]::Value, 4) | Out-Null } | ||
| 'REBOOT' | ||
| } | ||
|
|
@@ -249,6 +270,9 @@ foreach ($k in 'HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components', 'HK | |
| Remove-Item "$k\{9459C573-B17A-45AE-9F64-1857B5D58CEE}" -Recurse -Force | ||
| } | ||
|
|
||
| # The Edge installer Edge Update downloaded for its next update (Edge's app id only). | ||
| Remove-Item "${env:ProgramFiles(x86)}\Microsoft\EdgeUpdate\Download\{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}" -Recurse -Force | ||
|
|
||
| # Its Store placeholder and shortcuts. | ||
| Get-AppxPackage -AllUsers 'Microsoft.MicrosoftEdge.Stable' | Remove-AppxPackage -AllUsers | ||
| Remove-Item "$env:PUBLIC\Desktop\Microsoft Edge.lnk", "$env:USERPROFILE\Desktop\Microsoft Edge.lnk", "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk" -Force | ||
|
|
@@ -259,11 +283,11 @@ const EDGE_BLOCK: &str = r#" | |
| $ErrorActionPreference = 'SilentlyContinue' | ||
| # Microsoft's blocker for the automatic switch to the new Edge. | ||
| $eu = 'HKLM:\SOFTWARE\Microsoft\EdgeUpdate' | ||
| New-Item $eu -Force | Out-Null | ||
| if (-not (Test-Path $eu)) { New-Item $eu -Force | Out-Null } | ||
| Set-ItemProperty $eu -Name DoNotUpdateToEdgeWithChromium -Value 1 -Type DWord | ||
| # Edge Update policies: don't install Edge, nor put its shortcut on the desktop. | ||
| $pol = 'HKLM:\SOFTWARE\Policies\Microsoft\EdgeUpdate' | ||
| New-Item $pol -Force | Out-Null | ||
| if (-not (Test-Path $pol)) { New-Item $pol -Force | Out-Null } | ||
| Set-ItemProperty $pol -Name 'Install{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}' -Value 0 -Type DWord | ||
| Set-ItemProperty $pol -Name 'CreateDesktopShortcut{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}' -Value 0 -Type DWord | ||
| # Edge Update off: its services and scheduled tasks are disabled, not deleted (Allow turns them | ||
|
|
@@ -325,7 +349,7 @@ pub fn uninstall_edge() -> Result<bool> { | |
|
|
||
| /// Run `EDGE_REMOVE`; true when some files are deleted at the next restart. | ||
| fn remove_edge() -> Result<bool> { | ||
| Ok(ps(&format!("{AUTOSTART}{EDGE_REMOVE}"))?.lines().any(|l| l.trim() == "REBOOT")) | ||
| Ok(ps(&format!("{AUTOSTART}{RUN}{EDGE_REMOVE}"))?.lines().any(|l| l.trim() == "REBOOT")) | ||
| } | ||
|
|
||
| /// Remove the app and block it from coming back. Keeps the daily check running. | ||
|
|
@@ -345,7 +369,7 @@ pub fn remove(app: App) -> Result<String> { | |
| None | ||
| } | ||
| App::OneDrive => { | ||
| ps(ONEDRIVE_REMOVE)?; | ||
| ps(&format!("{RUN}{ONEDRIVE_REMOVE}"))?; | ||
| let old = ps(&format!("{AUTOSTART}{ONEDRIVE_BLOCK}"))?.trim().to_string(); | ||
| // Keep an entry saved by an earlier removal: this run found it already gone. | ||
| Some(old).filter(|s| !s.is_empty()).or_else(|| k.get(app).and_then(|r| r.default_run.clone())) | ||
|
|
@@ -458,11 +482,24 @@ mod tests { | |
| assert!(!EDGE_REMOVE.contains("sc.exe delete edgeupdate")); | ||
| } | ||
|
|
||
| /// `New-Item -Force` on a registry key that exists empties it (values and subkeys), so a | ||
| /// key is only ever created when it is missing; and no uninstaller is waited for with | ||
| /// `Start-Process -Wait`, which also waits for whatever it leaves running. | ||
| #[test] | ||
| fn keeps_existing_keys_and_waits_for_the_uninstaller_only() { | ||
| for s in [AUTOSTART, RUN, EDGE_REMOVE, EDGE_BLOCK, EDGE_ALLOW, ONEDRIVE_REMOVE, ONEDRIVE_BLOCK, ONEDRIVE_ALLOW] { | ||
| for line in s.lines().filter(|l| l.contains("New-Item") && !l.contains("-ItemType")) { | ||
| assert!(line.contains("if (-not (Test-Path "), "{line}"); | ||
| } | ||
| assert!(!s.contains("-Wait"), "{s}"); | ||
| } | ||
| } | ||
|
|
||
| /// The scripts parse (PowerShell's own parser: nothing runs). | ||
| #[test] | ||
| #[cfg(windows)] | ||
| fn scripts_parse() { | ||
| for s in [AUTOSTART, EDGE_REMOVE, EDGE_BLOCK, EDGE_ALLOW, ONEDRIVE_REMOVE, ONEDRIVE_BLOCK, ONEDRIVE_ALLOW] { | ||
| for s in [AUTOSTART, RUN, EDGE_REMOVE, EDGE_BLOCK, EDGE_ALLOW, ONEDRIVE_REMOVE, ONEDRIVE_BLOCK, ONEDRIVE_ALLOW] { | ||
| let check = "$e = $null; [void][System.Management.Automation.Language.Parser]::ParseInput($env:CLEANCORE_SCRIPT, [ref]$null, [ref]$e); if ($e) { $e | ForEach-Object { $_.Message }; exit 1 }"; | ||
| let o = std::process::Command::new("powershell").args(["-NoProfile", "-NonInteractive", "-Command", check]).env("CLEANCORE_SCRIPT", s).output().unwrap(); | ||
| assert!(o.status.success(), "{}\n{s}", String::from_utf8_lossy(&o.stdout)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Show keyboard focus on the buttons.
Sense::click()makes these buttons keyboard-focusable, but their painting only responds to hover. (docs.rs) Keyboard users cannot see which action will activate. Draw a visible focus state whenr.has_focus()is true.