Skip to content

Commit

Permalink
新增性能选项
Browse files Browse the repository at this point in the history
  • Loading branch information
Lessica committed Jan 1, 2024
1 parent f4574cf commit 84a3b03
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 39 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

Reveil is a replication of [Unveil](https://unveilapp.com) in pure SwiftUI.

**IMPORTANT**: iOS 15 and above is required.

> Currently, Reveil is in early development, and we are working hard to make it better.
![Screenshot](./Artworks/Screenshot.png)

## Why we developed this again?
Expand Down
8 changes: 8 additions & 0 deletions Reveil.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
0FA065812B3D83E6000A7ECE /* ObjCClassItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F16593C2AFA702C00268572 /* ObjCClassItem.swift */; };
0FA065822B3D83E6000A7ECE /* URLSchemeItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F1659392AF9FD4500268572 /* URLSchemeItem.swift */; };
0FA065852B3D8436000A7ECE /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = 0FA065842B3D8436000A7ECE /* ArgumentParser */; };
0FA065872B42803B000A7ECE /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 0FA065862B42803B000A7ECE /* Settings.bundle */; };
0FA065892B4282BC000A7ECE /* StandardUserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FA065882B4282BC000A7ECE /* StandardUserDefaults.swift */; };
0FD0D2682AE0CB27001DD1E8 /* Entry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FD0D2672AE0CB27001DD1E8 /* Entry.swift */; };
0FD0D26A2AE0CD95001DD1E8 /* Dashboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FD0D2692AE0CD95001DD1E8 /* Dashboard.swift */; };
0FD0D26C2AE0D39C001DD1E8 /* EntryExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0FD0D26B2AE0D39C001DD1E8 /* EntryExporter.swift */; };
Expand Down Expand Up @@ -222,6 +224,8 @@
0F7E1A582AD5976A0016F31A /* NetworkUsageListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkUsageListView.swift; sourceTree = "<group>"; };
0FA065782B3D8363000A7ECE /* ReveilHelper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ReveilHelper; sourceTree = BUILT_PRODUCTS_DIR; };
0FA0657A2B3D8363000A7ECE /* PresetsHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresetsHelper.swift; sourceTree = "<group>"; };
0FA065862B42803B000A7ECE /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
0FA065882B4282BC000A7ECE /* StandardUserDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardUserDefaults.swift; sourceTree = "<group>"; };
0FD0D2672AE0CB27001DD1E8 /* Entry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Entry.swift; sourceTree = "<group>"; };
0FD0D2692AE0CD95001DD1E8 /* Dashboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dashboard.swift; sourceTree = "<group>"; };
0FD0D26B2AE0D39C001DD1E8 /* EntryExporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryExporter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -408,6 +412,7 @@
0F4955F42ADAD2F200227265 /* DefaultsWriter.swift */,
0F4955F52ADAD2F200227265 /* PropertyListRepresentable.swift */,
0F4955F32ADAD2F200227265 /* AppCodableStorage.swift */,
0FA065882B4282BC000A7ECE /* StandardUserDefaults.swift */,
);
path = Storage;
sourceTree = "<group>";
Expand Down Expand Up @@ -492,6 +497,7 @@
CC21B5242ACD4B87003EC114 /* rsc-005-ipad-models.json */,
CC21B5252ACD4B87003EC114 /* rsc-006-ipod-models.json */,
0F0819372ADAE97200BB626C /* PinStorage.plist */,
0FA065862B42803B000A7ECE /* Settings.bundle */,
);
path = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -891,6 +897,7 @@
CC21B4BD2ACAE5E5003EC114 /* Localizable.strings in Resources */,
CC21B52A2ACD4B87003EC114 /* rsc-005-ipad-models.json in Resources */,
0F0819382ADAE97200BB626C /* PinStorage.plist in Resources */,
0FA065872B42803B000A7ECE /* Settings.bundle in Resources */,
CC4AE2BC2ACAA4B500DA23AC /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -976,6 +983,7 @@
CCA095F92AEE219300F5E55F /* CheckResult.swift in Sources */,
0F16593D2AFA702C00268572 /* ObjCClassItem.swift in Sources */,
0F4955DE2AD83A3800227265 /* NetworkDetailsListView.swift in Sources */,
0FA065892B4282BC000A7ECE /* StandardUserDefaults.swift in Sources */,
CC21B5492ACE809D003EC114 /* MemoryInformation.swift in Sources */,
0F4955F62ADAD2F200227265 /* DefaultsKeyObservation.swift in Sources */,
CC21B4EA2ACB1E9E003EC114 /* TrafficWidget.swift in Sources */,
Expand Down
49 changes: 49 additions & 0 deletions Reveil/Resources/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>Performance</string>
<key>FooterText</key>
<string>Restart “Reveil” to make things happen.</string>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Animated Text</string>
<key>Key</key>
<string>AnimatedText</string>
<key>DefaultValue</key>
<true/>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Animated Background</string>
<key>Key</key>
<string>AnimatedBackground</string>
<key>DefaultValue</key>
<true/>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Limit Frame Rate to 30</string>
<key>Key</key>
<string>LowFrameRate</string>
<key>DefaultValue</key>
<false/>
</dict>
</array>
</dict>
</plist>
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions Reveil/Storage/AppCodableStorage.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// AppCodableStorage.swift
// Reveil
//
// Created by Lessica on 2023/10/14.
//

