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

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.
@@ -23,7 +23,7 @@ android {
23
23
  isMinifyEnabled = false
24
24
  proguardFiles(
25
25
  getDefaultProguardFile("proguard-android-optimize.txt"),
26
- "proguard-rules.pro"
26
+ "proguard-rules.pro",
27
27
  )
28
28
  }
29
29
  }
@@ -43,16 +43,22 @@ dependencies {
43
43
  implementation(libs.lynx.devtool)
44
44
  }
45
45
 
46
- val publishingGroupId = (findProperty("SPARKLING_PUBLISHING_GROUP_ID") as? String)
47
- ?: System.getenv("SPARKLING_PUBLISHING_GROUP_ID")
48
- ?: "com.tiktok.sparkling"
49
- val publishingVersion = (findProperty("SPARKLING_PUBLISHING_VERSION") as? String)
50
- ?: System.getenv("SPARKLING_PUBLISHING_VERSION")
51
- ?: "2.0.0"
46
+ val publishingGroupId =
47
+ (findProperty("SPARKLING_PUBLISHING_GROUP_ID") as? String)
48
+ ?: System.getenv("SPARKLING_PUBLISHING_GROUP_ID")
49
+ ?: "com.tiktok.sparkling"
50
+ val publishingVersion =
51
+ (findProperty("SPARKLING_PUBLISHING_VERSION") as? String)
52
+ ?: System.getenv("SPARKLING_PUBLISHING_VERSION")
53
+ ?: "2.0.0"
52
54
 
53
55
  val androidSourcesJar by tasks.register<Jar>("androidSourcesJar") {
54
56
  archiveClassifier.set("sources")
55
- from(android.sourceSets.getByName("main").java.srcDirs)
57
+ from(
58
+ android.sourceSets
59
+ .getByName("main")
60
+ .java.srcDirs,
61
+ )
56
62
  }
57
63
 
