Skip to content

Commit 4d34f5c

Browse files
author
Gordon Hall
committed
worked on notifier class for blocking notification
1 parent 216961e commit 4d34f5c

File tree

10 files changed

+207
-5
lines changed

10 files changed

+207
-5
lines changed
Lines changed: 49 additions & 0 deletions
Loading

src/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
<link rel="stylesheet" type="text/css" href="styles/fonts.css" />
77
<link rel="stylesheet" type="text/less" href="styles/tv.less" />
88
<link rel="stylesheet" type="text/less" href="styles/tv-globalmenu.less" />
9+
<link rel="stylesheet" type="text/less" href="styles/notifier.less" />
910
<script type="application/javascript" src="vendor/mousetrap.js"></script>
1011
</head>
1112
<body>
1213
<h1 class="logo">UNTV</h1>
1314
<nav class="animated" id="menu-container"></nav>
15+
<div class="animated" id="notifier-container"></div>
1416
<div id="app">
1517
<div id="extensions-container" class="animated"></div>
1618
<ul class="notifications"></ul>

src/lib/notifier.coffee

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,84 @@ on the user's TV
77
###
88

99
{EventEmitter} = require "events"
10+
fs = require "fs"
11+
jade = require "jade"
12+
$ = require "../vendor/jquery-2.0.3"
1013

1114
class Notifier extends EventEmitter
12-
constructor: ->
15+
constructor: (@container, @menu, @remote) ->
16+
17+
view:
18+
large: fs.readFileSync "#{__dirname}/../views/notification-large.jade"
19+
small: fs.readFileSync "#{__dirname}/../views/notification-small.jade"
20+
21+
stealRemoteFocus: =>
22+
# borrow from the menu proto
23+
@menu.cacheRemoteListeners.call @
24+
# get rid of listeners
25+
do @remote.removeAllListeners
26+
# bind our own
27+
@remote.on "go:select", => do @dismiss
28+
@remote.on "scroll:up", => do @scrollUp
29+
@remote.on "scroll:down", => do @scrollDown
30+
31+
returnRemoteFocus: =>
32+
# kill our listeners
33+
do @remote.removeAllListeners
34+
# borrow from the menu proto and rebind cached ones
35+
@menu.rebindCachedListeners.call @
36+
37+
dismiss: =>
38+
@menu.container.animate
39+
top: "0%"
40+
bottom: "0%"
41+
, @animation_time, => @menu.container.removeClass "notifier-open"
42+
43+
($ "> *", @menu.container).animate
44+
top: "0%"
45+
bottom: "0%"
46+
, @animation_time, => ($ "> *", @menu.container).removeClass "notifier-open"
47+
48+
@container.animate
49+
top: "100%"
50+
bottom: "-100%"
51+
, @animation_time, => do @container.hide
52+
53+
do @returnRemoteFocus
54+
55+
notify: (from = "System Message", content, is_passive) =>
56+
view = if is_passive then @view.small.toString() else @view.large.toString()
57+
view = jade.compile view
58+
content = view
59+
initiator: from
60+
message: content
61+
@container.html content
62+
# play sound
63+
@remote.playEventSound "notify"
64+
# handle non-passive behavior
65+
if not is_passive
66+
# move the menu outta heeereee
67+
@menu.container.animate
68+
top: "-90%"
69+
bottom: "90%"
70+
, @animation_time, => @menu.container.addClass "notifier-open"
71+
72+
($ "> *", @menu.container).animate
73+
top: "-90%"
74+
bottom: "90%"
75+
, @animation_time, => ($ "> *", @menu.container).addClass "notifier-open"
76+
77+
do @container.show
78+
@container.animate
79+
top: "10%"
80+
bottom: "0%"
81+
, @animation_time
82+
83+
# steal remote focus
84+
do @stealRemoteFocus
85+
86+
animation_in: "" #"fadeInUp"
87+
animation_out: "" #"fadeOutDown"
88+
animation_time: 300
1389

1490
module.exports = Notifier

src/lib/tv-globalmenu.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ class GlobalMenu extends EventEmitter
8787
###
8888
Remote Listener Caching
8989
###
90-
cacheRemoteListeners: =>
90+
cacheRemoteListeners: ->
9191
cache = {}
9292
for event_type in @remote.events
9393
listeners = @remote.listeners event_type
9494
cache[event_type] = listeners if listeners.length
9595
@cached_remote_listeners = cache if (Object.keys cache).length
9696

