Skip to content

Commit 7de2183

Browse files
committed
Moved to electron-webpack directory structure
- smaller app icon - much less devDependencies (more to cull...) - moved renovate config into package.json - added DEBUG and LOCAL modes to dev easier with static files
1 parent e3de234 commit 7de2183

21 files changed

+2840
-238
lines changed

Diff for: .dockerignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222
dist/
2323
build/
2424
README.md
25-
renovate.json
26-
screenshot.png
25+
Screenshot.png

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.env
2+
Electron.app
13
node_modules/
24
dist/
35
build/
6+
app_contents/

Diff for: .vscode/settings.json

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,22 @@
88
"env": {
99
"es6": true
1010
}
11-
}
11+
},
12+
"workbench.colorCustomizations": {
13+
"activityBar.background": "#7da4b5",
14+
"activityBar.activeBackground": "#7da4b5",
15+
"activityBar.activeBorder": "#8e517c",
16+
"activityBar.foreground": "#15202b",
17+
"activityBar.inactiveForeground": "#15202b99",
18+
"activityBarBadge.background": "#8e517c",
19+
"activityBarBadge.foreground": "#e7e7e7",
20+
"titleBar.activeBackground": "#5c8da3",
21+
"titleBar.inactiveBackground": "#5c8da399",
22+
"titleBar.activeForeground": "#15202b",
23+
"titleBar.inactiveForeground": "#15202b99",
24+
"statusBar.background": "#5c8da3",
25+
"statusBarItem.hoverBackground": "#4a7182",
26+
"statusBar.foreground": "#15202b"
27+
},
28+
"peacock.color": "#5c8da3"
1229
}

Diff for: MixCloud.icns

4.22 KB
Binary file not shown.

Diff for: README.md

