This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Fix touchbar and add repost button to it. #233
Open
Impakt
wants to merge
22
commits into
salomvary:master
Choose a base branch
from
Impakt:add-repost-button-to-touchbar
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
275147e
Fixed touchbar and added repost button to it.
Impakt 727c4b5
fixed context menu and added open in browser link
Impakt 7d509ba
reduced string length again to ensure it appears on the touch bar
Impakt d43b5e6
added image to scrubber
Impakt 62c3c58
load the title to the touch bar, then both once the image has been lo…
Impakt 71c151f
formatting
Impakt a03272d
align touch bar scrubber
Impakt 013c844
removed unnecessary parameter
Impakt 0bef831
fixed eslint issues
Impakt 2285bde
removed context menu fix for another PR
Impakt 25a5800
formatting
Impakt dcc54eb
added padding to the right hand side of hte touchbar scrubber item so…
Impakt 213b778
pad string dynamically
Impakt ab6729a
removed unnecessary error listener
Impakt b4d22f0
display ajax spinner while waiting for artwork to load
99015e5
code style
b56a164
optimised touch bar screen usage
7588385
added repost button
c46da14
added repost button
7316dc3
changed reposted logic
50b0ce7
changed reposted logic
333d73c
attempt at adding media service
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
'use strict' | ||
|
||
const { TouchBar } = require('electron') | ||
const { TouchBar, nativeImage } = require('electron') | ||
|
||
const { TouchBarButton, TouchBarLabel, TouchBarSpacer } = TouchBar | ||
const MAX_TITLE_LENGTH = 38 | ||
const { TouchBarButton, TouchBarScrubber } = TouchBar | ||
|
||
const https = require('https'); | ||
|
||
module.exports = function touchBarMenu(window, soundcloud) { | ||
const nextTrack = new TouchBarButton({ | ||
|
@@ -34,41 +35,65 @@ module.exports = function touchBarMenu(window, soundcloud) { | |
} | ||
}) | ||
|
||
const trackInfo = new TouchBarLabel() | ||
const repost = new TouchBarButton({ | ||
icon: `${__dirname}/res/repost.png`, | ||
click: () => { | ||
soundcloud.repost() | ||
} | ||
}) | ||
|
||
const titleScrubber = new TouchBarScrubber({ | ||
continuous: false, | ||
items:[{ | ||
label: '' | ||
}] | ||
}) | ||
|
||
soundcloud.on('play', ({ title, subtitle }) => { | ||
soundcloud.on('play-new-track', ({ title, subtitle, artworkURL }) => { | ||
let displayTitle = `${title} by ${subtitle}` | ||
displayTitle = displayTitle.padEnd(displayTitle.length * 1.3, ' ') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems hacky but it was the only way to not have the string truncated in the touch bar. You can now swipe on the scrubber to see the whole string |
||
titleScrubber.items = [{ | ||
label: displayTitle | ||
}] | ||
https.get(artworkURL, res => { | ||
const data = []; | ||
res.on('data', chunk => { | ||
data.push(chunk); | ||
}); | ||
res.on('end', () => { | ||
titleScrubber.items = [{ | ||
label:'' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this stops the artwork from having rounded corners on the left hand side |
||
},{ | ||
icon: nativeImage.createFromBuffer(Buffer.concat(data)).resize({height:30, width:30}) | ||
}, { | ||
label: displayTitle | ||
}] | ||
}); | ||
}).on('error', () => { | ||
titleScrubber.items = [{ | ||
label: displayTitle | ||
}] | ||
}); | ||
}) | ||
|
||
soundcloud.on('play', () => { | ||
playPause.icon = `${__dirname}/res/pause.png` | ||
trackInfo.label = formatTitle(title, subtitle) | ||
}) | ||
|
||
soundcloud.on('pause', () => { | ||
playPause.icon = `${__dirname}/res/play.png` | ||
}) | ||
|
||
const touchBar = new TouchBar([ | ||
previousTrack, | ||
playPause, | ||
nextTrack, | ||
likeUnlike, | ||
new TouchBarSpacer({ size: 'flexible' }), | ||
trackInfo, | ||
new TouchBarSpacer({ size: 'flexible' }) | ||
]) | ||
const touchBar = new TouchBar({ | ||
items:[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was the reason why the touchbar wasn't working earlier |
||
previousTrack, | ||
playPause, | ||
nextTrack, | ||
likeUnlike, | ||
repost, | ||
titleScrubber | ||
] | ||
}) | ||
|
||
window.setTouchBar(touchBar) | ||
} | ||
|
||
function formatTitle(title, subtitle) { | ||
const titleAndSubtitle = `${title} by ${subtitle}` | ||
if (titleAndSubtitle.length > MAX_TITLE_LENGTH) { | ||
if (`${title} by X…`.length > MAX_TITLE_LENGTH) { | ||
return truncate(title) | ||
} | ||
return truncate(titleAndSubtitle) | ||
} | ||
return titleAndSubtitle | ||
} | ||
|
||
function truncate(text) { | ||
return text.substring(0, MAX_TITLE_LENGTH - 1) + '…' | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original PR included a reposted icon but no code associated with it. If there was a way to detect if a track has already been reposted we can update the icon, but i'm not sure how to do that.