fix(desktop): remove @tauri-apps/plugin-keyring npm usage; fallback to Store for token on Windows; drop Rust keyring plugin to simplify install

This commit is contained in:
Esdras Renan 2025-10-09 23:27:37 -03:00
parent c0228c0dad
commit fcd45ff034
4 changed files with 9 additions and 21 deletions

View file

@ -11,7 +11,6 @@
}, },
"dependencies": { "dependencies": {
"@tauri-apps/api": "^2", "@tauri-apps/api": "^2",
"@tauri-apps/plugin-keyring": "^2",
"@tauri-apps/plugin-opener": "^2", "@tauri-apps/plugin-opener": "^2",
"@tauri-apps/plugin-store": "^2" "@tauri-apps/plugin-store": "^2"
}, },

View file

@ -21,7 +21,6 @@ tauri-build = { version = "2", features = [] }
tauri = { version = "2", features = ["wry"] } tauri = { version = "2", features = ["wry"] }
tauri-plugin-opener = "2" tauri-plugin-opener = "2"
tauri-plugin-store = "2.4" tauri-plugin-store = "2.4"
tauri-plugin-keyring = "0.1"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
sysinfo = { version = "0.31", default-features = false, features = ["multithread", "network", "system", "disk"] } sysinfo = { version = "0.31", default-features = false, features = ["multithread", "network", "system", "disk"] }

View file

@ -2,7 +2,6 @@ mod agent;
use agent::{collect_inventory_plain, collect_profile, AgentRuntime, MachineProfile}; use agent::{collect_inventory_plain, collect_profile, AgentRuntime, MachineProfile};
use tauri_plugin_store::Builder as StorePluginBuilder; use tauri_plugin_store::Builder as StorePluginBuilder;
use tauri_plugin_keyring as keyring;
#[tauri::command] #[tauri::command]
fn collect_machine_profile() -> Result<MachineProfile, String> { fn collect_machine_profile() -> Result<MachineProfile, String> {
@ -39,7 +38,6 @@ pub fn run() {
.manage(AgentRuntime::new()) .manage(AgentRuntime::new())
.plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_opener::init())
.plugin(StorePluginBuilder::default().build()) .plugin(StorePluginBuilder::default().build())
.plugin(keyring::init())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
collect_machine_profile, collect_machine_profile,
collect_machine_inventory, collect_machine_inventory,

View file

@ -1,6 +1,5 @@
import { invoke } from "@tauri-apps/api/core" import { invoke } from "@tauri-apps/api/core"
import { Store } from "@tauri-apps/plugin-store" import { Store } from "@tauri-apps/plugin-store"
import { getPassword, setPassword, deletePassword } from "@tauri-apps/plugin-keyring"
type MachineOs = { type MachineOs = {
name: string name: string
@ -115,9 +114,6 @@ function setStatus(message: string) {
let storeInstance: Store | null = null let storeInstance: Store | null = null
const KEYRING_SERVICE = "sistema-de-chamados"
const KEYRING_ACCOUNT = "machine-token"
async function ensureStoreLoaded(): Promise<Store> { async function ensureStoreLoaded(): Promise<Store> {
if (!storeInstance) { if (!storeInstance) {
try { try {
@ -152,24 +148,20 @@ async function clearConfig() {
const store = await ensureStoreLoaded() const store = await ensureStoreLoaded()
await store.delete("config") await store.delete("config")
await store.save() await store.save()
try { await store.delete("token");
await deletePassword({ service: KEYRING_SERVICE, account: KEYRING_ACCOUNT }) await store.save()
} catch {
// ignore
}
} }
async function getMachineToken(): Promise<string | null> { async function getMachineToken(): Promise<string | null> {
try { const store = await ensureStoreLoaded()
const token = await getPassword({ service: KEYRING_SERVICE, account: KEYRING_ACCOUNT }) const token = await store.get<string>("token")
return token && token.length > 0 ? token : null return token ?? null
} catch {
return null
}
} }
async function setMachineToken(token: string) { async function setMachineToken(token: string) {
await setPassword({ service: KEYRING_SERVICE, account: KEYRING_ACCOUNT, password: token }) const store = await ensureStoreLoaded()
await store.set("token", token)
await store.save()
} }
async function collectMachineProfile(): Promise<MachineProfile> { async function collectMachineProfile(): Promise<MachineProfile> {
@ -618,7 +610,7 @@ async function handleRegister(profile: MachineProfile, form: HTMLFormElement) {
} }
const data = (await response.json()) as MachineRegisterResponse const data = (await response.json()) as MachineRegisterResponse
// Guarda token com segurança no Keyring // Guarda token localmente (Store). Em produção, podemos trocar por keyring do SO.
await setMachineToken(data.machineToken) await setMachineToken(data.machineToken)
const config: AgentConfig = { const config: AgentConfig = {
machineId: data.machineId, machineId: data.machineId,