this might not be happening

This commit is contained in:
Core 2022-01-07 14:50:06 +00:00
parent d15ee4de30
commit 8e1d2dc96b
No known key found for this signature in database
GPG key ID: 1B77805746C47C28
3 changed files with 385 additions and 241 deletions

View file

@ -1,55 +1,54 @@
const {join} = require("path"),
{ipcMain, app, shell, screen} = require("electron"),
express = require("express"),
path = require("path"),
getPort = require("get-port"),
yt = require("youtube-search-without-api-key"),
os = require("os");
const { BrowserWindow, ipcMain, shell, app, screen } = require("electron")
const { join } = require("path")
const getPort = require("get-port");
const express = require("express");
const path = require("path");
const windowStateKeeper = require("electron-window-state");
const os = require('os');
const yt = require('youtube-search-without-api-key');
const discord = require('./discordrpc');
const lastfm = require('./lastfm');
const { writeFile, writeFileSync, existsSync, mkdirSync } = require('fs');
const fs = require('fs');
const mpris = require('./mpris');
const mm = require('music-metadata');
const fetch = require('electron-fetch').default;
const { Stream } = require('stream');
module.exports = {
// Analytics for debugging.
const ElectronSentry = require("@sentry/electron");
ElectronSentry.init({ dsn: "https://68c422bfaaf44dea880b86aad5a820d2@o954055.ingest.sentry.io/6112214" });
browserWindow: {},
clientPort: 0,
EnvironmentVariables: {
"env": {
platform: os.platform(),
dev: app.isPackaged
}
},
//-------------------------------------------------------------------------------
// Public Methods
//-------------------------------------------------------------------------------
/**
* Creates the BrowserWindow for the application.
* @return {object} BrowserWindow
*/
async createBrowserWindow() {
const CiderBase = {
win: null,
requests: [],
audiostream: new Stream.PassThrough(),
async Start() {
this.clientPort = await getPort({ port: 9000 });
const windowStateKeeper = require("electron-window-state"),
BrowserWindow = require((process.platform === "win32") ? "electron-acrylic-window" : "electron").BrowserWindow;
const windowState = windowStateKeeper({
this.win = this.CreateBrowserWindow()
},
clientPort: 0,
CreateBrowserWindow() {
this.VerifyFiles()
// Set default window sizes
const mainWindowState = windowStateKeeper({
defaultWidth: 1024,
defaultHeight: 600
});
this.browserWindow = new BrowserWindow({
icon: join(__dirname, `../../../resources/icons/icon.ico`),
width: windowState.width,
height: windowState.height,
x: windowState.x,
y: windowState.y,
let win = null
const options = {
icon: join(__dirname, `../../resources/icons/icon.ico`),
width: mainWindowState.width,
height: mainWindowState.height,
x: mainWindowState.x,
y: mainWindowState.y,
minWidth: 844,
minHeight: 410,
frame: false,
title: "Cider",
vibrancy: 'dark',
transparent: process.platform === "darwin",
// transparent: true,
hasShadow: false,
webPreferences: {
webviewTag: true,
@ -62,74 +61,62 @@ module.exports = {
sandbox: true,
nativeWindowOpen: true,
contextIsolation: false,
preload: join(__dirname, '../../preload/cider-preload.js')
preload: join(__dirname, '../preload/cider-preload.js')
}
}
})
this.initializeWebServer();
this.initializeSession();
this.initializeHandlers();
CiderBase.InitWebServer()
windowState.manage(this.browserWindow);
this.browserWindow.webContents.setZoomFactor(screen.getPrimaryDisplay().scaleFactor)
// Create the BrowserWindow
if (process.platform === "darwin" || process.platform === "linux") {
win = new BrowserWindow(options)
} else {
if (app.cfg.get("visual.window_transparency") !== "disabled") {
const { BrowserWindow } = require("electron-acrylic-window");
}
win = new BrowserWindow(options)
win.setVibrancy("dark")
}
return this.browserWindow
// intercept "https://js-cdn.music.apple.com/hls.js/2.141.0/hls.js/hls.js" and redirect to local file "./apple-hls.js" instead
win.webContents.session.webRequest.onBeforeRequest(
{
urls: ["https://*/*.js"]
},
/**
* Initializes the BrowserWindow handlers for the application.
*/
initializeHandlers() {
const self = this;
this.browserWindow.on('closed', () => {
this.browserWindow = null;
});
if (process.platform === "win32") {
let WND_STATE = {
MINIMIZED: 0,
NORMAL: 1,
MAXIMIZED: 2,
FULL_SCREEN: 3
}
let wndState = WND_STATE.NORMAL
self.browserWindow.on("resize", (_event) => {
const isMaximized = self.browserWindow.isMaximized()
const isMinimized = self.browserWindow.isMinimized()
const isFullScreen = self.browserWindow.isFullScreen()
const state = wndState;
if (isMinimized && state !== WND_STATE.MINIMIZED) {
wndState = WND_STATE.MINIMIZED
} else if (isFullScreen && state !== WND_STATE.FULL_SCREEN) {
wndState = WND_STATE.FULL_SCREEN
} else if (isMaximized && state !== WND_STATE.MAXIMIZED) {
wndState = WND_STATE.MAXIMIZED
self.browserWindow.webContents.executeJavaScript(`app.chrome.maximized = true`)
} else if (state !== WND_STATE.NORMAL) {
wndState = WND_STATE.NORMAL
self.browserWindow.webContents.executeJavaScript(`app.chrome.maximized = false`)
}
(details, callback) => {
if (details.url.includes("hls.js")) {
callback({
redirectURL: `http://localhost:${CiderBase.clientPort}/apple-hls.js`
})
} else {
callback({
cancel: false
})
}
}
)
// Set window Handler
this.browserWindow.webContents.setWindowOpenHandler(({url}) => {
if (url.includes("apple") || url.includes("localhost")) {
return {action: "allow"}
}
shell.openExternal(url).catch(() => {
})
return {
action: 'deny'
win.webContents.session.webRequest.onBeforeSendHeaders(async (details, callback) => {
if (details.url === "https://buy.itunes.apple.com/account/web/info") {
details.requestHeaders['sec-fetch-site'] = 'same-site';
details.requestHeaders['DNT'] = '1';
let itspod = await win.webContents.executeJavaScript(`window.localStorage.getItem("music.ampwebplay.itspod")`)
if (itspod != null)
details.requestHeaders['Cookie'] = `itspod=${itspod}`
}
callback({ requestHeaders: details.requestHeaders })
})
//-------------------------------------------------------------------------------
// Renderer IPC Listeners
//-------------------------------------------------------------------------------
let location = `http://localhost:${CiderBase.clientPort}/`
win.loadURL(location)
win.on("closed", () => {
win = null
})
// Register listeners on Window to track size and position of the Window.
mainWindowState.manage(win);
// IPC stuff (senders)
ipcMain.on("cider-platform", (event) => {
event.returnValue = process.platform
})
@ -144,11 +131,56 @@ module.exports = {
// IPC stuff (listeners)
ipcMain.on('close', () => { // listen for close event
self.browserWindow.close();
win.close();
})
ipcMain.on('put-library-songs', (event, arg) => {
fs.writeFileSync(join(app.paths.ciderCache, "library-songs.json"), JSON.stringify(arg))
})
ipcMain.on('put-library-artists', (event, arg) => {
fs.writeFileSync(join(app.paths.ciderCache, "library-artists.json"), JSON.stringify(arg))
})
ipcMain.on('put-library-albums', (event, arg) => {
fs.writeFileSync(join(app.paths.ciderCache, "library-albums.json"), JSON.stringify(arg))
})
ipcMain.on('put-library-playlists', (event, arg) => {
fs.writeFileSync(join(app.paths.ciderCache, "library-playlists.json"), JSON.stringify(arg))
})
ipcMain.on('put-library-recentlyAdded', (event, arg) => {
fs.writeFileSync(join(app.paths.ciderCache, "library-recentlyAdded.json"), JSON.stringify(arg))
})
ipcMain.on('get-library-songs', (event) => {
let librarySongs = fs.readFileSync(join(app.paths.ciderCache, "library-songs.json"), "utf8")
event.returnValue = JSON.parse(librarySongs)
})
ipcMain.on('get-library-artists', (event) => {
let libraryArtists = fs.readFileSync(join(app.paths.ciderCache, "library-artists.json"), "utf8")
event.returnValue = JSON.parse(libraryArtists)
})
ipcMain.on('get-library-albums', (event) => {
let libraryAlbums = fs.readFileSync(join(app.paths.ciderCache, "library-albums.json"), "utf8")
event.returnValue = JSON.parse(libraryAlbums)
})
ipcMain.on('get-library-playlists', (event) => {
let libraryPlaylists = fs.readFileSync(join(app.paths.ciderCache, "library-playlists.json"), "utf8")
event.returnValue = JSON.parse(libraryPlaylists)
})
ipcMain.on('get-library-recentlyAdded', (event) => {
let libraryRecentlyAdded = fs.readFileSync(join(app.paths.ciderCache, "library-recentlyAdded.json"), "utf8")
event.returnValue = JSON.parse(libraryRecentlyAdded)
})
ipcMain.handle('getYTLyrics', async (event, track, artist) => {
const u = track + " " + artist + " official video";
var u = track + " " + artist + " official video";
const videos = await yt.search(u);
return videos
})
@ -169,38 +201,174 @@ module.exports = {
app.cfg.store = store
})
ipcMain.handle('setVibrancy', (event, key, value) => {
win.setVibrancy(value)
});
ipcMain.on('maximize', () => { // listen for maximize event
if (self.browserWindow.isMaximized()) {
self.browserWindow.unmaximize()
if (win.isMaximized()) {
win.unmaximize()
} else {
self.browserWindow.maximize()
win.maximize()
}
})
ipcMain.on('minimize', () => { // listen for minimize event
self.browserWindow.minimize();
win.minimize();
})
if (process.platform === "win32") {
let WND_STATE = {
MINIMIZED: 0,
NORMAL: 1,
MAXIMIZED: 2,
FULL_SCREEN: 3
}
let wndState = WND_STATE.NORMAL
win.on("resize", (_event) => {
const isMaximized = win.isMaximized()
const isMinimized = win.isMinimized()
const isFullScreen = win.isFullScreen()
const state = wndState;
if (isMinimized && state !== WND_STATE.MINIMIZED) {
wndState = WND_STATE.MINIMIZED
} else if (isFullScreen && state !== WND_STATE.FULL_SCREEN) {
wndState = WND_STATE.FULL_SCREEN
} else if (isMaximized && state !== WND_STATE.MAXIMIZED) {
wndState = WND_STATE.MAXIMIZED
win.webContents.executeJavaScript(`app.chrome.maximized = true`)
} else if (state !== WND_STATE.NORMAL) {
wndState = WND_STATE.NORMAL
win.webContents.executeJavaScript(`app.chrome.maximized = false`)
}
})
}
// Set window Handler
win.webContents.setWindowOpenHandler(({ url }) => {
if (url.includes("apple") || url.includes("localhost")) {
return { action: "allow" }
}
shell.openExternal(url).catch(() => {
})
return {
action: 'deny'
}
})
// Set scale
ipcMain.on('setScreenScale', (event, scale) => {
self.browserWindow.webContents.setZoomFactor(parseFloat(scale))
win.webContents.setZoomFactor(parseFloat(scale))
})
win.webContents.setZoomFactor(screen.getPrimaryDisplay().scaleFactor)
mpris.connect(win)
lastfm.authenticate()
// Discord
discord.connect((app.cfg.get("general.discord_rpc") == 1) ? '911790844204437504' : '886578863147192350');
ipcMain.on('playbackStateDidChange', (_event, a) => {
app.media = a;
discord.updateActivity(a)
mpris.updateState(a)
lastfm.scrobbleSong(a)
lastfm.updateNowPlayingSong(a)
});
ipcMain.on('nowPlayingItemDidChange', (_event, a) => {
app.media = a;
discord.updateActivity(a)
mpris.updateAttributes(a)
lastfm.scrobbleSong(a)
lastfm.updateNowPlayingSong(a)
});
ipcMain.on("getPreviewURL", (_event, url) => {
fetch(url)
.then(res => res.buffer())
.then(async (buffer) => {
try {
const metadata = await mm.parseBuffer(buffer, 'audio/x-m4a');
SoundCheckTag = metadata.native.iTunes[1].value
win.webContents.send('SoundCheckTag', SoundCheckTag)
} catch (error) {
console.error(error.message);
}
})
});
ipcMain.on('writeAudio', function (event, buffer) {
CiderBase.audiostream.write(Buffer.from(buffer));
})
return win
},
VerifyFiles() {
const expectedDirectories = [
"CiderCache"
]
const expectedFiles = [
"library-songs.json",
"library-artists.json",
"library-albums.json",
"library-playlists.json",
"library-recentlyAdded.json",
]
for (let i = 0; i < expectedDirectories.length; i++) {
if (!existsSync(path.join(app.getPath("userData"), expectedDirectories[i]))) {
mkdirSync(path.join(app.getPath("userData"), expectedDirectories[i]))
}
}
for (let i = 0; i < expectedFiles.length; i++) {
const file = path.join(app.paths.ciderCache, expectedFiles[i])
if (!existsSync(file)) {
writeFileSync(file, JSON.stringify([]))
}
}
},
EnvironmentVariables: {
"env": {
platform: os.platform(),
dev: app.isPackaged
}
},
LinkHandler: (startArgs) => {
if (!startArgs) return;
console.log("lfmtoken", String(startArgs))
if (String(startArgs).includes('auth')) {
let authURI = String(startArgs).split('/auth/')[1]
if (authURI.startsWith('lastfm')) { // If we wanted more auth options
const authKey = authURI.split('lastfm?token=')[1];
app.cfg.set('lastfm.enabled', true);
app.cfg.set('lastfm.auth_token', authKey);
CiderBase.win.webContents.send('LastfmAuthenticated', authKey);
lastfm.authenticate()
}
} else {
const formattedSongID = startArgs.replace('ame://', '').replace('/', '');
console.warn(`[LinkHandler] Attempting to load song id: ${formattedSongID}`);
// setQueue can be done with album, song, url, playlist id
this.win.webContents.executeJavaScript(`
MusicKit.getInstance().setQueue({ song: '${formattedSongID}'}).then(function(queue) {
MusicKit.getInstance().play();
});
`).catch((err) => console.error(err));
}
},
/**
* Starts the webserver
*/
initializeWebServer() {
const self = this;
const webapp = express(),
webRemotePath = path.join(__dirname, '../../renderer/');
async InitWebServer() {
const webapp = express();
const webRemotePath = path.join(__dirname, '../renderer/');
webapp.set("views", path.join(webRemotePath, "views"));
webapp.set("view engine", "ejs");
webapp.use(function (req, res, next) {
// if not localhost
if (req.headers.host.includes("localhost") && req.headers["user-agent"].includes("Cider")) {
if (req.url.includes("audio.webm") || (req.headers.host.includes("localhost") && req.headers["user-agent"].includes("Cider"))) {
next();
}
});
@ -208,52 +376,32 @@ module.exports = {
webapp.use(express.static(webRemotePath));
webapp.get('/', function (req, res) {
//res.sendFile(path.join(webRemotePath, 'index_old.html'));
res.render("main", self.EnvironmentVariables)
res.render("main", CiderBase.EnvironmentVariables)
});
webapp.listen(this.clientPort, function () {
console.log(`Cider client port: ${self.clientPort}`);
webapp.get('/audio.webm', function (req, res) {
try {
req.connection.setTimeout(Number.MAX_SAFE_INTEGER);
// CiderBase.requests.push({req: req, res: res});
// var pos = CiderBase.requests.length - 1;
// req.on("close", () => {
// console.info("CLOSED", CiderBase.requests.length);
// requests.splice(pos, 1);
// console.info("CLOSED", CiderBase.requests.length);
// });
CiderBase.audiostream.on('data', (data) => {
try {
res.write(data);
} catch (ex) {
console.log(ex)
}
})
} catch (ex) { console.log(ex) }
});
webapp.listen(CiderBase.clientPort, function () {
console.log(`Cider client port: ${CiderBase.clientPort}`);
});
},
/**
* Initializes the application session.
*/
initializeSession() {
const self = this;
// intercept "https://js-cdn.music.apple.com/hls.js/2.141.0/hls.js/hls.js" and redirect to local file "./apple-hls.js" instead
this.browserWindow.webContents.session.webRequest.onBeforeRequest(
{
urls: ["https://*/*.js"]
},
(details, callback) => {
if (details.url.includes("hls.js")) {
callback({
redirectURL: `http://localhost:${self.clientPort}/apple-hls.js`
})
} else {
callback({
cancel: false
})
}
}
)
this.browserWindow.webContents.session.webRequest.onBeforeSendHeaders(async (details, callback) => {
if (details.url === "https://buy.itunes.apple.com/account/web/info") {
details.requestHeaders['sec-fetch-site'] = 'same-site';
details.requestHeaders['DNT'] = '1';
let itspod = await this.browserWindow.webContents.executeJavaScript(`window.localStorage.getItem("music.ampwebplay.itspod")`)
if (itspod != null)
details.requestHeaders['Cookie'] = `itspod=${itspod}`
}
callback({requestHeaders: details.requestHeaders})
})
let location = `http://localhost:${this.clientPort}/`
this.browserWindow.loadURL(location).catch(err => {
console.log(err)
})
}
}
module.exports = CiderBase;

View file

@ -1,25 +1,26 @@
import * as path from "path";
import {app, ipcMain, shell} from "electron";
import * as electron from "electron";
import * as electronAcrylic from "electron-acrylic-window"
import * as windowStateKeeper from "electron-window-state";
import * as express from "express";
import * as getPort from "get-port";
import * as yt from "youtube-search-without-api-key";
export default class Win {
public win: null | undefined;
public app: Electron.App | undefined;
export class Win {
win: any | undefined;
app: electron.App | undefined;
private srcPath: string = path.join(__dirname, "../../src");
private resourcePath: string = path.join(__dirname, "../../resources");
private clientPort: number = 0;
private static envVars: object = {
private EnvironmentVariables: object = {
"env": {
// @ts-ignore
platform: process.platform,
// @ts-ignore
dev: app.isPackaged
dev: electron.app.isPackaged
}
};
private static options: any = {
icon: path.join(__dirname, `../../../resources/icons/icon.ico`),
private options: any = {
icon: path.join(this.resourcePath, `icons/icon.ico`),
width: 1024,
height: 600,
x: undefined,
@ -28,7 +29,6 @@ export default class Win {
minHeight: 400,
frame: false,
title: "Cider",
vibrancy: 'dark',
transparent: process.platform === "darwin",
hasShadow: false,
webPreferences: {
@ -42,27 +42,16 @@ export default class Win {
sandbox: true,
nativeWindowOpen: true,
contextIsolation: false,
preload: path.join(__dirname, '../../preload/cider-preload.js')
preload: path.join(this.srcPath, 'preload/cider-preload.js')
}
};
get options() {
return Win.options;
}
/**
* Creates the browser window
*/
public async createWindow(): Promise<Electron.BrowserWindow> {
async createWindow(): Promise<any | undefined> {
this.clientPort = await getPort({port: 9000});
let BrowserWindow;
if (process.platform === "win32") {
BrowserWindow = require("electron-acrylic-window").BrowserWindow;
} else {
BrowserWindow = require("electron").BrowserWindow;
}
// Load the previous state with fallback to defaults
const windowState = windowStateKeeper({
defaultWidth: 1024,
@ -71,63 +60,79 @@ export default class Win {
this.options.width = windowState.width;
this.options.height = windowState.height;
this.startWebServer()
if (process.platform === "win32") {
this.win = new electronAcrylic.BrowserWindow(this.options);
} else {
this.win = new electron.BrowserWindow(this.options);
}
// Create the browser window.
const win = new BrowserWindow(this.options);
console.debug('Browser window created');
this.win = win;
// and load the renderer.
this.startWebServer(win)
this.startSession(win);
this.startHandlers(win);
this.startSession(this.win);
this.startHandlers(this.win);
return win;
return this.win;
}
/**
* Starts the webserver for the renderer process.
* @param win The BrowserWindow
*/
private startWebServer(win: Electron.BrowserWindow): void {
const webapp = express(),
webRemotePath = path.join(__dirname, '../../renderer/');
private startWebServer(): void {
const webapp = express();
const webRemotePath = path.join(this.srcPath, 'renderer');
webapp.set("views", path.join(webRemotePath, "views"));
webapp.set("view engine", "ejs");
webapp.use((req, res, next) => {
webapp.use(function (req, res, next) {
// if not localhost
// @ts-ignore
if (req.headers.host.includes("localhost") && req.headers["user-agent"].includes("Cider")) {
if (req.url.includes("audio.webm") || (req.headers.host.includes("localhost") && req.headers["user-agent"].includes("Cider"))) {
next();
}
});
webapp.use(express.static(webRemotePath));
webapp.get('/', function (req, res) {
webapp.get('/', (req, res) => {
//res.sendFile(path.join(webRemotePath, 'index_old.html'));
res.render("main", Win.envVars)
console.log(req)
res.render("main", this.EnvironmentVariables)
});
// webelectron.app.get('/audio.webm', (req, res) => {
// try {
// req.connection.setTimeout(Number.MAX_SAFE_INTEGER);
// this.audiostream.on('data', (data) => {
// try {
// res.write(data);
// } catch (ex) {
// console.log(ex)
// }
// })
// } catch (ex) { console.log(ex) }
// });
webapp.listen(this.clientPort, () => {
console.debug(`Cider client port: ${this.clientPort}`);
console.log(`Cider client port: ${this.clientPort}`);
});
}
/**
* Starts the session for the renderer process.
* @param win The BrowserWindow
*/
private startSession(win: Electron.BrowserWindow): void {
private startSession(win: any): void {const self = this;
// intercept "https://js-cdn.music.apple.com/hls.js/2.141.0/hls.js/hls.js" and redirect to local file "./apple-hls.js" instead
win.webContents.session.webRequest.onBeforeRequest(
{
urls: ["https://*/*.js"]
},
(details, callback) => {
(details: { url: string | string[]; }, callback: (arg0: { redirectURL?: string; cancel?: boolean; }) => void) => {
if (details.url.includes("hls.js")) {
callback({
redirectURL: `http://localhost:${this.clientPort}/apple-hls.js`
redirectURL: `http://localhost:${self.clientPort}/apple-hls.js`
})
} else {
callback({
@ -137,7 +142,7 @@ export default class Win {
}
)
win.webContents.session.webRequest.onBeforeSendHeaders(async (details, callback) => {
win.webContents.session.webRequest.onBeforeSendHeaders(async (details: { url: string; requestHeaders: { [x: string]: string; }; }, callback: (arg0: { requestHeaders: any; }) => void) => {
if (details.url === "https://buy.itunes.apple.com/account/web/info") {
details.requestHeaders['sec-fetch-site'] = 'same-site';
details.requestHeaders['DNT'] = '1';
@ -161,11 +166,7 @@ export default class Win {
* Initializes the window handlers
* @param win The BrowserWindow
*/
private startHandlers(win: Electron.BrowserWindow): void {
win.on('closed', () => {
this.win = null;
});
private startHandlers(win: any): void {
if (process.platform === "win32") {
let WND_STATE = {
MINIMIZED: 0,
@ -186,20 +187,20 @@ export default class Win {
wndState = WND_STATE.FULL_SCREEN
} else if (isMaximized && state !== WND_STATE.MAXIMIZED) {
wndState = WND_STATE.MAXIMIZED
win.webContents.executeJavaScript(`app.chrome.maximized = true`)
win.webContents.executeJavaScript(`electron.app.chrome.maximized = true`)
} else if (state !== WND_STATE.NORMAL) {
wndState = WND_STATE.NORMAL
win.webContents.executeJavaScript(`app.chrome.maximized = false`)
win.webContents.executeJavaScript(`electron.app.chrome.maximized = false`)
}
})
}
// Set window Handler
win.webContents.setWindowOpenHandler(({url}) => {
if (url.includes("apple") || url.includes("localhost")) {
win.webContents.setWindowOpenHandler((x: any) => {
if (x.url.includes("apple") || x.url.includes("localhost")) {
return {action: "allow"}
}
shell.openExternal(url).catch(() => {
electron.shell.openExternal(x.url).catch(() => {
})
return {
action: 'deny'
@ -210,46 +211,45 @@ export default class Win {
// Renderer IPC Listeners
//-------------------------------------------------------------------------------
ipcMain.on("cider-platform", (event) => {
electron.ipcMain.on("cider-platform", (event) => {
event.returnValue = process.platform
})
ipcMain.on("get-gpu-mode", (event) => {
electron.ipcMain.on("get-gpu-mode", (event) => {
event.returnValue = process.platform
})
ipcMain.on("is-dev", (event) => {
event.returnValue = !app.isPackaged
electron.ipcMain.on("is-dev", (event) => {
event.returnValue = !electron.app.isPackaged
})
// IPC stuff (listeners)
ipcMain.on('close', () => { // listen for close event
electron.ipcMain.on('close', () => { // listen for close event
win.close();
})
ipcMain.handle('getYTLyrics', async (event, track, artist) => {
electron.ipcMain.handle('getYTLyrics', async (event, track, artist) => {
const u = track + " " + artist + " official video";
const videos = await yt.search(u);
return videos
return await yt.search(u)
})
// ipcMain.handle('getStoreValue', (event, key, defaultValue) => {
// return (defaultValue ? app.cfg.get(key, true) : app.cfg.get(key));
// electron.ipcMain.handle('getStoreValue', (event, key, defaultValue) => {
// return (defaultValue ? electron.app.cfg.get(key, true) : electron.app.cfg.get(key));
// });
//
// ipcMain.handle('setStoreValue', (event, key, value) => {
// app.cfg.set(key, value);
// electron.ipcMain.handle('setStoreValue', (event, key, value) => {
// electron.app.cfg.set(key, value);
// });
//
// ipcMain.on('getStore', (event) => {
// event.returnValue = app.cfg.store
// electron.ipcMain.on('getStore', (event) => {
// event.returnValue = electron.app.cfg.store
// })
//
// ipcMain.on('setStore', (event, store) => {
// app.cfg.store = store
// electron.ipcMain.on('setStore', (event, store) => {
// electron.app.cfg.store = store
// })
ipcMain.on('maximize', () => { // listen for maximize event
electron.ipcMain.on('maximize', () => { // listen for maximize event
if (win.isMaximized()) {
win.unmaximize()
} else {
@ -257,12 +257,12 @@ export default class Win {
}
})
ipcMain.on('minimize', () => { // listen for minimize event
electron.ipcMain.on('minimize', () => { // listen for minimize event
win.minimize();
})
// Set scale
ipcMain.on('setScreenScale', (event, scale) => {
electron.ipcMain.on('setScreenScale', (event, scale) => {
win.webContents.setZoomFactor(parseFloat(scale))
})
}

View file

@ -1,12 +1,8 @@
require('v8-compile-cache');
// import { app } from 'electron';
import { app } from 'electron';
// import { resolve } from 'path';
import { app, BrowserWindow } from "electron";
import * as path from "path";
// Analytics for debugging fun yeah.
// const ElectronSentry = require("@sentry/electron");
// ElectronSentry.init({ dsn: "https://68c422bfaaf44dea880b86aad5a820d2@o954055.ingest.sentry.io/6112214" });
@ -15,7 +11,7 @@ import * as path from "path";
// // Init()
//
import Win from "./base/win";
import {Win} from "./base/win";
const Cider = new Win()