Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 29, 2022
1 parent 5a9b0c4 commit fd73811
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 101 deletions.
7 changes: 5 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
only_rules:
- accessibility_trait_for_button
- array_init
- block_based_kvo
- class_delegate_protocol
Expand Down Expand Up @@ -68,7 +69,6 @@ only_rules:
- lower_acl_than_parent
- mark
- modifier_order
- multiline_arguments
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
Expand All @@ -78,12 +78,12 @@ only_rules:
- no_fallthrough_only
- no_space_in_method_call
- notification_center_detachment
- ns_number_init_as_function_reference
- nsobject_prefer_isequal
- number_separator
- opening_brace
- operator_usage_whitespace
- operator_whitespace
- orphaned_doc_comment
- overridden_super_call
- prefer_self_in_static_references
- prefer_self_type_over_type_of_self
Expand All @@ -110,6 +110,7 @@ only_rules:
- self_binding
- self_in_property_initialization
- shorthand_operator
- shorthand_optional_binding
- sorted_first_last
- statement_position
- static_operator
Expand Down Expand Up @@ -151,6 +152,8 @@ analyzer_rules:
- unused_declaration
- unused_import
- typesafe_array_init
for_where:
allow_for_as_filter: true
number_separator:
minimum_length: 5
identifier_name:
Expand Down
10 changes: 3 additions & 7 deletions Plash.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
E333EB1B2385244E005FCE44 /* SettingsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E333EB1A2385244E005FCE44 /* SettingsScreen.swift */; };
E3369A9A265E344300BAC78B /* URLCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3369A99265E344300BAC78B /* URLCommands.swift */; };
E34FCBCE264D32150022BDD3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = E34FCBCD264D32150022BDD3 /* App.swift */; };
E354442626061C9100CA060F /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = E354442526061C9100CA060F /* Migration.swift */; };
E354442F26062D6300CA060F /* WebsitesScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E354442E26062D6300CA060F /* WebsitesScreen.swift */; };
E354443C2607505100CA060F /* WebsitesController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E354443B2607505100CA060F /* WebsitesController.swift */; };
E3805F5B2466ED5600489E6C /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = E3805F5A2466ED5600489E6C /* KeyboardShortcuts */; };
Expand Down Expand Up @@ -84,7 +83,6 @@
E333EB1A2385244E005FCE44 /* SettingsScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SettingsScreen.swift; sourceTree = "<group>"; usesTabs = 1; };
E3369A99265E344300BAC78B /* URLCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLCommands.swift; sourceTree = "<group>"; };
E34FCBCD264D32150022BDD3 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
E354442526061C9100CA060F /* Migration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Migration.swift; sourceTree = "<group>"; };
E354442E26062D6300CA060F /* WebsitesScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebsitesScreen.swift; sourceTree = "<group>"; };
E354443B2607505100CA060F /* WebsitesController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebsitesController.swift; sourceTree = "<group>"; };
E384F27F24C3B37E002FD21B /* Events.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Events.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -158,7 +156,6 @@
E3EC5A85250D7A0C00ABE1A1 /* WelcomeScreen.swift */,
E3369A99265E344300BAC78B /* URLCommands.swift */,
E3FC71E2271ECA9200C9D255 /* IntentHandler.swift */,
E354442526061C9100CA060F /* Migration.swift */,
E32421572384F0E600D28A91 /* Utilities.swift */,
E32421372384E9D900D28A91 /* Assets.xcassets */,
E3FC71E0271ECA1700C9D255 /* Intents.intentdefinition */,
Expand Down Expand Up @@ -372,7 +369,6 @@
E333EB1B2385244E005FCE44 /* SettingsScreen.swift in Sources */,
E354442F26062D6300CA060F /* WebsitesScreen.swift in Sources */,
E354443C2607505100CA060F /* WebsitesController.swift in Sources */,
E354442626061C9100CA060F /* Migration.swift in Sources */,
E3EC5A86250D7A0C00ABE1A1 /* WelcomeScreen.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -649,7 +645,7 @@
repositoryURL = "https://github.com/getsentry/sentry-cocoa";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 7.28.0;
minimumVersion = 7.31.2;
};
};
E32421482384ED8300D28A91 /* XCRemoteSwiftPackageReference "Defaults" */ = {
Expand All @@ -665,15 +661,15 @@
repositoryURL = "https://github.com/sindresorhus/KeyboardShortcuts";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.8.0;
minimumVersion = 1.9.0;
};
};
E3C4E27F251540F7007A6078 /* XCRemoteSwiftPackageReference "LaunchAtLogin" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sindresorhus/LaunchAtLogin";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.2.0;
minimumVersion = 5.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
2 changes: 1 addition & 1 deletion Plash/AddWebsiteScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct AddWebsiteScreen: View {
}
}
.frame(width: 500)
.bindNativeWindow($hostingWindow)
.bindHostingWindow($hostingWindow)
// Note: Current only works when a text field is focused. (macOS 11.3)
.onExitCommand {
guard isEditing, hasChanges else {
Expand Down
14 changes: 13 additions & 1 deletion Plash/App.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import LaunchAtLogin

/*
TODO:
Expand All @@ -7,12 +8,19 @@ TODO:
- Fix "Edit Website" if it's not visible in the list. Use the new `Window` type in macOS 13.
TODO when targeting macOS 13:
- Focus filter support - set a certain website when in a specific focus.
- Document it.
- Use SwiftUI for the websites window. We cannot do it until the window can be manually toggled.
- Upload non-App Store version.
- Change the list to open on click instead of right-click.
- Also use `Foo.ID` instead of `Foo`.
- $rules[id: selection]
- Change the instruction about right-clicking.
TODO when Swift 6 is out:
- Convert all Combine usage to AsyncSequence.
TODO when targeting macOS 13:
TODO when targeting macOS 14:
= Use `MenuBarExtra`.
*/