97-
rebindCachedListeners: =>
97+
rebindCachedListeners: ->
9898
if @cached_remote_listeners
9999
for event_type, listeners of @cached_remote_listeners
100100
for handler in listeners

src/styles/notifier.less

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
** UNTV - notifier.css
3+
** Author: Gordon Hall
4+
*/
5+
6+
#notifier-container {
7+
position: fixed;
8+
top: 100%;
9+
left: 0;
10+
right: 0;
11+
bottom: -100%;
12+
z-index: 9;
13+
background: rgba(0,0,0,0.9);
14+
box-shadow: inset 0 12px 50px #000;
15+
}
16+
17+
#notifier-container > h2 {
18+
font-size: 42px;
19+
color: rgba(255,255,255,0.9);
20+
font-weight: normal;
21+
margin: 24px 24px 0 24px;
22+
padding: 12px 12px 12px 68px;
23+
text-shadow: 0 3px 5px #000;
24+
background: url('../assets/images/icons/notification.svg') left center no-repeat;
25+
background-size: 56px;
26+
}
27+
28+
#notifier-container > .content {
29+
color: #fff;
30+
font-size: 22px;
31+
line-height: 34px;
32+
margin: 0 24px 24px 24px;
33+
overflow: hidden;
34+
height: 426px;
35+
}
36+
37+
#notifier-container > aside {
38+
color: #fff;
39+
font-size: 18px;
40+
text-transform: uppercase;
41+
text-align: center;
42+
margin-bottom: 12px;
43+
font-weight: bold;
44+
}

src/styles/tv-globalmenu.less

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,33 @@
66

77
#menu-container {
88
position: fixed;
9-
top: 0;
9+
top: 0%;
1010
left: 0;
11+
bottom: 0%;
1112
width: 100%;
1213
height: 100%;
1314
background: rgba(0,0,0,0.6);
1415
z-index: 9;
1516
display: none;
17+
overflow: hidden;
1618
}
1719

1820
#menu-container.visible {
1921
display: block;
2022
}
2123

24+
@-webkit-keyframes slide_menu_out {
25+
0 {
26+
top: 0%;
27+
bottom: 0%;
28+
}
29+
30+
100% {
31+
top: 90%;
32+
bottom: -90%;
33+
}
34+
}
35+
2236
#menu-container > ul {
2337
color: #fff;
2438
list-style-type: none;

src/untv.coffee

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ Remote = require "./lib/remote-server"
1313
Notifier = require "./lib/notifier"
1414
config = JSON.parse fs.readFileSync "#{__dirname}/config.json"
1515
win = global.window.nwDispatcher.requireNwGui()?.Window.get()
16+
jade = require "jade"
1617

1718
###
1819
Setup Remote, Global Menu, and Player
1920
###
20-
notifier = new Notifier()
2121
remote = new Remote config.remote_port
2222
player = new Player ($ "#player-container"), remote
2323
menu = new GlobalMenu ($ "#menu-container"), remote, player
24+
notifier = new Notifier ($ "#notifier-container"), menu, remote
2425

2526
###
2627
Register Remote Control Server
@@ -55,3 +56,14 @@ registerExtension "#{ext_path}/#{directory}" for directory, index in ext_dir
5556
do ($ "#init-loader").hide
5657
do menu.open
5758
do win?.show
59+
60+
61+
setTimeout ->
62+
view = jade.compile fs.readFileSync "#{__dirname}/views/connect-remote.jade"
63+
content = view
64+
remote_ip: remote.interfaces()[0]?.address
65+
remote_port: config.remote_port
66+
67+
if not remote.connected then notifier.notify "System Message", content
68+
remote.on "remote:connected", -> do notifier.dismiss
69+
, 1000

src/views/connect-remote.jade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
p Connect your smartphone to http://#{remote_ip}:#{remote_port}

src/views/notification-large.jade

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
h2 #{initiator}
2+
.content!=message
3+
aside Swipe Up/Down to Scroll
4+
aside Tap to Dismiss

src/views/notification-small.jade

Whitespace-only changes.

0 commit comments

Comments
 (0)