Skip to content

Commit

Permalink
Migrate to Swift 6 for Kit and UI
Browse files Browse the repository at this point in the history
  • Loading branch information
morajabi committed Nov 9, 2024
1 parent 95b6505 commit daecf81
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 229 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ DerivedData/
**/.netrc

server/dist

buildServer.json
5 changes: 0 additions & 5 deletions .swift-format

This file was deleted.

2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--indent 4
--indent 2
76 changes: 40 additions & 36 deletions InlineKit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,45 @@
import PackageDescription

let package = Package(
name: "InlineKit",
platforms: [
.iOS(.v17),
.macOS(.v13),
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "InlineKit",
targets: ["InlineKit"]
),
],
dependencies: [
.package(url: "https://github.com/inlinehq/GRDB.swift", from: "3.0.8"),
.package(url: "https://github.com/inlinehq/GRDBQuery", from: "0.10.2"),
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.36.0"),
.package(url: "https://github.com/evgenyneu/keychain-swift.git", from: "24.0.0"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.28.2")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "InlineKit",
dependencies: [
.product(name: "GRDB", package: "GRDB.swift"),
.product(name: "GRDBQuery", package: "GRDBQuery"),
.product(name: "Sentry", package: "sentry-cocoa"),
.product(name: "KeychainSwift", package: "keychain-swift"),
]
),
name: "InlineKit",
defaultLocalization: "en",
platforms: [
.iOS(.v17),
.macOS(.v13),
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "InlineKit",
targets: ["InlineKit"]
),
],
dependencies: [
.package(url: "https://github.com/inlinehq/GRDB.swift", from: "3.0.8"),
.package(url: "https://github.com/inlinehq/GRDBQuery", from: "0.10.2"),
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.36.0"),
.package(url: "https://github.com/evgenyneu/keychain-swift.git", from: "24.0.0"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.28.2"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "InlineKit",
dependencies: [
.product(name: "GRDB", package: "GRDB.swift"),
.product(name: "GRDBQuery", package: "GRDBQuery"),
.product(name: "Sentry", package: "sentry-cocoa"),
.product(name: "KeychainSwift", package: "keychain-swift"),
],
swiftSettings: [
.swiftLanguageMode(.v6),
]
),

.testTarget(
name: "InlineKitTests",
dependencies: ["InlineKit"]
),
]
.testTarget(
name: "InlineKitTests",
dependencies: ["InlineKit"]
),
]
)
118 changes: 59 additions & 59 deletions InlineMac/InlineApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,79 @@ import SwiftUI

@main
struct InlineApp: App {
@NSApplicationDelegateAdaptor private var appDelegate: AppDelegate
@StateObject var viewModel = MainWindowViewModel()
@StateObject var ws = WebSocketManager()
@StateObject var navigation = NavigationModel()
@StateObject var auth = Auth.shared
@NSApplicationDelegateAdaptor private var appDelegate: AppDelegate
@StateObject var viewModel = MainWindowViewModel()
@StateObject var ws = WebSocketManager()
@StateObject var navigation = NavigationModel()
@StateObject var auth = Auth.shared

var body: some Scene {
WindowGroup(id: "main") {
MainWindow()
.environmentObject(self.ws)
.environmentObject(self.viewModel)
.environmentObject(self.navigation)
.environment(\.auth, auth)
.appDatabase(AppDatabase.shared)
.environment(\.logOut, logOut)
}
.defaultSize(width: 900, height: 600)
.windowStyle(
viewModel.topLevelRoute == .onboarding ? .hiddenTitleBar : .init()
)
.windowToolbarStyle(.unified)
.commands {
MainWindowCommands()
var body: some Scene {
WindowGroup(id: "main") {
MainWindow()
.environmentObject(self.ws)
.environmentObject(self.viewModel)
.environmentObject(self.navigation)
.environment(\.auth, auth)
.appDatabase(AppDatabase.shared)
.environment(\.logOut, logOut)
}
.defaultSize(width: 900, height: 600)
.windowStyle(
viewModel.topLevelRoute == .onboarding ? .hiddenTitleBar : .init()
)
.windowToolbarStyle(.unified)
.commands {
MainWindowCommands()

// Create Space
if auth.isLoggedIn {
CommandGroup(after: .newItem) {
Button(action: createSpace) {
Text("Create Space")
}
}
}
// Create Space
if auth.isLoggedIn {
CommandGroup(after: .newItem) {
Button(action: createSpace) {
Text("Create Space")
}
}
}
}

Settings {
SettingsView()
.environmentObject(self.ws)
.environmentObject(self.viewModel)
.environment(\.auth, Auth.shared)
.environment(\.logOut, logOut)
.appDatabase(AppDatabase.shared)
}
Settings {
SettingsView()
.environmentObject(self.ws)
.environmentObject(self.viewModel)
.environment(\.auth, Auth.shared)
.environment(\.logOut, logOut)
.appDatabase(AppDatabase.shared)
}
}

// Resets all state and data
func logOut() {
// Clear creds
Auth.shared.logOut()
// Resets all state and data
func logOut() {
// Clear creds
Auth.shared.logOut()

// Stop WebSocket
ws.loggedOut()
// Stop WebSocket
ws.loggedOut()

// Clear database
try? AppDatabase.loggedOut()
// Clear database
try? AppDatabase.loggedOut()

// Navigate outside of the app
viewModel.navigate(.onboarding)
// Navigate outside of the app
viewModel.navigate(.onboarding)

// Reset internal navigation
navigation.reset()
// Reset internal navigation
navigation.reset()

// Close Settings
if let window = NSApplication.shared.keyWindow {
window.close()
}
// Close Settings
if let window = NSApplication.shared.keyWindow {
window.close()
}
}

// -----
private func createSpace() {
navigation.createSpaceSheetPresented = true
}
// -----
private func createSpace() {
navigation.createSpaceSheetPresented = true
}
}

public extension EnvironmentValues {
@Entry var logOut: () -> Void = {}
@Entry var logOut: () -> Void = {}
}
3 changes: 1 addition & 2 deletions InlineMac/Views/Main/Sheets/CreateSpaceSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ struct CreateSpaceSheet: View {
@State private var spaceName: String = ""
@FormState var formState
@Environment(\.appDatabase) var db
@Environment (\.dismiss) var dismiss

@Environment(\.dismiss) var dismiss

var body: some View {
VStack {
Expand Down
Loading

0 comments on commit daecf81

Please sign in to comment.