Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7cd4603c7 | ||
|
|
24c5d3e1f2 | ||
|
|
de72fa5e3e | ||
|
|
00aa5a8526 | ||
|
|
432a34540d | ||
|
|
923540934e | ||
|
|
30120dacb2 | ||
|
|
f0b237d2a2 | ||
|
|
cd139ab7c7 | ||
|
|
0bf140dff2 | ||
|
|
9787d1619e |
No files matched your search
@@ -41,6 +41,18 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
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
|
- name: Unduh pnpm
|
||||||
uses: pnpm/setup@v2
|
uses: pnpm/setup@v2
|
||||||
with:
|
with:
|
||||||
@@ -53,15 +65,3 @@ jobs:
|
|||||||
npm config set -- '//${{ vars.ALAMAT_GITEA }}/api/packages/${{ needs.persiapan.outputs.organisasi }}/npm/:_authToken' "${{ secrets.KUNCI_PENERBITAN }}"
|
npm config set -- '//${{ vars.ALAMAT_GITEA }}/api/packages/${{ needs.persiapan.outputs.organisasi }}/npm/:_authToken' "${{ secrets.KUNCI_PENERBITAN }}"
|
||||||
npm publish
|
npm publish
|
||||||
rm -rf pnpm-lock.yaml .pnpm-store/
|
rm -rf pnpm-lock.yaml .pnpm-store/
|
||||||
|
|
||||||
- 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 }}
|
|
||||||
+10
-3
@@ -1,10 +1,10 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tauri-plugin-bluclas"
|
name = "tauri-plugin-bluclas"
|
||||||
version = "0.1.15"
|
version = "0.1.23"
|
||||||
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"
|
||||||
rust-version = "1.94.1"
|
rust-version = "1.98.0"
|
||||||
exclude = ["/examples", "/dist-js", "/guest-js", "/node_modules"]
|
exclude = ["/examples", "/dist-js", "/guest-js", "/node_modules"]
|
||||||
links = "tauri-plugin-bluclas"
|
links = "tauri-plugin-bluclas"
|
||||||
|
|
||||||
@@ -17,11 +17,18 @@ incremental = false
|
|||||||
strip = "symbols"
|
strip = "symbols"
|
||||||
debug = false
|
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.11.5" }
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
serialport = "4.10.0"
|
serialport = "4.10.1"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-plugin = { version = "2.6.3", features = ["build"] }
|
tauri-plugin = { version = "2.6.3", features = ["build"] }
|
||||||
@@ -1 +1,3 @@
|
|||||||
# Tauri Plugin bluclas
|
# Tauri Plugin bluclas
|
||||||
|
|
||||||
|
Program sederhana untuk interaksi dengan bluetooth classic
|
||||||
@@ -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,32 +74,37 @@ 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
|
||||||
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()) {
|
||||||
|
invoke.resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
menghubungkanKoneksi(args.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()
|
||||||
|
|||||||
+19
-2
@@ -1,4 +1,21 @@
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
import {
|
||||||
|
checkPermissions as checkPermissions_,
|
||||||
|
invoke,
|
||||||
|
PermissionState,
|
||||||
|
requestPermissions as requestPermissions_,
|
||||||
|
} from "@tauri-apps/api/core";
|
||||||
|
|
||||||
|
export async function checkPermissions(): Promise<PermissionState> {
|
||||||
|
return await checkPermissions_<{ bluetooth: PermissionState }>(
|
||||||
|
"bluclas",
|
||||||
|
).then((e) => e.bluetooth);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function requestPermissions(): Promise<PermissionState> {
|
||||||
|
return await requestPermissions_<{ bluetooth: PermissionState }>(
|
||||||
|
"bluclas",
|
||||||
|
).then((e) => e.bluetooth);
|
||||||
|
}
|
||||||
|
|
||||||
export type SDaftarPerangkatBlueclasResponDaftarPerangkat = {
|
export type SDaftarPerangkatBlueclasResponDaftarPerangkat = {
|
||||||
nama: string;
|
nama: string;
|
||||||
@@ -21,5 +38,5 @@ export type SBlueclasMuatanKirim = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function kirim(muatan: SBlueclasMuatanKirim): Promise<null> {
|
export async function kirim(muatan: SBlueclasMuatanKirim): Promise<null> {
|
||||||
return await invoke<null>("plugin:bluclas|kirim", { payload: muatan });
|
return await invoke<null>("plugin:bluclas|kirim", { muatan: muatan });
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@segubi/tauri-plugin-bluclas-api",
|
"name": "@segubi/tauri-plugin-bluclas-api",
|
||||||
"version": "0.1.15",
|
"version": "0.1.23",
|
||||||
"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",
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-typescript": "^12.3.0",
|
"@rollup/plugin-typescript": "^12.3.0",
|
||||||
"rollup": "^4.63.1",
|
"rollup": "^4.63.2",
|
||||||
"typescript": "^6.0.3",
|
"typescript": "^6.0.3",
|
||||||
"tslib": "^2.8.1"
|
"tslib": "^2.8.1"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -20,7 +20,8 @@ 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: [
|
||||||
|
|||||||
+2
-2
@@ -14,7 +14,7 @@ pub(crate) async fn daftar_perangkat<R: Runtime>(
|
|||||||
#[command]
|
#[command]
|
||||||
pub(crate) async fn kirim<R: Runtime>(
|
pub(crate) async fn kirim<R: Runtime>(
|
||||||
app: AppHandle<R>,
|
app: AppHandle<R>,
|
||||||
payload: SBlueclasMuatanKirim,
|
muatan: SBlueclasMuatanKirim,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
return app.bluclas().kirim(payload);
|
return app.bluclas().kirim(muatan);
|
||||||
}
|
}
|
||||||
+2
-3
@@ -1,11 +1,8 @@
|
|||||||
use crate::commands::{daftar_perangkat, kirim};
|
|
||||||
use tauri::{
|
use tauri::{
|
||||||
Manager, Runtime,
|
Manager, Runtime,
|
||||||
plugin::{Builder, TauriPlugin},
|
plugin::{Builder, TauriPlugin},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use models::*;
|
|
||||||
|
|
||||||
#[cfg(desktop)]
|
#[cfg(desktop)]
|
||||||
mod desktop;
|
mod desktop;
|
||||||
#[cfg(mobile)]
|
#[cfg(mobile)]
|
||||||
@@ -22,6 +19,8 @@ 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>;
|
||||||
|
|||||||
+2
-2
@@ -32,10 +32,10 @@ impl<R: Runtime> Bluclas<R> {
|
|||||||
.map_err(Into::into);
|
.map_err(Into::into);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn kirim(&self, payload: SBlueclasMuatanKirim) -> crate::Result<()> {
|
pub fn kirim(&self, muatan: SBlueclasMuatanKirim) -> crate::Result<()> {
|
||||||
return self
|
return self
|
||||||
.0
|
.0
|
||||||
.run_mobile_plugin("kirim", payload)
|
.run_mobile_plugin("kirim", muatan)
|
||||||
.map_err(Into::into);
|
.map_err(Into::into);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,19 +1,19 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct SDaftarPerangkatBlueclasResponDaftarPerangkat {
|
pub struct SDaftarPerangkatBlueclasResponDaftarPerangkat {
|
||||||
pub nama: String,
|
pub nama: String,
|
||||||
pub alamat: String,
|
pub alamat: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct SBlueclasResponDaftarPerangkat {
|
pub struct SBlueclasResponDaftarPerangkat {
|
||||||
pub data: Vec<SDaftarPerangkatBlueclasResponDaftarPerangkat>,
|
pub data: Vec<SDaftarPerangkatBlueclasResponDaftarPerangkat>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct SBlueclasMuatanKirim {
|
pub struct SBlueclasMuatanKirim {
|
||||||
pub alamat: String,
|
pub alamat: String,
|
||||||
|
|||||||
Reference in new issue
Block a user