Merge pull request 'Mengubah daftar respon dari map ke jsarray' (#3) from pengembangan into main
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
@@ -11,6 +11,7 @@ import app.tauri.annotation.InvokeArg
|
||||
import app.tauri.annotation.Permission
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import app.tauri.plugin.Invoke
|
||||
import app.tauri.plugin.JSArray
|
||||
import app.tauri.plugin.JSObject
|
||||
import app.tauri.plugin.Plugin
|
||||
import java.io.OutputStream
|
||||
@@ -45,17 +46,17 @@ class BluclasPlugin(private val activity: Activity) : Plugin(activity) {
|
||||
return
|
||||
}
|
||||
|
||||
println("KOTLIN")
|
||||
val daftar_res = adapter.bondedDevices.map { i ->
|
||||
mapOf(
|
||||
"nama" to (i.name ?: "Unknown"),
|
||||
"alamat" to i.address
|
||||
)
|
||||
val daftarRes = JSArray()
|
||||
adapter.bondedDevices.map { i ->
|
||||
val res = JSObject()
|
||||
res.put("nama", i.name ?: "Unknown")
|
||||
res.put("alamat", i.address)
|
||||
daftarRes.put(res)
|
||||
}
|
||||
|
||||
val objek_daftar_res = JSObject()
|
||||
objek_daftar_res.put("data", daftar_res)
|
||||
invoke.resolve(objek_daftar_res)
|
||||
val objekDaftarRes = JSObject()
|
||||
objekDaftarRes.put("data", daftarRes)
|
||||
invoke.resolve(objekDaftarRes)
|
||||
}
|
||||
|
||||
fun menghubungkanKoneksi(invoke: Invoke, alamat: String) {
|
||||
|
||||
+2
-2
@@ -7,14 +7,14 @@ use crate::Result;
|
||||
#[command]
|
||||
pub(crate) async fn daftar_perangkat<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
) -> Result<Vec<SBluetoothClassicResponPerangkat>> {
|
||||
) -> Result<SBlueclasClassicResponDaftarPerangkat> {
|
||||
return app.bluclas().daftar_perangkat();
|
||||
}
|
||||
|
||||
#[command]
|
||||
pub(crate) async fn kirim<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
payload: SBluetoothClassicMuatanKirim,
|
||||
payload: SBlueclasClassicMuatanKirim,
|
||||
) -> Result<()> {
|
||||
return app.bluclas().kirim(payload);
|
||||
}
|
||||
|
||||
+3
-8
@@ -14,16 +14,11 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||
pub struct Bluclas<R: Runtime>(AppHandle<R>);
|
||||
|
||||
impl<R: Runtime> Bluclas<R> {
|
||||
pub fn daftar_perangkat(&self) -> crate::Result<Vec<SBluetoothClassicResponPerangkat>> {
|
||||
let daftar_res: Vec<SBluetoothClassicResponPerangkat> =
|
||||
vec![SBluetoothClassicResponPerangkat {
|
||||
nama: String::new(),
|
||||
alamat: String::new(),
|
||||
}];
|
||||
return Ok(daftar_res);
|
||||
pub fn daftar_perangkat(&self) -> crate::Result<SBlueclasClassicResponDaftarPerangkat> {
|
||||
return Ok(SBlueclasClassicResponDaftarPerangkat { data: vec![] });
|
||||
}
|
||||
|
||||
pub fn kirim(&self, _: SBluetoothClassicMuatanKirim) -> crate::Result<()> {
|
||||
pub fn kirim(&self, _: SBlueclasClassicMuatanKirim) -> crate::Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,14 +25,14 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||
pub struct Bluclas<R: Runtime>(PluginHandle<R>);
|
||||
|
||||
impl<R: Runtime> Bluclas<R> {
|
||||
pub fn daftar_perangkat(&self) -> crate::Result<Vec<SBluetoothClassicResponPerangkat>> {
|
||||
pub fn daftar_perangkat(&self) -> crate::Result<SBlueclasClassicResponDaftarPerangkat> {
|
||||
return self
|
||||
.0
|
||||
.run_mobile_plugin("daftarPerangkat", ())
|
||||
.map_err(Into::into);
|
||||
}
|
||||
|
||||
pub fn kirim(&self, payload: SBluetoothClassicMuatanKirim) -> crate::Result<()> {
|
||||
pub fn kirim(&self, payload: SBlueclasClassicMuatanKirim) -> crate::Result<()> {
|
||||
return self
|
||||
.0
|
||||
.run_mobile_plugin("kirim", payload)
|
||||
|
||||
+8
-2
@@ -2,14 +2,20 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SBluetoothClassicResponPerangkat {
|
||||
pub struct SDaftarPerangkatBlueclasClassicResponDaftarPerangkat {
|
||||
pub nama: String,
|
||||
pub alamat: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SBlueclasClassicResponDaftarPerangkat {
|
||||
pub data: Vec<SDaftarPerangkatBlueclasClassicResponDaftarPerangkat>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SBluetoothClassicMuatanKirim {
|
||||
pub struct SBlueclasClassicMuatanKirim {
|
||||
pub alamat: String,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user