Repository navigation
Closed
Description
Establishing a DBus connection is currently done in KDEWalletKeychainAccess's constructor:
integrations-linux/src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java
Lines 24 to 43 in bd1beaa
| public KDEWalletKeychainAccess() { | |
| ConnectedWallet wallet = null; | |
| try { | |
| DBusConnection conn = null; | |
| try { | |
| conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION); | |
| } catch (RuntimeException e) { | |
| if (e.getMessage() == "Cannot Resolve Session Bus Address") { | |
| LOG.warn("SESSION DBus not found."); | |
| } | |
| } | |
| if (conn == null) { | |
| conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SYSTEM); | |
| } | |
| wallet = new ConnectedWallet(conn); | |
| } catch (DBusException e) { | |
| LOG.warn("Connecting to D-Bus failed.", e); | |
| } | |
| this.wallet = Optional.ofNullable(wallet); | |
| } |
Due to the nature of final fields and variable scope, this code isn't really beautiful. Instead we could add a factory method (static Optional<ConnectedWallet> connect()) with the "try-retry-fail" stuff in ConnectedWallet. Then simply invoke this from the constructor: this.wallet = ConnectedWallet.connect().
This should eliminate the need for local variables, as we can just return from inside the try-catch blocks.
Metadata
Metadata
Assignees
Labels
No labels
Activity
Refactor DBus Connection Initialization (#9)