1
0
Fork 1
mirror of https://github.com/zen-browser/desktop.git synced 2025-07-07 20:39:59 +02:00

fix: Fixed crashes with mods and default lightness will be 50%, b=no-bug, c=mods, workspaces

This commit is contained in:
mr. m 2025-06-30 08:31:25 +02:00
parent c84d500bd5
commit a06b7b6b38
No known key found for this signature in database
GPG key ID: 928E01ED4C97749F
15 changed files with 133 additions and 139 deletions

View file

@ -8,11 +8,9 @@ pref('zen.mods.auto-update-days', 20); // In days
#ifdef MOZILLA_OFFICIAL #ifdef MOZILLA_OFFICIAL
pref('zen.mods.auto-update', true); pref('zen.mods.auto-update', true);
pref('zen.rice.api.url', 'https://share.zen-browser.app', locked); pref('zen.injections.match-urls', 'https://zen-browser.app/*', locked);
pref('zen.injections.match-urls', 'https://zen-browser.app/*,https://share.zen-browser.app/*', locked);
#else #else
pref('zen.mods.auto-update', false); pref('zen.mods.auto-update', false);
pref('zen.rice.api.url', "http://localhost", locked);
pref('zen.injections.match-urls', 'http://localhost/*', locked); pref('zen.injections.match-urls', 'http://localhost/*', locked);
#endif #endif

View file

@ -1,20 +1,24 @@
diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp
index a16bef739fcde0f14ba7e53e0acfa3aa2ee1dd3a..f928c0f1df4e86bd344ab7e57dab112234fb92e8 100644 index a16bef739fcde0f14ba7e53e0acfa3aa2ee1dd3a..7c4bee2422f76272022f0c793aa52ea02e292bde 100644
--- a/dom/base/Document.cpp --- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp +++ b/dom/base/Document.cpp
@@ -3332,6 +3332,15 @@ void Document::FillStyleSetUserAndUASheets() { @@ -10,6 +10,7 @@
ServoStyleSet& styleSet = EnsureStyleSet(); #include "mozilla/dom/Document.h"
for (StyleSheet* sheet : *sheetService->UserStyleSheets()) { #include "mozilla/dom/DocumentInlines.h"
+ // If the url starts with "file://" and ends with 'zen-themes.css', then +#include "mozilla/ZenStyleSheetCache.h"
+ // skip it if the document is not in a chrome docshell.
+ // This is to avoid loading the user chrome stylesheet in the content #include <inttypes.h>
+ // process, which is not allowed. #include <stdlib.h>
+ auto spec = sheet->GetSheetURI()->GetSpecOrDefault(); @@ -3335,6 +3336,11 @@ void Document::FillStyleSetUserAndUASheets() {
+ if (!IsInChromeDocShell() && StringBeginsWith(spec, "file://"_ns) &&
+ StringEndsWith(spec, "zen-themes.css"_ns)) {
+ continue;
+ }
styleSet.AppendStyleSheet(*sheet); styleSet.AppendStyleSheet(*sheet);
} }
+ if (auto sheet = zen::ZenStyleSheetCache::Singleton()->GetModsSheet(); sheet && IsInChromeDocShell()) {
+ // The mods sheet is only used in the chrome docshell.
+ styleSet.AppendStyleSheet(*sheet);
+ }
+
StyleSheet* sheet = IsInChromeDocShell() ? cache->GetUserChromeSheet()
: cache->GetUserContentSheet();
if (sheet) {

View file

@ -1,13 +0,0 @@
diff --git a/layout/base/nsStyleSheetService.h b/layout/base/nsStyleSheetService.h
index 8c49b338bf8e6830874ace9a08e8c0713167ee58..53a48129b2b6b2adf15e0fe17da14c3b16577966 100644
--- a/layout/base/nsStyleSheetService.h
+++ b/layout/base/nsStyleSheetService.h
@@ -50,6 +50,8 @@ class nsStyleSheetService final : public nsIStyleSheetService,
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+ void UpdateZenModStyles(mozilla::StyleSheet* aSheet, nsIURI* aURI, bool aInsert);
+
static nsStyleSheetService* GetInstance();
static nsStyleSheetService* gInstance;

View file

@ -48,9 +48,18 @@
); );
} }
async #readStylesheet() {
const path = this.modsRootPath;
if (!(await IOUtils.exists(path))) {
return '';
}
return await IOUtils.readUTF8(this.#styleSheetPath);
}
async #insertStylesheet() { async #insertStylesheet() {
try { try {
this.#modsBackend.rebuildModsStyles(); const content = await this.#readStylesheet();
this.#modsBackend.rebuildModsStyles(content);
} catch (e) { } catch (e) {
console.warn('[ZenMods]: Error rebuilding mods styles:', e); console.warn('[ZenMods]: Error rebuilding mods styles:', e);
} }

