Skip to content

Commit

Permalink
πŸ”€ Merge pull request #293 from MrKai77/refactor-settings
Browse files Browse the repository at this point in the history
πŸ’„ Refactor UI
  • Loading branch information
MrKai77 committed Mar 29, 2024
2 parents 7254096 + 7d3e954 commit bf022a1
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 87 deletions.
8 changes: 4 additions & 4 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
A8063A6E2B19599D00EAB3D9 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8063A6D2B19599D00EAB3D9 /* SettingsView.swift */; };
A8063A712B195C9100EAB3D9 /* SettingsAccess in Frameworks */ = {isa = PBXBuildFile; productRef = A8063A702B195C9100EAB3D9 /* SettingsAccess */; };
A8063A732B19891900EAB3D9 /* grid.metal in Sources */ = {isa = PBXBuildFile; fileRef = A8063A722B19891900EAB3D9 /* grid.metal */; };
A80900D42AA3F9F30085C63B /* BetaIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A80900D22AA3F9F20085C63B /* BetaIndicator.swift */; };
A80900D42AA3F9F30085C63B /* UnstableIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A80900D22AA3F9F20085C63B /* UnstableIndicator.swift */; };
A80900D52AA3F9F30085C63B /* VisualEffectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A80900D32AA3F9F20085C63B /* VisualEffectView.swift */; };
A80D49BB2BAE479900493B67 /* WindowAction+Port.swift in Sources */ = {isa = PBXBuildFile; fileRef = A80D49BA2BAE479900493B67 /* WindowAction+Port.swift */; };
A81989062AC8EDB300EFF7A1 /* MenuBarHeaderText.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81989052AC8EDB300EFF7A1 /* MenuBarHeaderText.swift */; };
Expand Down Expand Up @@ -102,7 +102,7 @@
A8055EC12AFEDE0B00459D13 /* Keycorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keycorder.swift; sourceTree = "<group>"; };
A8063A6D2B19599D00EAB3D9 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
A8063A722B19891900EAB3D9 /* grid.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = grid.metal; sourceTree = "<group>"; };
A80900D22AA3F9F20085C63B /* BetaIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BetaIndicator.swift; sourceTree = "<group>"; };
A80900D22AA3F9F20085C63B /* UnstableIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnstableIndicator.swift; sourceTree = "<group>"; };
A80900D32AA3F9F20085C63B /* VisualEffectView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VisualEffectView.swift; sourceTree = "<group>"; };
A80D49BA2BAE479900493B67 /* WindowAction+Port.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WindowAction+Port.swift"; sourceTree = "<group>"; };
A81989052AC8EDB300EFF7A1 /* MenuBarHeaderText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarHeaderText.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -205,7 +205,7 @@
A82436052B7EE55C0052FBFB /* CrispValueAdjuster.swift */,
A82DDBDD2AEC736300D7F974 /* AnimationConfiguration.swift */,
A8504D2C2A85832F00C2EFDA /* SoftwareUpdater.swift */,
A80900D22AA3F9F20085C63B /* BetaIndicator.swift */,
A80900D22AA3F9F20085C63B /* UnstableIndicator.swift */,
A80900D32AA3F9F20085C63B /* VisualEffectView.swift */,
A85B560D2AAAD62C00386ACE /* EventMonitor.swift */,
A86B97AC2AB79E2500099D7F /* ShakeEffect.swift */,
Expand Down Expand Up @@ -578,7 +578,7 @@
A8330AC72A3AC19500673C8D /* NSScreen+Extensions.swift in Sources */,
A80900D52AA3F9F30085C63B /* VisualEffectView.swift in Sources */,
A8330AC12A3AC13100673C8D /* Defaults+Extensions.swift in Sources */,
A80900D42AA3F9F30085C63B /* BetaIndicator.swift in Sources */,
A80900D42AA3F9F30085C63B /* UnstableIndicator.swift in Sources */,
A8D6D2FF2B6C87F80061B11F /* PaddingConfigurationView.swift in Sources */,
A8E1575F298654960005761C /* AboutView.swift in Sources */,
A8DCC98A2981F43F00D41065 /* PreviewSettingsView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"location" : "https://github.com/sparkle-project/Sparkle",
"state" : {
"branch" : "2.x",
"revision" : "0a4caaf7a81eea2cece651ef4b17331fa0634dff"
"revision" : "0183bf2b3f8000bb222b631631c3164da55a0b0f"
}
},
{
Expand All @@ -56,5 +56,5 @@
}
}
],
"version" : 2
"version" : 3
}
7 changes: 7 additions & 0 deletions Loop/About Window/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ struct AboutView: View {
license: URL(
string: "https://github.com/sparkle-project/Sparkle/blob/2.x/LICENSE"
)!
),
PackageDescription(
name: "Swift Algorithms",
url: URL(
string: "https://github.com/apple/swift-algorithms"
)!,
license: URL(string: "https://github.com/apple/swift-algorithms/blob/main/LICENSE.txt")!
)
]

Expand Down
2 changes: 1 addition & 1 deletion Loop/Extensions/Defaults+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension Defaults.Keys {
static let windowSnapping = Key<Bool>("windowSnapping", default: false) // BETA
static let animateWindowResizes = Key<Bool>("animateWindowResizes", default: false) // BETA
static let padding = Key<PaddingModel>("padding", default: .zero)
static let restoreWindowFrameOnDrag = Key<Bool>("restoreWindowFrameOnDrag", default: true)
static let restoreWindowFrameOnDrag = Key<Bool>("restoreWindowFrameOnDrag", default: false)
static let resizeWindowUnderCursor = Key<Bool>("resizeWindowUnderCursor", default: false)
static let focusWindowOnResize = Key<Bool>("focusWindowOnResize", default: true)
static let animationConfiguration = Key<AnimationConfiguration>("animationConfiguration", default: .smooth)
Expand Down
4 changes: 3 additions & 1 deletion Loop/Managers/LoopManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ class LoopManager: ObservableObject {
let flags = event.modifierFlags.convertToCGKeyCode()
if flags.count > 1 && !self.currentlyPressedModifiers.contains(flags) {
for key in flags where CGKeyCode.keyToImage.contains(where: { $0.key == key }) {
self.currentlyPressedModifiers.insert(key)
if !self.currentlyPressedModifiers.map({ $0.baseModifier }).contains(key) {
self.currentlyPressedModifiers.insert(key)
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions Loop/Managers/WindowDragManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ class WindowDragManager {
}

private func setCurrentDraggingWindow() {
guard let mousePosition = NSEvent.mouseLocation.flipY,
let draggingWindow = WindowEngine.windowAtPosition(mousePosition) else {
guard
let mousePosition = NSEvent.mouseLocation.flipY,
let draggingWindow = WindowEngine.windowAtPosition(mousePosition),
!draggingWindow.isAppExcluded
else {
return
}

self.draggingWindow = draggingWindow
self.initialWindowFrame = draggingWindow.frame
}
Expand Down
1 change: 0 additions & 1 deletion Loop/Preview Window/PreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class PreviewController {
defer: true,
screen: NSApp.keyWindow?.screen
)
panel.hasShadow = false
panel.alphaValue = 0
panel.backgroundColor = NSColor.white.withAlphaComponent(0.00001)
panel.setFrame(NSRect(origin: screen.stageStripFreeFrame.center, size: .zero), display: true)
Expand Down
3 changes: 3 additions & 0 deletions Loop/Preview Window/PreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ struct PreviewView: View {
.foregroundColor(.white)
}

RoundedRectangle(cornerRadius: previewCornerRadius, style: .continuous)
.strokeBorder(.quinary, lineWidth: 1)

RoundedRectangle(cornerRadius: previewCornerRadius, style: .continuous)
.stroke(
LinearGradient(
Expand Down
58 changes: 38 additions & 20 deletions Loop/Settings/ExcludeListSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ struct ExcludeListSettingsView: View {
@EnvironmentObject var appListManager: AppListManager

@Default(.applicationExcludeList) var excludeList

@State private var selection: String?
@State private var selection = Set<String>()

var body: some View {
ZStack {
Expand All @@ -35,17 +34,40 @@ struct ExcludeListSettingsView: View {
.padding()
} else {
List(selection: $selection) {
ForEach(excludeList, id: \.self) { entry in
if let app = appListManager.installedApps.first(where: { $0.bundleID == entry }) {
Label {
Text(app.displayName)
.padding(.leading, 8)
} icon: {
Image(nsImage: app.icon)
ForEach(self.$excludeList, id: \.self) { entry in
Group {
if let app = appListManager.installedApps.first(where: {
$0.bundleID == entry.wrappedValue
}) {
HStack {
Image(nsImage: app.icon)
Text(app.displayName)
.padding(.leading, 2)
}
} else {
Text(entry.wrappedValue)
}
}
.padding(.vertical, 5)
.contextMenu {
Button("Delete") {
if self.selection.isEmpty {
self.excludeList.removeAll(where: { $0 == entry.wrappedValue })
} else {
for item in selection {
self.excludeList.removeAll(where: { $0 == item })
}
self.selection.removeAll()
}
}
} else {
Text(entry)
}
.tag(entry.wrappedValue)
}
.onMove { indices, newOffset in
self.excludeList.move(fromOffsets: indices, toOffset: newOffset)
}
.onDelete { offset in
self.excludeList.remove(atOffsets: offset)
}
}
.listStyle(.bordered(alternatesRowBackgrounds: true))
Expand Down Expand Up @@ -76,9 +98,10 @@ struct ExcludeListSettingsView: View {
Divider()

Button {
self.excludeList.removeAll(where: {
$0 == selection
})
for item in selection {
self.excludeList.removeAll(where: { $0 == item })
}
self.selection.removeAll()
} label: {
Rectangle()
.foregroundStyle(.white.opacity(0.00001))
Expand All @@ -91,7 +114,7 @@ struct ExcludeListSettingsView: View {
.aspectRatio(1, contentMode: .fit)
.padding(-5)
}
.disabled(self.selection == nil)
.disabled(self.selection.isEmpty)

Spacer()
}
Expand Down Expand Up @@ -141,8 +164,3 @@ struct ExcludeListSettingsView: View {
}
}
}

#Preview {
ExcludeListSettingsView()
.environmentObject(AppListManager())
}
26 changes: 4 additions & 22 deletions Loop/Settings/GeneralSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ struct GeneralSettingsView: View {
@Default(.currentIcon) var currentIcon
@Default(.notificationWhenIconUnlocked) var notificationWhenIconUnlocked
@Default(.timesLooped) var timesLooped
@Default(.animateWindowResizes) var animateWindowResizes
@Default(.padding) var padding
@Default(.windowSnapping) var windowSnapping
@Default(.animationConfiguration) var animationConfiguration
Expand Down Expand Up @@ -51,7 +50,7 @@ struct GeneralSettingsView: View {
Toggle("Hide menubar icon", isOn: $hideMenuBarIcon)

if hideMenuBarIcon {
Text("Re-open Loop again to see this window.")
Text("Re-open Loop to see this window.")
.font(.caption)
.foregroundColor(.secondary)
.textSelection(.enabled)
Expand All @@ -60,27 +59,10 @@ struct GeneralSettingsView: View {
}

Section {
Toggle(isOn: $windowSnapping) {
HStack {
Text("Window Snapping")
BetaIndicator("BETA")
}
}

Toggle(isOn: $animateWindowResizes) {
HStack {
Text("Animate windows being resized")
BetaIndicator("BETA")
}
}
.onChange(of: animateWindowResizes) { _ in
if animateWindowResizes == true {
PermissionsManager.ScreenRecording.requestAccess()
}
}
Toggle("Window Snapping", isOn: $windowSnapping)

HStack {
Text("Padding")
Text("Window Padding")
Spacer()
Button("Configure…") {
self.isConfiguringPadding = true
Expand Down Expand Up @@ -133,7 +115,7 @@ struct GeneralSettingsView: View {
}

VStack(alignment: .leading) {
Text("Loop more to unlock more icons! (You've looped \(timesLooped) times!)")
Text("Loop more to unlock new icons! (You've looped \(timesLooped) times!)")

if let iconFooter = iconFooter {
Text(iconFooter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ struct TriggerKeycorder: View {
let flags = event.modifierFlags.convertToCGKeyCode()
if flags.count > 1 && !self.selectionKey.contains(flags) {
for key in flags where CGKeyCode.keyToImage.contains(where: { $0.key == key }) {
self.selectionKey.insert(key)
withAnimation(.snappy(duration: 0.1)) {
self.isCurrentlyPressed = true
if !self.selectionKey.map({ $0.baseModifier }).contains(key) {
self.selectionKey.insert(key)
withAnimation(.snappy(duration: 0.1)) {
self.isCurrentlyPressed = true
}
}
}
}
Expand Down
30 changes: 20 additions & 10 deletions Loop/Settings/Keybindings/KeybindingsSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct KeybindingsSettingsView: View {

@StateObject private var keycorderModel = KeycorderModel()
@State private var suggestAddingTriggerDelay: Bool = false
@State private var selection: WindowAction?
@State private var selection = Set<WindowAction>()

var body: some View {
ZStack {
Expand All @@ -44,7 +44,7 @@ struct KeybindingsSettingsView: View {
CrispValueAdjuster(
"Trigger Delay",
value: $triggerDelay,
sliderRange: 0...10,
sliderRange: 0...1,
postscript: "sec",
step: 0.1,
lowerClamp: true
Expand Down Expand Up @@ -74,17 +74,26 @@ struct KeybindingsSettingsView: View {
ForEach(self.$keybinds) { keybind in
KeybindCustomizationViewItem(keybind: keybind, triggerKey: self.$triggerKey)
.contextMenu {
Button {
self.keybinds.removeAll(where: { $0 == keybind.wrappedValue })
} label: {
Label("Delete", systemImage: "trash")
Button("Delete") {
if self.selection.isEmpty {
self.keybinds.removeAll(where: { $0 == keybind.wrappedValue })
} else {
for item in selection {
self.keybinds.removeAll(where: { $0 == item })
}
self.selection.removeAll()
}
}
}
.tag(keybind.wrappedValue)
.fixedSize(horizontal: false, vertical: true)
}
.onMove { indices, newOffset in
self.keybinds.move(fromOffsets: indices, toOffset: newOffset)
}
.onDelete { offset in
self.keybinds.remove(atOffsets: offset)
}
}
.listStyle(.bordered(alternatesRowBackgrounds: true))
}
Expand Down Expand Up @@ -114,9 +123,10 @@ struct KeybindingsSettingsView: View {
Divider()

Button {
self.keybinds.removeAll(where: {
$0 == selection
})
for item in selection {
self.keybinds.removeAll(where: { $0 == item })
}
self.selection.removeAll()
} label: {
Rectangle()
.foregroundStyle(.white.opacity(0.00001))
Expand All @@ -129,7 +139,7 @@ struct KeybindingsSettingsView: View {
.aspectRatio(1, contentMode: .fit)
.padding(-5)
}
.disabled(self.selection == nil)
.disabled(self.selection.isEmpty)

Spacer()
}
Expand Down
Loading

0 comments on commit bf022a1

Please sign in to comment.