diff --git a/android/src/androidTest/java/ExampleInstrumentedTest.kt b/android/src/androidTest/java/ExampleInstrumentedTest.kt deleted file mode 100644 index 5d4060b..0000000 --- a/android/src/androidTest/java/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.plugin.bluclas - -import androidx.test.platform.app.InstrumentationRegistry -import androidx.test.ext.junit.runners.AndroidJUnit4 - -import org.junit.Test -import org.junit.runner.RunWith - -import org.junit.Assert.* - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.plugin.bluclas", appContext.packageName) - } -} diff --git a/android/src/main/java/BluclasPlugin.kt b/android/src/main/java/BluclasPlugin.kt new file mode 100644 index 0000000..985eeae --- /dev/null +++ b/android/src/main/java/BluclasPlugin.kt @@ -0,0 +1,111 @@ +package com.plugin.bluetooth_classic + +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/android/src/main/java/Example.kt b/android/src/main/java/Example.kt deleted file mode 100644 index 8635a06..0000000 --- a/android/src/main/java/Example.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.plugin.bluclas - -import android.util.Log - -class Example { - fun pong(value: String): String { - Log.i("Pong", value) - return value - } -} diff --git a/android/src/main/java/ExamplePlugin.kt b/android/src/main/java/ExamplePlugin.kt deleted file mode 100644 index 7582b80..0000000 --- a/android/src/main/java/ExamplePlugin.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.plugin.bluclas - -import android.app.Activity -import app.tauri.annotation.Command -import app.tauri.annotation.InvokeArg -import app.tauri.annotation.TauriPlugin -import app.tauri.plugin.JSObject -import app.tauri.plugin.Plugin -import app.tauri.plugin.Invoke - -@InvokeArg -class PingArgs { - var value: String? = null -} - -@TauriPlugin -class ExamplePlugin(private val activity: Activity): Plugin(activity) { - private val implementation = Example() - - @Command - fun ping(invoke: Invoke) { - val args = invoke.parseArgs(PingArgs::class.java) - - val ret = JSObject() - ret.put("value", implementation.pong(args.value ?: "default value :(")) - invoke.resolve(ret) - } -} diff --git a/android/src/test/java/ExampleUnitTest.kt b/android/src/test/java/ExampleUnitTest.kt deleted file mode 100644 index f0b237f..0000000 --- a/android/src/test/java/ExampleUnitTest.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.plugin.bluclas - -import org.junit.Test - -import org.junit.Assert.* - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} 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, - }, -})