Skip to content

Commit

Permalink
Merge pull request #9 from geteduroam/feature/GETEDUROAM-22
Browse files Browse the repository at this point in the history
Setting up Mac app
  • Loading branch information
johankool authored Apr 21, 2023
2 parents c2d8bf9 + 70ccdc9 commit 98c4337
Show file tree
Hide file tree
Showing 27 changed files with 500 additions and 129 deletions.
8 changes: 6 additions & 2 deletions geteduroam.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -444,6 +445,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -572,6 +574,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -605,7 +608,7 @@
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = "app.eduroam.geteduroam-test";
PRODUCT_BUNDLE_IDENTIFIER = app.eduroam.geteduroam.test;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
Expand Down Expand Up @@ -702,6 +705,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -735,7 +739,7 @@
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = "app.eduroam.geteduroam-test";
PRODUCT_BUNDLE_IDENTIFIER = app.eduroam.geteduroam.test;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
Expand Down
11 changes: 10 additions & 1 deletion geteduroam/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,61 @@
"size" : "1024x1024"
},
{
"filename" : "icon_16x16.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "icon_16x16@[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"filename" : "icon_32x32.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"filename" : "icon_32x32@[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"filename" : "icon_128x128.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"filename" : "icon_128x128@[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"filename" : "icon_256x256.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"filename" : "icon_256x256@[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "icon_512x512.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "Stroke 11395.png",
"filename" : "icon_512x512@2x@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions geteduroam/Assets.xcassets/Background.colorset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@
}
},
"idiom" : "universal"
},
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "0.000",
"blue" : "0.000",
"green" : "0.000",
"red" : "0.000"
}
},
"idiom" : "mac"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "0.000",
"blue" : "0.000",
"green" : "0.000",
"red" : "0.000"
}
},
"idiom" : "mac"
}
],
"info" : {
Expand Down
73 changes: 56 additions & 17 deletions geteduroam/GeteduroamApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ struct GeteduroamApp: App {

#if os(iOS)
@UIApplicationDelegateAdaptor private var appDelegate: GeteduroamAppDelegate
#elseif os(macOS)
@NSApplicationDelegateAdaptor private var appDelegate: GeteduroamAppDelegate
#endif

var store: StoreOf<Main>!

init() {
store = .init(initialState: .init(), reducer: Main(), prepareDependencies: { [appDelegate] in
$0.authClient = appDelegate
})
}

@StateObject var theme = Theme(
searchFont: .custom("OpenSans-Regular", size: 20, relativeTo: .body),
Expand All @@ -33,14 +22,64 @@ struct GeteduroamApp: App {
connectedFont: .custom("OpenSans-Bold", size: 14, relativeTo: .body),
infoHeaderFont: .custom("OpenSans-Bold", size: 14, relativeTo: .body),
infoDetailFont: .custom("OpenSans-Regular", size: 14, relativeTo: .body))

#elseif os(macOS)
@NSApplicationDelegateAdaptor private var appDelegate: GeteduroamAppDelegate

@StateObject var theme = Theme(
searchFont: .system(.body, design: .default, weight: .regular),
errorFont: .system(.body, design: .default, weight: .regular),
institutionNameFont: .system(.body, design: .default, weight: .bold),
institutionCountryFont: .system(.footnote, design: .default, weight: .regular),
profilesHeaderFont: .system(.body, design: .default, weight: .bold),
profileNameFont: .system(.body, design: .default, weight: .regular),
connectButtonFont: .system(.callout, design: .default, weight: .bold),
connectedFont: .system(.body, design: .default, weight: .regular),
infoHeaderFont: .system(.body, design: .default, weight: .bold),
infoDetailFont: .system(.body, design: .default, weight: .regular))
#endif

var store: StoreOf<Main>!

var body: some Scene {
@Environment(\.openURL) var openURL

init() {
store = .init(initialState: .init(), reducer: Main(), prepareDependencies: { [appDelegate] in
$0.authClient = appDelegate
})
}

#if os(iOS)
var body: some Scene {
WindowGroup {
// TODO: Create bwc version
// NavigationStack {
MainView(store: store)
.environmentObject(theme)
// }
MainView(store: store)
.environmentObject(theme)
}
}
#elseif os(macOS)
var body: some Scene {
Window("geteduroam", id: "mainWindow") {
MainView(store: store)
.environmentObject(theme)
.onAppear {
DispatchQueue.main.async {
NSApplication.shared.windows.forEach { window in
window.standardWindowButton(.zoomButton)?.isEnabled = false
}
}
}
.frame(minWidth: 300, maxWidth: .infinity, minHeight: 400, maxHeight: .infinity, alignment: .center)
}
.defaultPosition(.center)
.defaultSize(width: 540, height: 640)
.commands {
CommandGroup(replacing: CommandGroupPlacement.help) {
Button("geteduroam Help") {
openURL(URL(string: "https://eduroam.org")!)
}
}
}
}
#endif

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,12 @@ public class GeteduroamAppDelegate: NSObject, NSApplicationDelegate, ObservableO
}
}
}

public func applicationWillUpdate(_ notification: Notification) {
if let menu = NSApplication.shared.mainMenu {
menu.items.removeAll { $0.title == "View" } // TODO: Don't harcode title
// TODO: Also remove Zoom? menu.items.removeAll { $0.title == "Zoom" }
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct ReadableContentWidthPadding: ViewModifier {
}

private func readableWidthPadding(for _: UIDeviceOrientation) -> EdgeInsets {
// FIXME: This gives weird results in splitview on iPad
let screenBounds = UIScreen.main.bounds
measureViewController.view.frame = screenBounds
let readableContentFrame = measureViewController.view.readableContentGuide.layoutFrame
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import SwiftUI

/// Wraps SwiftUI's Visibility so it can be used on older OS versions.
public enum Visibility {
/// Corresponds to [automatic](https://developer.apple.com/documentation/swiftui/visibility/automatic)
case automatic

/// Corresponds to [visible](https://developer.apple.com/documentation/swiftui/visibility/visible)
case visible

/// Corresponds to [hidden](https://developer.apple.com/documentation/swiftui/visibility/hidden)
case hidden

@available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 13.0, *)
var original: SwiftUI.Visibility {
switch self {
case .automatic:
return .automatic
case .visible:
return .visible
case .hidden:
return .hidden

}
}
}

public extension Backport where Content: View {
/// Specifies the visibility of the background for scrollable views within this view.
/// - Parameter mode: Mode to apply
/// - Returns: View with background visibility applied if available
@ViewBuilder func scrollContentBackground(_ mode: Visibility) -> some View {
if #available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 13.0, *) {
content.scrollContentBackground(mode.original)
} else {
content
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum ScrollDismissesKeyboardMode {
/// Corresponds to [immediately](https://developer.apple.com/documentation/swiftui/scrolldismisseskeyboardmode/immediately)
case immediately

/// Corresponds to [interactively](https://developer.apple.com/documentation/swiftui/scrolldismisseskeyboardmode/automatic)
/// Corresponds to [interactively](https://developer.apple.com/documentation/swiftui/scrolldismisseskeyboardmode/interactively)
case interactively

/// Corresponds to [never](https://developer.apple.com/documentation/swiftui/scrolldismisseskeyboardmode/never)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import SwiftUI

struct ConnectButtonStyle: ButtonStyle {

// @EnvironmentObject var theme: Theme
let theme = Theme.demo
@EnvironmentObject var theme: Theme

func makeBody(configuration: Configuration) -> some View {
configuration.label
Expand Down
Loading

0 comments on commit 98c4337

Please sign in to comment.