@@ -6,8 +6,6 @@ import { createPinia } from "pinia";
66import { useSettingsStore } from "@/stores/settings" ;
77import { useKeysStore } from "./stores/keys" ;
88import { useServerConfigStore } from "./stores/servers" ;
9- import { readDir , exists } from "@tauri-apps/plugin-fs" ;
10- import { homeDir , join , BaseDirectory } from "@tauri-apps/api/path" ;
119
1210import "@/index.css" ;
1311
@@ -34,61 +32,6 @@ async function initAppSetttings() {
3432 mode . value = theme ;
3533 }
3634
37- await ensureSshKeysSynced ( ) ;
35+ await useKeysStore ( ) . syncWithFs ( ) ;
3836 await useServerConfigStore ( ) . load ( ) ;
3937}
40-
41- async function ensureSshKeysSynced ( ) {
42- const keysStore = useKeysStore ( ) ;
43- await keysStore . load ( ) ;
44-
45- const home = await homeDir ( ) ;
46- const sshRel = ".ssh" ;
47- const sshAbs = await join ( home , ".ssh" ) ;
48- const entries = await readDir ( sshRel , { baseDir : BaseDirectory . Home } ) ;
49- const scanned : Array < { name : string ; private : string ; public ?: string } > = [ ] ;
50- for ( const e of entries ) {
51- if ( e . isDirectory ) continue ;
52- const name = e . name ?? "" ;
53- if ( ! name . endsWith ( ".pub" ) ) {
54- continue ;
55- }
56- const stem = name . slice ( 0 , - 4 ) ;
57- if ( ! stem || stem === "config" || stem . startsWith ( "known_hosts" ) ) {
58- continue ;
59- }
60- const privateRel = `${ sshRel } /${ stem } ` ;
61- const hasPrivate = await exists ( privateRel , {
62- baseDir : BaseDirectory . Home ,
63- } ) ;
64- if ( ! hasPrivate ) {
65- continue ; // require private key pair
66- }
67- const publicPath = await join ( sshAbs , name ) ;
68- const privatePath = await join ( sshAbs , stem ) ;
69- scanned . push ( { name : stem , private : privatePath , public : publicPath } ) ;
70- }
71-
72- const existing = await keysStore . getKeys ( ) ;
73- const byPrivate = new Map ( existing . map ( ( k ) => [ k . private , k ] ) ) ;
74-
75- for ( const s of scanned ) {
76- const found = byPrivate . get ( s . private ) ;
77- if ( found ) {
78- if ( found . name !== s . name || found . public !== s . public ) {
79- await keysStore . addOrUpdateKey ( {
80- id : found . id ,
81- name : s . name ,
82- private : s . private ,
83- public : s . public ,
84- } ) ;
85- }
86- } else {
87- await keysStore . addOrUpdateKey ( {
88- name : s . name ,
89- private : s . private ,
90- public : s . public ,
91- } ) ;
92- }
93- }
94- }
0 commit comments