trying with the store and such
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
import { electronAPI } from "./preload";
|
||||
|
||||
export {};
|
||||
declare global {
|
||||
interface Window {
|
||||
electronAPI: typeof electronAPI;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import store, { STORE_ITEMS } from "./store";
|
||||
|
||||
import Channels from "./constants";
|
||||
import ElectronGoogleOAuth2 from "@getstation/electron-google-oauth2";
|
||||
import { browserWindow } from "../index";
|
||||
import { ipcMain } from "electron";
|
||||
import store from "./store";
|
||||
|
||||
const myApiOauth = new ElectronGoogleOAuth2(
|
||||
"423533244953-banligobgbof8hg89i6cr1l7u0p7c2pk.apps.googleusercontent.com",
|
||||
@@ -14,7 +15,7 @@ const myApiOauth = new ElectronGoogleOAuth2(
|
||||
export async function handleLogin() {
|
||||
// read saved refresh token if any
|
||||
// todo: fix this...should be working
|
||||
const refreshToken = await store.get("tokens");
|
||||
const authTokens = await store.get(STORE_ITEMS.AUTH_TOKENS);
|
||||
|
||||
// todo: remove this when I have way of getting access token from a refresh token
|
||||
// if (refreshToken) {
|
||||
@@ -35,7 +36,8 @@ export async function handleLogin() {
|
||||
// }
|
||||
|
||||
const tokens = await myApiOauth.openAuthWindowAndGetTokens();
|
||||
store.set("tokens", tokens);
|
||||
|
||||
store.set(STORE_ITEMS.AUTH_TOKENS, tokens);
|
||||
|
||||
browserWindow.webContents.send(Channels.AUTH_TOKENS, tokens);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { contextBridge, ipcRenderer } from "electron";
|
||||
|
||||
import Channels from "./constants";
|
||||
|
||||
const electronAPI = {
|
||||
auth: {
|
||||
initiateLogin() {
|
||||
ipcRenderer.send(Channels.ACTIVATE_LOG_IN);
|
||||
},
|
||||
receiveTokens(callback: any) {
|
||||
ipcRenderer.on(Channels.AUTH_TOKENS, callback);
|
||||
},
|
||||
},
|
||||
batteryApi: {},
|
||||
fileApi: {},
|
||||
store: {
|
||||
get(val: string) {
|
||||
return ipcRenderer.sendSync("electron-store-get", val);
|
||||
},
|
||||
set(property: string, val: any) {
|
||||
ipcRenderer.send("electron-store-set", property, val);
|
||||
},
|
||||
// Other method you want to add like has(), reset(), etc.
|
||||
},
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld("electronAPI", electronAPI);
|
||||
|
||||
export default electronAPI;
|
||||
@@ -1,4 +1,9 @@
|
||||
import Store from "electron-store";
|
||||
import { ipcMain } from "electron";
|
||||
const store = new Store();
|
||||
|
||||
export enum STORE_ITEMS {
|
||||
AUTH_TOKENS = "AUTH_TOKENS",
|
||||
}
|
||||
|
||||
export default store;
|
||||
|
||||
Reference in New Issue
Block a user