Skip to content

Commit d2517c8

Browse files
committed
Remove unnecessary openclaw dc account finding logic
1 parent f9a53da commit d2517c8

3 files changed

Lines changed: 7 additions & 157 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Lightweight **Vala** + **GTK4** + **libadwaita** desktop client that talks to [d
4646

4747
### Accounts & profile
4848

49-
- **Auto-discovery** of existing Delta Chat accounts from Delta Chat Desktop, Flatpak, Snap and OpenClaw installations — no re-login needed.
49+
- **Auto-discovery** of existing Delta Chat accounts from Delta Chat Desktop, Flatpak and Snap installations — no re-login needed.
5050
- **Auto-discovery of `deltachat-rpc-server`** from `$PATH`, `~/.local/bin`, pip user installs, virtualenvs, and Flatpak runtimes.
5151
- **Multi-account** switching from the settings dialog.
5252
- **My Profile** dialog to edit display name, status and avatar.

src/account_finder.vala

Lines changed: 6 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace Dc {
22

33
/**
4-
* Locates existing DeltaChat installations, config files, and the RPC server binary.
5-
* Supports Flatpak, native, and openclaw-deltachat configurations.
4+
* Locates existing DeltaChat installations and the RPC server binary.
5+
* Supports Flatpak, native, and Snap installations.
66
*/
77
public class AccountFinder {
88

@@ -93,15 +93,12 @@ namespace Dc {
9393
);
9494
check_deltachat_dir (results, snap_dir, "Delta Chat Desktop (Snap)");
9595

96-
/* openclaw-deltachat config files */
97-
find_openclaw_configs (results);
98-
9996
return results;
10097
}
10198

10299
/**
103100
* Find the best data directory to start the RPC server in.
104-
* Prefers Flatpak > native > openclaw > fallback.
101+
* Prefers Flatpak > native > fallback.
105102
*/
106103
public static string get_default_data_dir () {
107104
var installations = find_installations ();
@@ -114,44 +111,12 @@ namespace Dc {
114111
}
115112
/* Fallback: create in user config */
116113
string fallback = Path.build_filename (
117-
Environment.get_home_dir (), ".config", "openclaw-deltachat"
114+
Environment.get_home_dir (), ".config", "deltachat-gnome"
118115
);
119116
DirUtils.create_with_parents (fallback, 0700);
120117
return fallback;
121118
}
122119

123-
/**
124-
* Try to read credentials from the first found openclaw-deltachat config.
125-
* Returns an Account with email/password if found, null otherwise.
126-
*/
127-
public static Account? get_credentials_from_config () {
128-
string[] config_candidates = {
129-
Environment.get_variable ("OPENCLAW_DELTACHAT_CONFIG") ?? "",
130-
Environment.get_variable ("DELTACHAT_CONFIG") ?? "",
131-
Path.build_filename (Environment.get_home_dir (),
132-
".openclaw", "extensions", "deltachat", "deltachat-config.json"),
133-
Path.build_filename (Environment.get_home_dir (),
134-
"prg", "openclaw-deltachat", "deltachat-config.json"),
135-
"deltachat-config.json"
136-
};
137-
138-
foreach (string candidate in config_candidates) {
139-
if (candidate.length == 0) continue;
140-
141-
string path = expand_home (candidate);
142-
if (!Path.is_absolute (path)) {
143-
path = Path.build_filename (Environment.get_current_dir (), path);
144-
}
145-
146-
if (!FileUtils.test (path, FileTest.EXISTS)) continue;
147-
148-
var account = parse_openclaw_config (path);
149-
if (account != null) return account;
150-
}
151-
152-
return null;
153-
}
154-
155120
/* ---- Private helpers ---- */
156121

157122
/**
@@ -265,100 +230,6 @@ namespace Dc {
265230
return null;
266231
}
267232

268-
private static void find_openclaw_configs (GenericArray<FoundInstallation> results) {
269-
string[] candidates = {
270-
Path.build_filename (Environment.get_home_dir (),
271-
".openclaw", "extensions", "deltachat", "deltachat-config.json"),
272-
Path.build_filename (Environment.get_home_dir (),
273-
"prg", "openclaw-deltachat", "deltachat-config.json"),
274-
};
275-
276-
/* Also check env vars */
277-
string? env1 = Environment.get_variable ("OPENCLAW_DELTACHAT_CONFIG");
278-
string? env2 = Environment.get_variable ("DELTACHAT_CONFIG");
279-
280-
string[] all_candidates = {};
281-
if (env1 != null && env1.length > 0) all_candidates += expand_home (env1);
282-
if (env2 != null && env2.length > 0) all_candidates += expand_home (env2);
283-
foreach (string c in candidates) all_candidates += c;
284-
285-
foreach (string path in all_candidates) {
286-
if (!FileUtils.test (path, FileTest.EXISTS)) continue;
287-
288-
var account = parse_openclaw_config (path);
289-
if (account == null) continue;
290-
291-
var inst = new FoundInstallation ();
292-
inst.label = "OpenClaw config (%s)".printf (Path.get_basename (
293-
Path.get_dirname (path)));
294-
inst.data_path = Path.get_dirname (path);
295-
inst.email = account.email;
296-
inst.password = account.password;
297-
inst.source = "openclaw";
298-
results.add (inst);
299-
}
300-
}
301-
302-
private static Account? parse_openclaw_config (string path) {
303-
try {
304-
string contents;
305-
FileUtils.get_contents (path, out contents);
306-
307-
var parser = new Json.Parser ();
308-
parser.load_from_data (contents);
309-
310-
var root = parser.get_root ();
311-
if (root == null || root.get_node_type () != Json.NodeType.OBJECT) return null;
312-
313-
var obj = root.get_object ();
314-
if (!obj.has_member ("accounts")) return null;
315-
316-
var accounts_node = obj.get_member ("accounts");
317-
if (accounts_node.get_node_type () != Json.NodeType.ARRAY) return null;
318-
319-
var accounts = accounts_node.get_array ();
320-
if (accounts.get_length () == 0) return null;
321-
322-
var first = accounts.get_object_element (0);
323-
string? email = null;
324-
string? password = null;
325-
326-
if (first.has_member ("email"))
327-
email = first.get_string_member ("email");
328-
else if (first.has_member ("addr"))
329-
email = first.get_string_member ("addr");
330-
331-
if (first.has_member ("mail_pw"))
332-
password = first.get_string_member ("mail_pw");
333-
else if (first.has_member ("password"))
334-
password = first.get_string_member ("password");
335-
336-
if (email == null || email.length == 0) return null;
337-
338-
var account = new Account ();
339-
account.email = email;
340-
account.password = password ?? "";
341-
342-
if (first.has_member ("display_name") &&
343-
!first.get_member ("display_name").is_null ()) {
344-
account.display_name = first.get_string_member ("display_name");
345-
}
346-
347-
return account;
348-
} catch (Error e) {
349-
return null;
350-
}
351-
}
352-
353-
private static string expand_home (string path) {
354-
if (path == "~") return Environment.get_home_dir ();
355-
if (path.has_prefix ("~/")) {
356-
return Path.build_filename (
357-
Environment.get_home_dir (), path.substring (2));
358-
}
359-
return path;
360-
}
361-
362233
/**
363234
* Find and activate a configured account, or create one from
364235
* credentials. Returns the account id (>0) on success, or 0 with
@@ -384,17 +255,6 @@ namespace Dc {
384255
}
385256
}
386257

387-
var creds = get_credentials_from_config ();
388-
if (creds != null && creds.email.length > 0 && creds.password.length > 0) {
389-
int acct_id = yield rpc.add_account ();
390-
yield rpc.add_or_update_transport (acct_id, creds.email, creds.password);
391-
yield rpc.select_account (acct_id);
392-
yield rpc.start_io (acct_id);
393-
rpc.account_id = acct_id;
394-
toast_msg = "Configured account: " + creds.email;
395-
return acct_id;
396-
}
397-
398258
var installations = find_installations ();
399259
if (installations.length > 0) {
400260
var sb = new StringBuilder ("Found installations:\n");
@@ -404,12 +264,11 @@ namespace Dc {
404264
if (inst.email != null) sb.append (" (%s)".printf (inst.email));
405265
sb.append ("\n");
406266
}
407-
description = sb.str +
408-
"\nCreate a deltachat-config.json with email/password to connect.";
267+
description = sb.str + "\nAdd an account from Settings to connect.";
409268
} else {
410269
description =
411270
"No Delta Chat accounts found.\n" +
412-
"Create deltachat-config.json with your credentials.";
271+
"Add an account from Settings to connect.";
413272
}
414273
} catch (Error e) {
415274
toast_msg = "Account setup error: " + e.message;

src/models.vala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,6 @@ namespace Dc {
114114
return row;
115115
}
116116

117-
public class Account : Object {
118-
public int id { get; set; default = 0; }
119-
public string email { get; set; default = ""; }
120-
public string password { get; set; default = ""; }
121-
public bool configured { get; set; default = false; }
122-
public string? display_name { get; set; default = null; }
123-
}
124-
125117
public class ChatEntry : Object {
126118
public int id { get; set; default = 0; }
127119
public string name { get; set; default = ""; }
@@ -171,7 +163,6 @@ namespace Dc {
171163
public string label { get; set; default = ""; }
172164
public string data_path { get; set; default = ""; }
173165
public string? email { get; set; default = null; }
174-
public string? password { get; set; default = null; }
175166
public string source { get; set; default = ""; }
176167
}
177168

0 commit comments

Comments
 (0)