import SwiftUI

@MainActor
Expand Down
7 changes: 7 additions & 0 deletions Reveil/Storage/DefaultsKeyObservation.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// DefaultsKeyObservation.swift
// Reveil
//
// Created by Lessica on 2023/10/14.
//

import Foundation

/// API to observe UserDefaults with a `String` key (not `KeyPath`), as `AppStorage` and `.string( forKey:)` use
Expand Down
7 changes: 7 additions & 0 deletions Reveil/Storage/DefaultsWriter.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// DefaultsWriter.swift
// Reveil
//
// Created by Lessica on 2023/10/14.
//

import Combine
import Foundation

Expand Down
7 changes: 7 additions & 0 deletions Reveil/Storage/PropertyListRepresentable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// PropertyListRepresentable.swift
// Reveil
//
// Created by Lessica on 2023/10/14.
//

import DictionaryCoder
import Foundation

Expand Down
36 changes: 36 additions & 0 deletions Reveil/Storage/StandardUserDefaults.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// StandardUserDefaults.swift
// Reveil
//
// Created by Lessica on 2024/1/1.
//

import Foundation

private let gDefaultsKeyAnimatedText = "AnimatedText"
private let gDefaultsKeyAnimatedBackground = "AnimatedBackground"
private let gDefaultsKeyLowFrameRate = "LowFrameRate"

class StandardUserDefaults {
static let shared = StandardUserDefaults()

private init() {
UserDefaults.standard.register(defaults: [
gDefaultsKeyAnimatedText: true,
gDefaultsKeyAnimatedBackground: true,
gDefaultsKeyLowFrameRate: false,
])
}

lazy var isAnimatedTextEnabled: Bool = {
UserDefaults.standard.bool(forKey: gDefaultsKeyAnimatedText)
}()

lazy var isAnimatedBackgroundEnabled: Bool = {
UserDefaults.standard.bool(forKey: gDefaultsKeyAnimatedBackground)
}()

lazy var isLowFrameRateEnabled: Bool = {
UserDefaults.standard.bool(forKey: gDefaultsKeyLowFrameRate)
}()
}
16 changes: 12 additions & 4 deletions Reveil/Views/AnimatedText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ struct AnimatedText: View {
self.text = text
}

var isAnimatedTextEnabled: Bool {
StandardUserDefaults.shared.isAnimatedTextEnabled && !ProcessInfo.processInfo.isLowPowerModeEnabled
}

var body: some View {
if #available(iOS 16.0, *) {
Text(text)
.contentTransition(.numericText())
.animation(.spring(duration: 0.2), value: text)
if isAnimatedTextEnabled {
if #available(iOS 17.0, *) {
Text(text)
.contentTransition(.numericText())
.animation(.spring(duration: 0.2), value: text)
} else {
Text(text)
}
} else {
Text(text)
}
Expand Down
41 changes: 26 additions & 15 deletions Reveil/Views/ColorfulBackground.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,37 @@
import ColorfulX
import SwiftUI


