diff --git a/modules/gui/src-tauri/Cargo.toml b/modules/gui/src-tauri/Cargo.toml
index 6576123..5320252 100644
--- a/modules/gui/src-tauri/Cargo.toml
+++ b/modules/gui/src-tauri/Cargo.toml
@@ -17,7 +17,7 @@ tauri-build = { version = "1.2.0", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
-tauri = { version = "1.2.0", features = ["fs-read-dir", "http-all", "shell-all", "window-all"] }
+tauri = { version = "1.2.0", features = ["fs-create-dir", "fs-read-dir", "fs-read-file", "fs-write-file", "http-all", "path-all", "shell-all", "window-all"] }
uuid = "1.2.1"
futures = "0.3"
diff --git a/modules/gui/src-tauri/src/handlers/auth.rs b/modules/gui/src-tauri/src/handlers/auth.rs
new file mode 100644
index 0000000..31913f5
--- /dev/null
+++ b/modules/gui/src-tauri/src/handlers/auth.rs
@@ -0,0 +1,5 @@
+#[tauri::command]
+pub fn auth(package: String) {
+ println!("installing: {}", package);
+
+}
\ No newline at end of file
diff --git a/modules/gui/src-tauri/src/handlers/mod.rs b/modules/gui/src-tauri/src/handlers/mod.rs
index cc9a312..5ce0e78 100644
--- a/modules/gui/src-tauri/src/handlers/mod.rs
+++ b/modules/gui/src-tauri/src/handlers/mod.rs
@@ -1 +1,2 @@
-pub mod packages;
\ No newline at end of file
+pub mod packages;
+pub mod auth;
\ No newline at end of file
diff --git a/modules/gui/src-tauri/tauri.conf.json b/modules/gui/src-tauri/tauri.conf.json
index d5a16ef..fdf6b77 100644
--- a/modules/gui/src-tauri/tauri.conf.json
+++ b/modules/gui/src-tauri/tauri.conf.json
@@ -36,6 +36,11 @@
"name": "list-packages",
"cmd": "ls",
"args": ["-R ~/.tea/tea.xyz/var/www | grep 'xz\\|gz'"]
+ },
+ {
+ "name": "open",
+ "cmd": "open",
+ "args": ["-a iterm"]
}
],
"sidecar": false
@@ -74,10 +79,15 @@
},
"fs": {
"readDir": true,
+ "createDir": true,
+ "writeFile": true,
+ "readFile": true,
"scope": [
- "$HOME/.tea/*",
- "$APPDATA/*"
+ "$HOME/.tea/*"
]
+ },
+ "path": {
+ "all": true
}
},
"bundle": {
diff --git a/modules/gui/src/components/Auth/Auth.svelte b/modules/gui/src/components/Auth/Auth.svelte
deleted file mode 100644
index b26f89d..0000000
--- a/modules/gui/src/components/Auth/Auth.svelte
+++ /dev/null
@@ -1,46 +0,0 @@
-
-
-
{loop}:{statusMessage}
-
\ No newline at end of file
diff --git a/modules/gui/src/components/NavBar/NavBar.svelte b/modules/gui/src/components/NavBar/NavBar.svelte
index 8c483e8..1beb50c 100644
--- a/modules/gui/src/components/NavBar/NavBar.svelte
+++ b/modules/gui/src/components/NavBar/NavBar.svelte
@@ -4,6 +4,7 @@
import { searchStore } from '$libs/stores';
import SearchInput from '@tea/ui/SearchInput/SearchInput.svelte';
import Button from '@tea/ui/Button/Button.svelte';
+ import ProfileNavButton from './ProfileNavButton.svelte';
import { beforeUpdate } from 'svelte';
@@ -92,12 +93,7 @@
{/each}
diff --git a/modules/gui/src/components/NavBar/ProfileNavButton.svelte b/modules/gui/src/components/NavBar/ProfileNavButton.svelte
new file mode 100644
index 0000000..54d4f0b
--- /dev/null
+++ b/modules/gui/src/components/NavBar/ProfileNavButton.svelte
@@ -0,0 +1,36 @@
+
+
+{#if user}
+
+
+
+ @{user.login}
+
+
+{:else}
+
+
+
+
+
+ Login
+
+{/if}
diff --git a/modules/gui/src/components/ProfileBanner/ProfileBanner.svelte b/modules/gui/src/components/ProfileBanner/ProfileBanner.svelte
index cdd3d36..d487a16 100644
--- a/modules/gui/src/components/ProfileBanner/ProfileBanner.svelte
+++ b/modules/gui/src/components/ProfileBanner/ProfileBanner.svelte
@@ -1,23 +1,36 @@
-
-
-

-
-
-
Authenticated with GitHub
-
-
@Username
-
-
-
-
- Country: Germany
Wallet:
- Connect Now
-
+{#if user}
+
+
+

+
+
+
Authenticated with GitHub
+
+
@{user.login}
+
+
+
+
+ Country: {user?.country}
Wallet:
+ {#if user.wallet}
+ {user.wallet}
+ {:else}
+ Connect Now
+ {/if}
+
+
-
-
+
+{/if}
diff --git a/modules/gui/src/libs/api/mock.ts b/modules/gui/src/libs/api/mock.ts
index 6a6683e..9b16ae7 100644
--- a/modules/gui/src/libs/api/mock.ts
+++ b/modules/gui/src/libs/api/mock.ts
@@ -328,6 +328,16 @@ export async function getDeviceAuth(): Promise
{
// const data = await get(`/auth/device/${deviceId}`);
return {
status: 'SUCCESS',
- user: {},
+ user: {
+ developer_id: 'xxx',
+ name: 'Neil paul Molina',
+ login: 'getneil',
+ avatar_url: 'https://avatars.githubusercontent.com/u/7913978?v=4',
+ created_at: 'xxx',
+ updated_at: 'xxx',
+ country: 'germany',
+ wallet: 'wallet'
+ },
+ key: 'xxx'
};
-}
\ No newline at end of file
+}
diff --git a/modules/gui/src/libs/api/tauri.ts b/modules/gui/src/libs/api/tauri.ts
index e141980..fbf98dc 100644
--- a/modules/gui/src/libs/api/tauri.ts
+++ b/modules/gui/src/libs/api/tauri.ts
@@ -19,8 +19,8 @@ import type { GUIPackage, Course, Category, AuthStatus } from '../types';
import * as mock from './mock';
import { PackageStates } from '../types';
-const base = 'https://api.tea.xyz/v1';
-// const base = 'http://localhost:3000/v1';
+// const base = 'https://api.tea.xyz/v1';
+const base = 'http://localhost:3000/v1';
async function get(path: string, query?: { [key: string]: string }) {
console.log('path', path);
@@ -29,8 +29,8 @@ async function get(path: string, query?: { [key: string]: string }) {
console.log('uri:', uri);
const { data } = await client.get(uri.toString(), {
headers: {
- Authorization: 'public', // TODO: figure out why req w/o Authorization does not work
- 'cache-control': 'no-cache'
+ Authorization: 'public' // TODO: figure out why req w/o Authorization does not work
+ // 'cache-control': 'no-cache'
},
query: query || {}
});
@@ -170,10 +170,11 @@ export async function getCategorizedPackages(): Promise {
type DeviceAuth = {
status: AuthStatus;
user: User;
-}
+ key: string;
+};
export async function getDeviceAuth(): Promise {
const deviceId = 'xyxz123';
const data = await get(`/auth/device/${deviceId}`);
return data;
-}
\ No newline at end of file
+}
diff --git a/modules/gui/src/libs/stores.ts b/modules/gui/src/libs/stores.ts
index acedd96..b2571d4 100644
--- a/modules/gui/src/libs/stores.ts
+++ b/modules/gui/src/libs/stores.ts
@@ -6,6 +6,7 @@ import type { GUIPackage } from '$libs/types';
// TODO: figure out a better structure for managing states maybe turn them into separate files?
import { getPackages, getFeaturedPackages, getPackageReviews, getAllPosts } from '@api';
+import initAuthStore from './stores/auth';
export const backLink = writable('/');
@@ -170,3 +171,5 @@ function initSearchStore() {
}
export const searchStore = initSearchStore();
+
+export const authStore = initAuthStore();
diff --git a/modules/gui/src/libs/stores/auth.ts b/modules/gui/src/libs/stores/auth.ts
new file mode 100644
index 0000000..3ccf368
--- /dev/null
+++ b/modules/gui/src/libs/stores/auth.ts
@@ -0,0 +1,95 @@
+import { writable } from 'svelte/store';
+import { BaseDirectory, createDir, readTextFile, writeTextFile } from '@tauri-apps/api/fs';
+import { join } from '@tauri-apps/api/path';
+import { getDeviceAuth } from '@api';
+import type { User } from '@tea/ui/types';
+
+const basePath = '.tea/tea.xyz/gui';
+interface Session {
+ key: string;
+ user: any;
+}
+
+export default function initAuthStore() {
+ const deviceId = 'abcdevf'; // ideally randomly generated on install
+ const session = writable();
+ let pollLoop = 0;
+ initSession();
+
+ let timer: NodeJS.Timer | null;
+ // TODO:
+ // fetch session data from local
+ // fetch session data remotely
+ // update local session data
+
+ async function pollSession() {
+ if (!timer) {
+ timer = setInterval(async () => {
+ pollLoop++;
+ try {
+ const data = await getDeviceAuth();
+ if (data.status === 'SUCCESS') {
+ session.set({
+ key: data.key,
+ user: data.user
+ });
+ timer && clearInterval(timer);
+ timer = null;
+ }
+ console.log(data);
+ } catch (error) {
+ console.error(error);
+ }
+
+ if (pollLoop > 20 && timer) {
+ clearInterval(timer);
+ pollLoop = 0;
+ timer = null;
+ }
+ }, 2000);
+ }
+ }
+
+ return {
+ deviceId,
+ subscribe: (cb: (u: User) => void) => {
+ return session.subscribe((v) => v && cb(v.user));
+ },
+ pollSession
+ };
+}
+
+const initSession = async (): Promise => {
+ await createGuiDataFolder();
+ const session = await getSessionData();
+ console.log(session);
+};
+
+const createGuiDataFolder = async () => {
+ await createDir(basePath, {
+ dir: BaseDirectory.Home,
+ recursive: true
+ });
+};
+
+const getSessionData = async (): Promise => {
+ const sessionFilePath = await join(basePath, 'tmp.dat');
+ try {
+ const data = await readTextFile(sessionFilePath, {
+ dir: BaseDirectory.Home
+ });
+ // TODO: decrypt then return
+ console.log('data:', data);
+ } catch (error) {
+ console.error(error);
+ await writeTextFile(sessionFilePath, '', {
+ dir: BaseDirectory.Home
+ });
+ }
+ console.log(sessionFilePath);
+};
+
+const saveSessionData = async (data: { [key: string]: string | number | Date }) => {
+ const sessionFilePath = await join(basePath, 'tmp.dat');
+ // TODO: encrypt and write
+};
diff --git a/modules/gui/src/libs/types.ts b/modules/gui/src/libs/types.ts
index 8a8c272..dd9f8be 100644
--- a/modules/gui/src/libs/types.ts
+++ b/modules/gui/src/libs/types.ts
@@ -34,5 +34,5 @@ export enum AuthStatus {
UNKNOWN = 'UNKNOWN',
PENDING = 'PENDING',
SUCCESS = 'SUCCESS',
- FAILED = 'FAILED',
+ FAILED = 'FAILED'
}
diff --git a/modules/gui/src/routes/+page.svelte b/modules/gui/src/routes/+page.svelte
index 4fec90d..23eeb8c 100644
--- a/modules/gui/src/routes/+page.svelte
+++ b/modules/gui/src/routes/+page.svelte
@@ -9,7 +9,7 @@
import News from '$components/News/News.svelte';
import CategorizedPackages from '$components/CategorizedPackages/CategorizedPackages.svelte';
backLink.set('');
- console.log("test", window.location)
+ console.log('test', window.location);
diff --git a/modules/gui/src/routes/profile/+page.svelte b/modules/gui/src/routes/profile/+page.svelte
index fd6c7ca..149a3ec 100644
--- a/modules/gui/src/routes/profile/+page.svelte
+++ b/modules/gui/src/routes/profile/+page.svelte
@@ -6,15 +6,11 @@
import Badges from '$components/Badges/Badges.svelte';
import InstalledPackages from '$components/InstalledPackages/InstalledPackages.svelte';
import { backLink } from '$libs/stores';
- import Auth from '$components/Auth/Auth.svelte';
backLink.set('/');
PROFILE
-
diff --git a/modules/gui/static/images/github.png b/modules/gui/static/images/github.png
new file mode 100644
index 0000000..3a1bfa4
Binary files /dev/null and b/modules/gui/static/images/github.png differ
diff --git a/modules/ui/src/types.ts b/modules/ui/src/types.ts
index eac3436..d9bface 100644
--- a/modules/ui/src/types.ts
+++ b/modules/ui/src/types.ts
@@ -36,7 +36,10 @@ export type AirtablePost = {
};
export type User = {
- username: string;
+ developer_id: string;
+ avatar_url?: string;
+ name: string;
+ login: string;
country?: string;
- eth_wallet_address?: string;
-}
\ No newline at end of file
+ wallet?: string;
+};