Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Ponomarev committed Feb 5, 2017
0 parents commit 953e2e4
Show file tree
Hide file tree
Showing 17 changed files with 531 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": ["xo"],
"esnext": true,
"env": {
"node": true,
"browser": true
}
}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
*.js text eol=lf
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
/dist
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 'node'
43 changes: 43 additions & 0 deletions browser.css
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;
}
51 changes: 51 additions & 0 deletions browser.js
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()'));
21 changes: 21 additions & 0 deletions config.js
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'
}
}
});
115 changes: 115 additions & 0 deletions index.js
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());
}
});
Loading

0 comments on commit 953e2e4

Please sign in to comment.