struct ColorfulBackground: View {
@Environment(\.colorScheme) var colorScheme

var isAnimatedBackgroundEnabled: Bool {
StandardUserDefaults.shared.isAnimatedBackgroundEnabled && !ProcessInfo.processInfo.isLowPowerModeEnabled
}

var isLowFrameRateEnabled: Bool = StandardUserDefaults.shared.isLowFrameRateEnabled

var colorfulView: some View {
if colorScheme == .light {
ColorfulView(
color: .constant(ColorfulPreset.winter.colors),
speed: isAnimatedBackgroundEnabled ? .constant(0.5) : .constant(0),
frameLimit: isLowFrameRateEnabled ? 30 : 60
)
.opacity(0.5)
} else {
ColorfulView(
color: .constant(ColorfulPreset.aurora.colors),
speed: isAnimatedBackgroundEnabled ? .constant(0.5) : .constant(0),
frameLimit: isLowFrameRateEnabled ? 30 : 60
)
.opacity(0.25)
}
}

var body: some View {
Group {
if colorScheme == .light { // recreate pls
ColorfulView(
color: .constant(ColorfulPreset.winter.colors),
speed: .constant(0.5),
frameLimit: 60
)
.opacity(0.5)
} else {
ColorfulView(
color: .constant(ColorfulPreset.aurora.colors),
speed: .constant(0.5),
frameLimit: 60
)
.opacity(0.25)
}
self.colorfulView
}
.background(Color(PlatformColor.systemBackground))
.ignoresSafeArea()
Expand Down
43 changes: 23 additions & 20 deletions Reveil/Views/Dashboard/CheckmarkWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
// Created by Lessica on 2023/10/3.
//

import ColorfulX
import SwiftUI

struct CheckmarkWidget: View {
@StateObject var securityModel: Security = .shared
@State var openDetail: Bool = false

var isAnimatedBackgroundEnabled: Bool {
StandardUserDefaults.shared.isAnimatedBackgroundEnabled && !ProcessInfo.processInfo.isLowPowerModeEnabled
}

var isLowFrameRateEnabled: Bool = StandardUserDefaults.shared.isLowFrameRateEnabled

var label: String { securityModel.description }
var isLoading: Bool { securityModel.isLoading }
var isInsecure: Bool { securityModel.isInsecure }
Expand All @@ -25,17 +32,19 @@ struct CheckmarkWidget: View {
).capitalized
}

var backgroundColor: Color {
if isInsecure { return Color("SecurityLeaks") }
return Color(PlatformColor.secondarySystemBackgroundAlias)
}

var labelColor: Color {
return isInsecure ? .white : .primary
var animatedBackgroundColors: [Color] {
if isLoading { return ColorfulPreset.aurora.colors }
if isInsecure { return [.red, .pink, .red, .pink] }
return [.accent, .accent, .accent, .accent]
}

var descriptionColor: Color {
return isInsecure ? .white : .accent
var colorfulBackground: some View {
ColorfulView(
color: .init(get: { animatedBackgroundColors }, set: { _ in }),
speed: isAnimatedBackgroundEnabled ? .constant(0.5) : .constant(0),
transitionInterval: isAnimatedBackgroundEnabled ? .constant(1) : .constant(0),
frameLimit: isLowFrameRateEnabled ? 30 : 60
)
}

var body: some View {
Expand All @@ -51,7 +60,6 @@ struct CheckmarkWidget: View {
.font(Font.system(.body).weight(.regular))
}
}
.foregroundColor(labelColor)

HStack {
Image(systemName: isLoading ? "magnifyingglass.circle.fill" : (isInsecure ? "xmark.circle.fill" : "checkmark.circle.fill"))
Expand All @@ -61,19 +69,14 @@ struct CheckmarkWidget: View {
.lineLimit(1)
Spacer()
}
.foregroundColor(descriptionColor)
}
.foregroundColor(.white)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.all, 12)
.background(
RoundedRectangle(cornerRadius: 4)
.foregroundColor(backgroundColor)
.opacity(isInsecure ? 0.75 : 0.25)
)
.overlay {
RoundedRectangle(cornerRadius: 4)
.stroke(Color(PlatformColor.separatorAlias), lineWidth: 1)
.opacity(isInsecure ? 0 : 1)
.background {
self.colorfulBackground
.opacity(0.75)
.clipShape(RoundedRectangle(cornerRadius: 4))
}
.onChange(of: isLoading) { _ in
if isLoading { openDetail = false }
Expand Down

0 comments on commit 84a3b03

Please sign in to comment.