Skip to content

Commit cd5aafe

Browse files
fix(settings): prevent categorization crash when hostname not yet resolved (#759)
* fix(settings): prevent categorization crash when hostname not yet resolved The CategoryBuilder's fetchWords() could run before the hostname was resolved (race condition with QueryOptions component), causing it to construct invalid bucket IDs like 'aw-watcher-window_undefined' and display "Unable to find bucket matching" errors. Fix: bail out of fetchWords() if no valid hostname is available yet. The queryOptions watcher will re-trigger fetchWords() once QueryOptions emits a valid hostname, so the data loads correctly without errors. Fixes ActivityWatch/activitywatch#1182 * fix(settings): reset loading state on early return when hostname unavailable
1 parent c32b635 commit cd5aafe

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/views/settings/CategoryBuilder.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,17 @@ export default {
191191
async fetchWords() {
192192
this.loading = true;
193193
if (!this.queryOptions.hostname) {
194-
// FIXME: This is a hack to ensure that the hostname is set (otherwise isn't due to some race condition)
194+
// Try to resolve hostname from loaded buckets
195195
// Don't ever return the "unknown" hostname
196-
// TODO: ideally, only choose a hostname that has the right buckets
197-
this.queryOptions.hostname = _.filter(
198-
useBucketsStore().hosts,
199-
host => host !== 'unknown'
200-
)[0];
196+
const hosts = useBucketsStore().hosts;
197+
if (hosts && hosts.length > 0) {
198+
this.queryOptions.hostname = _.filter(hosts, host => host !== 'unknown')[0];
199+
}
200+
// If still no valid hostname, bail out and wait for QueryOptions to provide one
201+
if (!this.queryOptions.hostname) {
202+
this.loading = false;
203+
return;
204+
}
201205
}
202206
await this.categoryStore.load();
203207
const awclient = getClient();

0 commit comments

Comments
 (0)