View file

@ -11,29 +11,36 @@
#include "mozilla/css/SheetParsingMode.h" #include "mozilla/css/SheetParsingMode.h"
#include "mozilla/GlobalStyleSheetCache.h" #include "mozilla/GlobalStyleSheetCache.h"
#define GET_MODS_FILE(chromeFile, err) \
NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(chromeFile)); \
if (!chromeFile) { \
return err; \
} \
chromeFile->Append(ZEN_MODS_FILENAME);
namespace zen { namespace zen {
using namespace mozilla; using namespace mozilla;
NS_IMPL_ISUPPORTS(ZenStyleSheetCache, nsISupports) NS_IMPL_ISUPPORTS(ZenStyleSheetCache, nsISupports)
auto ZenStyleSheetCache::InvalidateModsSheet() -> void {
mModsSheet = nullptr;
}
auto ZenStyleSheetCache::GetModsSheet() -> StyleSheet* { auto ZenStyleSheetCache::GetModsSheet() -> StyleSheet* {
if (mModsSheet) { if (mModsSheet) {
// If the mods stylesheet is already loaded, return it. // If the mods stylesheet is already loaded, return it.
return mModsSheet; return mModsSheet;
} }
nsCOMPtr<nsIFile> chromeFile; nsCOMPtr<nsIFile> chromeFile;
GET_MODS_FILE(chromeFile, nullptr);
NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(chromeFile)); // Create the mods stylesheet if it doesn't exist.
if (!chromeFile) { bool exists;
// if we don't have a profile yet, that's OK! chromeFile->Exists(&exists);
return nullptr; if (!exists) {
nsresult rv = chromeFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
if (NS_FAILED(rv)) {
return nullptr;
}
} }
chromeFile->Append(ZEN_MODS_FILENAME);
LoadSheetFile(chromeFile, css::eUserSheetFeatures); LoadSheetFile(chromeFile, css::eUserSheetFeatures);
return mModsSheet; return mModsSheet;
} }
@ -49,7 +56,7 @@ auto ZenStyleSheetCache::LoadSheetFile(nsIFile* aFile,
auto loader = new mozilla::css::Loader; auto loader = new mozilla::css::Loader;
auto result = loader->LoadSheetSync(uri, aParsingMode, auto result = loader->LoadSheetSync(uri, aParsingMode,
css::Loader::UseSystemPrincipal::Yes); css::Loader::UseSystemPrincipal::Yes);
if (MOZ_UNLIKELY(result.isErr())) { if (MOZ_UNLIKELY(result.isErr())) {
return; return;
} }
@ -65,6 +72,20 @@ auto ZenStyleSheetCache::Singleton() -> ZenStyleSheetCache* {
return gZenModsCache; return gZenModsCache;
} }
nsresult ZenStyleSheetCache::RebuildModsStylesheets(const nsACString& aContents) {
// Re-parse the mods stylesheet. By doing so, we read
// Once we have the data as a nsACString, we call ReparseSheet from the
// StyleSheet class to re-parse the stylesheet.
auto sheet = GetModsSheet();
if (!sheet) {
return NS_ERROR_FAILURE;
}
ErrorResult aRv;
sheet->ReparseSheet(aContents, aRv);
return aRv.StealNSResult();
}
mozilla::StaticRefPtr<ZenStyleSheetCache> ZenStyleSheetCache::gZenModsCache; mozilla::StaticRefPtr<ZenStyleSheetCache> ZenStyleSheetCache::gZenModsCache;
} // namespace: zen } // namespace: zen

View file

