Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Move AppState to the same location as delegates
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T committed Jul 6, 2023
1 parent 8c8436c commit c4fa06e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions App/Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
CA986FB4298C1254000C6DD8 /* BraveWidgetsModels in Frameworks */ = {isa = PBXBuildFile; productRef = CA986FB3298C1254000C6DD8 /* BraveWidgetsModels */; };
CAADEFE026E2707F0020DC4C /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAADEFDF26E2707F0020DC4C /* SceneDelegate.swift */; };
CAAE653D287C9FCF00FA44A3 /* CPTemplateApplicationSceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAAE653C287C9FCF00FA44A3 /* CPTemplateApplicationSceneDelegate.swift */; };
CABDE77F2A55DD1C00A388A4 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABDE77E2A55DD1C00A388A4 /* AppState.swift */; };
E6231C011B90A44F005ABB0D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E6231C001B90A44F005ABB0D /* libz.tbd */; };
E6231C051B90A472005ABB0D /* libxml2.2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E6231C041B90A472005ABB0D /* libxml2.2.tbd */; };
F84B22041A0910F600AAB793 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F84B21E51A0910F600AAB793 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -315,6 +316,7 @@
CA0391F7271E143F000EB13C /* SingleStatWidget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleStatWidget.swift; sourceTree = "<group>"; };
CAADEFDF26E2707F0020DC4C /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
CAAE653C287C9FCF00FA44A3 /* CPTemplateApplicationSceneDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPTemplateApplicationSceneDelegate.swift; sourceTree = "<group>"; };
CABDE77E2A55DD1C00A388A4 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
E6231C001B90A44F005ABB0D /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
E6231C041B90A472005ABB0D /* libxml2.2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libxml2.2.tbd; path = usr/lib/libxml2.2.tbd; sourceTree = SDKROOT; };
E62AC15F1E956AFC00843532 /* Dev.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Dev.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -606,6 +608,7 @@
children = (
CAAE653C287C9FCF00FA44A3 /* CPTemplateApplicationSceneDelegate.swift */,
F84B21E51A0910F600AAB793 /* AppDelegate.swift */,
CABDE77E2A55DD1C00A388A4 /* AppState.swift */,
CAADEFDF26E2707F0020DC4C /* SceneDelegate.swift */,
);
path = Delegates;
Expand Down Expand Up @@ -1040,6 +1043,7 @@
2F4A572429E608C8003454F8 /* BrowserIntents.intentdefinition in Sources */,
F84B22041A0910F600AAB793 /* AppDelegate.swift in Sources */,
27BEDCCC28AD37CE0073425E /* BraveWidgets.intentdefinition in Sources */,
CABDE77F2A55DD1C00A388A4 /* AppState.swift in Sources */,
CAADEFE026E2707F0020DC4C /* SceneDelegate.swift in Sources */,
CAAE653D287C9FCF00FA44A3 /* CPTemplateApplicationSceneDelegate.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import Foundation
import UIKit
import BraveCore
import Brave
import Data
import RuntimeWarnings
import Shared
Expand All @@ -15,17 +16,21 @@ import Storage
import BraveNews
import os.log

private let adsRewardsLog = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ads-rewards")

/// Class that does startup initialization
/// Everything in this class can only be execute ONCE
/// IE: BraveCore initialization, BuildChannel, Migrations, etc.
public class AppState {
private let log = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "app-state")

public static let shared = AppState()

public let braveCore: BraveCoreMain
public let dau: DAU
public let migration: Migration
public let profile: Profile
public let rewards: BraveRewards
public let rewards: Brave.BraveRewards
public let newsFeedDataSource: FeedDataSource
private var didBecomeActive = false

Expand Down Expand Up @@ -63,7 +68,7 @@ public class AppState {
namespace: "TabManagerScreenshots",
quality: UIConstants.screenshotQuality)
} catch {
Logger.module.error("Failed to create an image store for files: \(self.profile.files.rootPath) and namespace: \"TabManagerScreenshots\": \(error.localizedDescription)")
log.error("Failed to create an image store for files: \(self.profile.files.rootPath) and namespace: \"TabManagerScreenshots\": \(error.localizedDescription)")
}
return nil
}()
Expand Down Expand Up @@ -193,14 +198,14 @@ public class AppState {
}
}

private static func migrateAdsConfirmations(for configruation: BraveRewards.Configuration) {
private static func migrateAdsConfirmations(for configuruation: Brave.BraveRewards.Configuration) {
// To ensure after a user launches 1.21 that their ads confirmations, viewed count and
// estimated payout remain correct.
//
// This hack is unfortunately neccessary due to a missed migration path when moving
// confirmations from ledger to ads, we must extract `confirmations.json` out of ledger's
// state file and save it as a new file under the ads directory.
let base = configruation.storageURL
let base = configuruation.storageURL
let ledgerStateContainer = base.appendingPathComponent("ledger/random_state.plist")
let adsConfirmations = base.appendingPathComponent("ads/confirmations.json")
let fm = FileManager.default
Expand Down
1 change: 0 additions & 1 deletion App/iOS/Delegates/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ extension SceneDelegate {
// Store the scene's activities
let windowId: UUID
let isPrivate: Bool
var userActivity = userActivity

if let userActivity = userActivity {
// Restore the scene with the WindowID from the User-Activity
Expand Down
1 change: 0 additions & 1 deletion Sources/Brave/Frontend/Browser/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class Tab: NSObject {

private(set) var type: TabType = .regular


var redirectURLs = [URL]()

var isPrivate: Bool {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Brave/Frontend/Rewards/BraveRewards.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ extension BraveRewards {
case staging
}

var storageURL: URL
public var storageURL: URL
public var environment: Environment
public var adsBuildChannel: BraveAds.BuildChannelInfo = .init()
public var isDebug: Bool?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ public struct CookieNotificationBlockingConsentView: View {
}
}



#if DEBUG
struct CookieNotificationBlockingConsentView_Previews: PreviewProvider {
static var previews: some View {
Expand Down

0 comments on commit c4fa06e

Please sign in to comment.