1
0
Fork 1
mirror of https://github.com/zen-browser/desktop.git synced 2025-07-10 05:35:29 +02:00
- Zen Mods: Default value not being loaded on theme install due to zen mods not being always triggered and default values not being in place when reading them (fixes #3887)
- Zen Mods: Fixed string preferences not changing completely by changing the event listener and replacing the throttle with a debounce, so we only listen to the last keydown (fixes #3558)
This commit is contained in:
Bryan Galdámez 2025-01-03 21:21:07 -06:00
parent 5e77f44e05
commit 2b1224b3df
2 changed files with 47 additions and 35 deletions

View file

@ -45,7 +45,7 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
window.gZenThemePicker.riceManager.openRicePage(data); window.gZenThemePicker.riceManager.openRicePage(data);
} }
compareversion(version1, version2) { compareVersions(version1, version2) {
var result = false; var result = false;
if (typeof version1 !== 'object') { if (typeof version1 !== 'object') {
version1 = version1.toString().split('.'); version1 = version1.toString().split('.');
@ -73,22 +73,31 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
async checkForThemeUpdates() { async checkForThemeUpdates() {
console.info('ZenThemeMarketplaceParent: Checking for theme updates'); console.info('ZenThemeMarketplaceParent: Checking for theme updates');
let updates = []; let updates = [];
this._themes = null; this._themes = null;
for (const theme of Object.values(await this.getThemes())) { for (const theme of Object.values(await this.getThemes())) {
const themeInfo = await this.sendQuery('ZenThemeMarketplace:GetThemeInfo', { themeId: theme.id }); const themeInfo = await this.sendQuery('ZenThemeMarketplace:GetThemeInfo', { themeId: theme.id });
if (!themeInfo) { if (!themeInfo) {
continue; continue;
} }
if (!this.compareversion(themeInfo.version, theme.version || '0.0.0') && themeInfo.version != theme.version) {
if (!this.compareVersions(themeInfo.version, theme.version || '0.0.0') && themeInfo.version != theme.version) {
console.info('ZenThemeMarketplaceParent: Theme update found', theme.id, theme.version, themeInfo.version); console.info('ZenThemeMarketplaceParent: Theme update found', theme.id, theme.version, themeInfo.version);
themeInfo.enabled = theme.enabled; themeInfo.enabled = theme.enabled;
updates.push(themeInfo); updates.push(themeInfo);
await this.removeTheme(theme.id, false); await this.removeTheme(theme.id, false);
this._themes[themeInfo.id] = themeInfo; this._themes[themeInfo.id] = themeInfo;
} }
} }
await this.updateThemes(this._themes); await this.updateThemes(this._themes);
this.sendAsyncMessage('ZenThemeMarketplace:CheckForUpdatesFinished', { updates }); this.sendAsyncMessage('ZenThemeMarketplace:CheckForUpdatesFinished', { updates });
} }
@ -166,27 +175,30 @@ export class ZenThemeMarketplaceParent extends JSWindowActorParent {
async checkForThemeChanges() { async checkForThemeChanges() {
const themes = await this.getThemes(); const themes = await this.getThemes();
const themeIds = Object.keys(themes); const themeIds = Object.keys(themes);
let changed = false;
for (const themeId of themeIds) { for (const themeId of themeIds) {
const theme = themes[themeId]; const theme = themes[themeId];
if (!theme) { if (!theme) {
continue; continue;
} }
const themePath = PathUtils.join(this.themesRootPath, themeId); const themePath = PathUtils.join(this.themesRootPath, themeId);
if (!(await IOUtils.exists(themePath))) { if (!(await IOUtils.exists(themePath))) {
await this.installTheme(theme); await this.installTheme(theme);
changed = true;
} }
} }
if (changed) {
this.triggerThemeUpdate(); this.triggerThemeUpdate();
}
} }
async removeTheme(themeId, triggerUpdate = true) { async removeTheme(themeId, triggerUpdate = true) {
const themePath = PathUtils.join(this.themesRootPath, themeId); const themePath = PathUtils.join(this.themesRootPath, themeId);
await IOUtils.remove(themePath, { recursive: true, ignoreAbsent: true }); await IOUtils.remove(themePath, { recursive: true, ignoreAbsent: true });
if (triggerUpdate) { if (triggerUpdate) {
this.triggerThemeUpdate(); this.triggerThemeUpdate();
} }

View file

@ -292,7 +292,7 @@ var gZenMarketplaceManager = {
preferencesWrapper.setAttribute('flex', '1'); preferencesWrapper.setAttribute('flex', '1');
for (const entry of preferences) { for (const entry of preferences) {
const { property, label, type, placeholder } = entry; const { property, label, type, placeholder, defaultValue } = entry;
switch (type) { switch (type) {
case 'dropdown': { case 'dropdown': {
@ -309,7 +309,7 @@ var gZenMarketplaceManager = {
menulist.setAttribute('sizetopopup', 'none'); menulist.setAttribute('sizetopopup', 'none');
menulist.setAttribute('id', property + '-popup-menulist'); menulist.setAttribute('id', property + '-popup-menulist');
const savedValue = Services.prefs.getStringPref(property, 'none'); const savedValue = Services.prefs.getStringPref(property, defaultValue ?? 'none');
menulist.setAttribute('value', savedValue); menulist.setAttribute('value', savedValue);
menulist.setAttribute('tooltiptext', property); menulist.setAttribute('tooltiptext', property);
@ -395,7 +395,7 @@ var gZenMarketplaceManager = {
checkboxElement.setAttribute('zen-pref', property); checkboxElement.setAttribute('zen-pref', property);
// Checkbox only works with "true" and "false" values, it's not like HTML checkboxes. // Checkbox only works with "true" and "false" values, it's not like HTML checkboxes.
if (Services.prefs.getBoolPref(property, false)) { if (Services.prefs.getBoolPref(property, defaultValue ?? false)) {
checkboxElement.setAttribute('checked', 'true'); checkboxElement.setAttribute('checked', 'true');
} }
@ -423,7 +423,7 @@ var gZenMarketplaceManager = {
container.setAttribute('align', 'center'); container.setAttribute('align', 'center');
container.setAttribute('role', 'group'); container.setAttribute('role', 'group');
const savedValue = Services.prefs.getStringPref(property, ''); const savedValue = Services.prefs.getStringPref(property, defaultValue ?? '');
const sanitizedProperty = property?.replaceAll(/\./g, '-'); const sanitizedProperty = property?.replaceAll(/\./g, '-');
const input = document.createElement('input'); const input = document.createElement('input');
@ -439,8 +439,8 @@ var gZenMarketplaceManager = {
} }
input.addEventListener( input.addEventListener(
'change', 'keydown',
ZenThemesCommon.throttle((event) => { ZenThemesCommon.debounce((event) => {
const value = event.target.value; const value = event.target.value;
Services.prefs.setStringPref(property, value); Services.prefs.setStringPref(property, value);
@ -1083,38 +1083,38 @@ Preferences.addAll([
default: false, default: false,
}, },
{ {
id: "zen.glance.activation-method", id: 'zen.glance.activation-method',
type: "string", type: 'string',
default: "ctrl", default: 'ctrl',
}, },
{ {
id: "zen.glance.enabled", id: 'zen.glance.enabled',
type: "bool", type: 'bool',
default: true, default: true,
}, },
{ {
id: "zen.theme.color-prefs.use-workspace-colors", id: 'zen.theme.color-prefs.use-workspace-colors',
type: "bool", type: 'bool',
default: false, default: false,
}, },
{ {
id: "zen.view.compact.color-toolbar", id: 'zen.view.compact.color-toolbar',
type: "bool", type: 'bool',
default: true, default: true,
}, },
{ {
id: "zen.urlbar.behavior", id: 'zen.urlbar.behavior',
type: "string", type: 'string',
default: "float", default: 'float',
}, },
{ {
id: "zen.view.compact.color-sidebar", id: 'zen.view.compact.color-sidebar',
type: "bool", type: 'bool',
default: true, default: true,
}, },
{ {
id: "zen.essentials.enabled", id: 'zen.essentials.enabled',
type: "bool", type: 'bool',
default: true, default: true,
}, },
{ {
@ -1123,18 +1123,18 @@ Preferences.addAll([
default: false, default: false,
}, },
{ {
id: "zen.tabs.show-newtab-vertical", id: 'zen.tabs.show-newtab-vertical',
type: "bool", type: 'bool',
default: true, default: true,
}, },
{ {
id: "zen.view.show-newtab-button-border-top", id: 'zen.view.show-newtab-button-border-top',
type: "bool", type: 'bool',
default: false, default: false,
}, },
{ {
id: "zen.view.show-newtab-button-top", id: 'zen.view.show-newtab-button-top',
type: "bool", type: 'bool',
default: true, default: true,
}, },
]); ]);