Skip to content

Commit 47a38da

Browse files
Micha HanselmannMarshallOfSound
authored andcommitted
feat: migrate custom macOS tray view to native one (electron#18981)
* restore stash revert some things work others dont tracking area for rescue manual popup restore drag n drop cleanup * fix: make tray not block main process (electron#18880) * fix: make tray not block main process * make AtomMenuModel refcounted * add support for ansi codes in title add remove TODOs * chore: use ScopedPumpMessagesInPrivateModes in tray (electron#18977) * chore: use ScopedPumpMessagesInPrivateModes in tray * revert refcounting of AtomMenuModel * Prefer WeakPtr for posting tasks to handle unexpected destruction * cleanup .h * cleanup .mm * add imports add missing include * fix: crash when tray popup called twice (electron#18999) * remove highlightMode and TODOs * remove unnecessary copy
1 parent cde7950 commit 47a38da

File tree

8 files changed

+50
-357
lines changed

8 files changed

+50
-357
lines changed

docs/api/tray.md

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -206,39 +206,6 @@ Sets the title displayed next to the tray icon in the status bar (Support ANSI c
206206

207207
Returns `String` - the title displayed next to the tray icon in the status bar
208208

209-
#### `tray.setHighlightMode(mode)` _macOS_
210-
211-
* `mode` String - Highlight mode with one of the following values:
212-
* `selection` - Highlight the tray icon when it is clicked and also when
213-
its context menu is open. This is the default.
214-
* `always` - Always highlight the tray icon.
215-
* `never` - Never highlight the tray icon.
216-
217-
Sets when the tray's icon background becomes highlighted (in blue).
218-
219-
**[Deprecated](breaking-changes.md#tray)**
220-
221-
**Note:** You can use `highlightMode` with a [`BrowserWindow`](browser-window.md)
222-
by toggling between `'never'` and `'always'` modes when the window visibility
223-
changes.
224-
225-
```javascript
226-
const { BrowserWindow, Tray } = require('electron')
227-
228-
const win = new BrowserWindow({ width: 800, height: 600 })
229-
const tray = new Tray('/path/to/my/icon')
230-
231-
tray.on('click', () => {
232-
win.isVisible() ? win.hide() : win.show()
233-
})
234-
win.on('show', () => {
235-
tray.setHighlightMode('always')
236-
})
237-
win.on('hide', () => {
238-
tray.setHighlightMode('never')
239-
})
240-
```
241-
242209
#### `tray.setIgnoreDoubleClickEvents(ignore)` _macOS_
243210

244211
* `ignore` Boolean

lib/browser/api/tray.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@ const { Tray } = process.electronBinding('tray')
66

77
Object.setPrototypeOf(Tray.prototype, EventEmitter.prototype)
88

9-
// Deprecations
10-
Tray.prototype.setHighlightMode = deprecate.removeFunction(Tray.prototype.setHighlightMode, 'setHighlightMode')
11-
129
module.exports = Tray

shell/browser/api/atom_api_tray.cc

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,6 @@
1818
#include "shell/common/node_includes.h"
1919
#include "ui/gfx/image/image.h"
2020

21-
namespace mate {
22-
23-
template <>
24-
struct Converter<electron::TrayIcon::HighlightMode> {
25-
static bool FromV8(v8::Isolate* isolate,
26-
v8::Local<v8::Value> val,
27-
electron::TrayIcon::HighlightMode* out) {
28-
using HighlightMode = electron::TrayIcon::HighlightMode;
29-
std::string mode;
30-
if (ConvertFromV8(isolate, val, &mode)) {
31-
if (mode == "always") {
32-
*out = HighlightMode::ALWAYS;
33-
return true;
34-
}
35-
if (mode == "selection") {
36-
*out = HighlightMode::SELECTION;
37-
return true;
38-
}
39-
if (mode == "never") {
40-
*out = HighlightMode::NEVER;
41-
return true;
42-
}
43-
}
44-
return false;
45-
}
46-
};
47-
} // namespace mate
48-
4921
namespace electron {
5022

5123
namespace api {
@@ -169,10 +141,6 @@ std::string Tray::GetTitle() {
169141
#endif
170142
}
171143

172-
void Tray::SetHighlightMode(TrayIcon::HighlightMode mode) {
173-
tray_icon_->SetHighlightMode(mode);
174-
}
175-
176144
void Tray::SetIgnoreDoubleClickEvents(bool ignore) {
177145
#if defined(OS_MACOSX)
178146
tray_icon_->SetIgnoreDoubleClickEvents(ignore);
@@ -235,7 +203,6 @@ void Tray::BuildPrototype(v8::Isolate* isolate,
235203
.SetMethod("setToolTip", &Tray::SetToolTip)
236204
.SetMethod("setTitle", &Tray::SetTitle)
237205
.SetMethod("getTitle", &Tray::GetTitle)
238-
.SetMethod("setHighlightMode", &Tray::SetHighlightMode)
239206
.SetMethod("setIgnoreDoubleClickEvents",
240207
&Tray::SetIgnoreDoubleClickEvents)
241208
.SetMethod("getIgnoreDoubleClickEvents",

shell/browser/api/atom_api_tray.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
7070
void SetToolTip(const std::string& tool_tip);
7171
void SetTitle(const std::string& title);
7272
std::string GetTitle();
73-
void SetHighlightMode(TrayIcon::HighlightMode mode);
7473
void SetIgnoreDoubleClickEvents(bool ignore);
7574
bool GetIgnoreDoubleClickEvents();
7675
void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);

shell/browser/ui/tray_icon.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ TrayIcon::~TrayIcon() {}
1212

1313
void TrayIcon::SetPressedImage(ImageType image) {}
1414

15-
void TrayIcon::SetHighlightMode(TrayIcon::HighlightMode mode) {}
16-
1715
void TrayIcon::DisplayBalloon(ImageType icon,
1816
const base::string16& title,
1917
const base::string16& contents) {}

shell/browser/ui/tray_icon.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ class TrayIcon {
3939
// status icon (e.g. Ubuntu Unity).
4040
virtual void SetToolTip(const std::string& tool_tip) = 0;
4141

42-
// Sets the status icon highlight mode. This only works on macOS.
43-
enum class HighlightMode {
44-
ALWAYS, // Always highlight the tray icon
45-
NEVER, // Never highlight the tray icon
46-
SELECTION // Highlight the tray icon when clicked or the menu is opened
47-
};
48-
virtual void SetHighlightMode(HighlightMode mode);
49-
5042
#if defined(OS_MACOSX)
5143
// Set/Get flag determining whether to ignore double click events.
5244
virtual void SetIgnoreDoubleClickEvents(bool ignore) = 0;

shell/browser/ui/tray_icon_cocoa.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
namespace electron {
1919

20-
class TrayIconCocoa : public TrayIcon, public AtomMenuModel::Observer {
20+
class TrayIconCocoa : public TrayIcon {
2121
public:
2222
TrayIconCocoa();
2323
~TrayIconCocoa() override;
@@ -27,7 +27,6 @@ class TrayIconCocoa : public TrayIcon, public AtomMenuModel::Observer {
2727
void SetToolTip(const std::string& tool_tip) override;
2828
void SetTitle(const std::string& title) override;
2929
std::string GetTitle() override;
30-
void SetHighlightMode(TrayIcon::HighlightMode mode) override;
3130
void SetIgnoreDoubleClickEvents(bool ignore) override;
3231
bool GetIgnoreDoubleClickEvents() override;
3332
void PopUpOnUI(AtomMenuModel* menu_model);
@@ -36,20 +35,13 @@ class TrayIconCocoa : public TrayIcon, public AtomMenuModel::Observer {
3635
void SetContextMenu(AtomMenuModel* menu_model) override;
3736
gfx::Rect GetBounds() override;
3837

39-
protected:
40-
// AtomMenuModel::Observer:
41-
void OnMenuWillClose() override;
42-
4338
private:
44-
// Atom custom view for NSStatusItem.
39+
// Electron custom view for NSStatusItem.
4540
base::scoped_nsobject<StatusItemView> status_item_view_;
4641

4742
// Status menu shown when right-clicking the system icon.
4843
base::scoped_nsobject<AtomMenuController> menu_;
4944

50-
// Used for unregistering observer.
51-
AtomMenuModel* menu_model_ = nullptr; // weak ref.
52-
5345
base::WeakPtrFactory<TrayIconCocoa> weak_factory_;
5446

5547
DISALLOW_COPY_AND_ASSIGN(TrayIconCocoa);

0 commit comments

Comments
 (0)