Skip to content

Commit

Permalink
Merge pull request #2 from strvcom/feature/universal-icon-support
Browse files Browse the repository at this point in the history
Universal icon support
  • Loading branch information
DanielCech authored Feb 6, 2023
2 parents 1ab61a6 + cd85e89 commit 6ff05a5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 17 deletions.
Binary file modified Bin/VersionIcon
Binary file not shown.
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
"version": "0.3.0"
}
},
{
"package": "Moderator",
"repositoryURL": "https://github.com/DanielCech/Moderator.git",
"state": {
"branch": "master",
"revision": "b9c7e870caba30204903cf768367b7a5dc4ae3fa",
"version": null
}
},
{
"package": "ScriptToolkit",
"repositoryURL": "https://github.com/DanielCech/ScriptToolkit.git",
Expand Down
10 changes: 8 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/JohnSundell/Files.git", from: "4.1.1"),
.package(url: "https://github.com/kareman/Moderator.git", from: "0.5.1"),
.package(url: "https://github.com/DanielCech/Moderator.git", from: "0.5.1"),
.package(url: "https://github.com/DanielCech/ScriptToolkit.git", .branch("master")),
.package(url: "https://github.com/kareman/SwiftShell.git", from: "5.0.1"),
.package(url: "https://github.com/kareman/FileSmith.git", from: "0.3.0"),
Expand All @@ -20,7 +20,13 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "VersionIcon",
dependencies: ["Files", "FileSmith", "SwiftShell", "ScriptToolkit", "Moderator"]),
dependencies: ["Files", "FileSmith", "SwiftShell", "ScriptToolkit", "Moderator"],
swiftSettings:
[
// Macro definition - uncomment only when debugging
// .define("DEBUGGING")
]
),
.testTarget(
name: "VersionIconTests",
dependencies: ["VersionIcon"]),
Expand Down
34 changes: 24 additions & 10 deletions Sources/VersionIcon/VersionIconDefinitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct IconMetadata: Codable {

func imageInfo(forSize size: String, scale: String) -> ImageInfo? {
for image in images {
if (image.size == size) && (image.scale == scale) {
if image.fits(size: size) && image.fits(scale: scale) {
return image
}
}
Expand All @@ -67,7 +67,17 @@ struct ImageInfo: Codable {
var size: String
var idiom: String
var filename: String?
var scale: String
var scale: String?

static let singleScale = "1x"

func fits(size: String) -> Bool {
self.size == size
}

func fits(scale: String?) -> Bool {
self.scale ?? ImageInfo.singleScale == scale
}
}


Expand All @@ -76,9 +86,9 @@ struct ImageInfo: Codable {
/// Getting information about the app with modified icon
func getAppSetup(scriptSetup: ScriptSetup) throws -> AppSetup {
#if DEBUGGING
let sourceRootPath = "/Users/danielcech/Documents/[Development]/[Projects]/harbor-iOS"
let projectDir = "/Users/danielcech/Documents/[Development]/[Projects]/harbor-iOS"
let infoPlistFile = "Harbor/Application/Info.plist"
let sourceRootPath = "/Users/danielcech/Documents/ios-project-template"
let projectDir = "/Users/danielcech/Documents/ios-project-template"
let infoPlistFile = "Example/Application/Info.plist"
#else
guard
let sourceRootPath = main.env["SRCROOT"],
Expand Down Expand Up @@ -124,9 +134,8 @@ func iconMetadata(iconFolder: Folder) throws -> IconMetadata {
return iconMetadata
}
catch {
print(error)
throw ScriptError.generalError(message: String(describing: error))
}
fatalError()
}

/// Get current version and build of the app in prefered format
Expand Down Expand Up @@ -204,8 +213,12 @@ func generateIcon(
// Resizing title
let resizedTitleImage = resizeImage(fileName: designStyle.title, size: newSize)

let iconImageData = try Data(contentsOf: URL(fileURLWithPath: originalAppIconFile.path))
guard let iconImage = NSImage(data: iconImageData) else { throw ScriptError.generalError(message: "Invalid image file") }
guard
let iconImageData = try? Data(contentsOf: URL(fileURLWithPath: originalAppIconFile.path)),
let iconImage = NSImage(data: iconImageData)
else {
return
}

var combinedImage = iconImage
if let unwrappedResizedRibbonImage = resizedRibbonImage {
Expand Down Expand Up @@ -252,7 +265,8 @@ func restoreIcon(
guard
let appIconFileName = appSetup.appIconContents.imageInfo(forSize: size, scale: scale)?.filename
else {
throw ScriptError.fileNotFound(message: "Target icon record with \(size):\(scale) not found in \(appSetup.appIconFolder.path) folder")
print(" Icon with size \(size):\(scale) not found")
return
}

let appIconFilePath = appSetup.appIconFolder.path.appendingPathComponent(path: appIconFileName)
Expand Down
18 changes: 18 additions & 0 deletions Sources/VersionIcon/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ do {
appSetup: appSetup
)

// Universal iOS marketing icon
try restoreIcon(
size: "1024x1024",
scale: "1x",
scriptSetup: scriptSetup,
appSetup: appSetup
)

exit(0)
}

Expand Down Expand Up @@ -187,6 +195,16 @@ do {
scriptSetup: scriptSetup,
appSetup: appSetup
)

// Universal iOS marketing icon
try generateIcon(
size: "1024x1024",
scale: "1x",
realSize: CGSize(width: 1024, height: 1024),
designStyle: designStyle,
scriptSetup: scriptSetup,
appSetup: appSetup
)

print("✅ Done")
}
Expand Down
6 changes: 2 additions & 4 deletions VersionIcon.podspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
Pod::Spec.new do |s|
s.name = 'VersionIcon'
s.module_name = 'VersionIcon'
s.version = '1.0.8'
s.version = '1.0.9'
s.summary = 'Script written in Swift that prepares the iOS app icon overlay with ribbon, build type and version (build) info'
s.homepage = 'https://github.com/DanielCech/VersionIcon'
s.license = 'MIT'
s.author = { "Daniel Cech" => "[email protected]" }
s.platform = :ios, '8.0'
s.ios.deployment_target = '8.0'
s.requires_arc = true
s.source = { :git => 'https://github.com/DanielCech/VersionIcon.git', :tag => s.version.to_s }
# s.source_files = 'Bin/**/*'
# s.resource_bundle = { 'PKHUDResources' => 'PKHUD/*.xcassets' }
s.source = { :git => 'https://github.com/strvcom/ios-version-icon.git', :tag => s.version.to_s }
s.preserve_paths = 'Bin/**/*'
s.swift_version = '4.0'
end
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /bin/bash
swift build
cp -rf .build/x86_64-apple-macosx/debug/VersionIcon Bin
cp -rf .build/arm64-apple-macosx/debug/VersionIcon Bin

0 comments on commit 6ff05a5

Please sign in to comment.