Skip to content

Commit

Permalink
add new module: screen
Browse files Browse the repository at this point in the history
Signed-off-by: Lessica <wuzheng28@huawei.com>
  • Loading branch information
Lessica committed Feb 2, 2024
1 parent 1c1cfbd commit 1ccb0be
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 78 deletions.
12 changes: 6 additions & 6 deletions .bartycrouch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tasks = ["interfaces", "code", "transform", "normalize"]

[update.interfaces]
paths = ["."]
paths = ["Reveil"]
subpathsToIgnore = [".git", "carthage", "pods", "build", ".build", "docs"]
defaultToBase = false
ignoreEmptyStrings = false
Expand All @@ -12,7 +12,7 @@ ignoreKeys = ["#bartycrouch-ignore!", "#bc-ignore!", "#i!"]
[update.code]
codePaths = ["."]
subpathsToIgnore = [".git", "carthage", "pods", "build", ".build", "docs"]
localizablePaths = ["."]
localizablePaths = ["Reveil"]
defaultToKeys = false
additive = false
customFunction = "LocalizedStringResource"
Expand All @@ -22,25 +22,25 @@ ignoreKeys = ["#bartycrouch-ignore!", "#bc-ignore!", "#i!"]
overrideComments = false

[update.transform]
codePaths = ["."]
codePaths = ["Reveil"]
subpathsToIgnore = [".git", "carthage", "pods", "build", ".build", "docs"]
localizablePaths = ["."]
localizablePaths = ["Reveil"]
transformer = "foundation"
supportedLanguageEnumPath = "."
typeName = "BartyCrouch"
translateMethodName = "translate"
separateWithEmptyLine = true

[update.normalize]
paths = ["."]
paths = ["Reveil"]
subpathsToIgnore = [".git", "carthage", "pods", "build", ".build", "docs"]
sourceLocale = "en"
harmonizeWithSource = true
sortByKeys = true
separateWithEmptyLine = true

