Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Immo-Ka iOS9// File : ImmoKa/App/ImmoKaApp.swift10// Description : point d'entrée de l'application.11// Module : ImmoKa12// Repository : https://git.spboucher.ai/immo-ka-ios-v313// Project Website : https://www.immo-ka.com14// Created : 2026-11-2515// Last Modified : 2026-11-3016//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author : Simon-Pierre Boucher22// Position : Professor of Finance23// Institution : Université du Québec en Outaouais (UQO)24// Department : Département des sciences administratives25// Organization : SP Boucher26//27// Website : https://spboucher.ai28// Git : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General : info@spboucher.ai35// Professional : contact@spboucher.ai36// Direct : simon@spboucher.ai37// Research : research@spboucher.ai38// Development : dev@spboucher.ai39// Support : support@spboucher.ai40// Security/Admin : admin@spboucher.ai41// Notifications : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification : Public68// Distribution : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License : None specified (no license file in this repository)82// Maintainer : Simon-Pierre Boucher83// Technical Contact: dev@spboucher.ai84//85// =============================================================================86// END OF SP BOUCHER SOURCE HEADER87// =============================================================================8889import CoreSpotlight90import SwiftData91import SwiftUI92import UIKit9394@main95struct ImmoKaApp: App {96 @State private var model = AppModel()97 @State private var library: Library98 @State private var account: Account99 @State private var door = DoorCenter()100 @Environment(\.scenePhase) private var scenePhase101102 init() {103 // base locale jetable (tests, captures) : la session l'est aussi, sauf `-IKKeychain YES`104 let ephemeral = UserDefaults.standard.bool(forKey: "IKInMemory")105 let keychain = !ephemeral || UserDefaults.standard.bool(forKey: "IKKeychain")106 let store: any SecretStore = keychain ? KeychainStore() : MemoryStore()107 #if DEBUG108 // -IKAccountReset YES : oublie la session gardée par un essai précédent109 if UserDefaults.standard.bool(forKey: "IKAccountReset") { store.delete("session.token"); store.delete("session.user") }110 #endif111 let library = Library(inMemory: ephemeral)112 _library = State(initialValue: library)113 _account = State(initialValue: Account(library: library, store: store, defaults: ephemeral ? nil : .standard))114 // grands titres de navigation en New York (serif, graisse 500), comme les titres éditoriaux de l'app115 if let d = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle).withDesign(.serif) {116 let medium = d.addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: UIFont.Weight.medium]])117 UINavigationBar.appearance().largeTitleTextAttributes = [.font: UIFont(descriptor: medium, size: 0)]118 }119 }120121 var body: some Scene {122 WindowGroup {123 RootView()124 .environment(model)125 .environment(library)126 .environment(account)127 .environment(door)128 .modelContainer(library.container)129 .preferredColorScheme(model.appearance.scheme)130 .tint(Theme.brand)131 .onOpenURL { model.handle(url: $0) }132 .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in133 if let url = activity.webpageURL { model.handle(url: url) }134 }135 // Spotlight : une propriété retrouvée depuis l'écran d'accueil ouvre sa fiche136 .onContinueUserActivity(CSSearchableItemActionType) { activity in137 if let id = activity.userInfo?[CSSearchableItemActivityIdentifier] as? String, let uid = Spotlight.uid(from: id) {138 model.open(.listing(uid))139 }140 }141 // App Intents et widgets : le lien posé à l'arrivée dans l'app142 .onChange(of: DeepLinkInbox.shared.pending) { _, url in143 if let url { model.handle(url: url); DeepLinkInbox.shared.pending = nil }144 }145 .onChange(of: scenePhase) { _, phase in146 // retour au premier plan : nouvelle synchronisation avec le compte, s'il y en a un147 if phase == .active { Task { await account.activate() } }148 }149 .task {150 account.sync.watchNetwork()151 await account.activate()152 }153 .task {154 library.indexExistingFavorites()155 if let url = DeepLinkInbox.shared.pending { model.handle(url: url); DeepLinkInbox.shared.pending = nil }156 ResponseCache.prune()157 await model.loadSourceNames()158 #if DEBUG159 // jeu d'essai pour les tests et captures : -IKSeed uid1,uid2 (favoris + comparateur)160 if let seed = UserDefaults.standard.string(forKey: "IKSeed") {161 for uid in seed.split(separator: ",").map(String.init) {162 guard let l = try? await APIClient.shared.fullListing(uid) else { continue }163 if !library.isFavorite(uid) { library.toggleFavorite(l) }164 if !library.compareIDs.contains(uid) { library.toggleCompare(uid) }165 }166 }167 #endif168 }169 }170 }171}172