Compare commits

...

8 Commits

Author SHA1 Message Date
David Sanders
74d641c7b3 build: ignore files in .git when running markdownlint-cli2 (#46608) 2025-04-10 18:37:07 -05:00
Shelley Vohr
446d0769ed feat: expose nativeTheme.shouldUseDarkColorsForSystemIntegratedUI (#46438)
feat: expose shouldUseDarkColorsForSystemIntegratedUI

Closes https://github.com/electron/electron/issues/46429.
Refs https://github.com/electron/electron/pull/19735.

This PR adds a new API `shouldUseDarkColorsForSystemIntegratedUI` to the
`nativeTheme` module. This API returns a boolean indicating whether the
system is using dark colors for system integrated UI elements. This is
useful for applications that want to adapt their UI to match the system
theme, especially for those that use system integrated UI elements like
the shell theme or taskbar appearance.
2025-04-10 12:08:29 +02:00
Jemil Suleimanov
013133867b docs: unify documentation example and fiddle for IPC pattern-1 (#46517)
* docs: unify documentation examples and fiddle

* docs: remove changes in ipc documentation
2025-04-10 12:08:10 +02:00
Yuri
de407e82b7 docs: updated tray doc with tooltip removing (#46515)
added tooltip removing doc
2025-04-09 11:50:08 -04:00
Charles Kerr
c6e6a03a24 fix: NativeWindow.window_id() returns same value for all windows (#46562)
fix: NativeWindow.window_id() returns same value for all windows
2025-04-09 10:45:06 -05:00
Shelley Vohr
c1c74b0a6c fix: re-enable OOP printing on Linux (#46529) 2025-04-09 15:42:16 +02:00
Shelley Vohr
45a0494287 fix: remove obsoleted --inspect-brk logic (#46560)
fix: remove obsoleted --inspect-brk logic
2025-04-09 15:35:40 +02:00
Shelley Vohr
521108e2a5 fix: crash on parent window close and focur/blur (#46559) 2025-04-09 15:35:30 +02:00
16 changed files with 63 additions and 45 deletions

View File

@@ -63,6 +63,14 @@ Your application should then always use `shouldUseDarkColors` to determine what
A `boolean` for if the OS / Chromium currently has high-contrast mode enabled
or is being instructed to show a high-contrast UI.
### `nativeTheme.shouldUseDarkColorsForSystemIntegratedUI` _macOS_ _Windows_ _Readonly_
A `boolean` property indicating whether or not the system theme has been set to dark or light.
On Windows this property distinguishes between system and app light/dark theme, returning
`true` if the system theme is set to dark theme and `false` otherwise. On macOS the return
value will be the same as `nativeTheme.shouldUseDarkColors`.
### `nativeTheme.shouldUseInvertedColorScheme` _macOS_ _Windows_ _Readonly_
A `boolean` for if the OS / Chromium currently has an inverted color scheme

View File

@@ -238,7 +238,7 @@ Sets the `image` associated with this tray icon when pressed on macOS.
* `toolTip` string
Sets the hover text for this tray icon.
Sets the hover text for this tray icon. Setting the text to an empty string will remove the tooltip.
#### `tray.setTitle(title[, options])` _macOS_

View File

@@ -1,6 +1,12 @@
const { app, BrowserWindow, ipcMain } = require('electron/main')
const path = require('node:path')
function handleSetTitle (event, title) {
const webContents = event.sender
const win = BrowserWindow.fromWebContents(webContents)
win.setTitle(title)
}
function createWindow () {
const mainWindow = new BrowserWindow({
webPreferences: {
@@ -8,16 +14,11 @@ function createWindow () {
}
})
ipcMain.on('set-title', (event, title) => {
const webContents = event.sender
const win = BrowserWindow.fromWebContents(webContents)
win.setTitle(title)
})
mainWindow.loadFile('index.html')
}
app.whenReady().then(() => {
ipcMain.on('set-title', handleSetTitle)
createWindow()
app.on('activate', function () {

View File

@@ -218,7 +218,6 @@ if (packagePath) {
} else {
// Call appCodeLoaded before just for safety, it doesn't matter here as _load is synchronous
appCodeLoaded!();
process._firstFileName = Module._resolveFilename(path.join(packagePath, mainStartupScript), null, false);
Module._load(path.join(packagePath, mainStartupScript), Module, true);
}
} else {

View File

@@ -932,3 +932,19 @@ index 63f170c95050416c595e62f4c460c4cd6b7dbd1c..157e3d046889f9c63fdf0fd5d503890f
// Does bookkeeping when an error occurs.
virtual mojom::ResultCode OnError();
diff --git a/printing/printing_context_linux.cc b/printing/printing_context_linux.cc
index fa55d2a1c5f4207cb8eda9305e8bf2af29352c91..13ca65c2c7c3c24882061d8e224bf93899d9a7ab 100644
--- a/printing/printing_context_linux.cc
+++ b/printing/printing_context_linux.cc
@@ -52,9 +52,8 @@ void PrintingContextLinux::AskUserForSettings(int max_pages,
bool is_scripted,
PrintSettingsCallback callback) {
if (!print_dialog_) {
- // Can only get here if the renderer is sending bad messages.
- // http://crbug.com/341777
- NOTREACHED();
+ print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this);
+ print_dialog_->UseDefaultSettings();
}
print_dialog_->ShowDialog(delegate_->GetParentView(), has_selection,

View File

@@ -7,24 +7,6 @@ This allows embedders to tell Node.js what the first "real" file is when
they use themselves as the entry point. We should try to upstream some form
of this.
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 9b5772fe9b8babbb892c7a5ec79258472da55a76..3568fd6ea0816f62d97d46f5d497bb1b23bf4e25 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -1555,6 +1555,13 @@ Module.prototype._compile = function(content, filename, format) {
this[kIsExecuting] = true;
if (this[kIsMainSymbol] && getOptionValue('--inspect-brk')) {
const { callAndPauseOnStart } = internalBinding('inspector');
+ // process._firstFileName is used by Embedders to tell node what
+ // the first "real" file is when they use themselves as the entry
+ // point
+ if (process._firstFileName) {
+ resolvedArgv = process._firstFileName;
+ delete process._firstFileName;
+ }
result = callAndPauseOnStart(compiledWrapper, thisValue, exports,
require, module, filename, dirname,
process, localGlobal, localBuffer);
diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js
index d1c05d1717cdc825c4e48885c963c9ed65bcf51c..278665921c5160ff10b3178db27d4df319fab6b3 100644
--- a/lib/internal/process/pre_execution.js

View File

@@ -278,7 +278,7 @@ const LINTERS = [{
}, {
key: 'md',
roots: ['.'],
ignoreRoots: ['node_modules', 'spec/node_modules'],
ignoreRoots: ['.git', 'node_modules', 'spec/node_modules'],
test: filename => filename.endsWith('.md'),
run: async (opts, filenames) => {
let errors = false;

View File

@@ -219,14 +219,14 @@ void BrowserWindow::CloseImmediately() {
}
void BrowserWindow::Focus() {
if (api_web_contents_->IsOffScreen())
if (api_web_contents_ && api_web_contents_->IsOffScreen())
FocusOnWebView();
else
BaseWindow::Focus();
}
void BrowserWindow::Blur() {
if (api_web_contents_->IsOffScreen())
if (api_web_contents_ && api_web_contents_->IsOffScreen())
BlurWebView();
else
BaseWindow::Blur();

View File

@@ -63,6 +63,10 @@ bool NativeTheme::ShouldUseHighContrastColors() {
return ui_theme_->UserHasContrastPreference();
}
bool NativeTheme::ShouldUseDarkColorsForSystemIntegratedUI() {
return ui_theme_->ShouldUseDarkColorsForSystemIntegratedUI();
}
bool NativeTheme::InForcedColorsMode() {
return ui_theme_->InForcedColorsMode();
}
@@ -109,6 +113,8 @@ gin::ObjectTemplateBuilder NativeTheme::GetObjectTemplateBuilder(
&NativeTheme::SetThemeSource)
.SetProperty("shouldUseHighContrastColors",
&NativeTheme::ShouldUseHighContrastColors)
.SetProperty("shouldUseDarkColorsForSystemIntegratedUI",
&NativeTheme::ShouldUseDarkColorsForSystemIntegratedUI)
.SetProperty("shouldUseInvertedColorScheme",
&NativeTheme::ShouldUseInvertedColorScheme)
.SetProperty("inForcedColorsMode", &NativeTheme::InForcedColorsMode)

View File

@@ -48,6 +48,7 @@ class NativeTheme final : public gin::Wrappable<NativeTheme>,
ui::NativeTheme::ThemeSource GetThemeSource() const;
bool ShouldUseDarkColors();
bool ShouldUseHighContrastColors();
bool ShouldUseDarkColorsForSystemIntegratedUI();
bool ShouldUseInvertedColorScheme();
bool InForcedColorsMode();
bool GetPrefersReducedTransparency();

View File

@@ -61,14 +61,6 @@ void InitializeFeatureList() {
std::string(",") + features::kMacWebContentsOcclusion.name;
#endif
#if BUILDFLAG(IS_LINUX) && BUILDFLAG(ENABLE_PRINTING)
disable_features +=
// EnableOopPrintDrivers is still a bit half-baked on Linux and
// causes crashes when trying to show dialogs.
// TODO(codebytere): figure out how to re-enable this with our patches.
std::string(",") + printing::features::kEnableOopPrintDrivers.name;
#endif
#if BUILDFLAG(ENABLE_PDF_VIEWER)
// Enable window.showSaveFilePicker api for saving pdf files.
// Refs https://issues.chromium.org/issues/373852607

View File

@@ -94,8 +94,6 @@ gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) {
NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
NativeWindow* parent)
: widget_(std::make_unique<views::Widget>()), parent_(parent) {
++next_id_;
options.Get(options::kFrame, &has_frame_);
options.Get(options::kTransparent, &transparent_);
options.Get(options::kEnableLargerThanScreen, &enable_larger_than_screen_);
@@ -820,9 +818,6 @@ void NativeWindow::HandlePendingFullscreenTransitions() {
SetFullScreen(next_transition);
}
// static
int32_t NativeWindow::next_id_ = 0;
bool NativeWindow::IsTranslucent() const {
// Transparent windows are translucent
if (transparent()) {

View File

@@ -409,7 +409,7 @@ class NativeWindow : public base::SupportsUserData,
NativeWindow* parent() const { return parent_; }
bool is_modal() const { return is_modal_; }
int32_t window_id() const { return next_id_; }
int32_t window_id() const { return window_id_; }
void add_child_window(NativeWindow* child) {
child_windows_.push_back(child);
@@ -472,7 +472,8 @@ class NativeWindow : public base::SupportsUserData,
private:
std::unique_ptr<views::Widget> widget_;
static int32_t next_id_;
static inline int32_t next_id_ = 0;
const int32_t window_id_ = ++next_id_;
// The content view, weak ref.
raw_ptr<views::View> content_view_ = nullptr;

View File

@@ -4930,6 +4930,18 @@ describe('BrowserWindow module', () => {
expect(w.getChildWindows().length).to.equal(0);
});
it('can handle parent window close with focus or blur events', (done) => {
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w });
c.on('closed', () => {
w.focus();
done();
});
w.close();
});
ifit(process.platform === 'darwin')('only shows the intended window when a child with siblings is shown', async () => {
const w = new BrowserWindow({ show: false });
const childOne = new BrowserWindow({ show: false, parent: w });

View File

@@ -102,6 +102,12 @@ describe('nativeTheme module', () => {
});
});
describe('nativeTheme.shouldUseDarkColorsForSystemIntegratedUI', () => {
it('returns a boolean', () => {
expect(nativeTheme.shouldUseDarkColorsForSystemIntegratedUI).to.be.a('boolean');
});
});
describe('nativeTheme.inForcedColorsMode', () => {
it('returns a boolean', () => {
expect(nativeTheme.inForcedColorsMode).to.be.a('boolean');

View File

@@ -255,7 +255,6 @@ declare namespace NodeJS {
once(event: 'document-end', listener: () => any): this;
// Additional properties
_firstFileName?: string;
_serviceStartupScript: string;
_getOrCreateArchive?: (path: string) => NodeJS.AsarArchive | null;