Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Lou-Ka iOS9// File : LouKa/App/LouKaApp.swift10// Description : point d'entrée de l'application.11// Module : LouKa12// Repository : https://git.spboucher.ai/lou-ka-ios-v313// Project Website : https://www.lou-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 SwiftUI9293@main94struct LouKaApp: App {95 @State private var model = AppModel()96 @State private var library: Library97 @State private var account: Account98 @State private var door = DoorCenter()99 @Environment(\.scenePhase) private var scenePhase100101 init() {102 // base locale jetable (tests, captures) : la session l'est aussi, sauf `-LKKeychain YES`103 let ephemeral = UserDefaults.standard.bool(forKey: "LKInMemory")104 let keychain = !ephemeral || UserDefaults.standard.bool(forKey: "LKKeychain")105 let store: any SecretStore = keychain ? KeychainStore() : MemoryStore()106 #if DEBUG107 // -LKAccountReset YES : oublie la session gardée par un essai précédent108 if UserDefaults.standard.bool(forKey: "LKAccountReset") { store.delete("session.token"); store.delete("session.user") }109 #endif110 let library = Library(inMemory: ephemeral)111 _library = State(initialValue: library)112 _account = State(initialValue: Account(library: library, store: store, defaults: ephemeral ? nil : .standard))113 }114115 var body: some Scene {116 WindowGroup {117 RootView()118 .environment(model)119 .environment(library)120 .environment(account)121 .environment(door)122 .modelContainer(library.container)123 .preferredColorScheme(model.appearance.scheme)124 .tint(Theme.brand)125 .onOpenURL { model.handle(url: $0) }126 .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in127 if let url = activity.webpageURL { model.handle(url: url) }128 }129 .onContinueUserActivity(CSSearchableItemActionType) { activity in130 if let uid = SpotlightIndex.uid(from: activity) { model.open(.listing(uid)) }131 }132 .onContinueUserActivity("com.spboucher.louka.v2.logement") { activity in133 if let url = activity.webpageURL { model.handle(url: url) }134 }135 .onChange(of: scenePhase) { _, phase in136 // retour au premier plan : nouvelle synchronisation avec le compte, s'il y en a un137 if phase == .active { Task { await account.activate() } }138 }139 .task {140 account.sync.watchNetwork()141 await account.activate()142 }143 .task {144 IntentRouter.shared.attach { model.handle(url: $0) }145 ResponseCache.prune()146 await model.loadSourceNames()147 #if DEBUG148 // jeu d'essai pour les tests et captures : -LKSeed uid1,uid2 (favoris + comparateur)149 if let seed = UserDefaults.standard.string(forKey: "LKSeed") {150 for uid in seed.split(separator: ",").map(String.init) {151 guard let l = try? await APIClient.shared.listingV3(uid) else { continue }152 if !library.isFavorite(uid) { library.toggleFavorite(l) }153 if !library.compareIDs.contains(uid) { library.toggleCompare(uid) }154 }155 }156 #endif157 }158 }159 }160}161