Skip to content

Commit

Permalink
Merge pull request #10 from Ammaar-Alam/app
Browse files Browse the repository at this point in the history
building stable version of ios app
  • Loading branch information
Ammaar-Alam authored Dec 9, 2024
2 parents 65c3ffc + 89c4e40 commit fcfdd03
Show file tree
Hide file tree
Showing 34 changed files with 1,469 additions and 507 deletions.
344 changes: 56 additions & 288 deletions Ammaar's Dorm Controls/Ammaar's Dorm Controls.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array/>
</plist>
Binary file not shown.

This file was deleted.

This file was deleted.

15 changes: 15 additions & 0 deletions Ammaar's Dorm Controls/Ammaar's Dorm Controls/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import UIKit
import SwiftUI

class AppDelegate: NSObject, UIApplicationDelegate {
// The shortcut handling code for older iOS versions or the original code snippet
// has been removed because we are using SceneDelegate for handling quick actions
// in iOS 13+.
//
// This ensures no placeholders or duplicate code. The scene delegate will handle
// shortcuts, so no changes are needed here.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}
}
146 changes: 146 additions & 0 deletions Ammaar's Dorm Controls/Ammaar's Dorm Controls/AppIntents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import AppIntents
import Foundation

@available(iOS 17.0, *)
enum DoorAction: String, CaseIterable, AppEnum {
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Door Action")

case open = "open"
case close = "close"
case emergencyClose = "emergency-close"

static var caseDisplayRepresentations: [DoorAction: DisplayRepresentation] = [
.open: DisplayRepresentation(
title: "Open Door",
subtitle: "Opens the dorm door",
image: .init(systemName: "arrow.up.circle")
),
.close: DisplayRepresentation(
title: "Close Door",
subtitle: "Closes the dorm door",
image: .init(systemName: "lock")
),
.emergencyClose: DisplayRepresentation(
title: "Emergency Close",
subtitle: "Force closes/untangles the door",
image: .init(systemName: "exclamationmark.triangle")
)
]
}

@available(iOS 17.0, *)
struct DoorActionIntent: AppIntent {
static var title: LocalizedStringResource = "Perform Door Action"
static var description = IntentDescription("Choose an action to perform on the door (open, close, or emergency close).")

@Parameter(title: "Action", default: .open)
var action: DoorAction

func perform() async throws -> some IntentResult & ProvidesDialog {
try await performDoorCommand(action.rawValue)
return .result(dialog: "Performed \(action) action on the door.")
}
}

@available(iOS 17.0, *)
struct OpenDoorIntent: AppIntent {
static var title: LocalizedStringResource = "Open Door"
static var description = IntentDescription("Opens the dorm door immediately.")

func perform() async throws -> some IntentResult & ProvidesDialog {
try await performDoorCommand("open")
return .result(dialog: "Door opened successfully!")
}
}

@available(iOS 17.0, *)
struct OpenDoorIn3SecIntent: AppIntent {
static var title: LocalizedStringResource = "Open Door (3 Seconds)"
static var description = IntentDescription("Opens the door immediately, waits 3 seconds, then closes it.")

func perform() async throws -> some IntentResult & ProvidesDialog {
try await performDoorCommand("open")
try await Task.sleep(nanoseconds: 3_000_000_000)
try await performDoorCommand("close")
return .result(dialog: "Opened, waited 3 seconds, and closed the door.")
}
}

@available(iOS 17.0, *)
struct CloseDoorIntent: AppIntent {
static var title: LocalizedStringResource = "Close Door"
static var description = IntentDescription("Closes the dorm door.")

func perform() async throws -> some IntentResult & ProvidesDialog {
try await performDoorCommand("close")
return .result(dialog: "Door closed successfully!")
}
}

@available(iOS 17.0, *)
struct GetDoorStatusIntent: AppIntent, WidgetConfigurationIntent {
static var title: LocalizedStringResource = "Door Status Configuration"
static var description = IntentDescription("Configures the door status widget.")
// No perform method needed.
}

@available(iOS 17.0, *)
extension AppIntent {
func performDoorCommand(_ command: String) async throws {
try await withCheckedThrowingContinuation { continuation in
NetworkManager.shared.sendCommand(command: command) { result in
switch result {
case .success:
continuation.resume()
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}

func getDoorStatus() async throws -> String {
try await withCheckedThrowingContinuation { continuation in
NetworkManager.shared.fetchDoorStatus { result in
switch result {
case .success(let status):
continuation.resume(returning: status.doorOpen ? "Door is Open" : "Door is Closed")
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
}

@available(iOS 17.0, *)
struct DoorShortcutsProvider: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
return [
AppShortcut(
intent: OpenDoorIn3SecIntent(),
phrases: ["Open door in three seconds"],
shortTitle: "Open in 3s",
systemImageName: "timer"
),
AppShortcut(
intent: OpenDoorIntent(),
phrases: ["Open door now"],
shortTitle: "Open Now",
systemImageName: "arrow.up.circle"
),
AppShortcut(
intent: CloseDoorIntent(),
phrases: ["Close the door"],
shortTitle: "Close Door",
systemImageName: "lock"
),
AppShortcut(
intent: DoorActionIntent(),
phrases: ["Perform a door action"],
shortTitle: "Perform Door Action",
systemImageName: "gear"
)
]
}
}
35 changes: 0 additions & 35 deletions Ammaar's Dorm Controls/Ammaar's Dorm Controls/ContentView.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

struct AppError: Identifiable {
let id = UUID()
let message: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

struct AuthStatus: Codable {
let authRequired: Bool
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Foundation
// No global constants needed currently.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

struct LoginResponse: Codable {
let message: String
let token: String
}
23 changes: 23 additions & 0 deletions Ammaar's Dorm Controls/Ammaar's Dorm Controls/MyDormDoorApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import SwiftUI

@main
struct MyDormDoorApp: App {
@StateObject var doorViewModel = DoorControlViewModel()
@StateObject var loginViewModel = LoginViewModel()
@State private var pendingShortcutAction: ShortcutActionType? = nil

var body: some Scene {
WindowGroup {
ContentView(pendingShortcutAction: $pendingShortcutAction)
.environmentObject(doorViewModel)
.environmentObject(loginViewModel)
.onAppear {
// If there was a shortcut action requested at launch, capture it now.
if let action = SceneDelegate.requestedShortcutAction {
pendingShortcutAction = action
SceneDelegate.requestedShortcutAction = nil
}
}
}
}
}
76 changes: 0 additions & 76 deletions Ammaar's Dorm Controls/Ammaar's Dorm Controls/NetworkManager.swift

This file was deleted.

Loading

0 comments on commit fcfdd03

Please sign in to comment.