Skip to content

Commit

Permalink
🐛 Fix preview window not showing in settings window
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Sep 30, 2023
1 parent 9eb4b29 commit 9ee1b82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Loop/Managers/KeybindMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KeybindMonitor {
// This is used when the user is pressing 2+ keys so that it doesn't switch back
// to the one key direction when they're letting go of the keys.
if event.type == .keyUp ||
(event.type == .flagsChanged &&
(event.type == .flagsChanged &&
!event.modifierFlags.intersection(.deviceIndependentFlagsMask).contains(.shift)) {
if (abs(lastKeyReleaseTime.timeIntervalSinceNow)) > 0.1 {
return
Expand Down
21 changes: 8 additions & 13 deletions Loop/Preview Window/PreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ import Defaults

struct PreviewView: View {

// Used to preview inside the app's settings
@State var previewMode = false

@State var currentResizeDirection: WindowDirection = .noAction
private let window: Window?
private var sidePadding: CGFloat = 0
private let previewMode: Bool

init(previewMode: Bool = false, window: Window?) {
self.window = window
self.sidePadding = previewPadding + previewBorderThickness / 2
self.previewMode = previewMode
}

@Default(.useSystemAccentColor) var useSystemAccentColor
Expand Down Expand Up @@ -87,12 +84,11 @@ struct PreviewView: View {
lineWidth: previewBorderThickness
)
}
.padding(sidePadding)
.padding(previewPadding + previewBorderThickness / 2)
.frame(width: currentResizeDirection == .noAction ? 0 : nil,
height: currentResizeDirection == .noAction ? 0 : nil)
.frame(width: currentResizeDirection == .center ? (window?.size.width ?? 10) - sidePadding : nil,
height: currentResizeDirection == .center ? (window?.size.height ?? 10) - sidePadding : nil)

// .frame(width: currentResizeDirection == .center ? (window?.size.width ?? 10) - sidePadding : nil,
// height: currentResizeDirection == .center ? (window?.size.height ?? 10) - sidePadding : nil)
.frame(width: currentResizeDirection == .lastDirection ? 0 : nil,
height: currentResizeDirection == .lastDirection ? 0 : nil)
.frame(width: currentResizeDirection == .topTwoThirds ? geo.size.height / 3 * 2 : nil)
Expand Down Expand Up @@ -138,16 +134,15 @@ struct PreviewView: View {
.opacity(currentResizeDirection == .noAction ? 0 : 1)
.animation(.interpolatingSpring(stiffness: 250, damping: 25), value: currentResizeDirection)
.onReceive(.directionChanged) { obj in
if !previewMode {
if !self.previewMode {
if let direction = obj.userInfo?["direction"] as? WindowDirection {
currentResizeDirection = direction
}
}
}

.onAppear {
if previewMode {
currentResizeDirection = .maximize
if self.previewMode {
self.currentResizeDirection = .maximize
}
}
}
Expand Down

0 comments on commit 9ee1b82

Please sign in to comment.