[lint]
paths = ["."]
paths = ["Reveil"]
subpathsToIgnore = [".git", "carthage", "pods", "build", ".build", "docs"]
duplicateKeys = true
emptyValues = true
8 changes: 8 additions & 0 deletions Reveil.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
0F08193A2ADAEA3400BB626C /* PinStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F0819392ADAEA3400BB626C /* PinStorage.swift */; };
0F08193D2ADAF1C600BB626C /* DictionaryCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 0F08193C2ADAF1C600BB626C /* DictionaryCoder */; };
0F08193F2ADEB35500BB626C /* EntryKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F08193E2ADEB35500BB626C /* EntryKey.swift */; };
0F0B385E2B6CAEFF00E2E1F2 /* ScreenInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F0B385D2B6CAEFF00E2E1F2 /* ScreenInformation.swift */; };
0F0B38602B6CAFFF00E2E1F2 /* ScreenInformationListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F0B385F2B6CAFFF00E2E1F2 /* ScreenInformationListView.swift */; };
0F1659342AF9FB5000268572 /* SecurityPresets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F1659332AF9FB5000268572 /* SecurityPresets.swift */; };
0F1659372AF9FCF600268572 /* PortItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F1659362AF9FCF600268572 /* PortItem.swift */; };
0F16593A2AF9FD4500268572 /* URLSchemeItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F1659392AF9FD4500268572 /* URLSchemeItem.swift */; };
Expand Down Expand Up @@ -206,6 +208,8 @@
0F0819372ADAE97200BB626C /* PinStorage.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = PinStorage.plist; sourceTree = "<group>"; };
0F0819392ADAEA3400BB626C /* PinStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinStorage.swift; sourceTree = "<group>"; };
0F08193E2ADEB35500BB626C /* EntryKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryKey.swift; sourceTree = "<group>"; };
0F0B385D2B6CAEFF00E2E1F2 /* ScreenInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenInformation.swift; sourceTree = "<group>"; };
0F0B385F2B6CAFFF00E2E1F2 /* ScreenInformationListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenInformationListView.swift; sourceTree = "<group>"; };
0F1659332AF9FB5000268572 /* SecurityPresets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecurityPresets.swift; sourceTree = "<group>"; };
0F1659362AF9FCF600268572 /* PortItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortItem.swift; sourceTree = "<group>"; };
0F1659392AF9FD4500268572 /* URLSchemeItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSchemeItem.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -517,6 +521,7 @@
isa = PBXGroup;
children = (
CC21B5302ACD5523003EC114 /* DeviceInformationListView.swift */,
0F0B385F2B6CAFFF00E2E1F2 /* ScreenInformationListView.swift */,
CC21B5342ACD6112003EC114 /* OperatingSystemListView.swift */,
CC21B53C2ACDA80F003EC114 /* CPUInformationListView.swift */,
CC21B54A2ACE8160003EC114 /* MemoryInformationListView.swift */,
Expand Down Expand Up @@ -604,6 +609,7 @@
isa = PBXGroup;
children = (
CC21B51D2ACD4AAB003EC114 /* DeviceInformation.swift */,
0F0B385D2B6CAEFF00E2E1F2 /* ScreenInformation.swift */,
CC21B5322ACD5FB9003EC114 /* OperatingSystem.swift */,
CC21B53A2ACDA7E1003EC114 /* CPUInformation.swift */,
CC21B5482ACE809D003EC114 /* MemoryInformation.swift */,
Expand Down Expand Up @@ -1028,11 +1034,13 @@
CCA095F52AED419B00F5E55F /* EmulatorChecker.swift in Sources */,
CC21B5572AD04EAB003EC114 /* NetworkInterfaces.swift in Sources */,
CC21B54D2ACF24E2003EC114 /* DiskSpace.swift in Sources */,
0F0B385E2B6CAEFF00E2E1F2 /* ScreenInformation.swift in Sources */,
0F2CA1282AE946B200C76A78 /* SecurityView.swift in Sources */,
CC3F94252B4C506B00E67A19 /* View+ListSectionSeparator.swift in Sources */,
0FD0D26C2AE0D39C001DD1E8 /* EntryExporter.swift in Sources */,
CC21B4CA2ACAF5DA003EC114 /* CPUActivity.swift in Sources */,
CC549F072AFA9F1800219CF8 /* EntryUpdater.swift in Sources */,
0F0B38602B6CAFFF00E2E1F2 /* ScreenInformationListView.swift in Sources */,
CC0052642B13458000DBF808 /* BatteryInformation.swift in Sources */,
CCA095ED2AED419B00F5E55F /* FishHookChecker.swift in Sources */,
CC21B52E2ACD4FD5003EC114 /* DetailsListView.swift in Sources */,
Expand Down
15 changes: 1 addition & 14 deletions Reveil/BartyCrouch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@ import Foundation

enum BartyCrouch {
enum SupportedLanguage: String {
// TODO: remove unsupported languages from the following cases list & add any missing languages
// case arabic = "ar"
case chineseSimplified = "zh-Hans"
// case chineseTraditional = "zh-Hant"
case english = "en"
// case french = "fr"
// case german = "de"
// case hindi = "hi"
// case italian = "it"
// case japanese = "ja"
// case korean = "ko"
// case malay = "ms"
// case portuguese = "pt-BR"
// case russian = "ru"
// case spanish = "es"
// case turkish = "tr"
case spanish = "es"
}

static func translate(key: String, translations: [SupportedLanguage: String], comment _: String? = nil) -> String {
Expand Down
37 changes: 37 additions & 0 deletions Reveil/Pages/Details/ScreenInformationListView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// ScreenInformationListView.swift
// Reveil
//
// Created by Lessica on 2023/10/4.
//

import SwiftUI

struct ScreenInformationListView: View, ModuleListView {
let module: Module = ScreenInformation.shared
let globalName: String = String(describing: ScreenInformation.self)

init() {}

init?(entryKey: EntryKey) {
guard module.updatableEntryKeys.contains(entryKey) else {
return nil
}
}

var body: some View {
DetailsListView(basicEntries: module.basicEntries)
.navigationTitle(module.moduleName)
}

func eventOccurred(globalTimer timer: GlobalTimer) { }
}

// MARK: - Previews

struct ScreenInformationListView_Previews: PreviewProvider {
static var previews: some View {
ScreenInformationListView()
.environmentObject(HighlightedEntryKey())
}
}
9 changes: 6 additions & 3 deletions Reveil/Pages/DetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ struct DetailsView: View {
static func createDetailsList() -> some View {
Group {
Group {
createEntry(title: DeviceInformation.shared.moduleName, icon: "desktopcomputer") {
DeviceInformationListView()
}
createEntry(title: Security.shared.moduleName, icon: "lock.shield") {
SecurityView()
}
createEntry(title: DeviceInformation.shared.moduleName, icon: "iphone") {
DeviceInformationListView()
}
createEntry(title: ScreenInformation.shared.moduleName, icon: "desktopcomputer") {
ScreenInformationListView()
}
createEntry(title: OperatingSystem.shared.moduleName, icon: "gearshape") {
OperatingSystemListView()
}
Expand Down
2 changes: 2 additions & 0 deletions Reveil/ViewModels/Dashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class Dashboard: ObservableObject {

var registeredModules: [Module] = [
DeviceInformation.shared,
ScreenInformation.shared,
OperatingSystem.shared,
CPUInformation.shared,
MemoryInformation.shared,
Expand All @@ -34,6 +35,7 @@ final class Dashboard: ObservableObject {

var registeredModuleListViewTypes: [any ModuleListView.Type] = [
DeviceInformationListView.self,
ScreenInformationListView.self,
OperatingSystemListView.self,
CPUInformationListView.self,
MemoryInformationListView.self,
Expand Down
2 changes: 2 additions & 0 deletions Reveil/ViewModels/Enums/EntryKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum EntryKey: Codable, Equatable, Hashable, RawRepresentable {
case BootromVersion
case RadioTech
case HostName

// Screen Information
case DisplayResolution
case ScreenPhysicalResolution
case ScreenPhysicalScale
Expand Down
55 changes: 0 additions & 55 deletions Reveil/ViewModels/Modules/DeviceInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,6 @@ final class DeviceInformation: Module {
return techName
}

private let mainScreen = UIScreen.main

private lazy var displaySizeDescription: String = {
let displayWidth = Int(mainScreen.fixedCoordinateSpace.bounds.width * mainScreen.scale)
let displayHeight = Int(mainScreen.fixedCoordinateSpace.bounds.height * mainScreen.scale)
return "\(displayWidth)×\(displayHeight)"
}()

private lazy var physicalSizeDescription: String = {
let physicalWidth = Int(mainScreen.nativeBounds.width)
let physicalHeight = Int(mainScreen.nativeBounds.height)
return "\(physicalWidth)×\(physicalHeight)"
}()

private lazy var logicalSizeDescription: String = {
let logicalWidth = Int(mainScreen.fixedCoordinateSpace.bounds.width)
let logicalHeight = Int(mainScreen.fixedCoordinateSpace.bounds.height)
return "\(logicalWidth)×\(logicalHeight)"
}()

lazy var basicEntries: [BasicEntry] = updatableEntryKeys.compactMap { basicEntry(key: $0) }

let usageEntry: UsageEntry<Double>? = nil
Expand All @@ -118,11 +98,6 @@ final class DeviceInformation: Module {
.BootromVersion,
.RadioTech,
.HostName,
.DisplayResolution,
.ScreenPhysicalResolution,
.ScreenPhysicalScale,
.ScreenLogicalResolution,
.ScreenLogicalScale,
]

func basicEntry(key: EntryKey, style _: ValueStyle = .detailed) -> BasicEntry? {
Expand Down Expand Up @@ -165,36 +140,6 @@ final class DeviceInformation: Module {
name: NSLocalizedString("HOST_NAME", comment: "Host Name"),
value: System.hostName() ?? BasicEntry.unknownValue
)
case .DisplayResolution:
return BasicEntry(
key: .DisplayResolution,
name: NSLocalizedString("DISPLAY_RESOLUTION", comment: "Display Resolution"),
value: displaySizeDescription
)
case .ScreenPhysicalResolution:
return BasicEntry(
key: .ScreenPhysicalResolution,
name: NSLocalizedString("SCREEN_PHYSICAL_RESOLUTION", comment: "Screen Physical Resolution"),
value: physicalSizeDescription
)
case .ScreenPhysicalScale:
return BasicEntry(
key: .ScreenPhysicalScale,
name: NSLocalizedString("SCREEN_PHYSICAL_SCALE", comment: "Screen Physical Scale"),
value: String(format: "%.3f", mainScreen.nativeScale)
)
case .ScreenLogicalResolution:
return BasicEntry(
key: .ScreenLogicalResolution,
name: NSLocalizedString("SCREEN_LOGICAL_RESOLUTION", comment: "Screen Logical Resolution"),
value: logicalSizeDescription
)
case .ScreenLogicalScale:
return BasicEntry(
key: .ScreenLogicalScale,
name: NSLocalizedString("SCREEN_LOGICAL_SCALE", comment: "Screen Logical Scale"),
value: String(format: "%.3f", mainScreen.scale)
)
default:
break
}
Expand Down
108 changes: 108 additions & 0 deletions Reveil/ViewModels/Modules/ScreenInformation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// ScreenInformation.swift
// Reveil
//
// Created by Lessica on 2023/10/4.
//

import UIKit

final class ScreenInformation: Module {
static let shared = ScreenInformation()
private init() {}

let moduleName = NSLocalizedString("SCREEN_INFORMATION", comment: "Screen Information")

private let mainScreen = UIScreen.main

private lazy var displaySizeDescription: String = {
let displayWidth = Int(mainScreen.fixedCoordinateSpace.bounds.width * mainScreen.scale)
let displayHeight = Int(mainScreen.fixedCoordinateSpace.bounds.height * mainScreen.scale)
return "\(displayWidth)×\(displayHeight)"
}()

private lazy var physicalSizeDescription: String = {
let physicalWidth = Int(mainScreen.nativeBounds.width)
let physicalHeight = Int(mainScreen.nativeBounds.height)
return "\(physicalWidth)×\(physicalHeight)"
}()

private lazy var logicalSizeDescription: String = {
let logicalWidth = Int(mainScreen.fixedCoordinateSpace.bounds.width)
let logicalHeight = Int(mainScreen.fixedCoordinateSpace.bounds.height)
return "\(logicalWidth)×\(logicalHeight)"
}()

lazy var basicEntries: [BasicEntry] = updatableEntryKeys.compactMap { basicEntry(key: $0) }

let usageEntry: UsageEntry<Double>? = nil

func reloadData() {}

func updateEntries() {
basicEntries.forEach { updateBasicEntry($0) }
}

let updatableEntryKeys: [EntryKey] = [
.DisplayResolution,
.ScreenPhysicalResolution,
.ScreenPhysicalScale,
.ScreenLogicalResolution,
.ScreenLogicalScale,
]

func basicEntry(key: EntryKey, style: ValueStyle = .detailed) -> BasicEntry? {
switch key {
case .DisplayResolution:
return BasicEntry(
key: .DisplayResolution,
name: NSLocalizedString("DISPLAY_RESOLUTION", comment: "Display Resolution"),
value: displaySizeDescription
)
case .ScreenPhysicalResolution:
return BasicEntry(
key: .ScreenPhysicalResolution,
name: style == .dashboard ? NSLocalizedString("SCREEN_PHYSICAL_RESOLUTION", comment: "Screen Physical Resolution") : NSLocalizedString("PHYSICAL_RESOLUTION", comment: "Physical Resolution"),
value: physicalSizeDescription
)
case .ScreenPhysicalScale:
return BasicEntry(
key: .ScreenPhysicalScale,
name: style == .dashboard ? NSLocalizedString("SCREEN_PHYSICAL_SCALE", comment: "Screen Physical Scale") : NSLocalizedString("PHYSICAL_SCALE", comment: "Physical Scale"),
value: String(format: "%.3f", mainScreen.nativeScale)
)
case .ScreenLogicalResolution:
return BasicEntry(
key: .ScreenLogicalResolution,
name: style == .dashboard ? NSLocalizedString("SCREEN_LOGICAL_RESOLUTION", comment: "Screen Logical Resolution") : NSLocalizedString("LOGICAL_RESOLUTION", comment: "Logical Resolution"),
value: logicalSizeDescription
)
case .ScreenLogicalScale:
return BasicEntry(
key: .ScreenLogicalScale,
name: style == .dashboard ? NSLocalizedString("SCREEN_LOGICAL_SCALE", comment: "Screen Logical Scale") : NSLocalizedString("LOGICAL_SCALE", comment: "Logical Scale"),
value: String(format: "%.3f", mainScreen.scale)
)
default:
break
}
return nil
}

func updateBasicEntry(_ basicEntry: BasicEntry, style _: ValueStyle = .detailed) {
switch basicEntry.key {
case .HostName:
basicEntry.value = System.hostName() ?? BasicEntry.unknownValue
default:
break
}
}

func usageEntry(key _: EntryKey, style _: ValueStyle = .detailed) -> UsageEntry<Double>? { nil }

func updateUsageEntry(_: UsageEntry<Double>, style _: ValueStyle) {}

func trafficEntryIO(key _: EntryKey, style _: ValueStyle) -> TrafficEntryIO? { nil }

func updateTrafficEntryIO(_: TrafficEntryIO, style _: ValueStyle) {}
}

0 comments on commit 1ccb0be

Please sign in to comment.