sparkling-debug-tool 2.1.0-rc.2 → 2.1.0-rc.20

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,19 +3,96 @@
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) {
25
+ // Preset values must be set BEFORE LynxEnv flags so the DevTool
26
+ // service picks them up during initialization.
27
+ LynxDevToolService.INSTANCE.setLynxDebugPresetValue(true)
28
+ LynxDevToolService.INSTANCE.setLogBoxPresetValue(true)
29
+ LynxDevToolService.INSTANCE.setLoadJsBridge(true)
30
+
15
31
  LynxServiceCenter.inst().registerService(LynxDevToolService.INSTANCE)
16
32
  LynxEnv.inst().enableLynxDebug(true)
17
33
  LynxEnv.inst().enableDevtool(true)
18
34
  LynxEnv.inst().enableLogBox(true)
19
35
  LynxDevtoolEnv.inst().enableLongPressMenu(true)
20
36
  }
37
+
38
+ @JvmStatic
39
+ fun getDevUrl(context: Context, fallback: String): String {
40
+ val stored = context.applicationContext
41
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
42
+ .getString(KEY_DEV_URL, null)
43
+ ?.trim()
44
+ return if (stored.isNullOrEmpty()) fallback else stored
45
+ }
46
+
47
+ @JvmStatic
48
+ fun setDevUrl(context: Context, url: String) {
49
+ context.applicationContext
50
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
51
+ .edit()
52
+ .putString(KEY_DEV_URL, url.trim())
53
+ .apply()
54
+ }
55
+
56
+ @JvmStatic
57
+ fun showDevUrlDialog(
58
+ activity: Activity,
59
+ initialUrl: String? = null,
60
+ onSaved: ((String) -> Unit)? = null,
61
+ ) {
62
+ if (Looper.myLooper() != Looper.getMainLooper()) {
63
+ activity.runOnUiThread { showDevUrlDialog(activity, initialUrl, onSaved) }
64
+ return
65
+ }
66
+
67
+ val input = EditText(activity).apply {
68
+ setText(initialUrl ?: "")
69
+ hint = "http://10.0.2.2:5969/main.lynx.bundle"
70
+ inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI
71
+ setSelection(text.length)
72
+ }
73
+
74
+ val dialog = AlertDialog.Builder(activity)
75
+ .setTitle("Set Sparkling Dev URL")
76
+ .setMessage("Update the main Lynx bundle URL for debug mode.")
77
+ .setView(input)
78
+ .setNegativeButton("Cancel", null)
79
+ .setPositiveButton("Save", null)
80
+ .create()
81
+
82
+ dialog.setOnShowListener {
83
+ val saveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
84
+ saveButton.setOnClickListener {
85
+ val value = input.text?.toString()?.trim().orEmpty()
86
+ if (value.isEmpty()) {
87
+ Toast.makeText(activity, "Dev URL cannot be empty", Toast.LENGTH_SHORT).show()
88
+ return@setOnClickListener
89
+ }
90
+ setDevUrl(activity, value)
91
+ onSaved?.invoke(value)
92
+ dialog.dismiss()
93
+ }
94
+ }
95
+
96
+ dialog.show()
97
+ }
21
98
  }
@@ -4,12 +4,76 @@
4
4
 
5
5
  import Foundation
6
6
  import Lynx
7
+ import UIKit
8
+ import DebugRouter
7
9
 
8
10
  @objcMembers
