mirror of
https://github.com/ivabus/gui
synced 2025-06-07 15:50:27 +03:00
cleanup and lint
This commit is contained in:
parent
3a00459b15
commit
721c278fd4
7 changed files with 13 additions and 33 deletions
|
@ -1,5 +0,0 @@
|
||||||
#[tauri::command]
|
|
||||||
pub fn auth(package: String) {
|
|
||||||
println!("installing: {}", package);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,2 +1 @@
|
||||||
pub mod packages;
|
pub mod packages;
|
||||||
pub mod auth;
|
|
|
@ -1,9 +1,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { open } from '@tauri-apps/api/shell';
|
import { open } from '@tauri-apps/api/shell';
|
||||||
import { authStore } from '$libs/stores';
|
import { authStore } from '$libs/stores';
|
||||||
import type { User } from '@tea/ui/types';
|
import type { Developer } from '@tea/ui/types';
|
||||||
|
|
||||||
let user: User | null = null;
|
let user: Developer | null = null;
|
||||||
const deviceId = authStore.deviceIdStore;
|
const deviceId = authStore.deviceIdStore;
|
||||||
|
|
||||||
const openGithub = () => {
|
const openGithub = () => {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import { authStore } from '$libs/stores';
|
import { authStore } from '$libs/stores';
|
||||||
import type { User } from '@tea/ui/types';
|
import type { Developer } from '@tea/ui/types';
|
||||||
|
|
||||||
let user: User | null = null;
|
let user: Developer | null = null;
|
||||||
const authPage = `http://localhost:3000/v1/auth/user?device_id=${authStore.deviceId}`; // https://api.tea.xyz/v1/auth/user?device_id=device_id
|
const authPage = `http://localhost:3000/v1/auth/user?device_id=${authStore.deviceId}`; // https://api.tea.xyz/v1/auth/user?device_id=device_id
|
||||||
|
|
||||||
authStore.subscribe((u) => (user = u));
|
authStore.subscribe((u) => (user = u));
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { getClient } from '@tauri-apps/api/http';
|
||||||
import { Command } from '@tauri-apps/api/shell';
|
import { Command } from '@tauri-apps/api/shell';
|
||||||
import { readDir, BaseDirectory } from '@tauri-apps/api/fs';
|
import { readDir, BaseDirectory } from '@tauri-apps/api/fs';
|
||||||
|
|
||||||
import type { Package, Review, AirtablePost, User, Bottle } from '@tea/ui/types';
|
import type { Package, Review, AirtablePost, Developer, Bottle } from '@tea/ui/types';
|
||||||
import type { GUIPackage, Course, Category, AuthStatus } from '../types';
|
import type { GUIPackage, Course, Category, AuthStatus } from '../types';
|
||||||
|
|
||||||
import * as mock from './mock';
|
import * as mock from './mock';
|
||||||
|
@ -171,7 +171,7 @@ export async function getCategorizedPackages(): Promise<Category[]> {
|
||||||
|
|
||||||
type DeviceAuth = {
|
type DeviceAuth = {
|
||||||
status: AuthStatus;
|
status: AuthStatus;
|
||||||
user: User;
|
user: Developer;
|
||||||
key: string;
|
key: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,13 @@ import { writable } from 'svelte/store';
|
||||||
import { BaseDirectory, createDir, readTextFile, writeTextFile } from '@tauri-apps/api/fs';
|
import { BaseDirectory, createDir, readTextFile, writeTextFile } from '@tauri-apps/api/fs';
|
||||||
import { join } from '@tauri-apps/api/path';
|
import { join } from '@tauri-apps/api/path';
|
||||||
import { getDeviceAuth, registerDevice } from '@api';
|
import { getDeviceAuth, registerDevice } from '@api';
|
||||||
import type { User } from '@tea/ui/types';
|
import type { Developer } from '@tea/ui/types';
|
||||||
|
|
||||||
const basePath = '.tea/tea.xyz/gui';
|
const basePath = '.tea/tea.xyz/gui';
|
||||||
interface Session {
|
interface Session {
|
||||||
device_id?: string;
|
device_id?: string;
|
||||||
key?: string;
|
key?: string;
|
||||||
user?: any;
|
user?: Developer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function initAuthStore() {
|
export default function initAuthStore() {
|
||||||
|
@ -69,8 +69,8 @@ export default function initAuthStore() {
|
||||||
return {
|
return {
|
||||||
deviceId,
|
deviceId,
|
||||||
deviceIdStore,
|
deviceIdStore,
|
||||||
subscribe: (cb: (u: User) => void) => {
|
subscribe: (cb: (u: Developer) => void) => {
|
||||||
return session.subscribe((v) => v && cb(v.user));
|
return session.subscribe((v) => v?.user && cb(v.user));
|
||||||
},
|
},
|
||||||
pollSession
|
pollSession
|
||||||
};
|
};
|
||||||
|
@ -96,7 +96,7 @@ const getLocalSessionData = async (): Promise<Session | void> => {
|
||||||
data = JSON.parse(encryptedData || '{}');
|
data = JSON.parse(encryptedData || '{}');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const deviceId = await getDeviceId();
|
const deviceId = await registerDevice();
|
||||||
data = {
|
data = {
|
||||||
device_id: deviceId
|
device_id: deviceId
|
||||||
};
|
};
|
||||||
|
@ -113,17 +113,3 @@ const saveLocallySessionData = async (data: Session) => {
|
||||||
dir: BaseDirectory.Home
|
dir: BaseDirectory.Home
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDeviceId = async (): Promise<string> => {
|
|
||||||
const hasLocal = false;
|
|
||||||
// get from local data
|
|
||||||
// else get from server
|
|
||||||
// GET /v1/auth/registerDevice
|
|
||||||
let deviceId = '';
|
|
||||||
if (hasLocal) {
|
|
||||||
} else {
|
|
||||||
deviceId = await registerDevice();
|
|
||||||
}
|
|
||||||
console.log('deviceId:', deviceId);
|
|
||||||
return deviceId;
|
|
||||||
};
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ export type AirtablePost = {
|
||||||
tags: string[];
|
tags: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type User = {
|
export type Developer = {
|
||||||
developer_id: string;
|
developer_id: string;
|
||||||
avatar_url?: string;
|
avatar_url?: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
Loading…
Reference in a new issue