-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maxim Ponomarev
committed
Feb 5, 2017
0 parents
commit 953e2e4
Showing
17 changed files
with
531 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[{package.json,*.yml,*rc}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": ["xo"], | ||
"esnext": true, | ||
"env": { | ||
"node": true, | ||
"browser": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* text=auto | ||
*.js text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- 'node' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
html | ||
{ | ||
overflow: hidden; | ||
} | ||
|
||
body | ||
{ | ||
font-family: -apple-system, | ||
BlinkMacSystemFont, | ||
'Segoe UI', | ||
Roboto, | ||
Oxygen-Sans, | ||
Ubuntu, | ||
Cantarell, | ||
'Helvetica Neue', | ||
sans-serif, | ||
'Apple Color Emoji', | ||
'Segoe UI Emoji', | ||
'Segoe UI Symbol' !important; | ||
text-rendering: optimizeLegibility !important; | ||
font-feature-settings: 'liga', 'clig', 'dlig', 'kern'; | ||
} | ||
|
||
/* Bind the toolbar as the window's draggable region */ | ||
.page-root .head { | ||
-webkit-app-region: drag; | ||
} | ||
|
||
.footer, .head__left, .logo, | ||
.nav__level_0 .footer__static-text | ||
{ | ||
display: none !important; | ||
} | ||
|
||
.nav__level_0 .nav__items | ||
{ | ||
padding-top: 30px !important; | ||
} | ||
|
||
.nav__level_0 .nav__banner | ||
{ | ||
padding-bottom: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
const electron = require('electron'); | ||
|
||
const ipc = electron.ipcRenderer; | ||
const webFrame = electron.webFrame; | ||
|
||
const el = { | ||
prefButton: '.page-root .settings', | ||
prefDialog: '.settings-stream.popup', | ||
mute: '.page-root .volume', | ||
play: '.page-station .player-controls__play', | ||
next: '.page-station .slider__item_next', | ||
like: '.page-station .button.like_action_like', | ||
dislike: '.page-station .button.like_action_dislike', | ||
activeStation: '.page-index .station_playing' | ||
}; | ||
|
||
function exec(command) { | ||
webFrame.executeJavaScript(`if (!window.a) a = new Mu.Adapter(); ${command};`); | ||
} | ||
|
||
function click(s) { | ||
const e = document.querySelector(s); | ||
if (e) { | ||
e.click(); | ||
} | ||
} | ||
|
||
ipc.on('preferences', () => { | ||
click(el.prefButton); | ||
window.setTimeout(() => { | ||
let w = document.documentElement.scrollWidth / 2 | 0; | ||
let h = document.documentElement.scrollHeight / 2 | 0; | ||
let pref = document.querySelector(el.prefDialog); | ||
let pw = pref.offsetWidth / 2 | 0; | ||
let ph = pref.offsetHeight / 2 | 0; | ||
pref.style.top = `${h - ph}px`; | ||
pref.style.left = `${w - pw}px`; | ||
}, 25); | ||
}); | ||
|
||
ipc.on('log-out', () => { | ||
|
||
}); | ||
|
||
ipc.on('play', () => exec('a.togglePause()')); | ||
ipc.on('next', () => exec('a.next()')); | ||
ipc.on('like', () => click(el.like)); | ||
ipc.on('dislike', () => click(el.dislike)); | ||
ipc.on('mute', () => exec('a.mute()')); | ||
ipc.on('HQ', () => exec('a.toggleHQ()')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
const Config = require('electron-config'); | ||
|
||
module.exports = new Config({ | ||
defaults: { | ||
lastWindowState: { | ||
width: 800, | ||
height: 700 | ||
}, | ||
element: { | ||
prefButton: '.page-root .settings', | ||
prefDialog: '.page-root .settings-stream.popup', | ||
mute: '.page-root .volume__icon', | ||
play: '.page-station .player-controls__play', | ||
next: '.page-station .slider__item_next', | ||
like: '.page-station .button.like_action_like', | ||
dislike: '.page-station .button.like_action_dislike', | ||
activeStation: '.page-index .station_playing' | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const electron = require('electron'); | ||
const menu = require('./menu'); | ||
const config = require('./config'); | ||
|
||
const app = electron.app; | ||
|
||
// require('electron-debug')({enabled: true}); | ||
// require('electron-context-menu')(); | ||
|
||
let win; | ||
let isQuitting = false; | ||
|
||
const isAlreadyRunning = app.makeSingleInstance(() => { | ||
if (win) { | ||
if (win.isMinimized()) { | ||
win.restore(); | ||
} | ||
|
||
win.show(); | ||
} | ||
}); | ||
|
||
if (isAlreadyRunning) { | ||
app.quit(); | ||
} | ||
|
||
function createMainWindow() { | ||
const lastWindowState = config.get('lastWindowState'); | ||
|
||
const win = new electron.BrowserWindow({ | ||
title: app.getName(), | ||
show: false, | ||
x: lastWindowState.x, | ||
y: lastWindowState.y, | ||
width: lastWindowState.width, | ||
height: lastWindowState.height, | ||
icon: process.platform === 'linux' && path.join(__dirname, 'static/Icon.png'), | ||
minWidth: 800, | ||
minHeight: 700, | ||
titleBarStyle: 'hidden-inset', | ||
autoHideMenuBar: true, | ||
backgroundColor: '#fff', | ||
webPreferences: { | ||
preload: path.join(__dirname, 'browser.js'), | ||
nodeIntegration: false, | ||
plugins: true | ||
} | ||
}); | ||
|
||
if (process.platform === 'darwin') { | ||
win.setSheetOffset(40); | ||
} | ||
|
||
win.loadURL('https://radio.yandex.ru/'); | ||
|
||
win.on('close', e => { | ||
if (!isQuitting) { | ||
e.preventDefault(); | ||
|
||
if (process.platform === 'darwin') { | ||
app.hide(); | ||
} else { | ||
win.hide(); | ||
} | ||
} | ||
}); | ||
|
||
win.on('page-title-updated', e => { | ||
e.preventDefault(); | ||
}); | ||
|
||
return win; | ||
} | ||
|
||
app.on('ready', () => { | ||
win = createMainWindow(); | ||
menu.create(win); | ||
|
||
electron.globalShortcut.register('MediaPlayPause', () => win.send('play')); | ||
electron.globalShortcut.register('MediaNextTrack', () => win.send('next')); | ||
|
||
const page = win.webContents; | ||
const argv = require('minimist')(process.argv.slice(1)); | ||
|
||
page.on('dom-ready', () => { | ||
page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8')); | ||
|
||
if (argv.minimize) { | ||
win.minimize(); | ||
} else { | ||
win.show(); | ||
} | ||
}); | ||
|
||
page.on('new-window', (e, url) => { | ||
e.preventDefault(); | ||
electron.shell.openExternal(url); | ||
}); | ||
}); | ||
|
||
app.on('activate', () => win.show()); | ||
|
||
app.on('before-quit', () => { | ||
isQuitting = true; | ||
|
||
electron.globalShortcut.unregister('MediaPlayPause'); | ||
electron.globalShortcut.unregister('MediaNextTrack'); | ||
|
||
if (!win.isFullScreen()) { | ||
config.set('lastWindowState', win.getBounds()); | ||
} | ||
}); |
Oops, something went wrong.