Skip to content

Commit

Permalink
loginWindowBackgroundImageURL image should be cached if not a file://…
Browse files Browse the repository at this point in the history
… URL #72
  • Loading branch information
twocanoes committed Jan 2, 2024
1 parent cc322be commit b2cfd64
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 13 deletions.
26 changes: 24 additions & 2 deletions NSImage+String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,34 @@ extension NSImage {
}

if let pathURL = pathURL {

let applicationSupportPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .localDomainMask, true)
let cacheDir = applicationSupportPath[0] as NSString

let imageName = pathURL.lastPathComponent
let cacheFolder = cacheDir.appendingPathComponent("com.twocanoes.xcreds") as NSString

if FileManager.default.fileExists(atPath: cacheFolder as String) == false {

try? FileManager.default.createDirectory(atPath: cacheFolder as String, withIntermediateDirectories: true)


}
let imageFullPath = cacheFolder.appendingPathComponent(imageName) as NSString
if FileManager.default.fileExists(atPath: imageFullPath as String) == true {
let image = NSImage.init(contentsOfFile: imageFullPath as String)
return image

}
let image = NSImage.init(contentsOf: pathURL)

if let image = image {
let tiff = image.tiffRepresentation
if let tiff = tiff {
let url = URL(fileURLWithPath:imageFullPath as String)
try? tiff.write(to:url )
}
return image
// image.size=screenRect.size
// backgroundImageView.image = image
}
}

Expand Down
2 changes: 1 addition & 1 deletion Profile Manifest/com.twocanoes.xcreds.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>pfm_app_url</key>
<string>https://github.com/twocanoes/xcreds</string>
<key>pfm_description</key>
<string>XCreds 4.0 (6186) OAuth Settings</string>
<string>XCreds 4.0 (6202) OAuth Settings</string>
<key>pfm_documentation_url</key>
<string>https://twocanoes.com/knowledge-base/xcreds-admin-guide/#preferences</string>
<key>pfm_domain</key>
Expand Down
4 changes: 0 additions & 4 deletions XCreds/DefaultsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class DefaultsHelper: NSObject {
return coreServicesDefaultImage
}
if includeDefault == true {
// let allBundles = Bundle.allBundles
// for currentBundle in allBundles {
// TCSLogWithMark(currentBundle.bundlePath)
// if currentBundle.bundlePath.contains("XCreds"), let imagePath = currentBundle.path(forResource: "DefaultBackground", ofType: "png") {

let bundle = Bundle.findBundleWithName(name: "XCreds")

Expand Down
12 changes: 6 additions & 6 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6201;
CURRENT_PROJECT_VERSION = 6202;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1469,7 +1469,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6201;
CURRENT_PROJECT_VERSION = 6202;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1590,7 +1590,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6201;
CURRENT_PROJECT_VERSION = 6202;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1627,7 +1627,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6201;
CURRENT_PROJECT_VERSION = 6202;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1777,7 +1777,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6201;
CURRENT_PROJECT_VERSION = 6202;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1819,7 +1819,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6201;
CURRENT_PROJECT_VERSION = 6202;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,68 @@
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "C9707779-01DE-4228-A230-8E2BDD8251B0"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "NSImage+String.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
landmarkName = "imageFromPathOrURL(pathURLString:)"
landmarkType = "7">
<Locations>
<Location
uuid = "C9707779-01DE-4228-A230-8E2BDD8251B0 - d5fb76e3eb1aabac"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "static __C.NSImage.imageFromPathOrURL(pathURLString: Swift.String) -&gt; Swift.Optional&lt;__C.NSImage&gt;"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/NSImage+String.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
offsetFromSymbolStart = "1332">
</Location>
<Location
uuid = "C9707779-01DE-4228-A230-8E2BDD8251B0 - d5fb76e3eb1aabac"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "static __C.NSImage.imageFromPathOrURL(pathURLString: Swift.String) -&gt; Swift.Optional&lt;__C.NSImage&gt;"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/NSImage+String.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
offsetFromSymbolStart = "1380">
</Location>
<Location
uuid = "C9707779-01DE-4228-A230-8E2BDD8251B0 - d5fb76e3eb1aabac"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "static __C.NSImage.imageFromPathOrURL(pathURLString: Swift.String) -&gt; Swift.Optional&lt;__C.NSImage&gt;"
moduleName = "XCreds"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/tperfitt/Documents/Projects/xcreds/NSImage+String.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
offsetFromSymbolStart = "1072">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

0 comments on commit b2cfd64

Please sign in to comment.