Lighter window background

Native windows get lighter when they’re backgrounded so they stand out
less (at least on OS X). Let’s do this too.

Even the Spotify app, which has dozens of developers gets this wrong.
We’re so awesome :)

Also:

- Renamed a bunch of state variables (next time will make separate
commit, sry)
- All window-related variables (e.g. isFullScreen, isFocused, etc.)
live in `state.window` now
- Remove negative class name, use CSS :not() instead
This commit is contained in:
Feross Aboukhadijeh
2016-03-08 17:18:31 -08:00
parent 2c70e2e3de
commit 67217bdc7e
5 changed files with 46 additions and 32 deletions

View File

@@ -67,6 +67,11 @@ body {
display: flex; display: flex;
flex-flow: column; flex-flow: column;
animation: fadein 0.3s; animation: fadein 0.3s;
background: rgb(40, 40, 40);
}
.app:not(.is-focused) {
background: rgb(50, 50, 50);
} }
/* /*
@@ -157,6 +162,10 @@ a:not(.disabled):hover, i:not(.disabled):hover {
line-height: 1.5em; line-height: 1.5em;
} }
.app:not(.is-focused) .header {
background: rgb(50, 50, 50);
}
.view-player .header { .view-player .header {
opacity: 0.8; opacity: 0.8;
} }
@@ -184,7 +193,7 @@ a:not(.disabled):hover, i:not(.disabled):hover {
float: left; float: left;
} }
.darwin.not-fullscreen .header .nav.left { .app.is-darwin:not(.is-fullscreen) .header .nav.left {
margin-left: 78px; margin-left: 78px;
} }

View File

@@ -95,7 +95,7 @@ function init () {
// ...keyboard shortcuts // ...keyboard shortcuts
document.addEventListener('keydown', function (e) { document.addEventListener('keydown', function (e) {
if (e.which === 27) { /* ESC means either exit fullscreen or go back */ if (e.which === 27) { /* ESC means either exit fullscreen or go back */
if (state.isFullScreen) { if (state.window.isFullScreen) {
dispatch('toggleFullScreen') dispatch('toggleFullScreen')
} else { } else {
dispatch('back') dispatch('back')
@@ -107,12 +107,14 @@ function init () {
// ...focus and blur. Needed to show correct dock icon text ("badge") in OSX // ...focus and blur. Needed to show correct dock icon text ("badge") in OSX
window.addEventListener('focus', function () { window.addEventListener('focus', function () {
state.isFocused = true state.window.isFocused = true
state.dock.badge = 0 state.dock.badge = 0
update()
}) })
window.addEventListener('blur', function () { window.addEventListener('blur', function () {
state.isFocused = false state.window.isFocused = false
update()
}) })
// Done! Ideally we want to get here <100ms after the user clicks the app // Done! Ideally we want to get here <100ms after the user clicks the app
@@ -133,9 +135,9 @@ function update () {
} }
function updateElectron () { function updateElectron () {
if (state.title !== state.prev.title) { if (state.window.title !== state.prev.title) {
state.prev.title = state.title state.prev.title = state.window.title
ipcRenderer.send('setTitle', state.title) ipcRenderer.send('setTitle', state.window.title)
} }
if (state.dock.progress !== state.prev.progress) { if (state.dock.progress !== state.prev.progress) {
state.prev.progress = state.dock.progress state.prev.progress = state.dock.progress
@@ -213,7 +215,7 @@ function setupIpc () {
}) })
ipcRenderer.on('fullscreenChanged', function (e, isFullScreen) { ipcRenderer.on('fullscreenChanged', function (e, isFullScreen) {
state.isFullScreen = isFullScreen state.window.isFullScreen = isFullScreen
update() update()
}) })
@@ -386,7 +388,7 @@ function addTorrentEvents (torrent) {
var torrentSummary = getTorrentSummary(torrent.infoHash) var torrentSummary = getTorrentSummary(torrent.infoHash)
torrentSummary.status = 'seeding' torrentSummary.status = 'seeding'
if (!state.isFocused) { if (!state.window.isFocused) {
state.dock.badge += 1 state.dock.badge += 1
} }
@@ -456,17 +458,17 @@ function openPlayer (torrentSummary) {
// otherwise, play the video // otherwise, play the video
state.url = '/player' state.url = '/player'
state.title = torrentSummary.name state.window.title = torrentSummary.name
update() update()
}) })
} }
function closePlayer () { function closePlayer () {
state.url = '/' state.url = '/'
state.title = config.APP_NAME state.window.title = config.APP_NAME
update() update()
if (state.isFullScreen) { if (state.window.isFullScreen) {
dispatch('toggleFullScreen', false) dispatch('toggleFullScreen', false)
} }
restoreBounds() restoreBounds()
@@ -519,7 +521,7 @@ function openAirplay (infoHash) {
// Set window dimensions to match video dimensions or fill the screen // Set window dimensions to match video dimensions or fill the screen
function setDimensions (dimensions) { function setDimensions (dimensions) {
state.mainWindowBounds = { state.window.bounds = {
x: window.screenX, x: window.screenX,
y: window.screenY, y: window.screenY,
width: window.outerWidth, width: window.outerWidth,
@@ -547,8 +549,8 @@ function setDimensions (dimensions) {
function restoreBounds () { function restoreBounds () {
ipcRenderer.send('setAspectRatio', 0) ipcRenderer.send('setAspectRatio', 0)
if (state.mainWindowBounds) { if (state.window.bounds) {
ipcRenderer.send('setBounds', state.mainWindowBounds, true) ipcRenderer.send('setBounds', state.window.bounds, true)
} }
} }

View File

@@ -7,31 +7,33 @@ module.exports = {
/* Temporary state disappears once the program exits. /* Temporary state disappears once the program exits.
* It can contain complex objects like open connections, etc. * It can contain complex objects like open connections, etc.
*/ */
url: '/',
client: null, /* the WebTorrent client */ client: null, /* the WebTorrent client */
prev: {}, /* used for state diffing in updateElectron() */
server: null, /* local WebTorrent-to-HTTP server */ server: null, /* local WebTorrent-to-HTTP server */
dock: { torrentPlaying: null, /* the torrent we're streaming. see client.torrents */
badge: 0, // history: [], /* track how we got to the current view. enables Back button */
progress: 0 // historyIndex: 0,
}, url: '/',
devices: { devices: {
airplay: null, /* airplay client. finds and manages AppleTVs */ airplay: null, /* airplay client. finds and manages AppleTVs */
chromecast: null /* chromecast client. finds and manages Chromecasts */ chromecast: null /* chromecast client. finds and manages Chromecasts */
}, },
torrentPlaying: null, /* the torrent we're streaming. see client.torrents */ dock: {
// history: [], /* track how we got to the current view. enables Back button */ badge: 0,
// historyIndex: 0, progress: 0
isFocused: true, },
isFullScreen: false, window: {
mainWindowBounds: null, /* x y width height */ bounds: null, /* x y width height */
title: config.APP_NAME, /* current window title */ isFocused: true,
isFullScreen: false,
title: config.APP_NAME /* current window title */
},
video: { video: {
isPaused: false,
currentTime: 0, /* seconds */ currentTime: 0, /* seconds */
duration: 1, /* seconds */ duration: 1, /* seconds */
isPaused: false,
mouseStationarySince: 0 /* Unix time in ms */ mouseStationarySince: 0 /* Unix time in ms */
}, },
prev: {}, /* used for state diffing in updateElectron() */
/* Saved state is read from and written to a file every time the app runs. /* Saved state is read from and written to a file every time the app runs.
* It should be simple and minimal and must be JSON. * It should be simple and minimal and must be JSON.

View File

@@ -22,8 +22,9 @@ function App (state, dispatch) {
!state.video.isPaused !state.video.isPaused
var cls = [ var cls = [
process.platform, /* 'windows', 'linux', or 'darwin' for OSX */ 'is-' + process.platform, /* 'is-darwin' (OS X), 'is-win32' (Windows), 'is-linux' */
state.isFullScreen ? 'fullscreen' : 'not-fullscreen', state.window.isFullScreen ? 'is-fullscreen' : '',
state.window.isFocused ? 'is-focused' : '',
isVideoPlayer ? 'view-player' : '', isVideoPlayer ? 'view-player' : '',
hideControls ? 'hide-video-controls' : '' hideControls ? 'hide-video-controls' : ''
] ]

View File

@@ -30,7 +30,7 @@ function Header (state, dispatch) {
function getTitle () { function getTitle () {
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
return hx`<div class='title'>${state.title}</div>` return hx`<div class='title'>${state.window.title}</div>`
} }
} }