Compare commits

..
24 changed files with 134 additions and 456 deletions

No files matched your search

-5
View File
@@ -1,5 +0,0 @@
[registry]
default = "gitea"
[registries.gitea]
index = "sparse+https://git.segubi.com/api/packages/segubi/cargo/"
-67
View File
@@ -1,67 +0,0 @@
name: Penerbitan Plugin
on:
pull_request:
branches: ["main"]
types: ["opened", "synchronize"]
jobs:
persiapan:
runs-on: ubuntu-latest
outputs:
organisasi: ${{ steps.var.outputs.organisasi }}
steps:
- name: Persiapan variabel
id: var
run: |
echo "organisasi=$(echo '${{ gitea.repository }}' | cut -d'/' -f1)" \
>> $GITEA_OUTPUT
penerbitan:
runs-on: ubuntu-latest
needs: persiapan
steps:
- name: Unduh paket untuk membangun citra
run: |
apt update -y
sudo apt install -y libwebkit2gtk-4.1-dev \
build-essential \
curl \
wget \
file \
libxdo-dev \
libssl-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
libudev-dev
apt clean -y
- name: Unduh program
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Unduh Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
rustflags: "-A warnings"
- name: Penerbitan peti Cargo
run: |
cargo publish
env:
CARGO_REGISTRIES_GITEA_TOKEN: Bearer ${{ secrets.KUNCI_PENERBITAN }}
- name: Unduh pnpm
uses: pnpm/setup@v2
with:
version: 11
- name: Penerbitan paket NPM
run: |
pnpm i
npm config set @${{ needs.persiapan.outputs.organisasi }}:registry=https://${{ vars.ALAMAT_GITEA }}/api/packages/${{ needs.persiapan.outputs.organisasi }}/npm/
npm config set -- '//${{ vars.ALAMAT_GITEA }}/api/packages/${{ needs.persiapan.outputs.organisasi }}/npm/:_authToken' "${{ secrets.KUNCI_PENERBITAN }}"
npm publish
rm -rf pnpm-lock.yaml .pnpm-store/
+7 -24
View File
@@ -1,34 +1,17 @@
[package] [package]
name = "tauri-plugin-bluclas" name = "tauri-plugin-bluclas"
version = "0.1.23" version = "0.1.0"
authors = [ "Rizky Denianto" ] authors = [ "You" ]
description = "Program sederhana untuk interaksi dengan bluetooth classic" description = ""
edition = "2024" edition = "2021"
rust-version = "1.98.0" rust-version = "1.77.2"
exclude = ["/examples", "/dist-js", "/guest-js", "/node_modules"] exclude = ["/examples", "/dist-js", "/guest-js", "/node_modules"]
links = "tauri-plugin-bluclas" links = "tauri-plugin-bluclas"
[profile.release]
lto = "fat"
codegen-units = 1
opt-level = 3
panic = "abort"
incremental = false
strip = "symbols"
debug = false
[package.metadata.platforms.support]
windows = { level = "full" }
linux = { level = "full" }
macos = { level = "none" }
android = { level = "full" }
ios = { level = "none" }
[dependencies] [dependencies]
tauri = { version = "2.11.5" } tauri = { version = "2.10.3" }
serde = "1.0" serde = "1.0"
thiserror = "2" thiserror = "2"
serialport = "4.10.1"
[build-dependencies] [build-dependencies]
tauri-plugin = { version = "2.6.3", features = ["build"] } tauri-plugin = { version = "2.5.4", features = ["build"] }
-2
View File
@@ -1,3 +1 @@
# Tauri Plugin bluclas # Tauri Plugin bluclas
Program sederhana untuk interaksi dengan bluetooth classic
-1
View File
@@ -1,3 +1,2 @@
/build /build
/.tauri /.tauri
/.gradle
-5
View File
@@ -1,8 +1,3 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
</manifest> </manifest>
+49 -56
View File
@@ -11,7 +11,6 @@ import app.tauri.annotation.InvokeArg
import app.tauri.annotation.Permission import app.tauri.annotation.Permission
import app.tauri.annotation.TauriPlugin import app.tauri.annotation.TauriPlugin
import app.tauri.plugin.Invoke import app.tauri.plugin.Invoke
import app.tauri.plugin.JSArray
import app.tauri.plugin.JSObject import app.tauri.plugin.JSObject
import app.tauri.plugin.Plugin import app.tauri.plugin.Plugin
import java.io.OutputStream import java.io.OutputStream
@@ -27,92 +26,86 @@ class KirimArgs {
@TauriPlugin( @TauriPlugin(
permissions = [ permissions = [
Permission( Permission(
strings = [ strings = [Manifest.permission.BLUETOOTH_CONNECT],
Manifest.permission.BLUETOOTH_SCAN, alias = "bluetoothConnect"
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.BLUETOOTH_ADVERTISE
],
alias = "bluetooth"
) )
] ]
) )
class BluclasPlugin(private val activity: Activity) : Plugin(activity) { class BluetoothClassicPlugin(private val activity: Activity) : Plugin(activity) {
private val uuid: UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB") private val SPP_UUID: UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")
private val bluetoothAdapter: BluetoothAdapter? = this.activity.getSystemService(BluetoothManager::class.java).getAdapter() private val adapter: BluetoothAdapter? = this.activity.getSystemService(BluetoothManager::class.java).getAdapter()
private var bluetoothSocket: BluetoothSocket? = null private var soket: BluetoothSocket? = null
private var outputStream: OutputStream? = null private var keluaran: OutputStream? = null
@Command
override fun checkPermissions(invoke: Invoke) {
super.checkPermissions(invoke)
}
@Command
override fun requestPermissions(invoke: Invoke) {
super.requestPermissions(invoke)
}
@Command @Command
fun daftarPerangkat(invoke: Invoke) { fun daftarPerangkat(invoke: Invoke) {
if (bluetoothAdapter == null) { if (adapter == null) {
invoke.reject("Bluetooth tidak didukung") invoke.reject("Bluetooth tidak didukung")
return return
} }
val daftarRes = JSArray() val daftar_res = adapter.bondedDevices.map { i ->
bluetoothAdapter.bondedDevices.map { i -> mapOf(
val res = JSObject() "nama" to (i.name ?: "Unknown"),
res.put("nama", i.name ?: "Unknown") "alamat" to i.address
res.put("alamat", i.address) )
daftarRes.put(res)
} }
val objekDaftarRes = JSObject() val objek_daftar_res = JSObject()
objekDaftarRes.put("data", daftarRes) objek_daftar_res.put("data", daftar_res)
invoke.resolve(objekDaftarRes) invoke.resolve(objek_daftar_res)
} }
fun menghubungkanKoneksi(alamat: String) { fun menghubungkanKoneksi(invoke: Invoke, alamat: String) {
val bluetoothDevice: BluetoothDevice = bluetoothAdapter!!.getRemoteDevice(alamat) try {
bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(uuid) val perangkat: BluetoothDevice = adapter!!.getRemoteDevice(alamat)
bluetoothSocket!!.connect()
outputStream = bluetoothSocket!!.outputStream soket = perangkat.createRfcommSocketToServiceRecord(SPP_UUID)
soket!!.connect()
keluaran = soket!!.outputStream
} catch (e: Exception) {
invoke.reject("Koneksi dengan perangkat gagal: ${e.message}")
}
invoke.resolve()
} }
fun memutusKoneksi() { fun memutusKoneksi(invoke: Invoke) {
outputStream?.close() try {
outputStream = null keluaran?.close()
bluetoothSocket?.close() keluaran = null
bluetoothSocket = null soket?.close()
soket = null
} catch (e: Exception) {
invoke.reject("Memutus koneksi perangkat gagal")
}
invoke.resolve()
} }
@Command @Command
fun kirim(invoke: Invoke) { fun kirim(invoke: Invoke) {
val args = invoke.parseArgs(KirimArgs::class.java) val args = invoke.parseArgs(KirimArgs::class.java)
val alamat = args.alamat
if (alamat.isNullOrEmpty()) { menghubungkanKoneksi(invoke, args.alamat ?: "")
invoke.resolve() if (keluaran == null) {
invoke.reject("Tidak ada perangkat yang terhubung")
return return
} }
try { try {
menghubungkanKoneksi(alamat) keluaran!!.write(args.data)
keluaran!!.flush()
if (outputStream == null) {
throw Exception("Tidak ada perangkat yang terhubung")
}
outputStream!!.write(args.data)
outputStream!!.flush()
} catch (e: Exception) { } catch (e: Exception) {
memutusKoneksi() memutusKoneksi(invoke)
invoke.reject("Mengirim data ke perangkat gagal: ${e.message}") invoke.reject("Mengirim data ke perangkat gagal: ${e.message}")
return
} }
memutusKoneksi() memutusKoneksi(invoke)
invoke.resolve() invoke.resolve()
} }
} }
+5 -10
View File
@@ -1,13 +1,8 @@
const COMMANDS: &[&str] = &[ const COMMANDS: &[&str] = &["ping"];
"check_permissions",
"request_permissions",
"daftar_perangkat",
"kirim",
];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS) tauri_plugin::Builder::new(COMMANDS)
.android_path("android") .android_path("android")
.ios_path("ios") .ios_path("ios")
.build(); .build();
} }
+7 -40
View File
@@ -1,42 +1,9 @@
import { import { invoke } from '@tauri-apps/api/core'
checkPermissions as checkPermissions_,
invoke,
PermissionState,
requestPermissions as requestPermissions_,
} from "@tauri-apps/api/core";
export async function checkPermissions(): Promise<PermissionState> { export async function ping(value: string): Promise<string | null> {
return await checkPermissions_<{ bluetooth: PermissionState }>( return await invoke<{value?: string}>('plugin:bluclas|ping', {
"bluclas", payload: {
).then((e) => e.bluetooth); value,
} },
}).then((r) => (r.value ? r.value : null));
export async function requestPermissions(): Promise<PermissionState> {
return await requestPermissions_<{ bluetooth: PermissionState }>(
"bluclas",
).then((e) => e.bluetooth);
}
export type SDaftarPerangkatBlueclasResponDaftarPerangkat = {
nama: string;
alamat: string;
};
export type SBlueclasResponDaftarPerangkat = {
data: SDaftarPerangkatBlueclasResponDaftarPerangkat[];
};
export async function daftarPerangkat(): Promise<SBlueclasResponDaftarPerangkat> {
return await invoke<SBlueclasResponDaftarPerangkat>(
"plugin:bluclas|daftar_perangkat",
).then((res: SBlueclasResponDaftarPerangkat) => res);
}
export type SBlueclasMuatanKirim = {
alamat: string;
data: number[];
};
export async function kirim(muatan: SBlueclasMuatanKirim): Promise<null> {
return await invoke<null>("plugin:bluclas|kirim", { muatan: muatan });
} }
+9 -9
View File
@@ -1,8 +1,8 @@
{ {
"name": "@segubi/tauri-plugin-bluclas-api", "name": "tauri-plugin-bluclas-api",
"version": "0.1.23", "version": "0.1.0",
"author": "Rizky Denianto", "author": "You",
"description": "Program sederhana untuk interaksi dengan bluetooth classic", "description": "",
"type": "module", "type": "module",
"types": "./dist-js/index.d.ts", "types": "./dist-js/index.d.ts",
"main": "./dist-js/index.cjs", "main": "./dist-js/index.cjs",
@@ -22,12 +22,12 @@
"pretest": "pnpm build" "pretest": "pnpm build"
}, },
"dependencies": { "dependencies": {
"@tauri-apps/api": "^2.11.1" "@tauri-apps/api": "^2.0.0"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-typescript": "^12.3.0", "@rollup/plugin-typescript": "^12.0.0",
"rollup": "^4.63.2", "rollup": "^4.9.6",
"typescript": "^6.0.3", "typescript": "^5.3.3",
"tslib": "^2.8.1" "tslib": "^2.6.2"
} }
} }
@@ -1,13 +0,0 @@
# Automatically generated - DO NOT EDIT!
"$schema" = "../../schemas/schema.json"
[[permission]]
identifier = "allow-check-permissions"
description = "Enables the check_permissions command without any pre-configured scope."
commands.allow = ["check_permissions"]
[[permission]]
identifier = "deny-check-permissions"
description = "Denies the check_permissions command without any pre-configured scope."
commands.deny = ["check_permissions"]
@@ -1,13 +0,0 @@
# Automatically generated - DO NOT EDIT!
"$schema" = "../../schemas/schema.json"
[[permission]]
identifier = "allow-daftar-perangkat"
description = "Enables the daftar_perangkat command without any pre-configured scope."
commands.allow = ["daftar_perangkat"]
[[permission]]
identifier = "deny-daftar-perangkat"
description = "Denies the daftar_perangkat command without any pre-configured scope."
commands.deny = ["daftar_perangkat"]
@@ -1,13 +0,0 @@
# Automatically generated - DO NOT EDIT!
"$schema" = "../../schemas/schema.json"
[[permission]]
identifier = "allow-kirim"
description = "Enables the kirim command without any pre-configured scope."
commands.allow = ["kirim"]
[[permission]]
identifier = "deny-kirim"
description = "Denies the kirim command without any pre-configured scope."
commands.deny = ["kirim"]
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!
"$schema" = "../../schemas/schema.json"
[[permission]]
identifier = "allow-ping"
description = "Enables the ping command without any pre-configured scope."
commands.allow = ["ping"]
[[permission]]
identifier = "deny-ping"
description = "Denies the ping command without any pre-configured scope."
commands.deny = ["ping"]
@@ -1,13 +0,0 @@
# Automatically generated - DO NOT EDIT!
"$schema" = "../../schemas/schema.json"
[[permission]]
identifier = "allow-request-permissions"
description = "Enables the request_permissions command without any pre-configured scope."
commands.allow = ["request_permissions"]
[[permission]]
identifier = "deny-request-permissions"
description = "Denies the request_permissions command without any pre-configured scope."
commands.deny = ["request_permissions"]
+5 -86
View File
@@ -4,10 +4,7 @@ Default permissions for the plugin
#### This default permission set includes the following: #### This default permission set includes the following:
- `allow-check-permissions` - `allow-ping`
- `allow-request-permissions`
- `allow-daftar-perangkat`
- `allow-kirim`
## Permission Table ## Permission Table
@@ -21,12 +18,12 @@ Default permissions for the plugin
<tr> <tr>
<td> <td>
`bluclas:allow-check-permissions` `bluclas:allow-ping`
</td> </td>
<td> <td>
Enables the check_permissions command without any pre-configured scope. Enables the ping command without any pre-configured scope.
</td> </td>
</tr> </tr>
@@ -34,90 +31,12 @@ Enables the check_permissions command without any pre-configured scope.
<tr> <tr>
<td> <td>
`bluclas:deny-check-permissions` `bluclas:deny-ping`
</td> </td>
<td> <td>
Denies the check_permissions command without any pre-configured scope. Denies the ping command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`bluclas:allow-daftar-perangkat`
</td>
<td>
Enables the daftar_perangkat command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`bluclas:deny-daftar-perangkat`
</td>
<td>
Denies the daftar_perangkat command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`bluclas:allow-kirim`
</td>
<td>
Enables the kirim command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`bluclas:deny-kirim`
</td>
<td>
Denies the kirim command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`bluclas:allow-request-permissions`
</td>
<td>
Enables the request_permissions command without any pre-configured scope.
</td>
</tr>
<tr>
<td>
`bluclas:deny-request-permissions`
</td>
<td>
Denies the request_permissions command without any pre-configured scope.
</td> </td>
</tr> </tr>
+1 -6
View File
@@ -1,8 +1,3 @@
[default] [default]
description = "Default permissions for the plugin" description = "Default permissions for the plugin"
permissions = [ permissions = ["allow-ping"]
"allow-check-permissions",
"allow-request-permissions",
"allow-daftar-perangkat",
"allow-kirim"
]
+8 -44
View File
@@ -295,58 +295,22 @@
"type": "string", "type": "string",
"oneOf": [ "oneOf": [
{ {
"description": "Enables the check_permissions command without any pre-configured scope.", "description": "Enables the ping command without any pre-configured scope.",
"type": "string", "type": "string",
"const": "allow-check-permissions", "const": "allow-ping",
"markdownDescription": "Enables the check_permissions command without any pre-configured scope." "markdownDescription": "Enables the ping command without any pre-configured scope."
}, },
{ {
"description": "Denies the check_permissions command without any pre-configured scope.", "description": "Denies the ping command without any pre-configured scope.",
"type": "string", "type": "string",
"const": "deny-check-permissions", "const": "deny-ping",
"markdownDescription": "Denies the check_permissions command without any pre-configured scope." "markdownDescription": "Denies the ping command without any pre-configured scope."
}, },
{ {
"description": "Enables the daftar_perangkat command without any pre-configured scope.", "description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-ping`",
"type": "string",
"const": "allow-daftar-perangkat",
"markdownDescription": "Enables the daftar_perangkat command without any pre-configured scope."
},
{
"description": "Denies the daftar_perangkat command without any pre-configured scope.",
"type": "string",
"const": "deny-daftar-perangkat",
"markdownDescription": "Denies the daftar_perangkat command without any pre-configured scope."
},
{
"description": "Enables the kirim command without any pre-configured scope.",
"type": "string",
"const": "allow-kirim",
"markdownDescription": "Enables the kirim command without any pre-configured scope."
},
{
"description": "Denies the kirim command without any pre-configured scope.",
"type": "string",
"const": "deny-kirim",
"markdownDescription": "Denies the kirim command without any pre-configured scope."
},
{
"description": "Enables the request_permissions command without any pre-configured scope.",
"type": "string",
"const": "allow-request-permissions",
"markdownDescription": "Enables the request_permissions command without any pre-configured scope."
},
{
"description": "Denies the request_permissions command without any pre-configured scope.",
"type": "string",
"const": "deny-request-permissions",
"markdownDescription": "Denies the request_permissions command without any pre-configured scope."
},
{
"description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-check-permissions`\n- `allow-request-permissions`\n- `allow-daftar-perangkat`\n- `allow-kirim`",
"type": "string", "type": "string",
"const": "default", "const": "default",
"markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-check-permissions`\n- `allow-request-permissions`\n- `allow-daftar-perangkat`\n- `allow-kirim`" "markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-ping`"
} }
] ]
} }
+1 -2
View File
@@ -20,8 +20,7 @@ export default {
plugins: [ plugins: [
typescript({ typescript({
declaration: true, declaration: true,
declarationDir: dirname(pkg.exports.import), declarationDir: dirname(pkg.exports.import)
rootDir: 'guest-js'
}) })
], ],
external: [ external: [
+5 -5
View File
@@ -1,20 +1,20 @@
use tauri::{AppHandle, Runtime, command}; use tauri::{command, AppHandle, Runtime};
use crate::models::*;
use crate::BluclasExt; use crate::BluclasExt;
use crate::Result; use crate::Result;
use crate::models::*;
#[command] #[command]
pub(crate) async fn daftar_perangkat<R: Runtime>( pub(crate) async fn daftar_perangkat<R: Runtime>(
app: AppHandle<R>, app: AppHandle<R>,
) -> Result<SBlueclasResponDaftarPerangkat> { ) -> Result<Vec<SBluetoothClassicResponPerangkat>> {
return app.bluclas().daftar_perangkat(); return app.bluclas().daftar_perangkat();
} }
#[command] #[command]
pub(crate) async fn kirim<R: Runtime>( pub(crate) async fn kirim<R: Runtime>(
app: AppHandle<R>, app: AppHandle<R>,
muatan: SBlueclasMuatanKirim, payload: SBluetoothClassicMuatanKirim,
) -> Result<()> { ) -> Result<()> {
return app.bluclas().kirim(muatan); return app.bluclas().kirim(payload);
} }
+9 -24
View File
@@ -1,7 +1,5 @@
use std::{mem, time::Duration};
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use tauri::{AppHandle, Runtime, plugin::PluginApi}; use tauri::{plugin::PluginApi, AppHandle, Runtime};
use crate::models::*; use crate::models::*;
@@ -16,29 +14,16 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
pub struct Bluclas<R: Runtime>(AppHandle<R>); pub struct Bluclas<R: Runtime>(AppHandle<R>);
impl<R: Runtime> Bluclas<R> { impl<R: Runtime> Bluclas<R> {
pub fn daftar_perangkat(&self) -> crate::Result<SBlueclasResponDaftarPerangkat> { pub fn daftar_perangkat(&self) -> crate::Result<Vec<SBluetoothClassicResponPerangkat>> {
let port = serialport::available_ports().unwrap_or(Vec::new()); let daftar_res: Vec<SBluetoothClassicResponPerangkat> =
let mut daftar_res: Vec<SDaftarPerangkatBlueclasResponDaftarPerangkat> = Vec::new(); vec![SBluetoothClassicResponPerangkat {
for i in port { nama: String::new(),
let res = SDaftarPerangkatBlueclasResponDaftarPerangkat { alamat: String::new(),
nama: i.port_name.clone(), }];
alamat: i.port_name, return Ok(daftar_res);
};
daftar_res.push(res);
}
return Ok(SBlueclasResponDaftarPerangkat { data: daftar_res });
} }
pub fn kirim(&self, muatan: SBlueclasMuatanKirim) -> crate::Result<()> { pub fn kirim(&self, _: SBluetoothClassicMuatanKirim) -> crate::Result<()> {
let mut pencetak = match serialport::new(&muatan.alamat, 9600)
.timeout(Duration::from_secs(4))
.open()
{
Ok(it) => it,
Err(_) => return Ok(()),
};
pencetak.write(&muatan.data).unwrap();
mem::drop(pencetak);
return Ok(()); return Ok(());
} }
} }
+7 -4
View File
@@ -1,8 +1,10 @@
use tauri::{ use tauri::{
Manager, Runtime,
plugin::{Builder, TauriPlugin}, plugin::{Builder, TauriPlugin},
Manager, Runtime,
}; };
pub use models::*;
#[cfg(desktop)] #[cfg(desktop)]
mod desktop; mod desktop;
#[cfg(mobile)] #[cfg(mobile)]
@@ -19,8 +21,6 @@ use desktop::Bluclas;
#[cfg(mobile)] #[cfg(mobile)]
use mobile::Bluclas; use mobile::Bluclas;
use crate::commands::{daftar_perangkat, kirim};
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the bluclas APIs. /// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the bluclas APIs.
pub trait BluclasExt<R: Runtime> { pub trait BluclasExt<R: Runtime> {
fn bluclas(&self) -> &Bluclas<R>; fn bluclas(&self) -> &Bluclas<R>;
@@ -35,7 +35,10 @@ impl<R: Runtime, T: Manager<R>> crate::BluclasExt<R> for T {
/// Initializes the plugin. /// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> { pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("bluclas") Builder::new("bluclas")
.invoke_handler(tauri::generate_handler![daftar_perangkat, kirim]) .invoke_handler(tauri::generate_handler![
commands::daftar_perangkat,
commands::kirim
])
.setup(|app, api| { .setup(|app, api| {
#[cfg(mobile)] #[cfg(mobile)]
let bluclas = mobile::init(app, api)?; let bluclas = mobile::init(app, api)?;
+4 -4
View File
@@ -1,7 +1,7 @@
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use tauri::{ use tauri::{
AppHandle, Runtime,
plugin::{PluginApi, PluginHandle}, plugin::{PluginApi, PluginHandle},
AppHandle, Runtime,
}; };
use crate::models::*; use crate::models::*;
@@ -25,17 +25,17 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
pub struct Bluclas<R: Runtime>(PluginHandle<R>); pub struct Bluclas<R: Runtime>(PluginHandle<R>);
impl<R: Runtime> Bluclas<R> { impl<R: Runtime> Bluclas<R> {
pub fn daftar_perangkat(&self) -> crate::Result<SBlueclasResponDaftarPerangkat> { pub fn daftar_perangkat(&self) -> crate::Result<Vec<SBluetoothClassicResponPerangkat>> {
return self return self
.0 .0
.run_mobile_plugin("daftarPerangkat", ()) .run_mobile_plugin("daftarPerangkat", ())
.map_err(Into::into); .map_err(Into::into);
} }
pub fn kirim(&self, muatan: SBlueclasMuatanKirim) -> crate::Result<()> { pub fn kirim(&self, payload: SBluetoothClassicMuatanKirim) -> crate::Result<()> {
return self return self
.0 .0
.run_mobile_plugin("kirim", muatan) .run_mobile_plugin("kirim", payload)
.map_err(Into::into); .map_err(Into::into);
} }
} }
+4 -10
View File
@@ -1,21 +1,15 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)] #[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SDaftarPerangkatBlueclasResponDaftarPerangkat { pub struct SBluetoothClassicResponPerangkat {
pub nama: String, pub nama: String,
pub alamat: String, pub alamat: String,
} }
#[derive(Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SBlueclasResponDaftarPerangkat { pub struct SBluetoothClassicMuatanKirim {
pub data: Vec<SDaftarPerangkatBlueclasResponDaftarPerangkat>,
}
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SBlueclasMuatanKirim {
pub alamat: String, pub alamat: String,
pub data: Vec<u8>, pub data: Vec<u8>,
} }