fix: emit updated on NativeTheme on the UI thread to avoid DCHECK (#20137)
* fix: emit updated on NativeTheme on the UI thread to avoid DCHECK * Update atom_api_native_theme.cc * spec: wait a few ticks for async events to emit so that test events do not leak into each other
This commit is contained in:
parent
2b316f3843
commit
0e61709fa7
4 changed files with 31 additions and 12 deletions
|
@ -6,6 +6,9 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "base/task/post_task.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "native_mate/object_template_builder.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
|
@ -26,10 +29,17 @@ NativeTheme::~NativeTheme() {
|
|||
theme_->RemoveObserver(this);
|
||||
}
|
||||
|
||||
void NativeTheme::OnNativeThemeUpdated(ui::NativeTheme* theme) {
|
||||
void NativeTheme::OnNativeThemeUpdatedOnUI() {
|
||||
Emit("updated");
|
||||
}
|
||||
|
||||
void NativeTheme::OnNativeThemeUpdated(ui::NativeTheme* theme) {
|
||||
base::PostTaskWithTraits(
|
||||
FROM_HERE, {content::BrowserThread::UI},
|
||||
base::BindOnce(&NativeTheme::OnNativeThemeUpdatedOnUI,
|
||||
base::Unretained(this)));
|
||||
}
|
||||
|
||||
void NativeTheme::SetThemeSource(ui::NativeTheme::ThemeSource override) {
|
||||
theme_->set_theme_source(override);
|
||||
#if defined(OS_MACOSX)
|
||||
|
|
|
@ -38,6 +38,7 @@ class NativeTheme : public mate::EventEmitter<NativeTheme>,
|
|||
|
||||
// ui::NativeThemeObserver:
|
||||
void OnNativeThemeUpdated(ui::NativeTheme* theme) override;
|
||||
void OnNativeThemeUpdatedOnUI();
|
||||
|
||||
private:
|
||||
ui::NativeTheme* theme_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue