diff --git a/android/.gitignore b/android/.gitignore
new file mode 100644
index 0000000..c0f21ec
--- /dev/null
+++ b/android/.gitignore
@@ -0,0 +1,2 @@
+/build
+/.tauri
diff --git a/android/build.gradle.kts b/android/build.gradle.kts
new file mode 100644
index 0000000..d271560
--- /dev/null
+++ b/android/build.gradle.kts
@@ -0,0 +1,44 @@
+plugins {
+ id("com.android.library")
+ id("org.jetbrains.kotlin.android")
+}
+
+android {
+ namespace = "com.plugin.bluclas"
+ compileSdk = 36
+
+ defaultConfig {
+ minSdk = 21
+
+ testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
+ consumerProguardFiles("consumer-rules.pro")
+ }
+
+ buildTypes {
+ release {
+ isMinifyEnabled = false
+ proguardFiles(
+ getDefaultProguardFile("proguard-android-optimize.txt"),
+ "proguard-rules.pro"
+ )
+ }
+ }
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+ }
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+}
+
+dependencies {
+
+ implementation("androidx.core:core-ktx:1.9.0")
+ implementation("androidx.appcompat:appcompat:1.6.0")
+ implementation("com.google.android.material:material:1.7.0")
+ testImplementation("junit:junit:4.13.2")
+ androidTestImplementation("androidx.test.ext:junit:1.1.5")
+ androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
+ implementation(project(":tauri-android"))
+}
diff --git a/android/proguard-rules.pro b/android/proguard-rules.pro
new file mode 100644
index 0000000..481bb43
--- /dev/null
+++ b/android/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
\ No newline at end of file
diff --git a/android/settings.gradle b/android/settings.gradle
new file mode 100644
index 0000000..d7782a4
--- /dev/null
+++ b/android/settings.gradle
@@ -0,0 +1,31 @@
+pluginManagement {
+ repositories {
+ mavenCentral()
+ gradlePluginPortal()
+ google()
+ }
+ resolutionStrategy {
+ eachPlugin {
+ switch (requested.id.id) {
+ case "com.android.library":
+ useVersion("8.0.2")
+ break
+ case "org.jetbrains.kotlin.android":
+ useVersion("1.8.20")
+ break
+ }
+ }
+ }
+}
+
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ mavenCentral()
+ google()
+
+ }
+}
+
+include ':tauri-android'
+project(':tauri-android').projectDir = new File('./.tauri/tauri-api')
diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..9a40236
--- /dev/null
+++ b/android/src/main/AndroidManifest.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/android/src/main/java/BluclasPlugin.kt b/android/src/main/java/BluclasPlugin.kt
new file mode 100644
index 0000000..5de84b4
--- /dev/null
+++ b/android/src/main/java/BluclasPlugin.kt
@@ -0,0 +1,111 @@
+package com.plugin.bluclas
+
+import android.Manifest
+import android.app.Activity
+import android.bluetooth.BluetoothAdapter
+import android.bluetooth.BluetoothDevice
+import android.bluetooth.BluetoothManager
+import android.bluetooth.BluetoothSocket
+import app.tauri.annotation.Command
+import app.tauri.annotation.InvokeArg
+import app.tauri.annotation.Permission
+import app.tauri.annotation.TauriPlugin
+import app.tauri.plugin.Invoke
+import app.tauri.plugin.JSObject
+import app.tauri.plugin.Plugin
+import java.io.OutputStream
+import java.util.*
+
+
+@InvokeArg
+class KirimArgs {
+ var alamat: String? = null
+ var data: ByteArray? = null
+}
+
+@TauriPlugin(
+ permissions = [
+ Permission(
+ strings = [Manifest.permission.BLUETOOTH_CONNECT],
+ alias = "bluetoothConnect"
+ )
+ ]
+)
+class BluetoothClassicPlugin(private val activity: Activity) : Plugin(activity) {
+ private val SPP_UUID: UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")
+
+ private val adapter: BluetoothAdapter? = this.activity.getSystemService(BluetoothManager::class.java).getAdapter()
+ private var soket: BluetoothSocket? = null
+ private var keluaran: OutputStream? = null
+
+ @Command
+ fun daftarPerangkat(invoke: Invoke) {
+ if (adapter == null) {
+ invoke.reject("Bluetooth tidak didukung")
+ return
+ }
+
+ val daftar_res = adapter.bondedDevices.map { i ->
+ mapOf(
+ "nama" to (i.name ?: "Unknown"),
+ "alamat" to i.address
+ )
+ }
+
+ val objek_daftar_res = JSObject()
+ objek_daftar_res.put("data", daftar_res)
+ invoke.resolve(objek_daftar_res)
+ }
+
+ fun menghubungkanKoneksi(invoke: Invoke, alamat: String) {
+ try {
+ val perangkat: BluetoothDevice = adapter!!.getRemoteDevice(alamat)
+
+ 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(invoke: Invoke) {
+ try {
+ keluaran?.close()
+ keluaran = null
+ soket?.close()
+ soket = null
+
+ } catch (e: Exception) {
+ invoke.reject("Memutus koneksi perangkat gagal")
+ }
+
+ invoke.resolve()
+ }
+
+ @Command
+ fun kirim(invoke: Invoke) {
+ val args = invoke.parseArgs(KirimArgs::class.java)
+
+ menghubungkanKoneksi(invoke, args.alamat ?: "")
+ if (keluaran == null) {
+ invoke.reject("Tidak ada perangkat yang terhubung")
+ return
+ }
+
+ try {
+ keluaran!!.write(args.data)
+ keluaran!!.flush()
+
+ } catch (e: Exception) {
+ memutusKoneksi(invoke)
+ invoke.reject("Mengirim data ke perangkat gagal: ${e.message}")
+ }
+
+ memutusKoneksi(invoke)
+ invoke.resolve()
+ }
+}
diff --git a/examples/tauri-app/.gitignore b/examples/tauri-app/.gitignore
deleted file mode 100644
index a547bf3..0000000
--- a/examples/tauri-app/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-# Logs
-logs
-*.log
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-pnpm-debug.log*
-lerna-debug.log*
-
-node_modules
-dist
-dist-ssr
-*.local
-
-# Editor directories and files
-.vscode/*
-!.vscode/extensions.json
-.idea
-.DS_Store
-*.suo
-*.ntvs*
-*.njsproj
-*.sln
-*.sw?
diff --git a/examples/tauri-app/.vscode/extensions.json b/examples/tauri-app/.vscode/extensions.json
deleted file mode 100644
index 61343e9..0000000
--- a/examples/tauri-app/.vscode/extensions.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "recommendations": [
- "svelte.svelte-vscode",
- "tauri-apps.tauri-vscode",
- "rust-lang.rust-analyzer"
- ]
-}
diff --git a/examples/tauri-app/README.md b/examples/tauri-app/README.md
deleted file mode 100644
index 72726a1..0000000
--- a/examples/tauri-app/README.md
+++ /dev/null
@@ -1,8 +0,0 @@
-# Svelte + Vite
-
-This template should help get you started developing with Tauri and Svelte in Vite.
-
-## Recommended IDE Setup
-
-[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer).
-
diff --git a/examples/tauri-app/index.html b/examples/tauri-app/index.html
deleted file mode 100644
index fad1c5d..0000000
--- a/examples/tauri-app/index.html
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
- Tauri + Svelte
-
-
-
-
-
-
-
diff --git a/examples/tauri-app/jsconfig.json b/examples/tauri-app/jsconfig.json
deleted file mode 100644
index 0882056..0000000
--- a/examples/tauri-app/jsconfig.json
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "compilerOptions": {
- "moduleResolution": "bundler",
- "target": "ESNext",
- "module": "ESNext",
- /**
- * svelte-preprocess cannot figure out whether you have
- * a value or a type, so tell TypeScript to enforce using
- * `import type` instead of `import` for Types.
- */
- "verbatimModuleSyntax": true,
- "isolatedModules": true,
- "resolveJsonModule": true,
- /**
- * To have warnings / errors of the Svelte compiler at the
- * correct position, enable source maps by default.
- */
- "sourceMap": true,
- "esModuleInterop": true,
- "skipLibCheck": true,
- "forceConsistentCasingInFileNames": true,
- "baseUrl": ".",
- /**
- * Typecheck JS in `.svelte` and `.js` files by default.
- * Disable this if you'd like to use dynamic types.
- */
- "checkJs": true
- },
- /**
- * Use global.d.ts instead of compilerOptions.types
- * to avoid limiting type declarations.
- */
- "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
-}
diff --git a/examples/tauri-app/package.json b/examples/tauri-app/package.json
deleted file mode 100644
index 7c1a5b4..0000000
--- a/examples/tauri-app/package.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "name": "tauri-app",
- "private": true,
- "version": "0.1.0",
- "type": "module",
- "scripts": {
- "dev": "vite",
- "build": "vite build",
- "preview": "vite preview",
- "tauri": "tauri"
- },
- "dependencies": {
- "@tauri-apps/api": "^2.0.0",
- "tauri-plugin-bluclas-api": "file:../../"
- },
- "devDependencies": {
- "@sveltejs/vite-plugin-svelte": "^6.0.0",
- "svelte": "^5.0.0",
- "vite": "^7.0.0",
- "@tauri-apps/cli": "^2.0.0"
- }
-}
diff --git a/examples/tauri-app/public/svelte.svg b/examples/tauri-app/public/svelte.svg
deleted file mode 100644
index c5e0848..0000000
--- a/examples/tauri-app/public/svelte.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/examples/tauri-app/public/tauri.svg b/examples/tauri-app/public/tauri.svg
deleted file mode 100644
index 31b62c9..0000000
--- a/examples/tauri-app/public/tauri.svg
+++ /dev/null
@@ -1,6 +0,0 @@
-
diff --git a/examples/tauri-app/public/vite.svg b/examples/tauri-app/public/vite.svg
deleted file mode 100644
index e7b8dfb..0000000
--- a/examples/tauri-app/public/vite.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/examples/tauri-app/src-tauri/.gitignore b/examples/tauri-app/src-tauri/.gitignore
deleted file mode 100644
index f4dfb82..0000000
--- a/examples/tauri-app/src-tauri/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-# Generated by Cargo
-# will have compiled files and executables
-/target/
-
diff --git a/examples/tauri-app/src-tauri/Cargo.toml b/examples/tauri-app/src-tauri/Cargo.toml
deleted file mode 100644
index f358d25..0000000
--- a/examples/tauri-app/src-tauri/Cargo.toml
+++ /dev/null
@@ -1,23 +0,0 @@
-[package]
-name = "tauri-app"
-version = "0.1.0"
-description = "A Tauri App"
-authors = ["you"]
-license = ""
-repository = ""
-edition = "2021"
-rust-version = "1.77.2"
-
-[lib]
-name = "tauri_app_lib"
-crate-type = ["staticlib", "cdylib", "rlib"]
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[build-dependencies]
-tauri-build = { version = "2.5.6", default-features = false }
-
-[dependencies]
-tauri = { version = "2.10.3" }
-tauri-plugin-bluclas = { path = "../../../" }
-
diff --git a/examples/tauri-app/src-tauri/build.rs b/examples/tauri-app/src-tauri/build.rs
deleted file mode 100644
index 795b9b7..0000000
--- a/examples/tauri-app/src-tauri/build.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-fn main() {
- tauri_build::build()
-}
diff --git a/examples/tauri-app/src-tauri/capabilities/default.json b/examples/tauri-app/src-tauri/capabilities/default.json
deleted file mode 100644
index 85caf85..0000000
--- a/examples/tauri-app/src-tauri/capabilities/default.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "$schema": "../gen/schemas/desktop-schema.json",
- "identifier": "default",
- "description": "enables the default permissions",
- "windows": [
- "main"
- ],
- "permissions": [
- "core:default",
- "bluclas:default"
- ]
-}
diff --git a/examples/tauri-app/src-tauri/icons/128x128.png b/examples/tauri-app/src-tauri/icons/128x128.png
deleted file mode 100644
index 77e7d23..0000000
Binary files a/examples/tauri-app/src-tauri/icons/128x128.png and /dev/null differ
diff --git a/examples/tauri-app/src-tauri/icons/128x128@2x.png b/examples/tauri-app/src-tauri/icons/128x128@2x.png
deleted file mode 100644
index 0f7976f..0000000
Binary files a/examples/tauri-app/src-tauri/icons/128x128@2x.png and /dev/null differ
diff --git a/examples/tauri-app/src-tauri/icons/32x32.png b/examples/tauri-app/src-tauri/icons/32x32.png
deleted file mode 100644
index 98fda06..0000000
Binary files a/examples/tauri-app/src-tauri/icons/32x32.png and /dev/null differ
diff --git a/examples/tauri-app/src-tauri/icons/icon.icns b/examples/tauri-app/src-tauri/icons/icon.icns
deleted file mode 100644
index 29d6685..0000000
Binary files a/examples/tauri-app/src-tauri/icons/icon.icns and /dev/null differ
diff --git a/examples/tauri-app/src-tauri/icons/icon.ico b/examples/tauri-app/src-tauri/icons/icon.ico
deleted file mode 100644
index 06c23c8..0000000
Binary files a/examples/tauri-app/src-tauri/icons/icon.ico and /dev/null differ
diff --git a/examples/tauri-app/src-tauri/icons/icon.png b/examples/tauri-app/src-tauri/icons/icon.png
deleted file mode 100644
index d1756ce..0000000
Binary files a/examples/tauri-app/src-tauri/icons/icon.png and /dev/null differ
diff --git a/examples/tauri-app/src-tauri/src/lib.rs b/examples/tauri-app/src-tauri/src/lib.rs
deleted file mode 100644
index 405d260..0000000
--- a/examples/tauri-app/src-tauri/src/lib.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-// Learn more about Tauri commands at https://v2.tauri.app/develop/calling-rust/#commands
-#[tauri::command]
-fn greet(name: &str) -> String {
- format!("Hello, {}! You've been greeted from Rust!", name)
-}
-
-#[cfg_attr(mobile, tauri::mobile_entry_point)]
-pub fn run() {
- tauri::Builder::default()
- .invoke_handler(tauri::generate_handler![greet])
- .plugin(tauri_plugin_bluclas::init())
- .run(tauri::generate_context!())
- .expect("error while running tauri application");
-}
diff --git a/examples/tauri-app/src-tauri/src/main.rs b/examples/tauri-app/src-tauri/src/main.rs
deleted file mode 100644
index 455963e..0000000
--- a/examples/tauri-app/src-tauri/src/main.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-// Prevents additional console window on Windows in release, DO NOT REMOVE!!
-#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
-
-fn main() {
- tauri_app_lib::run();
-}
diff --git a/examples/tauri-app/src-tauri/tauri.conf.json b/examples/tauri-app/src-tauri/tauri.conf.json
deleted file mode 100644
index 72ebf40..0000000
--- a/examples/tauri-app/src-tauri/tauri.conf.json
+++ /dev/null
@@ -1,37 +0,0 @@
-{
- "productName": "tauri-app",
- "version": "0.1.0",
- "identifier": "com.tauri.dev",
- "build": {
- "beforeDevCommand": "pnpm dev",
- "beforeBuildCommand": "pnpm build",
- "devUrl": "http://localhost:1420",
- "frontendDist": "../dist"
- },
- "app": {
- "withGlobalTauri": false,
- "security": {
- "csp": null
- },
- "windows": [
- {
- "fullscreen": false,
- "height": 600,
- "resizable": true,
- "title": "tauri-app",
- "width": 800
- }
- ]
- },
- "bundle": {
- "active": true,
- "targets": "all",
- "icon": [
- "icons/32x32.png",
- "icons/128x128.png",
- "icons/128x128@2x.png",
- "icons/icon.icns",
- "icons/icon.ico"
- ]
- }
-}
diff --git a/examples/tauri-app/src/App.svelte b/examples/tauri-app/src/App.svelte
deleted file mode 100644
index 6e2a1d2..0000000
--- a/examples/tauri-app/src/App.svelte
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
- Welcome to Tauri!
-
-
-
-
- Click on the Tauri, Vite, and Svelte logos to learn more.
-
-
-
-
-
-
-
-
-
{@html response}
-
-
-
-
-
diff --git a/examples/tauri-app/src/lib/Greet.svelte b/examples/tauri-app/src/lib/Greet.svelte
deleted file mode 100644
index 1da5e30..0000000
--- a/examples/tauri-app/src/lib/Greet.svelte
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
{greetMsg}
-
-
diff --git a/examples/tauri-app/src/main.js b/examples/tauri-app/src/main.js
deleted file mode 100644
index d3398c8..0000000
--- a/examples/tauri-app/src/main.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import "./style.css";
-import App from "./App.svelte";
-import { mount } from 'svelte';
-
-const app = mount(App, {
- target: document.getElementById("app"),
-});
-
-export default app;
diff --git a/examples/tauri-app/src/style.css b/examples/tauri-app/src/style.css
deleted file mode 100644
index c0f9e3b..0000000
--- a/examples/tauri-app/src/style.css
+++ /dev/null
@@ -1,102 +0,0 @@
-:root {
- font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
- font-size: 16px;
- line-height: 24px;
- font-weight: 400;
-
- color: #0f0f0f;
- background-color: #f6f6f6;
-
- font-synthesis: none;
- text-rendering: optimizeLegibility;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- -webkit-text-size-adjust: 100%;
-}
-
-.container {
- margin: 0;
- padding-top: 10vh;
- display: flex;
- flex-direction: column;
- justify-content: center;
- text-align: center;
-}
-
-.logo {
- height: 6em;
- padding: 1.5em;
- will-change: filter;
- transition: 0.75s;
-}
-
-.logo.tauri:hover {
- filter: drop-shadow(0 0 2em #24c8db);
-}
-
-.row {
- display: flex;
- justify-content: center;
-}
-
-a {
- font-weight: 500;
- color: #646cff;
- text-decoration: inherit;
-}
-
-a:hover {
- color: #535bf2;
-}
-
-h1 {
- text-align: center;
-}
-
-input,
-button {
- border-radius: 8px;
- border: 1px solid transparent;
- padding: 0.6em 1.2em;
- font-size: 1em;
- font-weight: 500;
- font-family: inherit;
- color: #0f0f0f;
- background-color: #ffffff;
- transition: border-color 0.25s;
- box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
-}
-
-button {
- cursor: pointer;
-}
-
-button:hover {
- border-color: #396cd8;
-}
-
-input,
-button {
- outline: none;
-}
-
-#greet-input {
- margin-right: 5px;
-}
-
-@media (prefers-color-scheme: dark) {
- :root {
- color: #f6f6f6;
- background-color: #2f2f2f;
- }
-
- a:hover {
- color: #24c8db;
- }
-
- input,
- button {
- color: #ffffff;
- background-color: #0f0f0f98;
- }
-}
diff --git a/examples/tauri-app/src/vite-env.d.ts b/examples/tauri-app/src/vite-env.d.ts
deleted file mode 100644
index 4078e74..0000000
--- a/examples/tauri-app/src/vite-env.d.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-///
-///
diff --git a/examples/tauri-app/vite.config.js b/examples/tauri-app/vite.config.js
deleted file mode 100644
index 82e1f23..0000000
--- a/examples/tauri-app/vite.config.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import { defineConfig } from "vite";
-import { svelte } from "@sveltejs/vite-plugin-svelte";
-
-const host = process.env.TAURI_DEV_HOST;
-
-// https://vite.dev/config/
-export default defineConfig({
- plugins: [svelte()],
-
- // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
- // prevent Vite from obscuring rust errors
- clearScreen: false,
- // tauri expects a fixed port, fail if that port is not available
- server: {
- host: host || false,
- port: 1420,
- strictPort: true,
- hmr: host ? {
- protocol: 'ws',
- host,
- port: 1421
- } : undefined,
- },
-})
diff --git a/src/commands.rs b/src/commands.rs
index a0bee4a..996abcf 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -1,13 +1,20 @@
-use tauri::{AppHandle, command, Runtime};
+use tauri::{command, AppHandle, Runtime};
use crate::models::*;
-use crate::Result;
use crate::BluclasExt;
+use crate::Result;
#[command]
-pub(crate) async fn ping(
+pub(crate) async fn daftar_perangkat(
app: AppHandle,
- payload: PingRequest,
-) -> Result {
- app.bluclas().ping(payload)
+) -> Result> {
+ return app.bluclas().daftar_perangkat();
+}
+
+#[command]
+pub(crate) async fn kirim(
+ app: AppHandle,
+ payload: SBluetoothClassicMuatanKirim,
+) -> Result<()> {
+ return app.bluclas().kirim(payload);
}
diff --git a/src/desktop.rs b/src/desktop.rs
index 2416875..a95b344 100644
--- a/src/desktop.rs
+++ b/src/desktop.rs
@@ -4,19 +4,26 @@ use tauri::{plugin::PluginApi, AppHandle, Runtime};
use crate::models::*;
pub fn init(
- app: &AppHandle,
- _api: PluginApi,
+ app: &AppHandle,
+ _api: PluginApi,
) -> crate::Result> {
- Ok(Bluclas(app.clone()))
+ Ok(Bluclas(app.clone()))
}
/// Access to the bluclas APIs.
pub struct Bluclas(AppHandle);
impl Bluclas {
- pub fn ping(&self, payload: PingRequest) -> crate::Result {
- Ok(PingResponse {
- value: payload.value,
- })
- }
+ pub fn daftar_perangkat(&self) -> crate::Result> {
+ let daftar_res: Vec =
+ vec![SBluetoothClassicResponPerangkat {
+ nama: String::new(),
+ alamat: String::new(),
+ }];
+ return Ok(daftar_res);
+ }
+
+ pub fn kirim(&self, _: SBluetoothClassicMuatanKirim) -> crate::Result<()> {
+ return Ok(());
+ }
}
diff --git a/src/lib.rs b/src/lib.rs
index fc82184..367cd81 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,6 @@
use tauri::{
- plugin::{Builder, TauriPlugin},
- Manager, Runtime,
+ plugin::{Builder, TauriPlugin},
+ Manager, Runtime,
};
pub use models::*;
@@ -23,26 +23,29 @@ use mobile::Bluclas;
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the bluclas APIs.
pub trait BluclasExt {
- fn bluclas(&self) -> &Bluclas;
+ fn bluclas(&self) -> &Bluclas;
}
impl> crate::BluclasExt for T {
- fn bluclas(&self) -> &Bluclas {
- self.state::>().inner()
- }
+ fn bluclas(&self) -> &Bluclas {
+ self.state::>().inner()
+ }
}
/// Initializes the plugin.
pub fn init() -> TauriPlugin {
- Builder::new("bluclas")
- .invoke_handler(tauri::generate_handler![commands::ping])
- .setup(|app, api| {
- #[cfg(mobile)]
- let bluclas = mobile::init(app, api)?;
- #[cfg(desktop)]
- let bluclas = desktop::init(app, api)?;
- app.manage(bluclas);
- Ok(())
- })
- .build()
+ Builder::new("bluclas")
+ .invoke_handler(tauri::generate_handler![
+ commands::daftar_perangkat,
+ commands::kirim
+ ])
+ .setup(|app, api| {
+ #[cfg(mobile)]
+ let bluclas = mobile::init(app, api)?;
+ #[cfg(desktop)]
+ let bluclas = desktop::init(app, api)?;
+ app.manage(bluclas);
+ Ok(())
+ })
+ .build()
}
diff --git a/src/mobile.rs b/src/mobile.rs
index a37ab08..311e47e 100644
--- a/src/mobile.rs
+++ b/src/mobile.rs
@@ -1,7 +1,7 @@
use serde::de::DeserializeOwned;
use tauri::{
- plugin::{PluginApi, PluginHandle},
- AppHandle, Runtime,
+ plugin::{PluginApi, PluginHandle},
+ AppHandle, Runtime,
};
use crate::models::*;
@@ -11,24 +11,31 @@ tauri::ios_plugin_binding!(init_plugin_bluclas);
// initializes the Kotlin or Swift plugin classes
pub fn init(
- _app: &AppHandle,
- api: PluginApi,
+ _app: &AppHandle,
+ api: PluginApi,
) -> crate::Result> {
- #[cfg(target_os = "android")]
- let handle = api.register_android_plugin("", "ExamplePlugin")?;
- #[cfg(target_os = "ios")]
- let handle = api.register_ios_plugin(init_plugin_bluclas)?;
- Ok(Bluclas(handle))
+ #[cfg(target_os = "android")]
+ let handle = api.register_android_plugin("com.plugin.bluclas", "BluclasPlugin")?;
+ #[cfg(target_os = "ios")]
+ let handle = api.register_ios_plugin(init_plugin_bluclas)?;
+ Ok(Bluclas(handle))
}
/// Access to the bluclas APIs.
pub struct Bluclas(PluginHandle);
impl Bluclas {
- pub fn ping(&self, payload: PingRequest) -> crate::Result {
- self
- .0
- .run_mobile_plugin("ping", payload)
- .map_err(Into::into)
- }
+ pub fn daftar_perangkat(&self) -> crate::Result> {
+ return self
+ .0
+ .run_mobile_plugin("daftarPerangkat", ())
+ .map_err(Into::into);
+ }
+
+ pub fn kirim(&self, payload: SBluetoothClassicMuatanKirim) -> crate::Result<()> {
+ return self
+ .0
+ .run_mobile_plugin("kirim", payload)
+ .map_err(Into::into);
+ }
}
diff --git a/src/models.rs b/src/models.rs
index 1b53e9e..42c5b61 100644
--- a/src/models.rs
+++ b/src/models.rs
@@ -1,13 +1,15 @@
use serde::{Deserialize, Serialize};
-#[derive(Debug, Deserialize, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct PingRequest {
- pub value: Option,
-}
-
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
-pub struct PingResponse {
- pub value: Option,
+pub struct SBluetoothClassicResponPerangkat {
+ pub nama: String,
+ pub alamat: String,
+}
+
+#[derive(Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct SBluetoothClassicMuatanKirim {
+ pub alamat: String,
+ pub data: Vec,
}