Skip to content

Commit

Permalink
Added setting to enable/disable nsd
Browse files Browse the repository at this point in the history
  • Loading branch information
Xcreen committed Dec 26, 2024
1 parent 6da1e32 commit 2813538
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SettingsFragment : Fragment() {
val openBrowserCheckBox = rootView.findViewById<CheckBox>(R.id.settings_open_browser_checkbox)
val disableLoggingCheckBox = rootView.findViewById<CheckBox>(R.id.settings_disable_logging_checkbox)
val enableAuth = rootView.findViewById<CheckBox>(R.id.settings_enable_auth)
val enableNSD = rootView.findViewById<CheckBox>(R.id.settings_enable_nsd)
val saveBtn = rootView.findViewById<Button>(R.id.settings_save_btn)
saveBtn.setOnClickListener { v ->
var saved = false
Expand Down Expand Up @@ -58,6 +59,9 @@ class SettingsFragment : Fragment() {
//Save Enable authentication
editor.putBoolean("enable_auth", enableAuth.isChecked)
editor.apply()
//Save Enable NSD
editor.putBoolean("enable_nsd", enableNSD.isChecked)
editor.apply()
if (saved) {
Toast.makeText(v.context, resources.getText(R.string.setting_saved), Toast.LENGTH_SHORT).show()
}
Expand All @@ -78,6 +82,10 @@ class SettingsFragment : Fragment() {
if (sharedPref.getBoolean("enable_auth", false)) {
enableAuth.isChecked = true
}
//Set current "NSD"-Option
if (sharedPref.getBoolean("enable_nsd", false)) {
enableNSD.isChecked = true
}
return rootView
}
}
6 changes: 4 additions & 2 deletions app/src/main/java/net/xcreen/restsms/server/SMSServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import javax.servlet.MultipartConfigElement

class SMSServer {
var port = 8080
var startNSD = false
var goodToken = ""
var authEnabled = false
private var jettyServer: Server? = null
Expand Down Expand Up @@ -75,8 +76,9 @@ class SMSServer {
serverLogging!!.log("error", "NSD Service unregistration failed: $errorCode")
}
}
nsdManager!!.registerService(nsdServiceInfo, NsdManager.PROTOCOL_DNS_SD, nsdRegistrationListener)

if(startNSD) {
nsdManager!!.registerService(nsdServiceInfo, NsdManager.PROTOCOL_DNS_SD, nsdRegistrationListener)
}
//Start Jetty
jettyServer!!.start()
jettyServer!!.join()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/net/xcreen/restsms/server/ServerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ServerService : Service() {
val sharedPref = PreferenceManager.getDefaultSharedPreferences(this)
val serverPort = sharedPref.getInt("server_port", 8080)
appContext?.smsServer?.port = serverPort
//Set NSD
appContext?.smsServer?.startNSD = sharedPref.getBoolean("enable_nsd", false)
//Set Auth params
val goodToken = sharedPref.getString("server_token", "") ?: ""
val authEnabled = sharedPref.getBoolean("enable_auth", false)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@
android:textColor="@color/colorWhite"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/settings_open_browser_checkbox" />

<CheckBox
android:id="@+id/settings_enable_nsd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/setting_enable_nsd"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="@color/colorWhite"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/settings_token_edittext" />
</androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<string name="setting_open_website">Open Browser after Server-Start</string>
<string name="setting_disable_logging">Disable writing/creating log-files</string>
<string name="setting_enable_auth">Enable authentication</string>
<string name="setting_enable_nsd">Enable Network Service Discovery</string>
<string name="setting_save">Save</string>
<string name="setting_invalid_port">Invalid Port!</string>
<string name="setting_invalid_port_range">Port must be between 0 and 65535!</string>
Expand Down

0 comments on commit 2813538

Please sign in to comment.