From 931b161d4f856e945e8d32c23c97d2ec66a65c61 Mon Sep 17 00:00:00 2001 From: Underthestars-zhy Date: Mon, 9 May 2022 19:00:04 +0800 Subject: [PATCH] high quality app icon --- IconChanger.xcodeproj/project.pbxproj | 8 +++---- IconChanger/IconList.swift | 33 ++++++++++++++++----------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/IconChanger.xcodeproj/project.pbxproj b/IconChanger.xcodeproj/project.pbxproj index 380ae45..9a825c2 100644 --- a/IconChanger.xcodeproj/project.pbxproj +++ b/IconChanger.xcodeproj/project.pbxproj @@ -331,7 +331,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_ASSET_PATHS = "\"IconChanger/Preview Content\""; DEVELOPMENT_TEAM = 44BN78992X; ENABLE_HARDENED_RUNTIME = YES; @@ -344,7 +344,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.1.2; + MARKETING_VERSION = 1.1.3; PRODUCT_BUNDLE_IDENTIFIER = com.zhuhaoyu.IconChanger; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -362,7 +362,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 6; DEVELOPMENT_ASSET_PATHS = "\"IconChanger/Preview Content\""; DEVELOPMENT_TEAM = 44BN78992X; ENABLE_HARDENED_RUNTIME = YES; @@ -375,7 +375,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.1.2; + MARKETING_VERSION = 1.1.3; PRODUCT_BUNDLE_IDENTIFIER = com.zhuhaoyu.IconChanger; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/IconChanger/IconList.swift b/IconChanger/IconList.swift index 133fa4c..718bfe1 100644 --- a/IconChanger/IconList.swift +++ b/IconChanger/IconList.swift @@ -45,21 +45,28 @@ struct IconList: View { } } else { ForEach(iconManager.apps, id: \.self) { app in - VStack { - Button { - setPath = app - } label: { - Image(nsImage: NSWorkspace.shared.icon(forFile: app)) - .resizable() - .scaledToFit() - .padding(.bottom) - } - .buttonStyle(BorderlessButtonStyle()) + if let rep = NSWorkspace.shared.icon(forFile: app) + .bestRepresentation(for: NSRect(x: 0, y: 0, width: 1024, height: 1024), context: nil, hints: nil) { + VStack { + Button { + setPath = app + } label: { + Image(nsImage: { () -> NSImage in + let image = NSImage(size: rep.size) + image.addRepresentation(rep) + return image + }()) + .resizable() + .scaledToFit() + .padding(.bottom) + } + .buttonStyle(BorderlessButtonStyle()) - Text(iconManager.getAppName(app)) - .multilineTextAlignment(.center) + Text(iconManager.getAppName(app)) + .multilineTextAlignment(.center) + } + .padding() } - .padding() } } }