Skip to content

Commit 994bc79

Browse files
committed
Merge remote-tracking branch 'origin/master' into nw10
2 parents 20f2ad7 + de26cd8 commit 994bc79

File tree

5 files changed

+121
-1
lines changed

5 files changed

+121
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ Fabrice Weinberg <fabrice@weinberg.me>
2525
Lv Kaiyang <kevinlui598@gmail.com>
2626
Lukas Benes <bender@false.cz>
2727
Lithare Emileit <litharemilit@gmail.com>
28+
Jefry Tedjokusumo <jtg_gg@yahoo.com.sg>

src/browser/native_window_win.cc

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#include "ui/gfx/native_widget_types.h"
4444
#include "ui/gfx/win/hwnd_util.h"
4545
#include "ui/gfx/path.h"
46+
#include "ui/gfx/canvas.h"
47+
#include "ui/gfx/icon_util.h"
48+
#include "ui/gfx/font_list.h"
49+
#include "ui/gfx/platform_font.h"
4650
#include "ui/gfx/image/image_skia_operations.h"
4751
#include "ui/views/controls/webview/webview.h"
4852
#include "ui/views/layout/box_layout.h"
@@ -470,8 +474,51 @@ void NativeWindowWin::FlashFrame(bool flash) {
470474
window_->FlashFrame(flash);
471475
}
472476

477+
HICON createBadgeIcon(const HWND hWnd, const TCHAR *value, const int sizeX, const int sizeY) {
478+
// canvas for the overlay icon
479+
gfx::Canvas canvas(gfx::Size(sizeX, sizeY), 1, false);
480+
481+
// drawing red circle
482+
SkPaint paint;
483+
paint.setColor(SK_ColorRED);
484+
canvas.DrawCircle(gfx::Point(sizeX / 2, sizeY / 2), sizeX / 2, paint);
485+
486+
// drawing the text
487+
gfx::PlatformFont *platform_font = gfx::PlatformFont::CreateDefault();
488+
const int fontSize = sizeY*0.65f;
489+
gfx::Font font(platform_font->GetFontName(), fontSize);
490+
platform_font->Release();
491+
platform_font = NULL;
492+
const int yMargin = (sizeY - fontSize) / 2;
493+
canvas.DrawStringRectWithFlags(value, gfx::FontList(font), SK_ColorWHITE, gfx::Rect(sizeX, fontSize + yMargin + 1), gfx::Canvas::TEXT_ALIGN_CENTER);
494+
495+
// return the canvas as windows native icon handle
496+
return IconUtil::CreateHICONFromSkBitmap(canvas.ExtractImageRep().sk_bitmap());
497+
}
498+
473499
void NativeWindowWin::SetBadgeLabel(const std::string& badge) {
474-
// TODO
500+
base::win::ScopedComPtr<ITaskbarList3> taskbar;
501+
HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL,
502+
CLSCTX_INPROC_SERVER);
503+
504+
if (FAILED(result)) {
505+
VLOG(1) << "Failed creating a TaskbarList3 object: " << result;
506+
return;
507+
}
508+
509+
result = taskbar->HrInit();
510+
if (FAILED(result)) {
511+
LOG(ERROR) << "Failed initializing an ITaskbarList3 interface.";
512+
return;
513+
}
514+
515+
HICON icon = NULL;
516+
HWND hWnd = window_->GetNativeWindow();
517+
if (badge.size())
518+
icon = createBadgeIcon(hWnd, UTF8ToUTF16(badge).c_str(), 32, 32);
519+
520+
taskbar->SetOverlayIcon(hWnd, icon, _T("Status"));
521+
DestroyIcon(icon);
475522
}
476523

477524
void NativeWindowWin::SetKiosk(bool kiosk) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<html>
2+
<head>
3+
<meta charset="utf8">
4+
<title>APP Single Instance</title>
5+
</head>
6+
<body>
7+
<div id="pid"></div>
8+
<script type="text/javascript">
9+
document.getElementById('pid').innerHTML = process.pid;
10+
var gui = require('nw.gui');
11+
var argv = gui.App.argv;
12+
var port = 13013;
13+
if (argv.length > 0){
14+
port = argv[0];
15+
}
16+
var net = require('net');
17+
var s = null;
18+
var connection = net.createConnection(port);
19+
connection.write('hello world');
20+
</script>
21+
</body>
22+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name":"ASI",
3+
"main":"index.html",
4+
"single-instance":true
5+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var child_process = require('child_process')
2+
var server = global.server;
3+
var server_port = global.port;
4+
var assert = require('assert');
5+
var path = require('path');
6+
7+
describe('Single Instance APP', function() {
8+
var counter = 0;
9+
var pushData = function(socket) {
10+
socket.on('data', function(data) {
11+
counter += 1;
12+
})
13+
};
14+
var runApp = function(path){
15+
var spawn = child_process.spawn;
16+
var child = spawn(process.execPath,[path,server_port]);
17+
return child;
18+
};
19+
20+
before(function(done) {
21+
server.on('connection',pushData);
22+
var app_path = path.join(global.tests_dir,'app-single-instance/app');
23+
console.log(app_path);
24+
console.log(process.cwd());
25+
var child1 = runApp(app_path);
26+
var child2 = runApp(app_path);
27+
var child3 = runApp(app_path);
28+
setTimeout(function(){
29+
child1.kill();
30+
child2.kill();
31+
child3.kill();
32+
done();
33+
},1000);
34+
});
35+
36+
it('app should be single instance', function(done) {
37+
assert.equal(counter,1);
38+
done();
39+
});
40+
41+
after(function(done) {
42+
server.removeListener('connection',pushData);
43+
done();
44+
});
45+
});

0 commit comments

Comments
 (0)