1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-16 12:21:11 +00:00

fix(windows): address code review issues

- Fix openInExplorer to actually execute explorer.exe (was a no-op)
- Load System.Windows.Forms assembly before using Clipboard
- Use Remove-SafeItem in purge for consistent safety checks
- Fix Dropbox typo (was DroplboxCache)
This commit is contained in:
Bhadra
2026-01-08 20:08:41 +05:30
parent 34affd75c4
commit cfe8ea0724
4 changed files with 13 additions and 21 deletions

View File

@@ -473,20 +473,16 @@ function Remove-ProjectArtifacts {
foreach ($artifact in $project.Artifacts) { foreach ($artifact in $project.Artifacts) {
if (Test-Path $artifact.Path) { if (Test-Path $artifact.Path) {
try { # Use safe removal with protection checks
if ($artifact.Type -eq "Directory") { $result = Remove-SafeItem -Path $artifact.Path -Description $artifact.Name -Recurse
Remove-Item -Path $artifact.Path -Recurse -Force -ErrorAction Stop
}
else {
Remove-Item -Path $artifact.Path -Force -ErrorAction Stop
}
if ($result.Removed -gt 0) {
Write-Host " $esc[32m$($script:Icons.Success)$esc[0m $($artifact.Name) ($($artifact.SizeHuman))" Write-Host " $esc[32m$($script:Icons.Success)$esc[0m $($artifact.Name) ($($artifact.SizeHuman))"
$script:TotalSizeCleaned += $artifact.SizeKB $script:TotalSizeCleaned += $artifact.SizeKB
$script:ItemsCleaned++ $script:ItemsCleaned++
} }
catch { elseif ($result.Failed -gt 0) {
Write-Host " $esc[31m$($script:Icons.Error)$esc[0m $($artifact.Name) - $_" Write-Host " $esc[31m$($script:Icons.Error)$esc[0m $($artifact.Name) - removal failed"
} }
} }
} }

View File

@@ -7,6 +7,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort" "sort"
@@ -671,19 +672,11 @@ func truncatePath(path string, maxLen int) string {
// openInExplorer opens a path in Windows Explorer // openInExplorer opens a path in Windows Explorer
func openInExplorer(path string) { func openInExplorer(path string) {
// Use explorer.exe to open the path // Use explorer.exe to open the path
cmd := fmt.Sprintf("explorer.exe /select,\"%s\"", path)
go func() { go func() {
_ = runCommand("cmd", "/c", cmd) exec.Command("explorer.exe", "/select,", path).Run()
}() }()
} }
// runCommand runs a command and returns the output
func runCommand(name string, args ...string) error {
cmd := fmt.Sprintf("%s %s", name, strings.Join(args, " "))
_ = cmd
return nil
}
func main() { func main() {
var startPath string var startPath string

View File

@@ -207,7 +207,7 @@ function Clear-OneDriveCache {
} }
} }
function Clear-DroplboxCache { function Clear-DropboxCache {
<# <#
.SYNOPSIS .SYNOPSIS
Clean Dropbox cache Clean Dropbox cache
@@ -405,7 +405,7 @@ function Invoke-AppCleanup {
# Productivity apps # Productivity apps
Clear-OfficeCache Clear-OfficeCache
Clear-OneDriveCache Clear-OneDriveCache
Clear-DroplboxCache Clear-DropboxCache
Clear-GoogleDriveCache Clear-GoogleDriveCache
# Creative apps # Creative apps

View File

@@ -289,6 +289,9 @@ function Clear-ClipboardHistory {
} }
try { try {
# Load Windows Forms assembly for clipboard access
Add-Type -AssemblyName System.Windows.Forms -ErrorAction SilentlyContinue
# Clear current clipboard # Clear current clipboard
[System.Windows.Forms.Clipboard]::Clear() [System.Windows.Forms.Clipboard]::Clear()