Skip to content

Commit

Permalink
Merge pull request #22 from Gabe-H/beta
Browse files Browse the repository at this point in the history
v4.3.0
  • Loading branch information
kyleawayan authored Sep 25, 2020
2 parents fc5afb3 + a126ef8 commit 771e794
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 39 deletions.
48 changes: 41 additions & 7 deletions app/main.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
const { app, BrowserWindow, ipcMain } = require("electron");
const windowStateKeeper = require('electron-window-state');
var SpotifyWebApi = require("spotify-web-api-node");
const { autoUpdater } = require("electron-updater");
var fetch = require('node-fetch');
var express = require("express");
var fetch = require('node-fetch')
var express = express();
const path = require("path");
require('dotenv').config();
var SpotifyWebApi = require("spotify-web-api-node");
var express = express();
require("./videos");
const path = require("path");

autoUpdater.checkForUpdatesAndNotify();
var server = express.listen(8080, "localhost");

const base_url = 'https://gemini-authorization.herokuapp.com/' // Include trailing '/'
// OPTIONAL: define client credentials in
// OPTIONAL: define client credentials in .env
const CLIENT_ID = process.env.CLIENT_ID || null;
const CLIENT_SECRET = process.env.CLIENT_SECRET || null;
const scopes = ["user-modify-playback-state", "user-read-playback-state"];
Expand All @@ -34,9 +35,15 @@ if (CLIENT_ID == null && CLIENT_SECRET == null) {

var win;
function createWindow() {
let mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 800
});
win = new BrowserWindow({
width: 640,
height: 640,
'x': mainWindowState.x,
'y': mainWindowState.y,
'width': mainWindowState.width,
'height': mainWindowState.height,
minWidth: 200,
minHeight: 200,
title: "Gemini",
Expand Down Expand Up @@ -66,6 +73,7 @@ function createWindow() {
var url = spotifyApi.createAuthorizeURL(scopes, '');
win.loadURL(url);
}
mainWindowState.manage(win);
}

// Callback path after Spotify auth
Expand Down Expand Up @@ -301,6 +309,32 @@ ipcMain.on("buttons", (event, arg) => {
break;
}
});
// Set window width to window height
ipcMain.on("set-square", (event, arg) => {
width = (win.getSize())[0];
height = (win.getSize())[1];
if (width < height) {
win.setSize(width, width);
} else if (height < width) {
win.setSize(height, height);
};
});
// Search Spotify for local files
ipcMain.on("search", (event, args) => {
console.log('searching for ', args)
spotifyApi.search(args, ['track'], {limit : 1}).then(function(data) {
if (data.body.tracks.items[0]) {
var imgURL = data.body.tracks.items[0].album.images[0].url;
console.log(imgURL);
event.reply("local-reply", imgURL);
} else {
console.log('no image');
event.reply("local-reply", '')
}
}, function (err) {
console.log(err)
}).catch((err) => catch_error(err))
});

