Skip to content

Commit

Permalink
Make “Browsing Mode” not go in front of all windows
Browse files Browse the repository at this point in the history
This is generally a better behavior and it helps #50.
  • Loading branch information
sindresorhus committed Dec 3, 2020
1 parent 972e8a1 commit 912efb2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Plash/DesktopWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class DesktopWindow: NSWindow {
var isInteractive = false {
didSet {
if isInteractive {
level = .floating
level = .desktopIcon
makeKeyAndOrderFront(self)
ignoresMouseEvents = false
} else {
Expand Down
9 changes: 9 additions & 0 deletions Plash/Menus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ extension AppDelegate {
isChecked: isBrowsingMode
) { [weak self] _ in
self?.isBrowsingMode.toggle()

SSApp.runOnce(identifier: "activatedBrowsingMode") {
DispatchQueue.main.async {
NSAlert.showModal(
message: "Browsing Mode lets you temporarily interact with the website. For example, to log into an account or scroll to a specific position on the website.",
informativeText: "If you don't currently see the website, you might need to hide some windows to reveal the desktop."
)
}
}
}

menu.addSeparator()
Expand Down
34 changes: 34 additions & 0 deletions Plash/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3143,3 +3143,37 @@ extension URL {
self.init(string: url)
}
}


extension SSApp {
/**
This is like `SSApp.runOnce()` but let's you have an else-statement too.

```
if SSApp.runOnceShouldRun(identifier: "foo") {
// True only the first time and only once.
} else {

}
```
*/
static func runOnceShouldRun(identifier: String) -> Bool {
let key = "SS_App_runOnce__\(identifier)"

guard !UserDefaults.standard.bool(forKey: key) else {
return false
}

UserDefaults.standard.set(true, forKey: key)
return true
}

/// Run a closure only once ever, even between relaunches of the app.
static func runOnce(identifier: String, _ execute: () -> Void) {
guard runOnceShouldRun(identifier: identifier) else {
return
}

execute()
}
}

0 comments on commit 912efb2

Please sign in to comment.