Skip to content

Commit

Permalink
some extra build tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeop committed Apr 21, 2018
1 parent f4e1902 commit 96d3725
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 79 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"electron:prod": "npm run build:electron && electron ./dist/bundle.electron.js",
"watch": "webpack-dev-server --inline --progress --env=dev",
"build:dist": "webpack --progress --colors --env=prod --define process.env.NODE_ENV=production && cp loader.css dist",
"build:electron:linux": "webpack --progress --colors --env.LINUX=true --config=webpack.config.electron.prod.js && cp index.prod.html dist",
"build:electron": "webpack --progress --colors --config=webpack.config.electron.prod.js && cp index.prod.html dist",
"build:electron:linux": "webpack --progress --colors --env.LINUX=true --config=webpack.config.electron.prod.js && cp index.prod.html dist/index.html",
"build:electron": "webpack --progress --colors --config=webpack.config.electron.prod.js && cp index.prod.html dist/index.html",
"test": "mocha --require babel-register",
"pack": "electron-builder --dir -c.extraMetadata.main=dist/bundle.electron.js",
"dist": "babel-node electron-builder -c.extraMetadata.main=dist/bundle.electron.js",
Expand Down Expand Up @@ -112,11 +112,12 @@
},
"files": [
"dist/",
"resources/",
"index.prod.html",
"dist/electron.bundle.js",
"package.json"
],
"extraFiles": [
"resources"
],
"linux": {
"desktop": {
"Name": "Nuclear",
Expand Down
Binary file added resources/media/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions server/main.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ const platform = require('electron-platform');
const path = require('path');
const url = require('url');
const getOption = require('./store').getOption;
var Player;


let win;
let player;
let tray;
let icon = nativeImage.createFromPath(path.resolve(__dirname, 'resources', 'media', 'icon.png'));

Expand All @@ -22,11 +19,14 @@ function createWindow() {
height: 768,
frame: !getOption('framelessWindow'),
icon: icon,
show: false,
webPreferences: {
experimentalFeatures: true
}
});

win.setTitle('nuclear music player');

installExtension(REACT_DEVELOPER_TOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
Expand All @@ -41,6 +41,10 @@ function createWindow() {
slashes: true
}));

win.once('ready-to-show', () => {
win.show()
});

win.webContents.openDevTools();

win.on('closed', () => {
Expand Down Expand Up @@ -78,7 +82,7 @@ function createWindow() {
ipcMain.on('maximize', () => {
win.isMaximized() ? win.unmaximize() : win.maximize();
});

ipcMain.on('songChange', (event, arg) => {
if (arg === null) {
return;
Expand Down
15 changes: 11 additions & 4 deletions server/main.dev.linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ function createWindow() {
height: 768,
frame: !getOption('framelessWindow'),
icon: icon,
show: false,
webPreferences: {
experimentalFeatures: true
}
});

win.setTitle('nuclear music player');

installExtension(REACT_DEVELOPER_TOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
Expand All @@ -46,6 +49,10 @@ function createWindow() {
slashes: true
}));

win.once('ready-to-show', () => {
win.show()
});

win.webContents.openDevTools();

win.on('closed', () => {
Expand Down Expand Up @@ -115,13 +122,13 @@ function createWindow() {

player.metadata = {
'mpris:trackid': player.objectPath('track/0'),
'mpris:artUrl': arg.thumbnail,
'xesam:title': arg.name,
'xesam:artist': arg.artist
'mpris:artUrl': arg.thumbnail,
'xesam:title': arg.name,
'xesam:artist': arg.artist
};

if (arg.streams && arg.streams.length > 0) {
player.metadata['mpris:length'] = arg.streams[0].duration * 1000 * 1000; // In microseconds
player.metadata['mpris:length'] = arg.streams[0].duration * 1000 * 1000; // In microseconds
}
});

Expand Down
79 changes: 14 additions & 65 deletions server/main.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ const { app, ipcMain, nativeImage, BrowserWindow, Menu, Tray } = require('electr
const platform = require('electron-platform');
const path = require('path');
const url = require('url');
const mpris = require('./mpris');
const getOption = require('./store').getOption;
var Player;

// GNU/Linux-specific
if (!platform.isDarwin && !platform.isWin32) {
Player = require('mpris-service');
}

let win;
let player;
let tray;
let icon = nativeImage.createFromPath(path.resolve(__dirname, 'resources', 'media', 'icon.png'));

Expand All @@ -26,17 +18,24 @@ function createWindow() {
height: 768,
frame: !getOption('framelessWindow'),
icon: icon,
show: false,
webPreferences: {
experimentalFeatures: true
}
});

win.setTitle('nuclear music player');

win.loadURL(url.format({
pathname: path.join(__dirname, 'index.prod.html'),
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));

win.once('ready-to-show', () => {
win.show()
});

win.on('closed', () => {
win = null;
});
Expand Down Expand Up @@ -72,62 +71,12 @@ function createWindow() {
win.isMaximized() ? win.unmaximize() : win.maximize();
});

// GNU/Linux-specific
if (!platform.isDarwin && !platform.isWin32) {
player = Player({
name: 'nuclear',
identity: 'nuclear music player',
supportedUriSchemes: ['file'],
supportedMimeTypes: ['audio/mpeg', 'application/ogg'],
supportedInterfaces: ['player'],
desktopEntry: 'nuclear'
});

player.on('quit', function () {
win = null;
});

player.on('next', mpris.onNext);
player.on('previous', mpris.onPrevious);
player.on('pause', mpris.onPause);
player.on('playpause', mpris.onPlayPause);
player.on('stop', mpris.onStop);
player.on('play', mpris.onPlay);

ipcMain.on('songChange', (event, arg) => {
if (arg === null) {
return;
}

changeWindowTitle(arg.artist, arg.name);

player.metadata = {
'mpris:trackid': player.objectPath('track/0'),
'mpris:artUrl': arg.thumbnail,
'xesam:title': arg.name,
'xesam:artist': arg.artist
};

if (arg.streams && arg.streams.length > 0) {
player.metadata['mpris:length'] = arg.streams[0].duration * 1000 * 1000; // In microseconds
}
});

ipcMain.on('play', (event, arg) => {
player.playbackStatus = 'Playing';
});

ipcMain.on('paused', (event, arg) => {
player.playbackStatus = 'Paused';
});
} else {
ipcMain.on('songChange', (event, arg) => {
if (arg === null) {
return;
}
changeWindowTitle(arg.artist, arg.name);
});
}
ipcMain.on('songChange', (event, arg) => {
if (arg === null) {
return;
}
changeWindowTitle(arg.artist, arg.name);
});
}

app.on('ready', createWindow);
Expand Down
9 changes: 8 additions & 1 deletion server/main.prod.linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,24 @@ function createWindow() {
height: 768,
frame: !getOption('framelessWindow'),
icon: icon,
show: false,
webPreferences: {
experimentalFeatures: true
}
});

win.setTitle('nuclear music player');

win.loadURL(url.format({
pathname: path.join(__dirname, 'index.prod.html'),
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));

win.once('ready-to-show', () => {
win.show()
});

win.on('closed', () => {
win = null;
});
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.electron.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const HappyPack = require('happypack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = env => {
let entry = env && env.LINUX ? './server/main.dev.linux.js' : './server/main.dev.js';
let entry = env && env.LINUX ? './server/main.prod.linux.js' : './server/main.prod.js';

return {
entry: entry,
Expand Down

0 comments on commit 96d3725

Please sign in to comment.