Skip to content

Commit

Permalink
add notification
Browse files Browse the repository at this point in the history
  • Loading branch information
p-x9 committed Mar 5, 2023
1 parent 9d89445 commit 9581ebe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/AppContainer/AppContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class AppContainer {

private let fileManager = FileManager.default

private let notificationCenter = NotificationCenter.default

/// home directory url
private lazy var homeDirectoryUrl: URL = {
URL(fileURLWithPath: NSHomeDirectory())
Expand Down Expand Up @@ -101,6 +103,8 @@ public class AppContainer {
return
}

notificationCenter.post(name: Self.containerWillChangeNotification, object: nil)

try exportUserDefaults()
exportCookies()

Expand All @@ -119,6 +123,8 @@ public class AppContainer {
incrementActivatedCount(uuid: container.uuid)
// update last activated date
try? updateInfo(of: container, keyValue: .init(\.lastActivatedDate, Date()))

notificationCenter.post(name: Self.containerDidChangeNotification, object: nil)
}

/// activate selected container
Expand Down
14 changes: 14 additions & 0 deletions Sources/AppContainer/Notification.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// AppContainer.Notification.swift
//
//
// Created by p-x9 on 2023/02/27.
//
//

import Foundation

extension AppContainer {
public static let containerWillChangeNotification = Notification.Name("com.p-x9.appcontainer.containerWillChange")
public static let containerDidChangeNotification = Notification.Name("com.p-x9.appcontainer.containerDidChange")
}

0 comments on commit 9581ebe

Please sign in to comment.