9
11
  public class SparklingDebugTool: NSObject {
12
+ private static let devURLKey = "sparkling.debug.dev_url"
13
+
10
14
  public static func setup() {
11
- LynxEnv.sharedInstance().lynxDebugEnabled = true
12
- LynxEnv.sharedInstance().devtoolEnabled = true
13
- LynxEnv.sharedInstance().logBoxEnabled = true
15
+ // Preset values must be set BEFORE LynxEnv flags so the DevTool
16
+ // service picks them up during initialization.
17
+
18
+ if let devtool = LynxServices.getInstanceWith(LynxServiceDevToolProtocol.self)
19
+ as? LynxServiceDevToolProtocol {
20
+ devtool.logBoxPresetValue = true
21
+ devtool.lynxDebugPresetValue = true
22
+ }
23
+
24
+ let env = LynxEnv.sharedInstance()
25
+ env.lynxDebugEnabled = true
26
+ env.devtoolEnabled = true
27
+ env.logBoxEnabled = true
28
+
29
+ // Enable DebugRouter so the DevTool desktop app can discover and
30
+ // connect to this app (via USB or network).
31
+ DebugRouter.instance().enableAllSessions()
32
+ }
33
+
34
+ public static func devURL(fallback: String) -> String {
35
+ let stored = UserDefaults.standard.string(forKey: devURLKey)?.trimmingCharacters(in: .whitespacesAndNewlines)
36
+ if let stored, !stored.isEmpty {
37
+ return stored
38
+ }
39
+ return fallback
40
+ }
41
+
42
+ public static func setDevURL(_ url: String) {
43
+ let normalized = url.trimmingCharacters(in: .whitespacesAndNewlines)
44
+ UserDefaults.standard.set(normalized, forKey: devURLKey)
45
+ }
46
+
47
+ public static func showDevURLDialog(
48
+ from viewController: UIViewController,
49
+ initialURL: String?,
50
+ onSaved: ((String) -> Void)? = nil
51
+ ) {
52
+ DispatchQueue.main.async {
53
+ let alert = UIAlertController(
54
+ title: "Set Sparkling Dev URL",
55
+ message: "Update the main Lynx bundle URL for debug mode.",
56
+ preferredStyle: .alert
57
+ )
58
+
59
+ alert.addTextField { textField in
60
+ textField.placeholder = "http://localhost:5969/main.lynx.bundle"
61
+ textField.keyboardType = .URL
62
+ textField.text = initialURL
63
+ textField.clearButtonMode = .whileEditing
64
+ }
65
+
66
+ alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
67
+ alert.addAction(UIAlertAction(title: "Save", style: .default, handler: { _ in
68
+ let value = alert.textFields?.first?.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
69
+ guard !value.isEmpty else {
70
+ return
71
+ }
72
+ setDevURL(value)
73
+ onSaved?(value)
74
+ }))
75
+
76
+ viewController.present(alert, animated: true)
77
+ }
14
78
  }
15
79
  }
@@ -1,12 +1,8 @@
1
- require 'json'
2
-
3
- package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
4
-
5
1
  Pod::Spec.new do |s|
6
2
  s.name = 'Sparkling-DebugTool'
7
- s.version = package['version']
8
- s.summary = package['description']
9
- s.description = package['description']
3
+ s.version = "2.1.0-rc.20"
4
+ s.summary = "Sparkling debug tool SDK"
5
+ s.description = "Sparkling debug tool SDK"
10
6
  s.license = { :type => 'Apache-2.0' }
11
7
  s.author = 'TikTok'
12
8
  s.homepage = 'https://github.com/tiktok/sparkling'
@@ -16,11 +12,11 @@ Pod::Spec.new do |s|
16
12
  s.static_framework = true
17
13
 
18
14
  s.source_files = [
19
- 'ios/Sources/**/*.{h,m,swift}',
20
15
  'Sources/**/*.{h,m,swift}'
21
16
  ]
22
17
 
23
18
  s.dependency 'Lynx', '~> 3.6.0'
24
19
  s.dependency 'LynxService/Devtool', '~> 3.6.0'
25
20
  s.dependency 'LynxDevtool/Framework', '~> 3.6.0'
21
+ s.dependency 'DebugRouter'
26
22
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparkling-debug-tool",
3
- "version": "2.1.0-rc.2",
3
+ "version": "2.1.0-rc.20",
4
4
  "description": "Sparkling debug tool SDK",
5
5
  "homepage": "https://tiktok.github.io/sparkling/",
6
6
  "repository": {