Skip to content

Commit

Permalink
fix: fixes issue with migrating category settings to the server (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Jun 10, 2024
1 parent 05c25c9 commit 54769b7
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/stores/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia';
import moment, { Moment } from 'moment';
import { getClient } from '~/util/awclient';
import { Category, defaultCategories } from '~/util/classes';
import { Category, defaultCategories, cleanCategory } from '~/util/classes';
import { View, defaultViews } from '~/stores/views';
import { isEqual } from 'lodash';

Expand Down Expand Up @@ -109,31 +109,32 @@ export const useSettingsStore = defineStore('settings', {
// Fetch from server, fall back to localStorage
const server_settings = await client.get_settings();

const all_keys = [
...Object.keys(localStorage).filter(key => {
// Skip built-in properties like length, setItem, etc.
return Object.prototype.hasOwnProperty.call(localStorage, key);
}),
...Object.keys(server_settings),
].filter(key => {
// Skip keys starting with underscore, as they are local to the vuex store.
return !key.startsWith('_');
});
const all_keys = [...Object.keys(localStorage), ...Object.keys(server_settings)].filter(
key => {
// Skip keys starting with underscore, as they are local to the vuex store.
return !key.startsWith('_');
}
);

const storage = {};
for (const key of all_keys) {
// If key is set in server, use that value, otherwise use localStorage
const set_in_server = server_settings[key] !== undefined;
const value = set_in_server ? server_settings[key] : localStorage.getItem(key);
let value = set_in_server ? server_settings[key] : localStorage.getItem(key);
//const locstr = set_in_server ? '[server]' : '[localStorage]';
//console.debug(`${locstr} ${key}:`, value);

// Keys ending with 'Data' are JSON-serialized objects in localStorage
if (key.endsWith('Data') && !set_in_server) {
if ((key.endsWith('Data') || key == 'views' || key == 'classes') && !set_in_server) {
try {
storage[key] = JSON.parse(value);
value = JSON.parse(value);
// Needed due to https://github.com/ActivityWatch/activitywatch/issues/1067
if (key == 'classes') {
value = value.map(cleanCategory);
}
storage[key] = value;
} catch (e) {
console.error('failed to parse', key, value);
console.error('failed to parse', key, value, e);
}
} else if (value === 'true' || value === 'false') {
storage[key] = value === 'true';
Expand Down

1 comment on commit 54769b7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are screenshots of this commit:

Screenshots using aw-server v0.12.3b18 (click to expand)

Screenshots using aw-server-rust master (click to expand)

Screenshots using aw-server-rust v0.12.3b18 (click to expand)

Please sign in to comment.