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:
parent
c0228c0dad
commit
fcd45ff034
4 changed files with 9 additions and 21 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import { invoke } from "@tauri-apps/api/core"
|
||||
import { Store } from "@tauri-apps/plugin-store"
|
||||
import { getPassword, setPassword, deletePassword } from "@tauri-apps/plugin-keyring"
|
||||
|
||||
type MachineOs = {
|
||||
name: string
|
||||
|
|
@ -115,9 +114,6 @@ function setStatus(message: string) {
|
|||
|
||||
let storeInstance: Store | null = null
|
||||
|
||||
const KEYRING_SERVICE = "sistema-de-chamados"
|
||||
const KEYRING_ACCOUNT = "machine-token"
|
||||
|
||||
async function ensureStoreLoaded(): Promise<Store> {
|
||||
if (!storeInstance) {
|
||||
try {
|
||||
|
|
@ -152,24 +148,20 @@ async function clearConfig() {
|
|||
const store = await ensureStoreLoaded()
|
||||
await store.delete("config")
|
||||
await store.save()
|
||||
try {
|
||||
await deletePassword({ service: KEYRING_SERVICE, account: KEYRING_ACCOUNT })
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
await store.delete("token");
|
||||
await store.save()
|
||||
}
|
||||
|
||||
async function getMachineToken(): Promise<string | null> {
|
||||
try {
|
||||
const token = await getPassword({ service: KEYRING_SERVICE, account: KEYRING_ACCOUNT })
|
||||
return token && token.length > 0 ? token : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
const store = await ensureStoreLoaded()
|
||||
const token = await store.get<string>("token")
|
||||
return token ?? null
|
||||
}
|
||||
|
||||
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> {
|
||||
|
|
@ -618,7 +610,7 @@ async function handleRegister(profile: MachineProfile, form: HTMLFormElement) {
|
|||
}
|
||||
|
||||
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)
|
||||
const config: AgentConfig = {
|
||||
machineId: data.machineId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue