From a844903dff0385a9cbb11e2b4d3145527427cad0 Mon Sep 17 00:00:00 2001 From: child_duckling <19170969+child-duckling@users.noreply.github.com> Date: Sat, 16 Apr 2022 23:59:30 -0700 Subject: [PATCH] connect auth works, now for settings sync --- src/main/base/app.ts | 5 ++--- src/main/base/browserwindow.ts | 22 +++++++++++++++++---- src/main/base/plugins.ts | 2 +- src/renderer/main/vueapp.js | 3 +++ src/renderer/views/pages/connect-linked.ejs | 21 +++++++++++--------- src/renderer/views/pages/settings.ejs | 17 +++++++++++++--- src/renderer/views/pages/webview.ejs | 3 +-- 7 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/main/base/app.ts b/src/main/base/app.ts index b036d95d..3ab49a66 100644 --- a/src/main/base/app.ts +++ b/src/main/base/app.ts @@ -167,9 +167,6 @@ export class AppEvents { utils.getWindow().webContents.send('LastfmAuthenticated', authKey); this.plugin.callPlugin('lastfm', 'authenticate', authKey); } - } else if (arg.includes("callback/discord?oauth=")){ // Discord OAuth [Connect] - utils.setStoreValue('connectUser', JSON.parse(arg.split("callback/discord?oauth=")[1])); - utils.getWindow().webContents.executeJavaScript("$root.appRoute('connect-linked')") } // Play else if (arg.includes('/play/')) { //Steer away from protocol:// specific conditionals @@ -206,6 +203,8 @@ export class AppEvents { shell.openExternal('https://opencollective.com/ciderapp') } else if (arg.includes('/beep')) { shell.beep() + } else { + utils.getWindow().webContents.executeJavaScript(`app.appRoute('${arg.split('//')[1]}')`) } } diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index 38bb0eae..082d1677 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -18,6 +18,7 @@ const wallpaper = require('wallpaper'); // @ts-ignore import * as AdmZip from "adm-zip"; +import * as util from "util"; /** * @file Creates the BrowserWindow @@ -526,16 +527,23 @@ export class BrowserWindow { console.log(ex); } }); - - app.get("/connect/get-user", (req, res) => { - res.send(utils.getStoreValue('connectUser')); // [Connect] Session redirect for webview + //region Connect Integration + app.get("/connect/set-cc-user/:data", (req, res) => { + //utils.getStoreValue('connectUser', JSON.parse()) // [Connect] Save user in store + utils.setStoreValue('connectUser', JSON.parse(req.params.data)) + res.redirect(`https://connect.cidercollective.dev/linked.html`) }); - //app.use(express.static()) + // [Connect] Set auth URL in store for `shell.openExternal` + utils.setStoreValue('cc_authURL', `https://connect.cidercollective.dev/callback/discord?app=cider&appPort=${this.clientPort}`) + console.log(`[Connect] Auth URL: ${utils.getStoreValue('cc_authURL')}`) + //endregion + app.listen(this.clientPort, () => { console.log(`Cider client port: ${this.clientPort}`); }); + /* * Remote Client -@quacksire * https://github.com/ciderapp/Apple-Music-Electron/blob/818189ed40ff600d76eb59d22016723a75885cd5/resources/functions/handler.js#L1173 @@ -1107,6 +1115,8 @@ export class BrowserWindow { //} }); + + if (process.platform === "darwin") { //macOS app.setUserActivity('com.CiderCollective.remote.pair', { ip: `${BrowserWindow.getIP()}` @@ -1161,6 +1171,10 @@ export class BrowserWindow { ipcMain.on('open-appdata', (_event) => { shell.openPath(app.getPath('userData')); }); + + ipcMain.on('cc-auth', (_event) => { + shell.openExternal(String(utils.getStoreValue('cc_authURL'))); + }); /* ********************************************************************************************* * Window Events * **********************************************************************************************/ diff --git a/src/main/base/plugins.ts b/src/main/base/plugins.ts index 1f501cd2..a09ee3e9 100644 --- a/src/main/base/plugins.ts +++ b/src/main/base/plugins.ts @@ -4,7 +4,7 @@ import * as electron from 'electron' import {utils} from './utils'; // -// Hello, this our loader for the various plugins that the Cider Development Team built for our +// Hello, this is our loader for the various plugins that the Cider Development Team built for our // numerous plugins internally and ones made by the community // // To learn how to make your own, visit https://github.com/ciderapp/Cider/wiki/Plugins diff --git a/src/renderer/main/vueapp.js b/src/renderer/main/vueapp.js index 422a6b31..0b08fdb8 100644 --- a/src/renderer/main/vueapp.js +++ b/src/renderer/main/vueapp.js @@ -4256,6 +4256,9 @@ const app = new Vue({ document.getElementById('settings.option.general.updateCider.check').innerHTML = app.getLz('term.check') }) }, + authCC(){ + ipcRenderer.send('cc-auth') + } } }) diff --git a/src/renderer/views/pages/connect-linked.ejs b/src/renderer/views/pages/connect-linked.ejs index 306e11d6..1d83dff1 100644 --- a/src/renderer/views/pages/connect-linked.ejs +++ b/src/renderer/views/pages/connect-linked.ejs @@ -1,14 +1,17 @@ -