feat: add tabbingIdentifier
property to BrowserWindow
(#39980)
feat: add tabbingIdentifier property to BrowserWindow
This commit is contained in:
parent
04b2ba84cd
commit
713d8c4167
8 changed files with 40 additions and 6 deletions
|
@ -475,6 +475,10 @@ events.
|
||||||
|
|
||||||
A `Integer` property representing the unique ID of the window. Each ID is unique among all `BrowserWindow` instances of the entire Electron application.
|
A `Integer` property representing the unique ID of the window. Each ID is unique among all `BrowserWindow` instances of the entire Electron application.
|
||||||
|
|
||||||
|
#### `win.tabbingIdentifier` _macOS_ _Readonly_
|
||||||
|
|
||||||
|
A `string` (optional) property that is equal to the `tabbingIdentifier` passed to the `BrowserWindow` constructor or `undefined` if none was set.
|
||||||
|
|
||||||
#### `win.autoHideMenuBar`
|
#### `win.autoHideMenuBar`
|
||||||
|
|
||||||
A `boolean` property that determines whether the window menu bar should hide itself automatically. Once set, the menu bar will only show when users press the single `Alt` key.
|
A `boolean` property that determines whether the window menu bar should hide itself automatically. Once set, the menu bar will only show when users press the single `Alt` key.
|
||||||
|
|
|
@ -953,6 +953,14 @@ void BaseWindow::AddTabbedWindow(NativeWindow* window,
|
||||||
args->ThrowError("AddTabbedWindow cannot be called by a window on itself.");
|
args->ThrowError("AddTabbedWindow cannot be called by a window on itself.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Value> BaseWindow::GetTabbingIdentifier() {
|
||||||
|
auto tabbing_id = window_->GetTabbingIdentifier();
|
||||||
|
if (!tabbing_id.has_value())
|
||||||
|
return v8::Undefined(isolate());
|
||||||
|
|
||||||
|
return gin::ConvertToV8(isolate(), tabbing_id.value());
|
||||||
|
}
|
||||||
|
|
||||||
void BaseWindow::SetAutoHideMenuBar(bool auto_hide) {
|
void BaseWindow::SetAutoHideMenuBar(bool auto_hide) {
|
||||||
window_->SetAutoHideMenuBar(auto_hide);
|
window_->SetAutoHideMenuBar(auto_hide);
|
||||||
}
|
}
|
||||||
|
@ -1305,6 +1313,7 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("moveTabToNewWindow", &BaseWindow::MoveTabToNewWindow)
|
.SetMethod("moveTabToNewWindow", &BaseWindow::MoveTabToNewWindow)
|
||||||
.SetMethod("toggleTabBar", &BaseWindow::ToggleTabBar)
|
.SetMethod("toggleTabBar", &BaseWindow::ToggleTabBar)
|
||||||
.SetMethod("addTabbedWindow", &BaseWindow::AddTabbedWindow)
|
.SetMethod("addTabbedWindow", &BaseWindow::AddTabbedWindow)
|
||||||
|
.SetProperty("tabbingIdentifier", &BaseWindow::GetTabbingIdentifier)
|
||||||
.SetMethod("setWindowButtonVisibility",
|
.SetMethod("setWindowButtonVisibility",
|
||||||
&BaseWindow::SetWindowButtonVisibility)
|
&BaseWindow::SetWindowButtonVisibility)
|
||||||
.SetMethod("_getWindowButtonVisibility",
|
.SetMethod("_getWindowButtonVisibility",
|
||||||
|
|
|
@ -198,9 +198,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
|
||||||
bool GetWindowButtonVisibility() const;
|
bool GetWindowButtonVisibility() const;
|
||||||
void SetWindowButtonPosition(absl::optional<gfx::Point> position);
|
void SetWindowButtonPosition(absl::optional<gfx::Point> position);
|
||||||
absl::optional<gfx::Point> GetWindowButtonPosition() const;
|
absl::optional<gfx::Point> GetWindowButtonPosition() const;
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BUILDFLAG(IS_MAC)
|
|
||||||
bool IsHiddenInMissionControl();
|
bool IsHiddenInMissionControl();
|
||||||
void SetHiddenInMissionControl(bool hidden);
|
void SetHiddenInMissionControl(bool hidden);
|
||||||
#endif
|
#endif
|
||||||
|
@ -215,6 +213,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
|
||||||
void MoveTabToNewWindow();
|
void MoveTabToNewWindow();
|
||||||
void ToggleTabBar();
|
void ToggleTabBar();
|
||||||
void AddTabbedWindow(NativeWindow* window, gin_helper::Arguments* args);
|
void AddTabbedWindow(NativeWindow* window, gin_helper::Arguments* args);
|
||||||
|
v8::Local<v8::Value> GetTabbingIdentifier();
|
||||||
void SetAutoHideMenuBar(bool auto_hide);
|
void SetAutoHideMenuBar(bool auto_hide);
|
||||||
bool IsMenuBarAutoHide();
|
bool IsMenuBarAutoHide();
|
||||||
void SetMenuBarVisibility(bool visible);
|
void SetMenuBarVisibility(bool visible);
|
||||||
|
|
|
@ -481,6 +481,10 @@ bool NativeWindow::AddTabbedWindow(NativeWindow* window) {
|
||||||
return true; // for non-Mac platforms
|
return true; // for non-Mac platforms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
absl::optional<std::string> NativeWindow::GetTabbingIdentifier() const {
|
||||||
|
return ""; // for non-Mac platforms
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindow::SetVibrancy(const std::string& type) {
|
void NativeWindow::SetVibrancy(const std::string& type) {
|
||||||
vibrancy_ = type;
|
vibrancy_ = type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,6 +256,7 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
virtual void MoveTabToNewWindow();
|
virtual void MoveTabToNewWindow();
|
||||||
virtual void ToggleTabBar();
|
virtual void ToggleTabBar();
|
||||||
virtual bool AddTabbedWindow(NativeWindow* window);
|
virtual bool AddTabbedWindow(NativeWindow* window);
|
||||||
|
virtual absl::optional<std::string> GetTabbingIdentifier() const;
|
||||||
|
|
||||||
// Toggle the menu bar.
|
// Toggle the menu bar.
|
||||||
virtual void SetAutoHideMenuBar(bool auto_hide);
|
virtual void SetAutoHideMenuBar(bool auto_hide);
|
||||||
|
|
|
@ -145,6 +145,7 @@ class NativeWindowMac : public NativeWindow,
|
||||||
void MoveTabToNewWindow() override;
|
void MoveTabToNewWindow() override;
|
||||||
void ToggleTabBar() override;
|
void ToggleTabBar() override;
|
||||||
bool AddTabbedWindow(NativeWindow* window) override;
|
bool AddTabbedWindow(NativeWindow* window) override;
|
||||||
|
absl::optional<std::string> GetTabbingIdentifier() const override;
|
||||||
void SetAspectRatio(double aspect_ratio,
|
void SetAspectRatio(double aspect_ratio,
|
||||||
const gfx::Size& extra_size) override;
|
const gfx::Size& extra_size) override;
|
||||||
void PreviewFile(const std::string& path,
|
void PreviewFile(const std::string& path,
|
||||||
|
|
|
@ -1643,6 +1643,13 @@ bool NativeWindowMac::AddTabbedWindow(NativeWindow* window) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
absl::optional<std::string> NativeWindowMac::GetTabbingIdentifier() const {
|
||||||
|
if ([window_ tabbingMode] == NSWindowTabbingModeDisallowed)
|
||||||
|
return absl::nullopt;
|
||||||
|
|
||||||
|
return base::SysNSStringToUTF8([window_ tabbingIdentifier]);
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetAspectRatio(double aspect_ratio,
|
void NativeWindowMac::SetAspectRatio(double aspect_ratio,
|
||||||
const gfx::Size& extra_size) {
|
const gfx::Size& extra_size) {
|
||||||
NativeWindow::SetAspectRatio(aspect_ratio, extra_size);
|
NativeWindow::SetAspectRatio(aspect_ratio, extra_size);
|
||||||
|
|
|
@ -2060,10 +2060,7 @@ describe('BrowserWindow module', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
w = new BrowserWindow({ show: false });
|
w = new BrowserWindow({ show: false });
|
||||||
});
|
});
|
||||||
afterEach(async () => {
|
afterEach(closeAllWindows);
|
||||||
await closeWindow(w);
|
|
||||||
w = null as unknown as BrowserWindow;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('BrowserWindow.selectPreviousTab()', () => {
|
describe('BrowserWindow.selectPreviousTab()', () => {
|
||||||
it('does not throw', () => {
|
it('does not throw', () => {
|
||||||
|
@ -2132,6 +2129,18 @@ describe('BrowserWindow module', () => {
|
||||||
}).to.throw('AddTabbedWindow cannot be called by a window on itself.');
|
}).to.throw('AddTabbedWindow cannot be called by a window on itself.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('BrowserWindow.tabbingIdentifier', () => {
|
||||||
|
it('is undefined if no tabbingIdentifier was set', () => {
|
||||||
|
const w = new BrowserWindow({ show: false });
|
||||||
|
expect(w.tabbingIdentifier).to.be.undefined('tabbingIdentifier');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the window tabbingIdentifier', () => {
|
||||||
|
const w = new BrowserWindow({ show: false, tabbingIdentifier: 'group1' });
|
||||||
|
expect(w.tabbingIdentifier).to.equal('group1');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('autoHideMenuBar state', () => {
|
describe('autoHideMenuBar state', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue