Skip to content

Commit

Permalink
Merge pull request #73 from mountainash/develop
Browse files Browse the repository at this point in the history
Dep updates and allowing login with Facebook
  • Loading branch information
mountainash authored Jun 6, 2021
2 parents 041edb8 + eebc9ec commit e29bdda
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 400 deletions.
4 changes: 0 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

[package.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Screenshot.pxd
node_modules/
dist/
build/
app_contents/
*app_contents/
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": true
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ npm run build
npm run start
```

Use the compile macOS .app with Dev Tools and some extra debugging enabled:
Use the compile macOS .app with Chromium Dev Tools and some extra debugging enabled:

```sh
npm run build:debug
Expand All @@ -52,13 +52,13 @@ docker-compose run --rm mixcloud-play {any command here}
Built app will output to `./dist/mac/Mixcloud Play.app`

### Auto Update Publishing (GitHub)
Publish app updates is set-up as per the [GithubOptions](https://www.electron.build/configuration/publish#githuboptions) for Electron Build's [Auto Update](https://www.electron.build/auto-update).
Publish app updates is set-up as per the [GithubOptions](https://www.electron.build/configuration/publish#githuboptions) for Electron Builds [Auto Update](https://www.electron.build/auto-update).

1. Update the app version number in both `package*.json` files.

```sh
export GH_TOKEN={token_with_repo_scope}
npm run publish:draft
npm run publish
```

A release in the specified GitHub repo should be drafted and ready for release.
Expand All @@ -68,6 +68,6 @@ A release in the specified GitHub repo should be drafted and ready for release.
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.

1. Build the app fist `docker-compose run --rm mixcloud-play`
1. `docker run --rm -it -v $(pwd):/project electronuserland/builder:12-11.19` to enter bash inside the container
1. `docker run --rm -it -v $(pwd):/project electronuserland/builder:14-05.21` to enter bash inside the container
1. `npm install -g asar`
1. `asar extract dist/mac/Mixcloud\ Play.app/Contents/Resources/app.asar app_contents` will extract the MacOS "dist" contents to `/app_contents/`
8 changes: 4 additions & 4 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ if (DEBUG) {
webview.openDevTools();
});
webview.addEventListener('console-message', (event) => {
console.log('Guest page logged a message:', event.message)
console.log('Guest page logged a message:', event.message);
});
}

Expand Down Expand Up @@ -224,15 +224,15 @@ webview.addEventListener('DOMContentLoaded', () => {
// add a listener to the form to capture login details and store them
const loginbutton = loginform.querySelector(DomHooks.loginbutton);

loginbutton.addEventListener('click', () => {
loginbutton.addEventListener('click', async () => {
let username = loginform.querySelector(DomHooks.usernameinput).value;
let password = loginform.querySelector(DomHooks.passwordinput).value;

if (username && password) {
// delete any exiting logins
keyStore.DeleteKeys();
await keyStore.DeleteKeys();
// store the users details for auto-login next time
keyStore.AddKey(username, password);
await keyStore.AddKey(username, password);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"

services:
mixcloud-play:
image: electronuserland/builder:12-11.19
image: electronuserland/builder:14-05.21
volumes:
- .:/project
- ~/.cache/electron:/root/.cache/electron
Expand Down
52 changes: 43 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ app.on('second-instance', () => {
const toggleWindow = () => {
win.show();
win.focus();
}
};

const initTray = () => {
if (!tray) {
Expand All @@ -76,6 +76,23 @@ function displayTrayContextMenu() {
tray.popUpContextMenu(trayContextMenu);
}

function basicURL(url) {
if (typeof url !== 'string') return false;

const parsed = new URL(url);
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:')
return false;

return true;
}

function isURLAllowed(url) {
return [
/^https:\/\/www\.facebook\.com\/.*/i,
/^https:\/\/www\.mixcloud\.com\/.*/i
].some((re) => url.match(re));
}

app.on('activate', () => { win.show() });
app.on('before-quit', () => isQuitting = true);

Expand Down Expand Up @@ -115,9 +132,26 @@ app.on('ready', () => {
page = win.webContents;

// Open new browser window on external open
page.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
page.setWindowOpenHandler(({url}) => {
if (url.startsWith('https://www.facebook.com/')) return { action: 'allow' };
else if (basicURL(url)) shell.openExternal(url);
return { action: 'deny' };
});

page.on('will-navigate', (e, url) => {
if (basicURL(url) && !isURLAllowed(url)) {
e.preventDefault();
shell.openExternal(url);
}
});

page.on('will-redirect', (e, url) => {
// `will-navigate` doesn't catch redirects
if (basicURL(url) && !isURLAllowed(url)) {
e.preventDefault();
win.loadURL(BASE_URL);
shell.openExternal(url);
}
});

if (DEBUG) {
Expand All @@ -127,7 +161,7 @@ app.on('ready', () => {
page.on('did-frame-finish-load', () => {
page.openDevTools();
});
};
}

page.on('dom-ready', () => {
page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8'));
Expand Down Expand Up @@ -168,7 +202,7 @@ app.on('ready', () => {
console.log('MediaNextTrack registration bound!');
}

var registered = globalShortcut.register('MediaPlayPause', () => {
registered = globalShortcut.register('MediaPlayPause', () => {
console.log('MediaPlayPause pressed', _isPlaying);
togglePlay();
});
Expand All @@ -178,7 +212,7 @@ app.on('ready', () => {
console.log('MediaPlayPause registration bound!');
}

var registered = globalShortcut.register('MediaPreviousTrack', () => {
registered = globalShortcut.register('MediaPreviousTrack', () => {
console.log('MediaPreviousTrack pressed');
page.send('back');
});
Expand All @@ -188,7 +222,7 @@ app.on('ready', () => {
console.log('MediaPreviousTrack registration bound!');
}

var registered = globalShortcut.register('MediaStop', () => {
registered = globalShortcut.register('MediaStop', () => {
console.log('MediaStop pressed');
});
if (!registered) {
Expand Down Expand Up @@ -269,7 +303,7 @@ ipcMain.on('nowPlaying', (_, title, subtitle) => {
ipcMain.on('handlePlay', (_, track) => {
app.dock.setBadge('');

tray.setTitle(track)
tray.setTitle(track);

const notification = new Notification({
title: 'Playing...',
Expand Down
Loading

0 comments on commit e29bdda

Please sign in to comment.