-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ViniciusDeep/feature/homePage
[Feature] Home page
- Loading branch information
Showing
19 changed files
with
739 additions
and
57 deletions.
There are no files selected for viewing
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,26 @@ | ||
# This workflow will build a Swift project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift | ||
|
||
name: Run Unit Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: macos-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Swift | ||
uses: swift-actions/setup-swift@v1 | ||
with: | ||
swift-version: '5.5' | ||
|
||
- name: Run tests | ||
run: swift test | ||
|
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,36 @@ | ||
# Xcode | ||
.DS_Store | ||
*/.DS_Store | ||
*.xcuserstate | ||
*.xcworkspace | ||
xcuserdata/ | ||
|
||
# Build products | ||
/build/ | ||
DerivedData/ | ||
*.build/ | ||
|
||
# Dependency directories | ||
Pods/ | ||
Carthage/Build/ | ||
|
||
# Swift Package Manager | ||
.build/ | ||
|
||
# IDE files | ||
*.swiftpm | ||
.idea/ | ||
*.pbxuser | ||
*.mode1v3 | ||
*.mode2v3 | ||
*.perspective | ||
*.perspectivev3 | ||
|
||
# macOS specific files | ||
.DS_Store | ||
profile | ||
|
||
# Miscellaneous | ||
*.log | ||
*.xccheckout | ||
|
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
6 changes: 6 additions & 0 deletions
6
...r.xcodeproj/xcuserdata/viniciusmangueira.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Bucket | ||
uuid = "A89C2A97-62B1-492F-BC76-6F7147D4BA49" | ||
type = "1" | ||
version = "2.0"> | ||
</Bucket> |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright © 2024 MacCleaner, LLC. All rights reserved. | ||
|
||
import Foundation | ||
|
||
struct FileDetail: Identifiable { | ||
let id = UUID() | ||
let name: String | ||
let size: Int64 | ||
let modificationDate: Date | ||
} | ||
|
||
func findLargeAndOldFiles(in directory: String, largerThan size: Int64, olderThan days: Int) -> [FileDetail] { | ||
var results = [FileDetail]() | ||
let fileManager = FileManager.default | ||
let calendar = Calendar.current | ||
let dateThreshold = calendar.date(byAdding: .day, value: -days, to: Date())! | ||
|
||
do { | ||
let urls = try fileManager.contentsOfDirectory( | ||
at: URL(fileURLWithPath: directory), | ||
includingPropertiesForKeys: [.fileSizeKey, .contentModificationDateKey], | ||
options: .skipsHiddenFiles | ||
) | ||
|
||
for url in urls { | ||
let resourceValues = try url.resourceValues(forKeys: [.fileSizeKey, .contentModificationDateKey]) | ||
if let fileSize = resourceValues.fileSize, let modificationDate = resourceValues.contentModificationDate { | ||
if fileSize > size, modificationDate < dateThreshold { | ||
results.append(FileDetail( | ||
name: url.lastPathComponent, | ||
size: Int64(fileSize), | ||
modificationDate: modificationDate | ||
)) | ||
} | ||
} | ||
} | ||
} catch { | ||
print("Error while enumerating files \(directory): \(error.localizedDescription)") | ||
} | ||
|
||
return results | ||
} |
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,31 @@ | ||
// Copyright © 2024 MacCleaner, LLC. All rights reserved. | ||
|
||
import Foundation | ||
|
||
struct StorageInfo { | ||
var totalSpace: Int64 | ||
var freeSpace: Int64 | ||
var usedSpace: Int64 | ||
} | ||
|
||
func getStorageInfo() -> StorageInfo? { | ||
if let homeDirectory = try? FileManager.default.url( | ||
for: .userDirectory, | ||
in: .localDomainMask, | ||
appropriateFor: nil, | ||
create: false | ||
) { | ||
do { | ||
let attributes = try FileManager.default.attributesOfFileSystem(forPath: homeDirectory.path) | ||
if let totalSpace = attributes[.systemSize] as? Int64, | ||
let freeSpace = attributes[.systemFreeSize] as? Int64 | ||
{ | ||
let usedSpace = totalSpace - freeSpace | ||
return StorageInfo(totalSpace: totalSpace, freeSpace: freeSpace, usedSpace: usedSpace) | ||
} | ||
} catch { | ||
print("Error retrieving storage information: \(error.localizedDescription)") | ||
} | ||
} | ||
return nil | ||
} |
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,24 @@ | ||
// Copyright © 2024 MacCleaner, LLC. All rights reserved. | ||
|
||
import Foundation | ||
|
||
func performSystemCleanup() -> Bool { | ||
let tempDirectories = [ | ||
NSTemporaryDirectory(), | ||
"/var/folders", | ||
] | ||
|
||
do { | ||
for dir in tempDirectories { | ||
let files = try FileManager.default.contentsOfDirectory(atPath: dir) | ||
for file in files { | ||
let filePath = (dir as NSString).appendingPathComponent(file) | ||
try FileManager.default.removeItem(atPath: filePath) | ||
} | ||
} | ||
return true | ||
} catch { | ||
print("Error during cleanup: \(error.localizedDescription)") | ||
return false | ||
} | ||
} |
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,75 @@ | ||
// Copyright © 2023 Wendy's International, LLC. All rights reserved. | ||
|
||
import Foundation | ||
|
||
class SystemMonitorHelper { | ||
static func getCPUUsage() -> Double { | ||
var cpuInfo: processor_info_array_t! | ||
var numCPUs: mach_msg_type_number_t = 0 | ||
var prevIdleTicks: UInt64 = 0 | ||
var prevTotalTicks: UInt64 = 0 | ||
|
||
var numCPUsCopy = numCPUs | ||
|
||
let err = host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numCPUs, &cpuInfo, &numCPUsCopy) | ||
if err == KERN_SUCCESS { | ||
let cpuLoadInfo = cpuInfo! | ||
.withMemoryRebound(to: Int32.self, capacity: Int(numCPUsCopy)) { ptr in | ||
ptr | ||
} | ||
var totalTicks: UInt64 = 0 | ||
var idleTicks: UInt64 = 0 | ||
for cpu in 0 ..< Int(numCPUsCopy) { | ||
totalTicks += UInt64(cpuLoadInfo[cpu]) | ||
} | ||
idleTicks = UInt64(cpuLoadInfo[Int(CPU_STATE_IDLE)]) | ||
let totalTicksDiff = Double(totalTicks - prevTotalTicks) | ||
let idleTicksDiff = Double(idleTicks - prevIdleTicks) | ||
let usage = (totalTicksDiff - idleTicksDiff) / totalTicksDiff * 100.0 | ||
prevIdleTicks = idleTicks | ||
prevTotalTicks = totalTicks | ||
return usage | ||
} else { | ||
print("Error getting CPU usage: \(String(describing: mach_error_string(err)))") | ||
return 0.0 | ||
} | ||
} | ||
|
||
static func getMemoryUsage() -> Double { | ||
var taskInfo = mach_task_basic_info() | ||
var count = mach_msg_type_number_t(MemoryLayout<mach_task_basic_info>.size / MemoryLayout<integer_t>.size) | ||
let kerr: kern_return_t = withUnsafeMutablePointer(to: &taskInfo) { | ||
$0.withMemoryRebound(to: integer_t.self, capacity: 1) { | ||
task_info( | ||
mach_task_self_, | ||
task_flavor_t(MACH_TASK_BASIC_INFO), | ||
$0, | ||
&count | ||
) | ||
} | ||
} | ||
if kerr == KERN_SUCCESS { | ||
let usedMemory = taskInfo.resident_size | ||
let totalMemory = ProcessInfo.processInfo.physicalMemory | ||
return Double(usedMemory) / Double(totalMemory) * 100.0 | ||
} else { | ||
print("Error getting memory usage: \(String(describing: mach_error_string(kerr)))") | ||
return 0.0 | ||
} | ||
} | ||
|
||
static func getDiskUsage() -> Double { | ||
do { | ||
let systemAttributes = try FileManager.default.attributesOfFileSystem(forPath: "/") | ||
if let totalSize = systemAttributes[.systemSize] as? Int64, | ||
let freeSize = systemAttributes[.systemFreeSize] as? Int64 | ||
{ | ||
let usedSize = totalSize - freeSize | ||
return Double(usedSize) / Double(totalSize) * 100.0 | ||
} | ||
} catch { | ||
print("Error getting disk usage: \(error.localizedDescription)") | ||
} | ||
return 0.0 | ||
} | ||
} |
Oops, something went wrong.