Initial support for dynamic properties
This commit is contained in:
parent
cbb6f8c33e
commit
98f5858b11
10 changed files with 46 additions and 33 deletions
|
@ -853,8 +853,8 @@ void Window::SetTouchBar(mate::Arguments* args) {
|
||||||
window_->SetTouchBar(args);
|
window_->SetTouchBar(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::RefreshTouchBarItem(mate::Arguments* args) {
|
void Window::RefreshTouchBarItem(const std::string& item_id) {
|
||||||
window_->RefreshTouchBarItem(args);
|
window_->RefreshTouchBarItem(item_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Window::ID() const {
|
int32_t Window::ID() const {
|
||||||
|
|
|
@ -207,7 +207,7 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
void SetVibrancy(mate::Arguments* args);
|
void SetVibrancy(mate::Arguments* args);
|
||||||
void DestroyTouchBar();
|
void DestroyTouchBar();
|
||||||
void SetTouchBar(mate::Arguments* args);
|
void SetTouchBar(mate::Arguments* args);
|
||||||
void RefreshTouchBarItem(mate::Arguments* args);
|
void RefreshTouchBarItem(const std::string& item_id);
|
||||||
|
|
||||||
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
|
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
|
||||||
|
|
||||||
|
|
|
@ -347,7 +347,7 @@ void NativeWindow::DestroyTouchBar() {
|
||||||
void NativeWindow::SetTouchBar(mate::Arguments* args) {
|
void NativeWindow::SetTouchBar(mate::Arguments* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::RefreshTouchBarItem(mate::Arguments* args) {
|
void NativeWindow::RefreshTouchBarItem(const std::string& item_id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::FocusOnWebView() {
|
void NativeWindow::FocusOnWebView() {
|
||||||
|
|
|
@ -173,7 +173,7 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
// Touchbar API
|
// Touchbar API
|
||||||
virtual void DestroyTouchBar();
|
virtual void DestroyTouchBar();
|
||||||
virtual void SetTouchBar(mate::Arguments* args);
|
virtual void SetTouchBar(mate::Arguments* args);
|
||||||
virtual void RefreshTouchBarItem(mate::Arguments* args);
|
virtual void RefreshTouchBarItem(const std::string& item_id);
|
||||||
|
|
||||||
// Webview APIs.
|
// Webview APIs.
|
||||||
virtual void FocusOnWebView();
|
virtual void FocusOnWebView();
|
||||||
|
|
|
@ -104,7 +104,7 @@ class NativeWindowMac : public NativeWindow,
|
||||||
void SetVibrancy(const std::string& type) override;
|
void SetVibrancy(const std::string& type) override;
|
||||||
void DestroyTouchBar() override;
|
void DestroyTouchBar() override;
|
||||||
void SetTouchBar(mate::Arguments* args) override;
|
void SetTouchBar(mate::Arguments* args) override;
|
||||||
void RefreshTouchBarItem(mate::Arguments* args) override;
|
void RefreshTouchBarItem(const std::string& item_id) override;
|
||||||
std::vector<mate::PersistentDictionary> GetTouchBarItems();
|
std::vector<mate::PersistentDictionary> GetTouchBarItems();
|
||||||
|
|
||||||
// content::RenderWidgetHost::InputEventObserver:
|
// content::RenderWidgetHost::InputEventObserver:
|
||||||
|
|
|
@ -354,7 +354,8 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
- (void)setEnableLargerThanScreen:(bool)enable;
|
- (void)setEnableLargerThanScreen:(bool)enable;
|
||||||
- (void)enableWindowButtonsOffset;
|
- (void)enableWindowButtonsOffset;
|
||||||
- (void)resetTouchBar;
|
- (void)resetTouchBar;
|
||||||
- (void)refreshTouchBarItem:(mate::Arguments*)args;
|
- (void)refreshTouchBarItem:(const std::string&)item_id;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation AtomNSWindow
|
@implementation AtomNSWindow
|
||||||
|
@ -371,8 +372,8 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
self.touchBar = nil;
|
self.touchBar = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)refreshTouchBarItem:(mate::Arguments*)args {
|
- (void)refreshTouchBarItem:(const std::string&)item_id {
|
||||||
[atom_touch_bar_ refreshTouchBarItem:args];
|
[atom_touch_bar_ refreshTouchBarItem:item_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTouchBar*)makeTouchBar {
|
- (NSTouchBar*)makeTouchBar {
|
||||||
|
@ -1381,8 +1382,8 @@ void NativeWindowMac::SetTouchBar(mate::Arguments* args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::RefreshTouchBarItem(mate::Arguments* args) {
|
void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) {
|
||||||
[window_ refreshTouchBarItem:args];
|
[window_ refreshTouchBarItem:item_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<mate::PersistentDictionary> NativeWindowMac::GetTouchBarItems() {
|
std::vector<mate::PersistentDictionary> NativeWindowMac::GetTouchBarItems() {
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
- (NSTouchBar*)makeTouchBarFromItemOptions:(const std::vector<mate::PersistentDictionary>&)item_options;
|
- (NSTouchBar*)makeTouchBarFromItemOptions:(const std::vector<mate::PersistentDictionary>&)item_options;
|
||||||
- (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items;
|
- (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items;
|
||||||
- (NSMutableArray*)identifierArrayFromDicts:(const std::vector<mate::PersistentDictionary>&)dicts;
|
- (NSMutableArray*)identifierArrayFromDicts:(const std::vector<mate::PersistentDictionary>&)dicts;
|
||||||
- (void)refreshTouchBarItem:(mate::Arguments*)args;
|
- (void)refreshTouchBarItem:(const std::string&)item_id;
|
||||||
- (void)clear;
|
- (void)clear;
|
||||||
|
|
||||||
- (NSString*)idFromIdentifier:(NSString*)identifier withPrefix:(NSString*)prefix;
|
- (NSString*)idFromIdentifier:(NSString*)identifier withPrefix:(NSString*)prefix;
|
||||||
|
|
|
@ -101,32 +101,29 @@ static NSTouchBarItemIdentifier SliderIdentifier = @"com.electron.touchbar.slide
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)refreshTouchBarItem:(mate::Arguments*)args {
|
- (void)refreshTouchBarItem:(const std::string&)item_id {
|
||||||
std::string item_id;
|
|
||||||
std::string type;
|
|
||||||
mate::PersistentDictionary options;
|
|
||||||
if (!args->GetNext(&options)) return;
|
|
||||||
if (!options.Get("type", &type)) return;
|
|
||||||
if (!options.Get("id", &item_id)) return;
|
|
||||||
if (item_map.find(item_id) == item_map.end()) return;
|
if (item_map.find(item_id) == item_map.end()) return;
|
||||||
|
if (![self hasItemWithID:item_id]) return;
|
||||||
|
|
||||||
if (type == "button") {
|
mate::PersistentDictionary options = item_id_map[item_id];
|
||||||
|
std::string item_type;
|
||||||
|
options.Get("type", &item_type);
|
||||||
|
|
||||||
|
if (item_type == "button") {
|
||||||
[self updateButton:(NSCustomTouchBarItem*)item_map[item_id]
|
[self updateButton:(NSCustomTouchBarItem*)item_map[item_id]
|
||||||
withOptions:options];
|
withOptions:options];
|
||||||
} else if (type == "label") {
|
} else if (item_type == "label") {
|
||||||
[self updateLabel:(NSCustomTouchBarItem*)item_map[item_id]
|
[self updateLabel:(NSCustomTouchBarItem*)item_map[item_id]
|
||||||
withOptions:options];
|
withOptions:options];
|
||||||
} else if (type == "colorpicker") {
|
} else if (item_type == "colorpicker") {
|
||||||
[self updateColorPicker:(NSColorPickerTouchBarItem*)item_map[item_id]
|
[self updateColorPicker:(NSColorPickerTouchBarItem*)item_map[item_id]
|
||||||
withOptions:options];
|
withOptions:options];
|
||||||
} else if (type == "slider") {
|
} else if (item_type == "slider") {
|
||||||
[self updateSlider:(NSSliderTouchBarItem*)item_map[item_id]
|
[self updateSlider:(NSSliderTouchBarItem*)item_map[item_id]
|
||||||
withOptions:options];
|
withOptions:options];
|
||||||
} else if (type == "popover") {
|
} else if (item_type == "popover") {
|
||||||
[self updatePopover:(NSPopoverTouchBarItem*)item_map[item_id]
|
[self updatePopover:(NSPopoverTouchBarItem*)item_map[item_id]
|
||||||
withOptions:options];
|
withOptions:options];
|
||||||
} else if (type == "group") {
|
|
||||||
args->ThrowError("You can not update the config of a group. Update the individual items or replace the group");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,8 @@ BrowserWindow.prototype._init = function () {
|
||||||
this._touchBar.emit('interaction', id, details)
|
this._touchBar.emit('interaction', id, details)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this._touchBarListener = this._refreshTouchBarItem.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserWindow.getFocusedWindow = () => {
|
BrowserWindow.getFocusedWindow = () => {
|
||||||
|
@ -208,8 +210,11 @@ Object.assign(BrowserWindow.prototype, {
|
||||||
// TouchBar API
|
// TouchBar API
|
||||||
BrowserWindow.prototype.setTouchBar = function (touchBar) {
|
BrowserWindow.prototype.setTouchBar = function (touchBar) {
|
||||||
if (touchBar == null) {
|
if (touchBar == null) {
|
||||||
this._destroyTouchBar()
|
if (this._touchBar != null) {
|
||||||
|
this._touchBar.removeListener('change', this._touchBarListener)
|
||||||
this._touchBar = null
|
this._touchBar = null
|
||||||
|
}
|
||||||
|
this._destroyTouchBar()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,11 +223,8 @@ BrowserWindow.prototype.setTouchBar = function (touchBar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._touchBar = touchBar
|
this._touchBar = touchBar
|
||||||
|
this._touchBar.on('change', this._touchBarListener)
|
||||||
this._setTouchBar(touchBar.ordereredItems)
|
this._setTouchBar(touchBar.ordereredItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserWindow.prototype._updateTouchBarItem = function (itemID) {
|
|
||||||
this._refreshTouchBarItem(itemID)
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = BrowserWindow
|
module.exports = BrowserWindow
|
||||||
|
|
|
@ -14,6 +14,9 @@ class TouchBar extends EventEmitter {
|
||||||
this.ordereredItems = []
|
this.ordereredItems = []
|
||||||
const registerItem = (item) => {
|
const registerItem = (item) => {
|
||||||
this.items[item.id] = item
|
this.items[item.id] = item
|
||||||
|
item.on('change', () => {
|
||||||
|
this.emit('change', item.id, item.type)
|
||||||
|
})
|
||||||
if (item.child instanceof TouchBar) {
|
if (item.child instanceof TouchBar) {
|
||||||
item.child.ordereredItems.forEach(registerItem)
|
item.child.ordereredItems.forEach(registerItem)
|
||||||
}
|
}
|
||||||
|
@ -35,8 +38,9 @@ class TouchBar extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TouchBarItem {
|
class TouchBarItem extends EventEmitter {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
|
super()
|
||||||
this.id = `${itemIdIncrementor++}`
|
this.id = `${itemIdIncrementor++}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +85,16 @@ TouchBar.Label = class TouchBarLabel extends TouchBarItem {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
super(config)
|
super(config)
|
||||||
this.type = 'label'
|
this.type = 'label'
|
||||||
this.label = config.label
|
this._label = config.label
|
||||||
|
}
|
||||||
|
|
||||||
|
set label (newLabel) {
|
||||||
|
this._label = newLabel
|
||||||
|
this.emit('change')
|
||||||
|
}
|
||||||
|
|
||||||
|
get label () {
|
||||||
|
return this._label
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue