Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Modules/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ let package = Package(
revision: "bf141adc75e2769eb469a3e095bdc93dc30be8de"
),
.package(url: "https://github.com/wordpress-mobile/AztecEditor-iOS", from: "1.20.0"),
.package(url: "https://github.com/kean/Pulse", from: "5.0.0"),
.package(url: "https://github.com/kean/PulseLogHandler", from: "5.0.0"),
],
targets: XcodeSupport.targets + [
.target(name: "AsyncImageKit", dependencies: [
Expand Down Expand Up @@ -371,6 +373,9 @@ enum XcodeSupport {
.product(name: "MediaEditor", package: "MediaEditor-iOS"),
.product(name: "NSObject-SafeExpectations", package: "NSObject-SafeExpectations"),
.product(name: "NSURL-IDN", package: "NSURL-IDN"),
.product(name: "Pulse", package: "Pulse"),
.product(name: "PulseUI", package: "Pulse"),
.product(name: "PulseLogHandler", package: "PulseLogHandler"),
.product(name: "Reachability", package: "Reachability"),
.product(name: "Starscream", package: "Starscream"),
.product(name: "SVProgressHUD", package: "SVProgressHUD"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,60 @@
@ObservedObject
var viewModel: ExperimentalFeaturesViewModel

@AppStorage("isDeveloperModeEnabled")
private var isDeveloperModeEnabled = false

@State private var tapCount = 0

package init(viewModel: ExperimentalFeaturesViewModel) {
self.viewModel = viewModel
}

private var regularFeatures: [Feature] {
viewModel.items.filter { !$0.isSuperExperimental }
}

private var developerFeatures: [Feature] {
viewModel.items.filter { $0.isSuperExperimental }
}

public var body: some View {
List {
Section {
ForEach(viewModel.items) { item in
ForEach(regularFeatures) { item in

Check warning on line 28 in Modules/Sources/WordPressUI/Views/Settings/ExperimentalFeatures/ExperimentalFeaturesList.swift

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 2 closure expressions.

See more on https://sonarcloud.io/project/issues?id=wordpress-mobile_WordPress-iOS&issues=AZqoQlqspU-08slyAwCj&open=AZqoQlqspU-08slyAwCj&pullRequest=25005
Toggle(item.name, isOn: viewModel.binding(for: item))
}
} footer: {
if !viewModel.notes.isEmpty {
VStack(alignment: .leading, spacing: 4) {
ForEach(viewModel.notes, id: \.self) { note in
Text(note)
.font(.footnote)
.foregroundColor(.secondary)
VStack(alignment: .leading, spacing: 12) {

Check warning on line 32 in Modules/Sources/WordPressUI/Views/Settings/ExperimentalFeatures/ExperimentalFeaturesList.swift

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 2 closure expressions.

See more on https://sonarcloud.io/project/issues?id=wordpress-mobile_WordPress-iOS&issues=AZqoQlqspU-08slyAwCk&open=AZqoQlqspU-08slyAwCk&pullRequest=25005
if !viewModel.notes.isEmpty {
VStack(alignment: .leading, spacing: 4) {
ForEach(viewModel.notes, id: \.self) { note in
Text(note)
.font(.footnote)
.foregroundColor(.secondary)
}
}
}

if !isDeveloperModeEnabled {
HStack {
Spacer()
boltButton
Spacer()
}
}
}
.padding(.top, 8)
}

if isDeveloperModeEnabled && !developerFeatures.isEmpty {
Section {
ForEach(developerFeatures) { item in

Check warning on line 56 in Modules/Sources/WordPressUI/Views/Settings/ExperimentalFeatures/ExperimentalFeaturesList.swift

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 2 closure expressions.

See more on https://sonarcloud.io/project/issues?id=wordpress-mobile_WordPress-iOS&issues=AZqoQlqspU-08slyAwCl&open=AZqoQlqspU-08slyAwCl&pullRequest=25005
Toggle(item.name, isOn: viewModel.binding(for: item))
}
} header: {
Text(Strings.developerToolsSectionTitle)
}
}
}
.listStyle(.insetGrouped)
Expand All @@ -34,6 +68,39 @@
}
}

private var boltButton: some View {
Image(systemName: "bolt.fill")
.font(.system(size: 20))
.foregroundColor(.secondary)
.symbolEffect(.bounce.up, value: tapCount)
.onTapGesture {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does onTapGesture(count: 5) { isDeveloperModeEnabled = true } work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to change it and try it.
I generated all the original code.

handleBoltTap()
}
}

private func handleBoltTap() {
tapCount += 1

let generator = UIImpactFeedbackGenerator(style: impactStyle(for: tapCount))
generator.impactOccurred()

if tapCount >= 5 {
withAnimation {
isDeveloperModeEnabled = true
}
}
}

private func impactStyle(for count: Int) -> UIImpactFeedbackGenerator.FeedbackStyle {
switch count {
case 1: return .light
case 2: return .medium
case 3: return .heavy
case 4: return .rigid
default: return .rigid
}
}

public static func asViewController(
viewModel: ExperimentalFeaturesViewModel
) -> UIHostingController<Self> {
Expand All @@ -50,6 +117,12 @@
value: "Experimental Features",
comment: "The title for the experimental features list"
)

static let developerToolsSectionTitle = NSLocalizedString(
"experimentalFeaturesList.developTools.section.title",
value: "Developer Tools",
comment: "Section title for developer tools"
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import Foundation
public struct Feature: Identifiable {
public let name: String
public let key: String
public let isSuperExperimental: Bool

public var id: String { key }

public init(name: String, key: String) {
public init(name: String, key: String, isSuperExperimental: Bool = false) {
self.name = name
self.key = key
self.isSuperExperimental = isSuperExperimental
}

package static let SampleData: [Feature] = [
Expand Down
59 changes: 59 additions & 0 deletions WordPress/Classes/Networking/PulseMiddleware.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Pulse
import WordPressAPI
import WordPressAPIInternal

final class PulseMiddleware: Middleware {

private static let errorStatusCodes: [UInt16] = [
400, 401, 402, 403, 404, 419, 429,
500
]

func process(
requestExecutor: any RequestExecutor,
response: WpNetworkResponse,
request: WpNetworkRequest,
context: RequestContext?
) async throws -> WpNetworkResponse {

LoggerStore.shared.storeRequest(
convertToUrlRequest(request),
response: try convertToUrlResponse(response),
error: Self.errorStatusCodes.contains(response.statusCode) ? parseBodyAsError(response.body) : nil,
data: response.body
)
return response
}

private func convertToUrlRequest(_ original: WpNetworkRequest) -> URLRequest {
let url = URL(string: original.url())!
var request = URLRequest(url: url)
request.httpMethod = "\(original.method())"
request.allHTTPHeaderFields = original.headerMap().toFlatMap()
request.httpBody = original.body()?.contents()
return request
}

private func convertToUrlResponse(_ original: WpNetworkResponse) throws -> URLResponse? {
HTTPURLResponse(
url: try original.requestUrl.asURL(),
statusCode: Int(original.statusCode),
httpVersion: nil,
headerFields: original.responseHeaderMap.toFlatMap()
)
}

// TODO: This implementation should probably use the underlying Rust implementation

Check warning on line 46 in WordPress/Classes/Networking/PulseMiddleware.swift

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=wordpress-mobile_WordPress-iOS&issues=AZq274KURcpTkwSKUv_7&open=AZq274KURcpTkwSKUv_7&pullRequest=25005
private func parseBodyAsError(_ data: Data) -> Error? {
try? JSONDecoder().decode(WpError.self, from: data)
}

struct WpError: Codable, Error {
let code: Int
let message: String

var description: String {
message
}
}
}
5 changes: 4 additions & 1 deletion WordPress/Classes/Networking/WordPressClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ extension WordPressClient {
urlSession: session,
apiUrlResolver: resolver,
authenticationProvider: provider,
appNotifier: notifier
middlewarePipeline: MiddlewarePipeline(middlewares: [
PulseMiddleware()
]),
appNotifier: notifier,
)
self.init(api: api, rootUrl: apiRootURL)
}
Expand Down
8 changes: 8 additions & 0 deletions WordPress/Classes/System/WordPressAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import AutomatticTracks
import BuildSettingsKit
import CocoaLumberjackSwift
import DesignSystem
import Logging
import Pulse
import PulseLogHandler
import Reachability
import SFHFKeychainUtils
import SVProgressHUD
Expand Down Expand Up @@ -80,6 +83,9 @@ public class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
DesignSystem.FontManager.registerCustomFonts()
AssertionLoggerDependencyContainer.logger = AssertionLogger()
UITestConfigurator.prepareApplicationForUITests(in: application, window: window)
if FeatureFlag.pulse.enabled {
LoggingSystem.bootstrap(PersistentLogHandler.init)
}

AppAppearance.overrideAppearance()
MemoryCache.shared.register()
Expand Down Expand Up @@ -115,6 +121,8 @@ public class WordPressAppDelegate: UIResponder, UIApplicationDelegate {

public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
DDLogInfo("didFinishLaunchingWithOptions state: \(application.applicationState)")
Logger(label: "App")
.info("didFinishLaunchingWithOptions state: \(application.applicationState)")

ABTest.start()

Expand Down
4 changes: 4 additions & 0 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum FeatureFlag: Int, CaseIterable {
case intelligence
case newSupport
case nativeBlockInserter
case pulse

/// Returns a boolean indicating if the feature is enabled.
///
Expand Down Expand Up @@ -86,6 +87,8 @@ public enum FeatureFlag: Int, CaseIterable {
return false
case .nativeBlockInserter:
return true
case .pulse:
return BuildConfiguration.current == .debug
}
}

Expand Down Expand Up @@ -130,6 +133,7 @@ extension FeatureFlag {
case .intelligence: "Intelligence"
case .newSupport: "New Support"
case .nativeBlockInserter: "Native Block Inserter"
case .pulse: "Extensive Logging"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extension EditorConfiguration {
// Limited to Jetpack-connected sites until editor assets endpoint is available in WordPress core
.setShouldUsePlugins(Self.shouldEnablePlugins(for: blog, appPassword: applicationPassword))
.setLocale(WordPressComLanguageDatabase.shared.deviceLanguage.slug)
.setEnableNetworkLogging(true)

if let blogUrl = blog.url {
builder = builder.setSiteUrl(blogUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

let configuration = EditorConfigurationBuilder(content: initialContent ?? "")
.setShouldHideTitle(true)
.setEnableNetworkLogging(true)
.build()

let editorVC = GutenbergKit.EditorViewController(configuration: configuration)
Expand All @@ -61,6 +62,7 @@
}

extension CommentGutenbergEditorViewController: GutenbergKit.EditorViewControllerDelegate {

func editorDidLoad(_ viewContoller: GutenbergKit.EditorViewController) {
// Do nothing
}
Expand Down Expand Up @@ -108,4 +110,9 @@
func editor(_ viewController: GutenbergKit.EditorViewController, didCloseModalDialog dialogType: String) {
// Do nothing
}

func editor(_ viewController: GutenbergKit.EditorViewController, didLogNetworkRequest request: GutenbergKit.NetworkRequest) {

}

Check failure on line 116 in WordPress/Classes/ViewRelated/Comments/Controllers/Editor/CommentGutenbergEditorViewController.swift

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a nested comment explaining why this function is empty, or complete the implementation.

See more on https://sonarcloud.io/project/issues?id=wordpress-mobile_WordPress-iOS&issues=AZq274E7RcpTkwSKUv_6&open=AZq274E7RcpTkwSKUv_6&pullRequest=25005

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import WordPressData
import WordPressShared
import ShareExtensionCore
import SVProgressHUD
import PulseUI
import WordPressFlux
import DesignSystem
import WordPressUI
Expand Down Expand Up @@ -550,6 +551,12 @@ private extension AppSettingsViewController {
action: pushDebugMenu()
)

let loggerRow = NavigationItemRow(title: Strings.logger, icon: UIImage(systemName: "record.circle")) { [weak self] _ in
UserDefaults.standard.set(false, forKey: "pulse-disable-support-prompts")
let mainVC = PulseUI.MainViewController()
self?.present(mainVC, animated: true)
}

let designSystem = NavigationItemRow(
title: NSLocalizedString("Design System", comment: "Navigates to design system gallery only available in development builds"),
icon: UIImage(systemName: "paintpalette"),
Expand Down Expand Up @@ -586,6 +593,10 @@ private extension AppSettingsViewController {
rows.append(designSystem)
}

if FeatureFlag.pulse.enabled {
rows.append(loggerRow)
}

if let presenter = RootViewCoordinator.shared.whatIsNewScenePresenter as? WhatIsNewScenePresenter,
presenter.versionHasAnnouncements,
FeatureFlag.whatsNew.enabled {
Expand Down Expand Up @@ -636,5 +647,11 @@ extension AppSettingsViewController {
value: "Experimental Features",
comment: "The list item of experimental features that users can choose to enable"
)

static let logger = NSLocalizedString(
"applicationSettings.logger",
value: "Logger",
comment: "A item in the menu"
)
}
}
Loading