Expand All @@ -21,6 +29,10 @@ struct AppMain: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
@StateObject private var appState = AppState.shared

init() {
LaunchAtLogin.migrateIfNeeded()
}

var body: some Scene {
Settings {
SettingsScreen()
Expand Down
1 change: 0 additions & 1 deletion Plash/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ final class AppState: ObservableObject {
// Make the invisible native SwitUI window not block access to the desktop. (macOS 12.0)
NSApp.windows.first?.ignoresMouseEvents = true

migrate()
_ = statusItemButton
_ = desktopWindow
setUpEvents()
Expand Down
2 changes: 1 addition & 1 deletion Plash/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI
import Defaults
import KeyboardShortcuts
import Defaults

enum Constants {
static let menuBarIcon = NSImage(named: "MenuBarIcon")!
Expand Down
5 changes: 0 additions & 5 deletions Plash/Migration.swift

This file was deleted.

158 changes: 79 additions & 79 deletions Plash/SettingsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,84 @@ import LaunchAtLogin
import Defaults
import KeyboardShortcuts

struct SettingsScreen: View {
var body: some View {
TabView {
GeneralSettings()
.settingsTabItem(.general)
ShortcutsSettings()
.settingsTabItem(.shortcuts)
AdvancedSettings()
.settingsTabItem(.advanced)
}
.frame(width: 340)
.windowLevel(.floating + 1) // To ensure it's always above the Plash browser window.
}
}

private struct GeneralSettings: View {
var body: some View {
VStack(alignment: .leading) {
VStack(alignment: .leading) {
LaunchAtLogin.Toggle()
ShowOnAllSpacesSetting()
Defaults.Toggle("Deactivate while on battery", key: .deactivateOnBattery)
ReloadIntervalSetting()
}
.padding()
.padding(.horizontal)
Divider()
OpacitySetting()
.padding()
.padding(.horizontal)
}
.padding(.vertical)
}
}

private struct ShortcutsSettings: View {
private let maxWidth = 160.0

var body: some View {
Form {
KeyboardShortcuts.Recorder("Toggle browsing mode:", name: .toggleBrowsingMode)
.fixedSize()
KeyboardShortcuts.Recorder("Reload website:", name: .reload)
KeyboardShortcuts.Recorder("Next website:", name: .nextWebsite)
KeyboardShortcuts.Recorder("Previous website:", name: .previousWebsite)
KeyboardShortcuts.Recorder("Random website:", name: .randomWebsite)
}
.padding()
.padding()
.offset(x: -10)
}
}

private struct AdvancedSettings: View {
var body: some View {
VStack {
Form {
BringBrowsingModeToFrontSetting()
OpenExternalLinksInBrowserSetting()
HideMenuBarIconSetting()
Defaults.Toggle("Mute audio", key: .muteAudio)
}
.padding()
.padding(.horizontal)
.fillFrame(.horizontal, alignment: .leading)
Divider()
DisplaySetting()
.padding()
.padding(.horizontal)
Divider()
ClearWebsiteDataSetting()
.padding()
.padding(.horizontal)
}
.padding(.vertical)
}
}

private struct ShowOnAllSpacesSetting: View {
var body: some View {
Defaults.Toggle(
Expand Down Expand Up @@ -61,7 +139,7 @@ private struct ReloadIntervalSetting: View {
var body: some View {
HStack {
Toggle("Reload every", isOn: $isEnabled)
Stepper(
Stepper( // swiftlint:disable:this accessibility_trait_for_button
value: reloadIntervalInMinutes.didSet { _ in
// We have to unfocus the text field because sometimes it's in a state where it does not update the value. Some kind of bug with the formatter. (macOS 12.4)
isTextFieldFocused = false
Expand Down Expand Up @@ -152,84 +230,6 @@ private struct ClearWebsiteDataSetting: View {
}
}

private struct GeneralSettings: View {
var body: some View {
VStack(alignment: .leading) {
VStack(alignment: .leading) {
LaunchAtLogin.Toggle()
ShowOnAllSpacesSetting()
Defaults.Toggle("Deactivate while on battery", key: .deactivateOnBattery)
ReloadIntervalSetting()
}
.padding()
.padding(.horizontal)
Divider()
OpacitySetting()
.padding()
.padding(.horizontal)
}
.padding(.vertical)
}
}

private struct ShortcutsSettings: View {
private let maxWidth = 160.0

var body: some View {
Form {
KeyboardShortcuts.Recorder("Toggle browsing mode:", name: .toggleBrowsingMode)
.fixedSize()
KeyboardShortcuts.Recorder("Reload website:", name: .reload)
KeyboardShortcuts.Recorder("Next website:", name: .nextWebsite)
KeyboardShortcuts.Recorder("Previous website:", name: .previousWebsite)
KeyboardShortcuts.Recorder("Random website:", name: .randomWebsite)
}
.padding()
.padding()
.offset(x: -10)
}
}

private struct AdvancedSettings: View {
var body: some View {
VStack {
Form {
BringBrowsingModeToFrontSetting()
OpenExternalLinksInBrowserSetting()
HideMenuBarIconSetting()
Defaults.Toggle("Mute audio", key: .muteAudio)
}
.padding()
.padding(.horizontal)
.fillFrame(.horizontal, alignment: .leading)
Divider()
DisplaySetting()
.padding()
.padding(.horizontal)
Divider()
ClearWebsiteDataSetting()
.padding()
.padding(.horizontal)
}
.padding(.vertical)
}
}

struct SettingsScreen: View {
var body: some View {
TabView {
GeneralSettings()
.settingsTabItem(.general)
ShortcutsSettings()
.settingsTabItem(.shortcuts)
AdvancedSettings()
.settingsTabItem(.advanced)
}
.frame(width: 340)
.windowLevel(.floating)
}
}

struct SettingsScreen_Previews: PreviewProvider {
static var previews: some View {
SettingsScreen()
Expand Down
8 changes: 4 additions & 4 deletions Plash/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5389,7 +5389,7 @@ extension View {
/**
Bind the native backing-window of a SwiftUI window to a property.
*/
func bindNativeWindow(_ window: Binding<NSWindow?>) -> some View {
func bindHostingWindow(_ window: Binding<NSWindow?>) -> some View {
background(WindowAccessor(window))
}
}
Expand All @@ -5403,23 +5403,23 @@ private struct WindowViewModifier: ViewModifier {
onWindow(window)

return content
.bindNativeWindow($window)
.bindHostingWindow($window)
}
}

extension View {
/**
Access the native backing-window of a SwiftUI window.
*/
func accessNativeWindow(_ onWindow: @escaping (NSWindow?) -> Void) -> some View {
func accessHostingWindow(_ onWindow: @escaping (NSWindow?) -> Void) -> some View {
modifier(WindowViewModifier(onWindow: onWindow))
}

/**
Set the window level of a SwiftUI window.
*/
func windowLevel(_ level: NSWindow.Level) -> some View {
accessNativeWindow {
accessHostingWindow {
$0?.level = level
}
}
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ However, I there is a [workaround](https://github.com/sindresorhus/Plash/issues/

Plash uses very little memory. Usually around 40 MB. However, the websites you display can take up a lot of memory, and sometimes even have a memory leaks.

#### The menu bar does not adapt to the Plash wallpaper

The menu bar adapts its color from the actual system wallpaper. Plash is not actually a wallpaper, but rather runs right above the wallpaper. So Plash cannot influence the menu bar color.

#### Can Plash block ads?

Not built-in, but you can block ads system-wide with a [DNS ad-blocker](https://alternate-dns.com).
Expand Down

0 comments on commit fd73811

Please sign in to comment.