Skip to content

Commit 4f48a46

Browse files
committed
nw2: fix Window.setBadgeLabel and Window.setProgressBar
Fix nwjs#7464
1 parent 9fddfa2 commit 4f48a46

File tree

5 files changed

+56
-14
lines changed

5 files changed

+56
-14
lines changed

src/api/nw_current_window_internal.idl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ namespace nw.currentWindowInternal {
2727
static void showDevToolsInternal(optional ShowDevToolsCallback callback);
2828
static void showDevTools2Internal(long id, optional ShowDevToolsCallback callback);
2929
static void closeDevTools();
30-
static void setBadgeLabel(DOMString badge);
30+
static void setBadgeLabelInternal(DOMString badge, optional long id);
3131
static void requestAttentionInternal(long count);
32-
static void setProgressBar(double progress);
32+
static void setProgressBarInternal(double progress, optional long id);
3333
static void enterKioskModeInternal(optional long id);
3434
static void leaveKioskModeInternal(optional long id);
3535
static void toggleKioskModeInternal(optional long id);

src/api/nw_window_api.cc

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ static HWND getHWND(AppWindow* window) {
195195
window->GetBaseWindow());
196196
return views::HWNDForWidget(native_app_window_views->widget()->GetTopLevelWidget());
197197
}
198+
199+
static HWND getHWND(Browser* browser) {
200+
if (browser == NULL) return NULL;
201+
const HWND browser_hwnd =
202+
views::HWNDForNativeView(browser->window()->GetNativeWindow());
203+
return browser_hwnd;
204+
}
198205
#endif
199206

