Skip to content

Commit

Permalink
Add settings view and pinboard key setting (#80)
Browse files Browse the repository at this point in the history
This change adds a new Settings view to the macOS app with a couple of tabs: General and Account. General is entirely empty, but Account contains the Pinboard key, meaning new users will now be able to get started with the app.
  • Loading branch information
jbmorley authored Apr 9, 2021
1 parent bbc3d0d commit 187499a
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ios/Bookmarks/Interface/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ struct SettingsView: View {
Section(header: Text("Pinboard")) {
TextField("API Token", text: $settings.pinboardApiKey)
Button(action: {
UIApplication.shared.open(URL(string: "https://pinboard.in/settings/password")!, options: [:], completionHandler: nil)
UIApplication.shared.open(URL(string: "https://pinboard.in/settings/password")!,
options: [:],
completionHandler: nil)
}, label: {
Text("Get your API token")
})
Expand Down
12 changes: 12 additions & 0 deletions macos/Bookmarks-macOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/* Begin PBXBuildFile section */
D81EA6032620F3D5000AB851 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = D81EA6022620F3D5000AB851 /* Sparkle */; };
D840B006262103C4001E95D1 /* AccountSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D840B005262103C4001E95D1 /* AccountSettingsView.swift */; };
D840B00A2621042B001E95D1 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D840B0092621042B001E95D1 /* SettingsView.swift */; };
D840B01226210AF6001E95D1 /* GeneralSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D840B01126210AF6001E95D1 /* GeneralSettingsView.swift */; };
D891C454261E32F90024E1A6 /* BookmarksApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D891C453261E32F90024E1A6 /* BookmarksApp.swift */; };
D891C456261E32F90024E1A6 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D891C455261E32F90024E1A6 /* ContentView.swift */; };
D891C458261E32FB0024E1A6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D891C457261E32FB0024E1A6 /* Assets.xcassets */; };
Expand Down Expand Up @@ -54,6 +57,9 @@

/* Begin PBXFileReference section */
D81EA5FF2620F3BF000AB851 /* sparkle */ = {isa = PBXFileReference; lastKnownFileType = folder; name = sparkle; path = ../sparkle; sourceTree = "<group>"; };
D840B005262103C4001E95D1 /* AccountSettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountSettingsView.swift; sourceTree = "<group>"; };
D840B0092621042B001E95D1 /* SettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
D840B01126210AF6001E95D1 /* GeneralSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralSettingsView.swift; sourceTree = "<group>"; };
D891C450261E32F90024E1A6 /* Bookmarks.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Bookmarks.app; sourceTree = BUILT_PRODUCTS_DIR; };
D891C453261E32F90024E1A6 /* BookmarksApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksApp.swift; sourceTree = "<group>"; };
D891C455261E32F90024E1A6 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -168,8 +174,11 @@
D8B04B43261F4A1200376ADD /* Views */ = {
isa = PBXGroup;
children = (
D840B005262103C4001E95D1 /* AccountSettingsView.swift */,
D8B04B3F261F49F100376ADD /* BookmarkCell.swift */,
D891C455261E32F90024E1A6 /* ContentView.swift */,
D840B01126210AF6001E95D1 /* GeneralSettingsView.swift */,
D840B0092621042B001E95D1 /* SettingsView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -326,7 +335,10 @@
buildActionMask = 2147483647;
files = (
D8B6E2C52620990400B2C239 /* Item.swift in Sources */,
D840B006262103C4001E95D1 /* AccountSettingsView.swift in Sources */,
D891C456261E32F90024E1A6 /* ContentView.swift in Sources */,
D840B01226210AF6001E95D1 /* GeneralSettingsView.swift in Sources */,
D840B00A2621042B001E95D1 /* SettingsView.swift in Sources */,
D891C454261E32F90024E1A6 /* BookmarksApp.swift in Sources */,
D8B04B40261F49F100376ADD /* BookmarkCell.swift in Sources */,
);
Expand Down
3 changes: 3 additions & 0 deletions macos/Bookmarks/BookmarksApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ struct BookmarksApp: App {
WindowGroup {
ContentView(store: manager.store)
}
SwiftUI.Settings {
SettingsView()
}
}
}
48 changes: 48 additions & 0 deletions macos/Bookmarks/Views/AccountSettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2018-2021 InSeven Limited
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import SwiftUI

import BookmarksCore

struct AccountSettingsView: View {

@Environment(\.manager) var manager: BookmarksManager

@ObservedObject var settings: BookmarksCore.Settings

var body: some View {
VStack {
Form {
Section {
TextField("API Token", text: $settings.pinboardApiKey)
Button(action: {
NSWorkspace.shared.open(URL(string: "https://pinboard.in/settings/password")!)
}, label: {
Text("Get your API token")
})
.buttonStyle(LinkButtonStyle())
}
}
Spacer()
}
}

}
39 changes: 39 additions & 0 deletions macos/Bookmarks/Views/GeneralSettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2018-2021 InSeven Limited
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import SwiftUI

import BookmarksCore

struct GeneralSettingsView: View {

@Environment(\.manager) var manager: BookmarksManager

@ObservedObject var settings: BookmarksCore.Settings

var body: some View {
VStack {
Form {
}
Spacer()
}
}

}
52 changes: 52 additions & 0 deletions macos/Bookmarks/Views/SettingsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2018-2021 InSeven Limited
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import SwiftUI

import BookmarksCore

struct SettingsView: View {

private enum Tabs: Hashable {
case general
case account
}

@Environment(\.manager) var manager: BookmarksManager

var body: some View {
EmptyView()
TabView {
GeneralSettingsView(settings: manager.settings)
.tabItem {
Label("General", systemImage: "gear")
}
.tag(Tabs.general)
AccountSettingsView(settings: manager.settings)
.tabItem {
Label("Account", systemImage: "at")
}
.tag(Tabs.account)
}
.padding()
.frame(minWidth: 320, maxWidth: .infinity)
}

}

0 comments on commit 187499a

Please sign in to comment.