[connect] untested sync backend

This commit is contained in:
child_duckling 2022-05-01 17:54:37 -07:00
parent e1c7def8bc
commit 825d1b3bc2
2 changed files with 55 additions and 3 deletions

View file

@ -37,6 +37,7 @@ export class BrowserWindow {
platform: process.platform, platform: process.platform,
dev: app.isPackaged, dev: app.isPackaged,
osRelease: os.release(), osRelease: os.release(),
updatable: !process.windowsStore || !process.mas,
components: [ components: [
"pages/podcasts", "pages/podcasts",
"pages/apple-account-settings", "pages/apple-account-settings",
@ -1214,13 +1215,20 @@ export class BrowserWindow {
shell.openPath(app.getPath('userData')); shell.openPath(app.getPath('userData'));
}); });
//#region Cider Connect
ipcMain.on('cc-auth', (_event) => { ipcMain.on('cc-auth', (_event) => {
shell.openExternal(String(utils.getStoreValue('cc_authURL'))); shell.openExternal(String(utils.getStoreValue('cc_authURL')));
}); });
ipcMain.on('cc-logout', (_event) => { ipcMain.on('cc-logout', (_event) => { //Make sure to update the default store
utils.setStoreValue('connectUser', { utils.setStoreValue('connectUser', {
auth: null "auth": null,
"sync": {
themes: false,
plugins: false,
settings: false,
}
}); });
utils.getWindow().reload(); utils.getWindow().reload();
}); });

View file

@ -1,7 +1,7 @@
import * as ElectronStore from 'electron-store'; import * as ElectronStore from 'electron-store';
import * as electron from "electron"; import * as electron from "electron";
import {app} from "electron"; import {app} from "electron";
import fetch from "electron-fetch";
export class Store { export class Store {
static cfg: ElectronStore; static cfg: ElectronStore;
@ -212,6 +212,11 @@ export class Store {
}, },
"connectUser": { "connectUser": {
"auth": null, "auth": null,
"sync": {
themes: false,
plugins: false,
settings: false,
}
}, },
} }
private migrations: any = { private migrations: any = {
@ -261,6 +266,7 @@ export class Store {
return target return target
} }
/** /**
* IPC Handler * IPC Handler
*/ */
@ -281,5 +287,43 @@ export class Store {
Store.cfg.store = store Store.cfg.store = store
}) })
} }
pushToCloud(): void {
if (Store.cfg.get('connectUser.auth') === null) return;
var syncData = Object();
if (Store.cfg.get('connectUser.sync.themes')) {
syncData.push({
themes: Store.cfg.store.themes
})
}
if (Store.cfg.get('connectUser.sync.plugins')) {
syncData.push({
plugins: Store.cfg.store.plugins
})
}
if (Store.cfg.get('connectUser.sync.settings')) {
syncData.push({
general: Store.cfg.get('general'),
home: Store.cfg.get('home'),
libraryPrefs: Store.cfg.get('libraryPrefs'),
advanced: Store.cfg.get('advanced'),
})
}
let postBody = {
id: Store.cfg.get('connectUser.id'),
app: electron.app.getName(),
version: electron.app.isPackaged ? electron.app.getVersion() : 'dev',
syncData: syncData
}
fetch('https://connect.cidercollective.dev/api/v1/setttings/set', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(postBody)
})
}
} }