Skip to content

Commit ceed648

Browse files
authored
Make auto-subscribe to app notifications configurable (#59)
So we can avoid them on macCatalyst
1 parent e451ca1 commit ceed648

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/SQLite/SQLiteDatabase.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public final class SQLiteDatabase: DatabaseProtocol, @unchecked Sendable {
4545
public static func makeShared(
4646
path: String,
4747
busyTimeout: TimeInterval = 5,
48-
collationSequences: [String: @Sendable (String, String) -> ComparisonResult] = [:]
48+
collationSequences: [String: @Sendable (String, String) -> ComparisonResult] = [:],
49+
observeLifecycleEvents: Bool = true
4950
) throws -> SQLiteDatabase {
5051
guard path != ":memory:" else {
5152
throw SQLiteError.SQLITE_IOERR
@@ -71,7 +72,8 @@ public final class SQLiteDatabase: DatabaseProtocol, @unchecked Sendable {
7172
database = try SQLiteDatabase(
7273
path: url.path,
7374
busyTimeout: busyTimeout,
74-
collationSequences: collationSequences
75+
collationSequences: collationSequences,
76+
observeLifecycleEvents: observeLifecycleEvents
7577
)
7678
} catch {
7779
databaseError = error
@@ -95,7 +97,8 @@ public final class SQLiteDatabase: DatabaseProtocol, @unchecked Sendable {
9597
public init(
9698
path: String = ":memory:",
9799
busyTimeout: TimeInterval = 5,
98-
collationSequences: [String: @Sendable (String, String) -> ComparisonResult] = [:]
100+
collationSequences: [String: @Sendable (String, String) -> ComparisonResult] = [:],
101+
observeLifecycleEvents: Bool = true
99102
) throws {
100103
database = try Self.open(
101104
at: path,
@@ -116,7 +119,9 @@ public final class SQLiteDatabase: DatabaseProtocol, @unchecked Sendable {
116119
try checkIsSQLiteVersionSupported(sqliteVersion)
117120
precondition(enforcesForeignKeyConstraints)
118121

119-
registerForAppNotifications()
122+
if observeLifecycleEvents {
123+
registerForAppNotifications()
124+
}
120125
changeNotifier.start()
121126
}
122127

0 commit comments

Comments
 (0)