passepartout-apple/Passepartout/App/macOS/Global/Theme.swift

100 lines
2.9 KiB
Swift
Raw Normal View History

//
// Theme.swift
2021-01-01 16:53:28 +00:00
// Passepartout
//
// Created by Davide De Rosa on 7/29/18.
// Copyright (c) 2021 Davide De Rosa. All rights reserved.
//
// https://github.com/passepartoutvpn
//
// This file is part of Passepartout.
//
// Passepartout 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
// (at your option) any later version.
//
// Passepartout 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 Passepartout. If not, see <http://www.gnu.org/licenses/>.
//
import Cocoa
import PassepartoutCore
struct Theme {
struct Palette {
var colorPrimaryText: NSColor = .labelColor
var colorSecondaryText: NSColor = .secondaryLabelColor
var colorOff: NSColor = .red
var colorOn = NSColor(red: 0.0, green: 0.8, blue: 0.0, alpha: 1.0)
var colorIndeterminate: NSColor = .orange
var colorInline = NSColor(red: 0, green: 0.478431, blue: 1, alpha: 1)
}
static let current = Theme()
var palette: Palette
private init() {
palette = Palette()
}
}
// FIXME: load from index JSON
extension Infrastructure.Metadata {
var logo: NSImage? {
guard let image = ImageAsset.Image(named: name) else {
return Asset.Providers.placeholder.image
}
return image
}
2021-04-10 13:49:51 +00:00
var guidanceString: String? {
let prefix = "account.sections.guidance.footer.infrastructure"
let key = "\(prefix).\(name)"
var format = NSLocalizedString(key, tableName: "Core", bundle: Bundle(for: AppDelegate.self), comment: "")
// i.e. key not found
if format == key {
let purpose = name.credentialsPurpose
let defaultKey = "\(prefix).default.\(purpose)"
format = NSLocalizedString(defaultKey, tableName: "Core", bundle: Bundle(for: AppDelegate.self), comment: "")
2021-04-10 13:49:51 +00:00
}
2021-04-10 13:49:51 +00:00
return String(format: format, locale: .current, description)
}
}
extension ConnectionProfile {
var image: NSImage? {
if let profile = self as? ProviderConnectionProfile {
return profile.infrastructure.metadata?.logo
} else {
// return NSImage(named: NSImage.applicationIconName)//smartBadgeTemplateName)
return nil
}
}
}
extension PoolGroup {
var logo: NSImage? {
return ImageAsset(name: country.lowercased()).image
}
}
extension String {
var image: NSImage? {
return ImageAsset(name: lowercased()).image
}
}