200207
void NwCurrentWindowInternalCloseFunction::DoClose(AppWindow* window) {
@@ -576,7 +583,7 @@ static base::win::ScopedHICON createBadgeIcon(const HWND hWnd, const TCHAR *valu
576583

577584
#ifndef OS_MACOSX
578585
ExtensionFunction::ResponseAction
579-
NwCurrentWindowInternalSetBadgeLabelFunction::Run() {
586+
NwCurrentWindowInternalSetBadgeLabelInternalFunction::Run() {
580587
EXTENSION_FUNCTION_VALIDATE(args_);
581588
std::string badge;
582589
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &badge));
@@ -599,7 +606,17 @@ NwCurrentWindowInternalSetBadgeLabelFunction::Run() {
599606
}
600607

601608
base::win::ScopedHICON icon;
602-
HWND hWnd = getHWND(getAppWindow(this));
609+
HWND hWnd;
610+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
611+
int id = 0;
612+
args_->GetInteger(1, &id);
613+
Browser* browser = getBrowser(this, id);
614+
if (!browser)
615+
return RespondNow(Error("cannot find browser window"));
616+
hWnd = getHWND(browser);
617+
} else
618+
hWnd = getHWND(getAppWindow(this));
619+
603620
if (hWnd == NULL) {
604621
error_ = kNoAssociatedAppWindow;
605622
LOG(ERROR) << error_;
@@ -656,7 +673,7 @@ NwCurrentWindowInternalRequestAttentionInternalFunction::Run() {
656673
}
657674

658675
ExtensionFunction::ResponseAction
659-
NwCurrentWindowInternalSetProgressBarFunction::Run() {
676+
NwCurrentWindowInternalSetProgressBarInternalFunction::Run() {
660677
EXTENSION_FUNCTION_VALIDATE(args_);
661678
double progress;
662679
EXTENSION_FUNCTION_VALIDATE(args_->GetDouble(0, &progress));
@@ -678,7 +695,16 @@ NwCurrentWindowInternalSetProgressBarFunction::Run() {
678695
return RespondNow(Error(error_));
679696
}
680697

681-
HWND hWnd = getHWND(getAppWindow(this));
698+
HWND hWnd;
699+
if (base::FeatureList::IsEnabled(::features::kNWNewWin)) {
700+
int id = 0;
701+
args_->GetInteger(1, &id);
702+
Browser* browser = getBrowser(this, id);
703+
if (!browser)
704+
return RespondNow(Error("cannot find browser window"));
705+
hWnd = getHWND(browser);
706+
} else
707+
hWnd = getHWND(getAppWindow(this));
682708
if (hWnd == NULL) {
683709
error_ = kNoAssociatedAppWindow;
684710
LOG(ERROR) << error_;

src/api/nw_window_api.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,16 @@ class NwCurrentWindowInternalSetShadowInternalFunction : public ExtensionFunctio
151151
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.setShadowInternal", UNKNOWN)
152152
};
153153

154-
class NwCurrentWindowInternalSetBadgeLabelFunction : public ExtensionFunction {
154+
class NwCurrentWindowInternalSetBadgeLabelInternalFunction : public ExtensionFunction {
155155
public:
156-
NwCurrentWindowInternalSetBadgeLabelFunction(){}
156+
NwCurrentWindowInternalSetBadgeLabelInternalFunction(){}
157157

158158
protected:
159-
~NwCurrentWindowInternalSetBadgeLabelFunction() override {}
159+
~NwCurrentWindowInternalSetBadgeLabelInternalFunction() override {}
160160

161161
// ExtensionFunction:
162162
ResponseAction Run() override;
163-
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.setBadgeLabel", UNKNOWN)
163+
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.setBadgeLabelInternal", UNKNOWN)
164164
};
165165

166166
class NwCurrentWindowInternalRequestAttentionInternalFunction : public ExtensionFunction {
@@ -177,16 +177,16 @@ class NwCurrentWindowInternalRequestAttentionInternalFunction : public Extension
177177
DISALLOW_COPY_AND_ASSIGN(NwCurrentWindowInternalRequestAttentionInternalFunction);
178178
};
179179

180-
class NwCurrentWindowInternalSetProgressBarFunction : public ExtensionFunction {
180+
class NwCurrentWindowInternalSetProgressBarInternalFunction : public ExtensionFunction {
181181
public:
182-
NwCurrentWindowInternalSetProgressBarFunction(){}
182+
NwCurrentWindowInternalSetProgressBarInternalFunction(){}
183183

184184
protected:
185-
~NwCurrentWindowInternalSetProgressBarFunction() override {}
185+
~NwCurrentWindowInternalSetProgressBarInternalFunction() override {}
186186

187187
// ExtensionFunction:
188188
ResponseAction Run() override;
189-
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.setProgressBar", UNKNOWN)
189+
DECLARE_EXTENSION_FUNCTION("nw.currentWindowInternal.setProgressBarInternal", UNKNOWN)
190190
private:
191191
void Callback();
192192
};

src/resources/api_nw_newwin.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ NWWindow.prototype.setShadow = function(shadow) {
327327
currentNWWindowInternal.setShadowInternal(shadow, this.cWindow.id);
328328
};
329329

330+
NWWindow.prototype.setBadgeLabel = function(label) {
331+
currentNWWindowInternal.setBadgeLabelInternal(label, this.cWindow.id);
332+
};
333+
334+
NWWindow.prototype.setProgressBar = function(progress) {
335+
currentNWWindowInternal.setProgressBarInternal(progress, this.cWindow.id);
336+
};
337+
330338
NWWindow.prototype.setShowInTaskbar = function(show) {
331339
currentNWWindowInternal.setShowInTaskbarInternal(show, this.cWindow.id);
332340
};

src/resources/api_nw_window.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ apiBridge.registerCustomHook(function(bindingsAPI) {
351351
currentNWWindowInternal.setShowInTaskbarInternal(show);
352352
};
353353

354+
NWWindow.prototype.setProgressBar = function(progress) {
355+
currentNWWindowInternal.setProgressBarInternal(progress);
356+
};
357+
358+
NWWindow.prototype.setBadgeLabel = function(label) {
359+
currentNWWindowInternal.setBadgeLabelInternal(label);
360+
};
361+
354362
NWWindow.prototype.enterKioskMode = function() {
355363
currentNWWindowInternal.enterKioskModeInternal();
356364
};

0 commit comments

Comments
 (0)