Add MainActor on AnalysticsManager shared property (#24)
All checks were successful
openium/resgen.swift/pipeline/head This commit looks good
All checks were successful
openium/resgen.swift/pipeline/head This commit looks good
Reviewed-on: #24
This commit was merged in pull request #24.
This commit is contained in:
@@ -104,6 +104,7 @@ enum AnalyticsGenerator {
|
||||
|
||||
\(visibility) class AnalyticsManager {
|
||||
|
||||
@MainActor
|
||||
\(visibility) static var shared = AnalyticsManager()
|
||||
|
||||
private init() {}
|
||||
@@ -144,7 +145,7 @@ enum AnalyticsGenerator {
|
||||
) -> String {
|
||||
"""
|
||||
private var isDebugMode: Bool = false
|
||||
|
||||
|
||||
private var isEnabled: Bool {
|
||||
if ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" {
|
||||
false
|
||||
@@ -152,7 +153,7 @@ enum AnalyticsGenerator {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private let logger = Logger(subsystem: "resgen", category: "analytics")
|
||||
|
||||
// MARK: - Enable Methods
|
||||
@@ -198,18 +199,18 @@ enum AnalyticsGenerator {
|
||||
private static func getPrivateLogFunction() -> String {
|
||||
"""
|
||||
// MARK: - Private Log Methods
|
||||
|
||||
|
||||
private func formattedParams(_ params: [String: Any]?) -> String {
|
||||
guard let params = params, !params.isEmpty else { return "-" }
|
||||
|
||||
|
||||
let formattedParams = params.map { key, value in
|
||||
" \\(key): \\(value)"
|
||||
}
|
||||
.joined(separator: "\\n")
|
||||
|
||||
|
||||
return "\\n" + formattedParams
|
||||
}
|
||||
|
||||
|
||||
private func logScreen(
|
||||
name: String,
|
||||
path: String,
|
||||
@@ -219,11 +220,11 @@ enum AnalyticsGenerator {
|
||||
if isDebugMode {
|
||||
logger.log("Analytics disabled")
|
||||
}
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
managers.values.forEach { manager in
|
||||
|
||||
|
||||
if isDebugMode {
|
||||
logger.debug(\"""
|
||||
🖥️ Screen:
|
||||
@@ -232,7 +233,7 @@ enum AnalyticsGenerator {
|
||||
Params: \\(self.formattedParams(params), privacy: .public)
|
||||
\""")
|
||||
}
|
||||
|
||||
|
||||
manager.logScreen(
|
||||
name: name,
|
||||
path: path,
|
||||
@@ -240,7 +241,7 @@ enum AnalyticsGenerator {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func logEvent(
|
||||
name: String,
|
||||
action: String,
|
||||
@@ -251,11 +252,11 @@ enum AnalyticsGenerator {
|
||||
if isDebugMode {
|
||||
logger.log("Analytics disabled")
|
||||
}
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
managers.values.forEach { manager in
|
||||
|
||||
|
||||
if isDebugMode {
|
||||
logger.debug(\"""
|
||||
📊 Event:
|
||||
@@ -265,7 +266,7 @@ enum AnalyticsGenerator {
|
||||
Params: \\(self.formattedParams(params), privacy: .public)
|
||||
\""")
|
||||
}
|
||||
|
||||
|
||||
manager.logEvent(
|
||||
name: name,
|
||||
action: action,
|
||||
|
||||
@@ -16,12 +16,14 @@ struct GenerateOptions: ParsableArguments {
|
||||
@Argument(help: "Configuration file.", transform: { $0.replaceTiltWithHomeDirectoryPath() })
|
||||
var configurationFile: String
|
||||
|
||||
@Option(help: "Project directory. It will be added to every relative path (path that does not start with `/`",
|
||||
transform: {
|
||||
if $0.last == "/" {
|
||||
return $0
|
||||
@Option(
|
||||
help: "Project directory. It will be added to every relative path (path that does not start with `/`",
|
||||
transform: {
|
||||
if $0.last == "/" {
|
||||
return $0
|
||||
}
|
||||
return $0 + "/"
|
||||
}
|
||||
return $0 + "/"
|
||||
})
|
||||
)
|
||||
var projectDirectory: String
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user