sparkling-debug-tool 2.1.0-rc.10 → 2.1.0-rc.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,13 +3,23 @@
3
3
  // LICENSE file in the root directory of this source tree.
4
4
  package com.tiktok.sparkling.debugtool
5
5
 
6
+ import android.app.Activity
7
+ import android.app.AlertDialog
6
8
  import android.app.Application
9
+ import android.content.Context
10
+ import android.os.Looper
11
+ import android.text.InputType
12
+ import android.widget.EditText
13
+ import android.widget.Toast
7
14
  import com.lynx.devtool.LynxDevtoolEnv
8
15
  import com.lynx.service.devtool.LynxDevToolService
9
16
  import com.lynx.tasm.LynxEnv
10
17
  import com.lynx.tasm.service.LynxServiceCenter
11
18
 
12
19
  object SparklingDebugTool {
20
+ private const val PREFS_NAME = "sparkling_debug_tool"
21
+ private const val KEY_DEV_URL = "dev_url"
22
+
13
23
  @JvmStatic
14
24
  fun init(application: Application) {
15
25
  LynxServiceCenter.inst().registerService(LynxDevToolService.INSTANCE)
@@ -18,4 +28,65 @@ object SparklingDebugTool {
18
28
  LynxEnv.inst().enableLogBox(true)
19
29
  LynxDevtoolEnv.inst().enableLongPressMenu(true)
20
30
  }
31
+
32
+ @JvmStatic
33
+ fun getDevUrl(context: Context, fallback: String): String {
34
+ val stored = context.applicationContext
35
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
36
+ .getString(KEY_DEV_URL, null)
37
+ ?.trim()
38
+ return if (stored.isNullOrEmpty()) fallback else stored
39
+ }
40
+
41
+ @JvmStatic
42
+ fun setDevUrl(context: Context, url: String) {
43
+ context.applicationContext
44
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
45
+ .edit()
46
+ .putString(KEY_DEV_URL, url.trim())
47
+ .apply()
48
+ }
49
+
50
+ @JvmStatic
51
+ fun showDevUrlDialog(
52
+ activity: Activity,
53
+ initialUrl: String? = null,
54
+ onSaved: ((String) -> Unit)? = null,
55
+ ) {
56
+ if (Looper.myLooper() != Looper.getMainLooper()) {
57
+ activity.runOnUiThread { showDevUrlDialog(activity, initialUrl, onSaved) }
58
+ return
59
+ }
60
+
61
+ val input = EditText(activity).apply {
62
+ setText(initialUrl ?: "")
63
+ hint = "http://10.0.2.2:5969/main.lynx.bundle"
64
+ inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI
65
+ setSelection(text.length)
66
+ }
67
+
68
+ val dialog = AlertDialog.Builder(activity)
69
+ .setTitle("Set Sparkling Dev URL")
70
+ .setMessage("Update the main Lynx bundle URL for debug mode.")
71
+ .setView(input)
72
+ .setNegativeButton("Cancel", null)
73
+ .setPositiveButton("Save", null)
74
+ .create()
75
+
76
+ dialog.setOnShowListener {
77
+ val saveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
78
+ saveButton.setOnClickListener {
79
+ val value = input.text?.toString()?.trim().orEmpty()
80
+ if (value.isEmpty()) {
81
+ Toast.makeText(activity, "Dev URL cannot be empty", Toast.LENGTH_SHORT).show()
82
+ return@setOnClickListener
83
+ }
84
+ setDevUrl(activity, value)
85
+ onSaved?.invoke(value)
86
+ dialog.dismiss()
87
+ }
88
+ }
89
+
90
+ dialog.show()
91
+ }
21
92
  }
@@ -4,12 +4,61 @@
4
4
 
5
5
  import Foundation
6
6
  import Lynx
7
+ import UIKit
7
8
 
8
9
  @objcMembers
9
10
  public class SparklingDebugTool: NSObject {
11
+ private static let devURLKey = "sparkling.debug.dev_url"
12
+
10
13
  public static func setup() {
11
14
  LynxEnv.sharedInstance().lynxDebugEnabled = true
12
15
  LynxEnv.sharedInstance().devtoolEnabled = true
13
16
  LynxEnv.sharedInstance().logBoxEnabled = true
14
17
  }
18
+
19
+ public static func devURL(fallback: String) -> String {
20
+ let stored = UserDefaults.standard.string(forKey: devURLKey)?.trimmingCharacters(in: .whitespacesAndNewlines)
21
+ if let stored, !stored.isEmpty {
22
+ return stored
23
+ }
24
+ return fallback
25
+ }
26
+
27
+ public static func setDevURL(_ url: String) {
28
+ let normalized = url.trimmingCharacters(in: .whitespacesAndNewlines)
29
+ UserDefaults.standard.set(normalized, forKey: devURLKey)
30
+ }
31
+
32
+ public static func showDevURLDialog(
33
+ from viewController: UIViewController,
34
+ initialURL: String?,
35
+ onSaved: ((String) -> Void)? = nil
36
+ ) {
37
+ DispatchQueue.main.async {
38
+ let alert = UIAlertController(
39
+ title: "Set Sparkling Dev URL",
40
+ message: "Update the main Lynx bundle URL for debug mode.",
41
+ preferredStyle: .alert
42
+ )
43
+
44
+ alert.addTextField { textField in
45
+ textField.placeholder = "http://localhost:5969/main.lynx.bundle"
46
+ textField.keyboardType = .URL
47
+ textField.text = initialURL
48
+ textField.clearButtonMode = .whileEditing
49
+ }
50
+
51
+ alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
52
+ alert.addAction(UIAlertAction(title: "Save", style: .default, handler: { _ in
53
+ let value = alert.textFields?.first?.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
54
+ guard !value.isEmpty else {
55
+ return
56
+ }
57
+ setDevURL(value)
58
+ onSaved?(value)
59
+ }))
60
+
61
+ viewController.present(alert, animated: true)
62
+ }
63
+ }
15
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparkling-debug-tool",
3
- "version": "2.1.0-rc.10",
3
+ "version": "2.1.0-rc.12",
4
4
  "description": "Sparkling debug tool SDK",
5
5
  "homepage": "https://tiktok.github.io/sparkling/",
6
6
  "repository": {