function restart_express() {
server.listen(8080, "localhost");
Expand Down
6 changes: 5 additions & 1 deletion app/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ contextBridge.exposeInMainWorld("actions", {
minimize: () => ipcRenderer.send("buttons", "minimize"),
maximize: () => ipcRenderer.send("buttons", "maximize"),
top: () => ipcRenderer.send("buttons", "top"),
topmac: () => ipcRenderer.send("buttons", "topmac")
topmac: () => ipcRenderer.send("buttons", "topmac"),
topmac: () => ipcRenderer.send("buttons", "topmac"),

square: () => ipcRenderer.send("set-square", ""),
search: (args) => ipcRenderer.send("search", args)
});

contextBridge.exposeInMainWorld("controls", {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gemini",
"version": "4.2.1",
"version": "4.3.0",
"description": "Aesthetic now playing screen for Spotify",
"main": "./app/main.js",
"scripts": {
Expand All @@ -18,6 +18,7 @@
"@fortawesome/fontawesome-free": "^5.14.0",
"dotenv": "^8.2.0",
"electron-updater": "^4.3.4",
"electron-window-state": "^5.0.3",
"express": "^4.17.1",
"jquery": "^3.5.1",
"node-fetch": "^2.6.1",
Expand Down
73 changes: 44 additions & 29 deletions src/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,72 @@ window.playing.init();
// Initial setup
ipcRenderer.on("init-playing-reply", (event, data) => {
switch (data.statusCode) {
case 200:
case 200: // Song is playing
switch (data.body.item.is_local) {
case false:
case false: // Non local music
switch (data.body.currently_playing_type) {
case "track":
case "track": // For track (not podcast)
var thisName = data.body.item.name;
if (
data.body.item.name.includes("Remix") ||
data.body.item.name.includes("Mix") ||
data.body.item.name.includes("Version") ||
data.body.item.name.includes("Live") ||
data.body.item.name.includes("Ver.") ||
data.body.item.name.includes("ver.")
thisName.includes("Remix") ||
thisName.includes("Mix") ||
thisName.includes("Version") ||
thisName.includes("Live") ||
thisName.includes("Ver.") ||
thisName.includes("ver.")
) {
document.getElementById(
"song"
).innerHTML = data.body.item.name.split(/\[/)[0];
document.getElementById("song").innerHTML = data.body.item.name.split(/\[/)[0];
} else {
document.getElementById(
"song"
).innerHTML = data.body.item.name.split(/[\[(-]/)[0];
}
}; // Special title cases

// Initialize background var
myBg = `<img src="${data.body.item.album.images[0].url}">`;
// Check if song uri has a video (defined in gemini-media repo)
window.doesSong.haveVideo(data.body.item.uri);
fadeIn();
setInterval(update, update_ms);
mySong = data.body.item.id;
var thisArtist = data.body.item.artists;
var showArtist = data.body.item.artists[0].name;
for (i = 1; i < data.body.item.artists.length; i++) {

mySong = data.body.item.id; // Set song placeholder
var thisArtist = data.body.item.artists; // .artists array in json response
var showArtist = data.body.item.artists[0].name; // Temporary artist string
for (i = 1; i < data.body.item.artists.length; i++) { // Append to showArtist if more than 1 artist
showArtist += ", " + thisArtist[i].name;
}
document.getElementById("artist").innerHTML = showArtist;
};
document.getElementById("artist").innerHTML = showArtist; // Artist element to appended artist str
fadeIn(); // Show text on screen

// Set album placeholder
myAlbum = data.body.item.album.id;
// Trigger functions
set_toggle(data.body.is_playing);
set_shuffle(data.body.shuffle_state);
set_repeat(data.body.repeat_state);
myRepeat = data.body.repeat_state;
// Start sending 1s updates to main.js
setInterval(update, update_ms);
break;
case "episode":
case "episode": // Case podcast
// Not enough info from API yet,
set_podcast(data);
// Start sending 1s updates to main.js
setInterval(update, update_ms);
break;
}
break;
case true:
case true: // Case local track
mySong = data.body.item.uri;
var song = data.body.item.name;
var artist = data.body.item.artists[0].name
var args = song;
console.log(mySong)
window.doesSong.haveVideo(mySong);
console.log(mySong); // Log song uri since it's not obtainable from Spotify app. For use with a special case
window.doesSong.haveVideo(mySong); // Check for special

if (artist != '') {
args = song+' '+artist;
}
};
window.actions.search([
args
]);
if (data.body.item.artists[0].name == ''){
document.getElementById('artist').innerHTML = '';
} else {
Expand All @@ -101,7 +113,6 @@ ipcRenderer.on("init-playing-reply", (event, data) => {
set_toggle(data.body.is_playing);
set_shuffle(data.body.shuffle_state);
set_repeat(data.body.repeat_state);
myRepeat = data.body.repeat_state;
break;
}
break;
Expand Down Expand Up @@ -251,7 +262,10 @@ function show_data(data) {
var args = song;
if (artist != '') {
args = song+' '+artist;
}
};
window.actions.search([
args
]);
mySong = data.body.item.uri;
console.log(mySong);
fadeOut();
Expand Down Expand Up @@ -291,6 +305,7 @@ function set_shuffle(data) {
}

function set_repeat(data) {
myRepeat = data;
switch(data) {
case 'off':
$("#repeat").removeClass().addClass("fas fa-sync-alt");
Expand Down
2 changes: 2 additions & 0 deletions src/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function showHeader() {
function doc_keyUp(e) {
if (e.ctrlKey && e.keyCode == 83) {
window.reset.signin();
} else if (e.ctrlKey && e.keyCode == 68) {
window.actions.square()
} else {
switch (e.keyCode) {
case 27:
Expand Down
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,14 @@ electron-updater@^4.3.4:
lodash.isequal "^4.5.0"
semver "^7.3.2"

electron-window-state@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/electron-window-state/-/electron-window-state-5.0.3.tgz#4f36d09e3f953d87aff103bf010f460056050aa8"
integrity sha512-1mNTwCfkolXl3kMf50yW3vE2lZj0y92P/HYWFBrb+v2S/pCka5mdwN3cagKm458A7NjndSwijynXgcLWRodsVg==
dependencies:
jsonfile "^4.0.0"
mkdirp "^0.5.1"

electron@^10.1.1:
version "10.1.1"
resolved "https://registry.yarnpkg.com/electron/-/electron-10.1.1.tgz#44ff9207afc9df253d3b5ea40c7e6513c5dc08d8"
Expand Down Expand Up @@ -1310,7 +1318,7 @@ minimist@^1.2.0, minimist@^1.2.5:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==

mkdirp@^0.5.4:
mkdirp@^0.5.1, mkdirp@^0.5.4:
version "0.5.5"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def"
integrity sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==
Expand Down

0 comments on commit 771e794

Please sign in to comment.