+30-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ Mixcloud Play
22
=====
33
Mixcloud Play is the missing desktop experience for [Mixcloud.com](https://www.mixcloud.com) with support for media controls and showing current track in menu bar. Enjoy listening to new music for hours...
44

5-
## [Download for Mac](https://github.com/mountainash/MixCloud-Play/releases/download/v0.9.7/MixCloud.Play.app.zip)
5+
## [Download for Mac](https://github.com/mountainash/Mixcloud-Play/releases/download/v0.9.7/MixCloud.Play.app.zip)
66

7-
![screenshot](https://raw.githubusercontent.com/uffou/MixCloud-Play/master/Screenshot.png)
7+
![screenshot](https://raw.githubusercontent.com/mountainash/Mixcloud-Play/master/Screenshot.png)
88

99
## Features
1010
1. Media controls - play/pause, next
@@ -13,22 +13,41 @@ Mixcloud Play is the missing desktop experience for [Mixcloud.com](https://www.m
1313
4. Modern desktop look
1414

1515
## Getting started
16+
## Building
17+
```sh
18+
yarn dist
19+
```
20+
21+
### Development
22+
Download "Electron.app" into the project root.
23+
1624
```sh
1725
yarn
18-
yarn watch
19-
yarn start
26+
yarn build:local
27+
Electron.app/Contents/MacOS/Electron .
2028
```
2129

22-
## Building
30+
Use the compile macOS .app with Dev Tools and some extra debugging enabled.
31+
2332
```sh
24-
yarn dist
25-
OR
26-
yarn pack
33+
yarn
34+
yarn dist:debug
2735
```
2836

29-
## Docker
37+
38+
### Docker Compose
3039
```sh
3140
docker-compose build
32-
docker-compose run --rm mixcloud-play
41+
docker-compose run --rm mixcloud-play {any command here}
3342
```
34-
Built app will output to `./dist/mac/MixCloud Play.app`
43+
44+
Built app will output to `./dist/mac/Mixcloud Play.app`
45+
46+
## Dev Tips
47+
### Asar Extract
48+
Linking/locating files inside the build can be hard to know what's going on inside the app.asar (inside Electron). Us the following commands to extract the contents of the .asar.
49+
50+
1. Build the app fist `docker-compose run --rm mixcloud-play`
51+
1. `docker run --rm -it -v $(pwd):/project electronuserland/builder:12-11.19` to enter bash inside the container
52+
1. `npm install -g asar`
53+
1. `asar extract dist/mac/Mixcloud\ Play.app/Contents/Resources/app.asar app_contents` will extract the MacOS "dist" contents to `/app_contents/`

Diff for: docker-compose.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ version: "3"
22

33
services:
44
mixcloud-play:
5-
image: electronuserland/builder:wine-mono-11.19
5+
image: electronuserland/builder:12-11.19
66
volumes:
7-
- .:/usr/src/app
8-
- ./node_modules:/project/node_modules
7+
- .:/project
98
- ~/.cache/electron:/root/.cache/electron
109
- ~/.cache/electron-builder:/root/.cache/electron-builder
1110
environment:
1211
ELECTRON_CACHE: "/root/.cache/electron"
1312
ELECTRON_BUILDER_CACHE: "/root/.cache/electron-builder"
14-
working_dir: /usr/src/app
13+
working_dir: /project
1514
command: /bin/bash -c "yarn && yarn dist"

Diff for: package.json

+39-19
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"macOS",
99
"mixcloud",
1010
"wrapper",
11-
"media keys"
11+
"media keys",
12+
"electron"
1213
],
1314
"author": {
1415
"name": "Codemotion Ltd."
@@ -25,43 +26,62 @@
2526
"type": "git",
2627
"url": "[email protected]:uffou/MixCloud-Play.git"
2728
},
29+
"homepage": "https://github.com/uffou/MixCloud-Play/issues",
2830
"bugs": {
2931
"url": "https://github.com/uffou/MixCloud-Play/issues"
3032
},
3133
"license": "UNLICENSED",
3234
"scripts": {
33-
"start": "electron .",
34-
"pack": "electron-builder --dir",
35-
"build": "electron-builder --dir -m",
36-
"dist": "electron-builder -m"
35+
"dev": "electron-webpack dev",
36+
"compile": "electron-webpack",
37+
"compile:debug": "ELECTRON_WEBPACK_APP_DEBUG=true electron-webpack",
38+
"compile:local": "ELECTRON_WEBPACK_APP_LOCAL=true yarn compile:debug",
39+
"build": "electron-builder --mac",
40+
"dist": "yarn compile && yarn build",
41+
"dist:debug": "yarn compile:debug && yarn build",
42+
"dist:dir": "yarn dist --dir -c.compression=store -c.mac.identity=null"
43+
},
44+
"electronWebpack": {
45+
"title": false,
46+
"staticSourceDirectory": "static",
47+
"main": {
48+
"extraEntries": ["@/preload.js"]
49+
},
50+
"renderer": {
51+
"template": "src/renderer/index.html"
52+
}
3753
},
3854
"build": {
3955
"files": [
40-
"build"
56+
"static"
4157
],
4258
"appId": "com.codemotionapps.mixcloud",
4359
"copyright": "Copyright © 2019 Codemotion Ltd.",
4460
"productName": "Mixcloud Play",
4561
"mac": {
62+
"target": "tar.gz",
4663
"category": "public.app-category.music",
47-
"icon": "Mixcloud.icns",
48-
"target": "dmg"
64+
"icon": "Mixcloud.icns"
4965
}
5066
},
51-
"main": "build/main.js",
67+
"main": "dist/main/main.js",
5268
"devDependencies": {
5369
"@babel/core": "7.8.7",
5470
"@babel/plugin-proposal-class-properties": "7.8.3",
55-
"@babel/plugin-proposal-decorators": "7.8.3",
56-
"@babel/plugin-proposal-function-bind": "7.8.3",
5771
"@babel/preset-env": "7.8.7",
58-
"babel-loader": "8.0.6",
5972
"copy-webpack-plugin": "5.1.1",
60-
"electron": "3",
61-
"electron-builder": "^22.4.0",
62-
"webpack": "4.42.0",
63-
"webpack-cli": "3.3.11"
73+
"electron": "3.1.13",
74+
"electron-builder": "22.4.0",
75+
"electron-webpack": "2.7.4",
76+
"webpack": "4.42.0"
77+
},
78+
"resolutions": {
79+
"webpack-sources": "1.4.3"
80+
},
81+
"dependencies": {
82+
"source-map-support": "0.5.16"
6483
},
65-
"dependencies": {},
66-
"postinstall": "electron-builder install-app-deps"
67-
}
84+
"renovate": {
85+
"extends": ["config:base"]
86+
}
87+
}

Diff for: renovate.json

-5
This file was deleted.

Diff for: src/@util/noop.js

-1
This file was deleted.

Diff for: src/main.js renamed to src/main/main.js

+67-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const path = require('path');
1+
// 'use strict'
22

3-
const {
3+
import {
44
app,
55
BrowserWindow,
66
globalShortcut,
@@ -9,23 +9,41 @@ const {
99
Notification,
1010
Tray,
1111
shell
12-
} = require('electron');
13-
const menuTemplate = require(`./menu`);
12+
} from 'electron'
1413

15-
var mainWindow = null;
16-
var tray = null;
17-
var contextMenu = null;
14+
import * as path from 'path'
15+
import * as url from 'url'
16+
17+
const DEBUG = process.env.ELECTRON_WEBPACK_APP_DEBUG || false
18+
const LOCAL = process.env.ELECTRON_WEBPACK_APP_LOCAL || false
19+
20+
if (DEBUG)
21+
console.log(JSON.stringify(process.env, null, 4))
22+
console.info(__dirname)
23+
console.info(__static)
24+
25+
const getStatic = (val) => {
26+
if (LOCAL) {
27+
return path.resolve(__dirname, '../../static/'+val) // __dirname is /build/main/
28+
}
29+
return path.resolve(__static, val)
30+
}
31+
32+
let mainWindow = null
33+
const menuTemplate = require('./menu.js')
34+
35+
let tray = null;
36+
let contextMenu = null;
1837
var _isPlaying = false;
19-
var DEBUG = false;
2038

2139
const toggleWindow = () => {
2240
mainWindow.show();
2341
mainWindow.focus();
24-
};
42+
}
2543

26-
async function initTray() {
44+
const initTray = () => {
2745
if (!tray) {
28-
tray = new Tray(path.join(__dirname, './img/logoTemplate.png'));
46+
tray = new Tray(getStatic('logoTemplate.png'));
2947
tray.on('click', togglePlay);
3048
tray.on('right-click', displayContextMenu);
3149
tray.on('double-click', toggleWindow);
@@ -80,21 +98,45 @@ app.on('ready', () => {
8098

8199
mainWindow = new BrowserWindow({
82100
titleBarStyle: 'hiddenInset',
101+
backgroundColor: '#ADADAD',
83102
width: 1100,
84103
minWidth: 768,
85104
height: 800,
86105
minHeight: 400,
106+
isMinimizable: false, // don't seem to work in current version
107+
isMaximizable: false,
87108
webPreferences: {
88-
// preload: 'preload.js', //
109+
preload: 'preload.js',
89110
nodeIntegration: true //TODO turn this off
90111
}
91-
});
112+
})
92113

93-
mainWindow.loadFile(path.join(__dirname, 'index.html'));
94-
//mainWindow.loadURL(path.join('file://', __dirname, '/index.html'))
114+
let template_path = LOCAL ? '../renderer/index.html' : 'index.html'
115+
116+
mainWindow.loadURL(url.format({
117+
pathname: path.join(__dirname, template_path),
118+
protocol: 'file'
119+
}))
95120

96121
if (DEBUG) {
97-
mainWindow.openDevTools();
122+
// mainWindow.openDevTools();
123+
124+
// auto-open dev tools
125+
mainWindow.webContents.on('did-frame-finish-load', () => {
126+
mainWindow.webContents.openDevTools();
127+
})
128+
129+
// add inspect element on right click menu
130+
mainWindow.webContents.on('context-menu', (e, props) => {
131+
Menu.buildFromTemplate([
132+
{label: 'Inspect element',
133+
click() {
134+
mainWindow.inspectElement(props.x, props.y);
135+
},
136+
},
137+
]).popup(mainWindow);
138+
});
139+
98140
}
99141

100142
// mainWindow.on('focus', () => {
@@ -232,4 +274,12 @@ ipcMain.on('handlePlay', (_, track) => {
232274
setTimeout(() => {
233275
notification.close();
234276
}, 7000);
235-
});
277+
});
278+
279+
app.on('window-all-closed', () => {
280+
// On OS X it is common for applications and their menu bar
281+
// to stay active until the user quits explicitly with Cmd + Q
282+
if (process.platform !== 'darwin') {
283+
app.quit()
284+
}
285+
})

Diff for: src/menu.js renamed to src/main/menu.js

File renamed without changes.

Diff for: src/preload.js renamed to src/main/preload.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const path = require(`path`);
22

33
const { ipcRenderer, webFrame, shell } = require(`electron`);
44

5+
console.log('preload called');
6+
57
// Open all links in external browser
68
document.addEventListener('click', function(event) {
79
if (event.target.href) {

Diff for: src/index.html renamed to src/renderer/index.html

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset="utf-8" />
4+
<meta charset="utf-8">
55
<title>Mixcloud Play</title>
6-
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
76
</head>
87
<body>
9-
<div id="dragger"></div>
10-
<div id="hud">
8+
<div id="hud" style="display:none">
119
<div id="info">
1210
<p id="name"><span class="label">ℹ️</span> <span id="title">track title</span> <span id="artist">track artist</span></p>
1311
<p id="link"><span class="label">🔗</span> <span id="url">https://mixcloud.com/play/this/song</span></p>
@@ -24,10 +22,9 @@
2422
allowpopups
2523
disablewebsecurity
2624
preload="./preload.js"
27-
src="https://www.mixcloud.com"
25+
src="https://www.mixcloud.com/"
2826
partition="persist:mixcloud"
2927
webpreferences="nativeWindowOpen=true;experimentalFeatures"
3028
></webview>
31-
<script src="renderer.js"></script>
3229
</body>
3330
</html>

0 commit comments

Comments
 (0)