58
64
  val emptyJavadocJar by tasks.register<Jar>("javadocJar") {
@@ -103,9 +109,10 @@ afterEvaluate {
103
109
  repositories {
104
110
  maven {
105
111
  name = "MavenCentral"
106
- val repoUrl = (findProperty("mavenCentralRepoUrl") as? String)
107
- ?: System.getenv("MAVEN_CENTRAL_REPO_URL")
108
- ?: "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
112
+ val repoUrl =
113
+ (findProperty("mavenCentralRepoUrl") as? String)
114
+ ?: System.getenv("MAVEN_CENTRAL_REPO_URL")
115
+ ?: "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
109
116
  url = uri(repoUrl)
110
117
  credentials {
111
118
  username = (findProperty("mavenCentralUsername") as? String)
@@ -121,12 +128,15 @@ afterEvaluate {
121
128
  }
122
129
 
123
130
  signing {
124
- val signingKeyId = (findProperty("signing.keyId") as? String)
125
- ?: System.getenv("SIGNING_KEY_ID")
126
- val signingPassword = (findProperty("signing.password") as? String)
127
- ?: System.getenv("SIGNING_PASSWORD")
128
- val signingSecretKeyRingFile = (findProperty("signing.secretKeyRingFile") as? String)
129
- ?: System.getenv("SIGNING_SECRET_KEY_RING_FILE")
131
+ val signingKeyId =
132
+ (findProperty("signing.keyId") as? String)
133
+ ?: System.getenv("SIGNING_KEY_ID")
134
+ val signingPassword =
135
+ (findProperty("signing.password") as? String)
136
+ ?: System.getenv("SIGNING_PASSWORD")
137
+ val signingSecretKeyRingFile =
138
+ (findProperty("signing.secretKeyRingFile") as? String)
139
+ ?: System.getenv("SIGNING_SECRET_KEY_RING_FILE")
130
140
  val signingKey = System.getenv("SIGNING_KEY")
131
141
 
132
142
  if (!signingKeyId.isNullOrBlank() && !signingPassword.isNullOrBlank()) {
@@ -146,8 +156,11 @@ signing {
146
156
 
147
157
  afterEvaluate {
148
158
  signing {
149
- val hasSigningConfig = !(System.getenv("SIGNING_KEY_ID").isNullOrBlank() ||
150
- System.getenv("SIGNING_PASSWORD").isNullOrBlank())
159
+ val hasSigningConfig =
160
+ !(
161
+ System.getenv("SIGNING_KEY_ID").isNullOrBlank() ||
162
+ System.getenv("SIGNING_PASSWORD").isNullOrBlank()
163
+ )
151
164
  if (hasSigningConfig) {
152
165
  sign(extensions.getByType<PublishingExtension>().publications["release"])
153
166
  } else {
@@ -3,19 +3,110 @@
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.setLoadQJSBridge(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(
40
+ context: Context,
41
+ fallback: String,
42
+ ): String {
43
+ val stored =
44
+ context.applicationContext
45
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
46
+ .getString(KEY_DEV_URL, null)
47
+ ?.trim()
48
+ return if (stored.isNullOrEmpty()) fallback else stored
49
+ }
50
+
51
+ @JvmStatic
52
+ fun setDevUrl(
53
+ context: Context,
54
+ url: String,
55
+ ) {
56
+ context.applicationContext
57
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
58
+ .edit()
59
+ .putString(KEY_DEV_URL, url.trim())
60
+ .apply()
61
+ }
62
+
63
+ @JvmStatic
64
+ fun showDevUrlDialog(
65
+ activity: Activity,
66
+ initialUrl: String? = null,
67
+ onSaved: ((String) -> Unit)? = null,
68
+ ) {
69
+ if (Looper.myLooper() != Looper.getMainLooper()) {
70
+ activity.runOnUiThread { showDevUrlDialog(activity, initialUrl, onSaved) }
71
+ return
72
+ }
73
+
74
+ val input =
75
+ EditText(activity).apply {
76
+ setText(initialUrl ?: "")
77
+ hint = "http://10.0.2.2:5969/main.lynx.bundle"
78
+ inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI
79
+ setSelection(text.length)
80
+ }
81
+
82
+ val dialog =
83
+ AlertDialog
84
+ .Builder(activity)
85
+ .setTitle("Set Sparkling Dev URL")
86
+ .setMessage("Update the main Lynx bundle URL for debug mode.")
87
+ .setView(input)
88
+ .setNegativeButton("Cancel", null)
89
+ .setPositiveButton("Save", null)
90
+ .create()
91
+
92
+ dialog.setOnShowListener {
93
+ val saveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
94
+ saveButton.setOnClickListener {
95
+ val value =
96
+ input.text
97
+ ?.toString()
98
+ ?.trim()
99
+ .orEmpty()
100
+ if (value.isEmpty()) {
101
+ Toast.makeText(activity, "Dev URL cannot be empty", Toast.LENGTH_SHORT).show()
102
+ return@setOnClickListener
103
+ }
104
+ setDevUrl(activity, value)
105
+ onSaved?.invoke(value)
106
+ dialog.dismiss()
107
+ }
108
+ }
109
+
110
+ dialog.show()
111
+ }
21
112
  }
@@ -2,14 +2,82 @@
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
4
 
5
+ import DebugRouter
5
6
  import Foundation
6
7
  import Lynx
8
+ import UIKit
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
+ {
21
+ devtool.logBoxPresetValue = true
22
+ devtool.lynxDebugPresetValue = true
23
+ }
24
+
25
+ let env = LynxEnv.sharedInstance()
26
+ env.lynxDebugEnabled = true
27
+ env.devtoolEnabled = true
28
+ env.logBoxEnabled = true
29
+
30
+ // Enable DebugRouter so the DevTool desktop app can discover and
31
+ // connect to this app (via USB or network).
32
+ DebugRouter.instance().enableAllSessions()
33
+ }
34
+
35
+ public static func devURL(fallback: String) -> String {
36
+ let stored = UserDefaults.standard.string(forKey: devURLKey)?.trimmingCharacters(in: .whitespacesAndNewlines)
37
+ if let stored, !stored.isEmpty {
38
+ return stored
39
+ }
40
+ return fallback
41
+ }
42
+
43
+ public static func setDevURL(_ url: String) {
44
+ let normalized = url.trimmingCharacters(in: .whitespacesAndNewlines)
45
+ UserDefaults.standard.set(normalized, forKey: devURLKey)
46
+ }
47
+
48
+ public static func showDevURLDialog(
49
+ from viewController: UIViewController,
50
+ initialURL: String?,
51
+ onSaved: ((String) -> Void)? = nil
52
+ ) {
53
+ DispatchQueue.main.async {
54
+ let alert = UIAlertController(
55
+ title: "Set Sparkling Dev URL",
56
+ message: "Update the main Lynx bundle URL for debug mode.",
57
+ preferredStyle: .alert
58
+ )
59
+
60
+ alert.addTextField { textField in
61
+ textField.placeholder = "http://localhost:5969/main.lynx.bundle"
62
+ textField.keyboardType = .URL
63
+ textField.text = initialURL
64
+ textField.clearButtonMode = .whileEditing
65
+ }
66
+
67
+ alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
68
+ alert.addAction(
69
+ UIAlertAction(
70
+ title: "Save", style: .default,
71
+ handler: { _ in
72
+ let value = alert.textFields?.first?.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
73
+ guard !value.isEmpty else {
74
+ return
75
+ }
76
+ setDevURL(value)
77
+ onSaved?(value)
78
+ }))
79
+
80
+ viewController.present(alert, animated: true)
81
+ }
14
82
  }
15
83
  }
@@ -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.24"
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
- s.dependency 'Lynx', '~> 3.6.0'
24
- s.dependency 'LynxService/Devtool', '~> 3.6.0'
25
- s.dependency 'LynxDevtool/Framework', '~> 3.6.0'
18
+ s.dependency 'Lynx'
19
+ s.dependency 'LynxService/Devtool'
20
+ s.dependency 'LynxDevtool/Framework'
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.24",
4
4
  "description": "Sparkling debug tool SDK",
5
5
  "homepage": "https://tiktok.github.io/sparkling/",
6
6
  "repository": {