Skip to content

Commit

Permalink
Clover.app, conversion of icns image to png optimizing themes
Browse files Browse the repository at this point in the history
  • Loading branch information
vectorsigma72 committed Mar 8, 2020
1 parent c4da0ef commit bc29fe4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CloverApp/Clover/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,7 @@ extension io_object_t {
return nil
}
}

extension NSBitmapImageRep {
var png: Data? { representation(using: .png, properties: [:]) }
}
14 changes: 14 additions & 0 deletions CloverApp/Clover/ThemeManager/ThemeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,19 @@ final class ThemeManager: NSObject, URLSessionDataDelegate {
while let file = enumerator?.nextObject() as? String {
let fullPath = path.addPath(file)
if file.fileExtension == "png" || file.fileExtension == "icns" {
if let data = try? Data(contentsOf: URL(fileURLWithPath: fullPath)) {
if data[0] != 0x89 || data[0] != 0x50 || data[0] != 0x4E || data[0] != 0x47 {
// convert it to png
if let png = NSBitmapImageRep(data: data)?.png {
do {
try png.write(to: URL(fileURLWithPath: fullPath))
} catch {
err = error
return
}
}
}
}
do {
let data = try PNG8Image().png8ImageData(atPath: fullPath)
try data.write(to: URL(fileURLWithPath: fullPath))
Expand All @@ -500,3 +513,4 @@ final class ThemeManager: NSObject, URLSessionDataDelegate {
}

}

2 changes: 2 additions & 0 deletions CloverApp/Clover/ThemeManager/ThemeManagerVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ NSTableViewDelegate, NSTableViewDataSource, WebFrameLoadDelegate, WebUIDelegate
|| fm.fileExists(atPath: self.targetVolume!) {
let themePath = self.targetVolume!.addPath("EFI/CLOVER/themes").addPath(v.name)
if fm.fileExists(atPath: themePath) {
self.spinner.startAnimation(nil)
var error : Error? = nil
self.manager?.optimizeTheme(at: themePath, err: &error)
if (error != nil) {
Expand All @@ -238,6 +239,7 @@ NSTableViewDelegate, NSTableViewDataSource, WebFrameLoadDelegate, WebUIDelegate
}
return
}
self.spinner.stopAnimation(nil)
success = true
}
}
Expand Down

0 comments on commit bc29fe4

Please sign in to comment.