Skip to content

Commit

Permalink
Merge pull request #1019 from kiwix/1018-get-the-logo-size-from-assets
Browse files Browse the repository at this point in the history
Get image size from assets, instead of hard coding it
  • Loading branch information
kelson42 authored Nov 2, 2024
2 parents fd1d20f + 6f3ba23 commit 7644188
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
9 changes: 2 additions & 7 deletions Model/Brand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ enum Brand {
static let appName: String = Config.value(for: .displayName) ?? "Kiwix"
static let appStoreId: String = Config.value(for: .appStoreID) ?? "id997079563"
static let loadingLogoImage: String = "welcomeLogo"
static let loadingLogoWidth: Int = Config.value(for: .logoWidth) ?? 192
static let loadingLogoHeight: Int = Config.value(for: .logoHeight) ?? 140
static var loadingLogoSize: CGSize {
CGSize(width: loadingLogoWidth, height: loadingLogoHeight)
}
static var loadingLogoSize: CGSize = ImageInfo.sizeOf(imageName: loadingLogoImage)!

static let aboutText: String = Config.value(for: .aboutText) ?? "settings.about.description".localized
static let aboutWebsite: String = Config.value(for: .aboutWebsite) ?? "https://www.kiwix.org"

Expand Down Expand Up @@ -84,8 +81,6 @@ enum Config: String {
case showSearchSnippetInSettings = "SETTINGS_SHOW_SEARCH_SNIPPET"
case aboutText = "CUSTOM_ABOUT_TEXT"
case aboutWebsite = "CUSTOM_ABOUT_WEBSITE"
case logoWidth = "LOGO_WIDTH"
case logoHeight = "LOGO_HEIGHT"

static func value<T>(for key: Config) -> T? where T: LosslessStringConvertible {
guard let object = Bundle.main.object(forInfoDictionaryKey: key.rawValue) else {
Expand Down
28 changes: 28 additions & 0 deletions Model/Utilities/ImageInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is part of Kiwix for iOS & macOS.
//
// Kiwix is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// any later version.
//
// Kiwix is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kiwix; If not, see https://www.gnu.org/licenses/.

import Foundation
import SwiftUI

enum ImageInfo {
static func sizeOf(imageName: String) -> CGSize? {
#if os(macOS)
NSImage(named: imageName)?.size
#else
guard let cgImage = UIImage(named: imageName)?.cgImage else { return nil }
return CGSize(width: cgImage.width, height: cgImage.height)
#endif
}
}

0 comments on commit 7644188

Please sign in to comment.