@ -21,13 +21,6 @@ class ZenStyleSheetCache final : public nsISupports {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
/**
* @brief Clear up the cache and create a new mods stylesheet.
* This is called when we need to recalculate the mods stylesheets.
* @returns The mods stylesheet.
*/
auto InvalidateModsSheet() -> void;
/** /**
* @brief Get the mods stylesheet. * @brief Get the mods stylesheet.
* This is called when we need to get the mods stylesheets. * This is called when we need to get the mods stylesheets.
@ -35,6 +28,15 @@ class ZenStyleSheetCache final : public nsISupports {
*/ */
auto GetModsSheet() -> StyleSheet*; auto GetModsSheet() -> StyleSheet*;
/**
* @brief Rebuild the mods stylesheets.
* This is re-parses the mods stylesheet and applies it to all
* the connected documents.
* @param aContents The contents of the mods stylesheet.
* @returns NS_OK on success, or an error code on failure.
*/
nsresult RebuildModsStylesheets(const nsACString& aContents);
static auto Singleton() -> ZenStyleSheetCache*; static auto Singleton() -> ZenStyleSheetCache*;
private: private:
ZenStyleSheetCache() = default; ZenStyleSheetCache() = default;

View file

@ -15,17 +15,11 @@
*/ */
[scriptable, uuid(a0ee4792-b186-4497-936d-53a8989fe836)] [scriptable, uuid(a0ee4792-b186-4497-936d-53a8989fe836)]
interface nsIZenModsBackend : nsISupports { interface nsIZenModsBackend : nsISupports {
/*
* @brief Remove, clear cache and create a new mods stylesheet.
* This is called when we need to recalculate the mods stylesheets.
* @returns The mods stylesheet.
*/
void invalidateModsSheet();
/** /**
* @brief Unregister and register the mods stylesheet. * @brief Unregister and register the mods stylesheet.
* This is called when we need to recalculate the mods stylesheets. * This is called when we need to recalculate the mods stylesheets.
* @returns void * @returns void
*/ */
void rebuildModsStyles(); void rebuildModsStyles(in ACString aContents);
}; };

View file

@ -45,61 +45,9 @@ auto nsZenModsBackend::CheckEnabled() -> bool {
return mEnabled; return mEnabled;
} }
auto nsZenModsBackend::RebuildModsStyles() -> nsresult { auto nsZenModsBackend::RebuildModsStyles(const nsACString& aContents) -> nsresult {
// Invalidate the mods stylesheet cache.
GetZenStyleSheetCache()->InvalidateModsSheet();
// Rebuild the mods stylesheets.
auto modsSheet = GetZenStyleSheetCache()->GetModsSheet();
if (!modsSheet) {
return NS_ERROR_FAILURE;
}
// Get the service from @mozilla.org/content/style-sheet-service;1
if (auto* sss = nsStyleSheetService::GetInstance()) {
// Register the mods stylesheet.
sss->UpdateZenModStyles(modsSheet, modsSheet->GetSheetURI(), CheckEnabled());
}
// Notify that the mods stylesheets have been rebuilt. // Notify that the mods stylesheets have been rebuilt.
return NS_OK; return GetZenStyleSheetCache()->RebuildModsStylesheets(aContents);
}
NS_IMETHODIMP
nsZenModsBackend::InvalidateModsSheet() {
if (!mEnabled) {
return NS_ERROR_NOT_AVAILABLE;
}
GetZenStyleSheetCache()->InvalidateModsSheet();
return NS_OK;
} }
} // namespace: zen } // namespace: zen
void nsStyleSheetService::UpdateZenModStyles(mozilla::StyleSheet* aSheet, nsIURI* aURI, bool aInsert) {
auto sheetType = nsStyleSheetService::USER_SHEET;
this->UnregisterSheet(aURI, sheetType);
if (!aSheet || !aInsert) {
return; // Nothing to update.
}
mSheets[sheetType].AppendElement(aSheet);
// Hold on to a copy of the registered PresShells.
for (mozilla::PresShell* presShell : mPresShells.Clone()) {
// Only allow on chrome documents.
auto doc = presShell->GetDocument();
if (doc && !doc->IsInChromeDocShell()) {
continue;
}
presShell->NotifyStyleSheetServiceSheetAdded(aSheet, sheetType);
}
if (XRE_IsParentProcess()) {
nsTArray<mozilla::dom::ContentParent*> children;
mozilla::dom::ContentParent::GetAll(children);
if (children.IsEmpty()) {
return;
}
for (uint32_t i = 0; i < children.Length(); i++) {
mozilla::Unused << children[i]->SendLoadAndRegisterSheet(aURI, sheetType);
}
}
}

View file

