mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-07 06:40:54 +00:00
4.4.0
The Profile Update! Now, it's possible to create custom settings profiles. The important thing about profiles is that you can have different profiles run according to different rules. Want some settings to only apply on your dashboard? Use a Current Page rule set to Dashboard. Want your chat wider in theater mode? Create a profile for Theater Mode. * Added: Profile Editor. * Added: Ability to import and export specific profiles. * Added: Ability to update profiles from JSON files for more advanced users. * Fixed: Update `sortablejs` dependency to fix issue with sorting behavior. * Fixed: Several issues in the settings profile system which never came up because custom profiles weren't available. * Fixed: Hotkeys freezing chat when they shouldn't, up until the first time the mouse hovers over chat. * API Added: `deep_equals(object, other, ignore_undefined = false)` method of `FrankerFaceZ.utilities.object` for comparing two objects, deeply. * API Changed: `<setting-check-box />` controls can now display their indeterminate state. * API Fixed: `deep_copy()` eating Promises and Functions.
This commit is contained in:
parent
734a73eb0e
commit
c34b7e30e2
31 changed files with 1421 additions and 129 deletions
|
@ -5,7 +5,7 @@
|
|||
// ============================================================================
|
||||
|
||||
import Module from 'utilities/module';
|
||||
import {has} from 'utilities/object';
|
||||
import {deep_equals, has} from 'utilities/object';
|
||||
|
||||
import {CloudStorageProvider, LocalStorageProvider} from './providers';
|
||||
import SettingsProfile from './profile';
|
||||
|
@ -92,6 +92,8 @@ export default class SettingsManager extends Module {
|
|||
|
||||
const duration = performance.now() - this._start_time;
|
||||
this.log.info(`Initialization complete after ${duration.toFixed(5)}ms -- Values: ${this.provider.size} -- Profiles: ${this.__profiles.length}`)
|
||||
|
||||
this.scheduleUpdates();
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,6 +118,34 @@ export default class SettingsManager extends Module {
|
|||
}
|
||||
|
||||
|
||||
scheduleUpdates() {
|
||||
if ( this._update_timer )
|
||||
clearTimeout(this._update_timer);
|
||||
|
||||
this._update_timer = setTimeout(() => this.checkUpdates(), 5000);
|
||||
}
|
||||
|
||||
|
||||
checkUpdates() {
|
||||
const promises = [];
|
||||
for(const profile of this.__profiles) {
|
||||
if ( ! profile || ! profile.url )
|
||||
continue;
|
||||
|
||||
const out = profile.checkUpdate();
|
||||
promises.push(out instanceof Promise ? out : Promise.resolve(out));
|
||||
}
|
||||
|
||||
Promise.all(promises).then(data => {
|
||||
let success = 0;
|
||||
for(const thing of data)
|
||||
if ( thing )
|
||||
success++;
|
||||
|
||||
this.log.info(`Successfully refreshed ${success} of ${data.length} profiles from remote URLs.`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// ========================================================================
|
||||
// Provider Interaction
|
||||
|
@ -194,7 +224,6 @@ export default class SettingsManager extends Module {
|
|||
// to keys.
|
||||
old_ids = new Set(old_profiles.map(x => x.id)),
|
||||
|
||||
moved_ids = new Set,
|
||||
new_ids = new Set,
|
||||
changed_ids = new Set,
|
||||
|
||||
|
@ -203,30 +232,38 @@ export default class SettingsManager extends Module {
|
|||
SettingsProfile.Default
|
||||
]);
|
||||
|
||||
let changed = false;
|
||||
let reordered = false,
|
||||
changed = false;
|
||||
|
||||
for(const profile_data of raw_profiles) {
|
||||
const id = profile_data.id,
|
||||
slot_id = profiles.length,
|
||||
old_profile = old_profile_ids[id],
|
||||
old_slot_id = parseInt(old_profiles[profiles.length] || -1, 10);
|
||||
old_slot_id = old_profile ? old_profiles.indexOf(old_profile) : -1;
|
||||
|
||||
old_ids.delete(id);
|
||||
|
||||
if ( old_slot_id !== id ) {
|
||||
moved_ids.add(old_slot_id);
|
||||
moved_ids.add(id);
|
||||
if ( old_slot_id !== slot_id )
|
||||
reordered = true;
|
||||
|
||||
// Monkey patch to the new profile format...
|
||||
if ( profile_data.context && ! Array.isArray(profile_data.context) ) {
|
||||
if ( profile_data.context.moderator )
|
||||
profile_data.context = SettingsProfile.Moderation.context;
|
||||
else
|
||||
profile_data.context = null;
|
||||
}
|
||||
|
||||
// TODO: Better method for checking if the profile data has changed.
|
||||
if ( old_profile && JSON.stringify(old_profile.data) === JSON.stringify(profile_data) ) {
|
||||
if ( old_profile && deep_equals(old_profile.data, profile_data, true) ) {
|
||||
// Did the order change?
|
||||
if ( old_profiles[profiles.length] !== old_profile )
|
||||
if ( old_slot_id !== slot_id )
|
||||
changed = true;
|
||||
|
||||
profiles.push(profile_ids[id] = old_profile);
|
||||
continue;
|
||||
}
|
||||
|
||||
const new_profile = profiles.push(profile_ids[id] = new SettingsProfile(this, profile_data));
|
||||
const new_profile = profile_ids[id] = new SettingsProfile(this, profile_data);
|
||||
if ( old_profile ) {
|
||||
// Move all the listeners over.
|
||||
new_profile.__listeners = old_profile.__listeners;
|
||||
|
@ -237,6 +274,7 @@ export default class SettingsManager extends Module {
|
|||
} else
|
||||
new_ids.add(id);
|
||||
|
||||
profiles.push(new_profile);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
@ -252,7 +290,7 @@ export default class SettingsManager extends Module {
|
|||
for(const id of changed_ids)
|
||||
this.emit(':profile-changed', profile_ids[id]);
|
||||
|
||||
if ( moved_ids.size )
|
||||
if ( reordered )
|
||||
this.emit(':profiles-reordered');
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue