Menggunakan nama variabel sesuai dengan nama kelas
This commit is contained in:
1 parent
923540934e
commit
432a34540d
3 files changed
+19
-19
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tauri-plugin-bluclas"
|
name = "tauri-plugin-bluclas"
|
||||||
version = "0.1.19"
|
version = "0.1.20"
|
||||||
authors = [ "Rizky Denianto" ]
|
authors = [ "Rizky Denianto" ]
|
||||||
description = "Program sederhana untuk interaksi dengan bluetooth classic"
|
description = "Program sederhana untuk interaksi dengan bluetooth classic"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|||||||
@@ -37,11 +37,11 @@ class KirimArgs {
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
class BluclasPlugin(private val activity: Activity) : Plugin(activity) {
|
class BluclasPlugin(private val activity: Activity) : Plugin(activity) {
|
||||||
private val uuidSpp: UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")
|
private val uuid: UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")
|
||||||
|
|
||||||
private val adapter: BluetoothAdapter? = this.activity.getSystemService(BluetoothManager::class.java).getAdapter()
|
private val bluetoothAdapter: BluetoothAdapter? = this.activity.getSystemService(BluetoothManager::class.java).getAdapter()
|
||||||
private var soket: BluetoothSocket? = null
|
private var bluetoothSocket: BluetoothSocket? = null
|
||||||
private var keluaran: OutputStream? = null
|
private var outputStream: OutputStream? = null
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
override fun checkPermissions(invoke: Invoke) {
|
override fun checkPermissions(invoke: Invoke) {
|
||||||
@@ -55,13 +55,13 @@ class BluclasPlugin(private val activity: Activity) : Plugin(activity) {
|
|||||||
|
|
||||||
@Command
|
@Command
|
||||||
fun daftarPerangkat(invoke: Invoke) {
|
fun daftarPerangkat(invoke: Invoke) {
|
||||||
if (adapter == null) {
|
if (bluetoothAdapter == null) {
|
||||||
invoke.reject("Bluetooth tidak didukung")
|
invoke.reject("Bluetooth tidak didukung")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val daftarRes = JSArray()
|
val daftarRes = JSArray()
|
||||||
adapter.bondedDevices.map { i ->
|
bluetoothAdapter.bondedDevices.map { i ->
|
||||||
val res = JSObject()
|
val res = JSObject()
|
||||||
res.put("nama", i.name ?: "Unknown")
|
res.put("nama", i.name ?: "Unknown")
|
||||||
res.put("alamat", i.address)
|
res.put("alamat", i.address)
|
||||||
@@ -74,17 +74,17 @@ class BluclasPlugin(private val activity: Activity) : Plugin(activity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun menghubungkanKoneksi(alamat: String) {
|
fun menghubungkanKoneksi(alamat: String) {
|
||||||
val perangkat: BluetoothDevice = adapter!!.getRemoteDevice(alamat)
|
val bluetoothDevice: BluetoothDevice = bluetoothAdapter!!.getRemoteDevice(alamat)
|
||||||
soket = perangkat.createInsecureRfcommSocketToServiceRecord(uuidSpp)
|
bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(uuid)
|
||||||
soket!!.connect()
|
bluetoothSocket!!.connect()
|
||||||
keluaran = soket!!.outputStream
|
outputStream = bluetoothSocket!!.outputStream
|
||||||
}
|
}
|
||||||
|
|
||||||
fun memutusKoneksi() {
|
fun memutusKoneksi() {
|
||||||
keluaran?.close()
|
outputStream?.close()
|
||||||
keluaran = null
|
outputStream = null
|
||||||
soket?.close()
|
bluetoothSocket?.close()
|
||||||
soket = null
|
bluetoothSocket = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
@@ -99,12 +99,12 @@ class BluclasPlugin(private val activity: Activity) : Plugin(activity) {
|
|||||||
try {
|
try {
|
||||||
menghubungkanKoneksi(alamat)
|
menghubungkanKoneksi(alamat)
|
||||||
|
|
||||||
if (keluaran == null) {
|
if (outputStream == null) {
|
||||||
throw Exception("Tidak ada perangkat yang terhubung")
|
throw Exception("Tidak ada perangkat yang terhubung")
|
||||||
}
|
}
|
||||||
|
|
||||||
keluaran!!.write(args.data)
|
outputStream!!.write(args.data)
|
||||||
keluaran!!.flush()
|
outputStream!!.flush()
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
memutusKoneksi()
|
memutusKoneksi()
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@segubi/tauri-plugin-bluclas-api",
|
"name": "@segubi/tauri-plugin-bluclas-api",
|
||||||
"version": "0.1.19",
|
"version": "0.1.20",
|
||||||
"author": "Rizky Denianto",
|
"author": "Rizky Denianto",
|
||||||
"description": "Program sederhana untuk interaksi dengan bluetooth classic",
|
"description": "Program sederhana untuk interaksi dengan bluetooth classic",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
Reference in new issue
Block a user