@ -840,11 +840,9 @@
const relativeY = pixelY - rect.top; const relativeY = pixelY - rect.top;
if (!clickedDot && this.dots.length < 1) { if (!clickedDot && this.dots.length < 1) {
if (this.dots.length === 0) { this.spawnDot({ x: relativeX, y: relativeY }, this.dots.length === 0);
this.spawnDot({ x: relativeX, y: relativeY }, true); // Set brightness to 50%
} else { this.#currentLightness = 50;
this.spawnDot({ x: relativeX, y: relativeY });
}
this.updateCurrentWorkspace(true); this.updateCurrentWorkspace(true);
} else if (!clickedDot && existingPrimaryDot) { } else if (!clickedDot && existingPrimaryDot) {

View file

@ -16,6 +16,15 @@
window.addEventListener('ZenWorkspacesUIUpdate', this, true); window.addEventListener('ZenWorkspacesUIUpdate', this, true);
this.initDragAndDrop(); this.initDragAndDrop();
this.addEventListener('mouseover', (e) => {
if (this.isReorderMode) {
return;
}
const target = e.target.closest('toolbarbutton[zen-workspace-id]');
if (target) {
this.scrollLeft = target.offsetLeft - 10;
}
});
} }
initDragAndDrop() { initDragAndDrop() {
@ -118,6 +127,7 @@
} else { } else {
this.removeAttribute('dont-show'); this.removeAttribute('dont-show');
} }
gZenWorkspaces.onWindowResize();
} }
on_command(event) { on_command(event) {

View file

@ -2872,30 +2872,46 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
if (!parent || this._processingResize) { if (!parent || this._processingResize) {
return; return;
} }
this._processingResize = true; if (!gZenPinnedTabManager.expandedSidebarMode) {
// Once we are overflowing, we align the buttons to always stay inside the container, for (const icon of parent.children) {
// meaning we need to remove the overflow attribute to reset the width if (icon.tagName === 'toolbarbutton') {
parent.removeAttribute('icons-overflow'); icon.style.width = ''; // Reset to default size when in expanded mode
requestAnimationFrame(() => { }
const overflow = parent.scrollWidth > parent.clientWidth; }
parent.toggleAttribute('icons-overflow', overflow); parent.removeAttribute('icons-overflow');
// The maximum width a button has when it overflows based on the number of buttons return;
const numButtons = parent.children.length + 1; // +1 to exclude the active button }
const maxWidth = 100 / numButtons; const maxButtonSize = 30; // IMPORTANT: This should match the CSS size of the icons
parent.style.setProperty('--zen-overflowed-workspace-button-width', `${maxWidth}%`); const minButtonSize = 15;
this._processingResize = false; const separation = 3; // Space between icons
// Scroll to the active workspace button if it's not visible // Calculate the total width needed for all icons
const activeButton = parent.querySelector('.zen-workspace-button.active'); const totalWidth = Array.from(parent.children).reduce((width, icon) => {
if (!activeButton) { if (icon.tagName === 'toolbarbutton') {
return; return width + minButtonSize + separation;
} }
const parentRect = parent.getBoundingClientRect(); return width;
const activeRect = activeButton.getBoundingClientRect(); }, 0);
if (activeRect.left < parentRect.left || activeRect.right > parentRect.right) {
parent.scrollLeft = activeButton.offsetLeft; // Check if the total width exceeds the parent's width
if (totalWidth > parent.clientWidth) {
parent.setAttribute('icons-overflow', 'true');
} else {
parent.removeAttribute('icons-overflow');
}
// Set the width of each icon to the maximum size they can fit on
const widthPerButton = Math.max(
Math.floor(
(parent.clientWidth - separation * (parent.children.length - 1)) / parent.children.length
),
minButtonSize
);
for (const icon of parent.children) {
if (icon.tagName === 'toolbarbutton') {
icon.style.width = `${Math.min(widthPerButton, maxButtonSize)}px`;
} }
}); }
} }
fixTabInsertLocation(tab) { fixTabInsertLocation(tab) {

View file

@ -95,6 +95,7 @@ zen-workspace-creation {
--input-bgcolor: transparent; --input-bgcolor: transparent;
padding: 0 !important; padding: 0 !important;
width: 100%; width: 100%;
outline: none;
} }
} }

View file

@ -5,7 +5,7 @@
*/ */
&:not(:hover) { &:not(:hover) {
width: min(var(--zen-overflowed-workspace-button-width), 25px); width: min(var(--zen-overflowed-workspace-button-width,10px), 25px) !important;
min-width: 10px; min-width: 10px;
&::after { &::after {
@ -29,3 +29,7 @@
display: none; display: none;
} }
} }
&:hover {
width: 20px !important;
}

View file

@ -11,8 +11,8 @@
align-items: center; align-items: center;
display: flex; display: flex;
font-size: x-small; font-size: x-small;
padding: 0 3px; margin: 0 3px;
margin: 0; padding: 0;
appearance: auto; appearance: auto;
position: relative; position: relative;
@ -34,7 +34,7 @@
& toolbarbutton { & toolbarbutton {
margin: 0; margin: 0;
width: 30px; max-width: 30px;
height: 30px; height: 30px;
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -84,9 +84,11 @@
&[icons-overflow] { &[icons-overflow] {
gap: 0 !important; gap: 0 !important;
justify-content: space-between;
& toolbarbutton { & toolbarbutton {
margin: 0; margin: 0;
background: transparent;
} }
/* Inlcude separately since ther'es a bug in the /* Inlcude separately since ther'es a bug in the

View file

@ -19,7 +19,7 @@
"brandShortName": "Zen", "brandShortName": "Zen",
"brandFullName": "Zen Browser", "brandFullName": "Zen Browser",
"release": { "release": {
"displayVersion": "1.14b", "displayVersion": "1.14.1b",
"github": { "github": {
"repo": "zen-browser/desktop" "repo": "zen-browser/desktop"
}, },