mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2026-06-22 04:11:37 +10:00
client now fetches user information from Drop server
This commit is contained in:
@@ -1,22 +1,26 @@
|
|||||||
<template>
|
<template>
|
||||||
<NuxtLayout class="select-none">
|
<NuxtLayout class="select-none w-screen h-screen">
|
||||||
<NuxtPage />
|
<NuxtPage />
|
||||||
</NuxtLayout>
|
</NuxtLayout>
|
||||||
{{ state }}
|
|
||||||
<input type="text" v-model="debugLocation" />
|
|
||||||
<NuxtLink :to="debugLocation">Go</NuxtLink>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
import { AppStatus } from "./types.d.ts";
|
import { AppStatus, type AppState } from "./types.d.ts";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import { useAppState } from "./composables/app-state.js";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const state: { status: AppStatus } = await invoke("fetch_state");
|
const state = useAppState();
|
||||||
switch (state.status) {
|
state.value = await invoke("fetch_state");
|
||||||
|
|
||||||
|
router.beforeEach(async () => {
|
||||||
|
state.value = await invoke("fetch_state");
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (state.value.status) {
|
||||||
case AppStatus.NotConfigured:
|
case AppStatus.NotConfigured:
|
||||||
router.push("/setup");
|
router.push("/setup");
|
||||||
break;
|
break;
|
||||||
@@ -39,6 +43,4 @@ listen("auth/failed", () => {
|
|||||||
listen("auth/finished", () => {
|
listen("auth/finished", () => {
|
||||||
router.push("/");
|
router.push("/");
|
||||||
});
|
});
|
||||||
|
|
||||||
const debugLocation = ref("");
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<Menu as="div" class="relative inline-block">
|
<Menu v-if="state.user" as="div" class="relative inline-block">
|
||||||
<MenuButton>
|
<MenuButton>
|
||||||
<HeaderWidget>
|
<HeaderWidget>
|
||||||
<div class="inline-flex items-center text-zinc-300 hover:text-white">
|
<div class="inline-flex items-center text-zinc-300 hover:text-white">
|
||||||
<img :src="userData.image" class="w-5 h-5 rounded-sm" />
|
<img :src="profilePictureUrl" class="w-5 h-5 rounded-sm" />
|
||||||
<span class="ml-2 text-sm font-bold">{{ userData.name }}</span>
|
<span class="ml-2 text-sm font-bold">{{
|
||||||
|
state.user.displayName
|
||||||
|
}}</span>
|
||||||
<ChevronDownIcon class="ml-3 h-4" />
|
<ChevronDownIcon class="ml-3 h-4" />
|
||||||
</div>
|
</div>
|
||||||
</HeaderWidget>
|
</HeaderWidget>
|
||||||
@@ -27,12 +29,25 @@
|
|||||||
class="transition inline-flex items-center w-full py-3 px-4 hover:bg-zinc-800"
|
class="transition inline-flex items-center w-full py-3 px-4 hover:bg-zinc-800"
|
||||||
>
|
>
|
||||||
<div class="inline-flex items-center text-zinc-300">
|
<div class="inline-flex items-center text-zinc-300">
|
||||||
<img :src="userData.image" class="w-5 h-5 rounded-sm" />
|
<img :src="profilePictureUrl" class="w-5 h-5 rounded-sm" />
|
||||||
<span class="ml-2 text-sm font-bold">{{ userData.name }}</span>
|
<span class="ml-2 text-sm font-bold">{{
|
||||||
|
state.user.displayName
|
||||||
|
}}</span>
|
||||||
</div>
|
</div>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<div class="h-0.5 rounded-full w-full bg-zinc-800" />
|
<div class="h-0.5 rounded-full w-full bg-zinc-800" />
|
||||||
<div class="flex flex-col mb-1">
|
<div class="flex flex-col mb-1">
|
||||||
|
<MenuItem v-slot="{ active }">
|
||||||
|
<NuxtLink
|
||||||
|
@click="() => openAdminUrl()"
|
||||||
|
:class="[
|
||||||
|
active ? 'bg-zinc-800 text-zinc-100' : 'text-zinc-400',
|
||||||
|
'transition block px-4 py-2 text-sm',
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
Admin Dashboard
|
||||||
|
</NuxtLink>
|
||||||
|
</MenuItem>
|
||||||
<MenuItem v-for="(nav, navIdx) in navigation" v-slot="{ active }">
|
<MenuItem v-for="(nav, navIdx) in navigation" v-slot="{ active }">
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
:href="nav.route"
|
:href="nav.route"
|
||||||
@@ -56,18 +71,22 @@ import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/vue";
|
|||||||
import { ChevronDownIcon } from "@heroicons/vue/16/solid";
|
import { ChevronDownIcon } from "@heroicons/vue/16/solid";
|
||||||
import type { NavigationItem } from "./types";
|
import type { NavigationItem } from "./types";
|
||||||
import HeaderWidget from "./HeaderWidget.vue";
|
import HeaderWidget from "./HeaderWidget.vue";
|
||||||
|
import { useAppState } from "~/composables/app-state";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
const userData = {
|
const state = useAppState();
|
||||||
image: "https://avatars.githubusercontent.com/u/64579723?v=4",
|
const profilePictureUrl: string = await invoke("gen_drop_url", {
|
||||||
name: "DecDuck",
|
path: `/api/v1/object/${state.value.user?.profilePicture}`,
|
||||||
};
|
});
|
||||||
|
const adminUrl: string = await invoke("gen_drop_url", {
|
||||||
|
path: "/admin",
|
||||||
|
});
|
||||||
|
|
||||||
|
async function openAdminUrl() {
|
||||||
|
await invoke("open_url", { path: adminUrl });
|
||||||
|
}
|
||||||
|
|
||||||
const navigation: NavigationItem[] = [
|
const navigation: NavigationItem[] = [
|
||||||
{
|
|
||||||
label: "Admin Dashboard",
|
|
||||||
route: "/admin",
|
|
||||||
prefix: "",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: "Account settings",
|
label: "Account settings",
|
||||||
route: "/account",
|
route: "/account",
|
||||||
@@ -78,5 +97,5 @@ const navigation: NavigationItem[] = [
|
|||||||
route: "/signout",
|
route: "/signout",
|
||||||
prefix: "",
|
prefix: "",
|
||||||
},
|
},
|
||||||
];
|
].filter((e) => e !== undefined);
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import type { AppState } from "~/types";
|
||||||
|
|
||||||
|
export const useAppState = () => useState<AppState>("state");
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col bg-zinc-900 h-screen w-screen overflow-hidden">
|
<div class="flex flex-col bg-zinc-900 overflow-hidden">
|
||||||
<Header class="select-none" />
|
<Header class="select-none" />
|
||||||
<div class="grow overflow-y-scroll">
|
<div class="grow overflow-y-scroll">
|
||||||
<slot />
|
<slot />
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col bg-zinc-950 h-screen w-screen overflow-hidden">
|
<div class="flex flex-col bg-zinc-950 overflow-hidden">
|
||||||
<MiniHeader />
|
<MiniHeader />
|
||||||
<div class="grow overflow-y-scroll">
|
<div class="grow overflow-y-scroll">
|
||||||
<slot />
|
<slot />
|
||||||
|
|||||||
+5
-1
@@ -1 +1,5 @@
|
|||||||
<template></template>
|
<template>{{state}}</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
const state = useAppState();
|
||||||
|
</script>
|
||||||
@@ -185,7 +185,6 @@ pub fn setup() -> Result<(AppStatus, Option<User>), Error> {
|
|||||||
let user_result = fetch_user();
|
let user_result = fetch_user();
|
||||||
if user_result.is_err() {
|
if user_result.is_err() {
|
||||||
return Ok((AppStatus::SignedInNeedsReauth, None));
|
return Ok((AppStatus::SignedInNeedsReauth, None));
|
||||||
|
|
||||||
}
|
}
|
||||||
return Ok((AppStatus::SignedIn, Some(user_result.unwrap())))
|
return Ok((AppStatus::SignedIn, Some(user_result.unwrap())))
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-5
@@ -12,7 +12,7 @@ use std::{
|
|||||||
use auth::{auth_initiate, recieve_handshake};
|
use auth::{auth_initiate, recieve_handshake};
|
||||||
use data::DatabaseInterface;
|
use data::DatabaseInterface;
|
||||||
use log::info;
|
use log::info;
|
||||||
use remote::use_remote;
|
use remote::{gen_drop_url, open_url, use_remote};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use structured_logger::{json::new_writer, Builder};
|
use structured_logger::{json::new_writer, Builder};
|
||||||
use tauri_plugin_deep_link::DeepLinkExt;
|
use tauri_plugin_deep_link::DeepLinkExt;
|
||||||
@@ -24,10 +24,16 @@ pub enum AppStatus {
|
|||||||
SignedIn,
|
SignedIn,
|
||||||
SignedInNeedsReauth,
|
SignedInNeedsReauth,
|
||||||
}
|
}
|
||||||
#[derive(Clone, Copy, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub struct User {}
|
pub struct User {
|
||||||
|
id: String,
|
||||||
|
username: String,
|
||||||
|
admin: bool,
|
||||||
|
displayName: String,
|
||||||
|
profilePicture: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Serialize)]
|
#[derive(Clone, Serialize)]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
status: AppStatus,
|
status: AppStatus,
|
||||||
user: Option<User>,
|
user: Option<User>,
|
||||||
@@ -83,7 +89,9 @@ pub fn run() {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
fetch_state,
|
fetch_state,
|
||||||
auth_initiate,
|
auth_initiate,
|
||||||
use_remote
|
use_remote,
|
||||||
|
gen_drop_url,
|
||||||
|
open_url,
|
||||||
])
|
])
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
|
use openssl::x509::store::HashDir;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use tauri::async_runtime::handle;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{AppState, AppStatus, DB};
|
use crate::{AppState, AppStatus, DB};
|
||||||
@@ -59,3 +61,26 @@ pub async fn use_remote<'a>(
|
|||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn open_url(path: String) -> Result<(), String> {
|
||||||
|
webbrowser::open(&path).unwrap();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn gen_drop_url(app: tauri::AppHandle, path: String) -> Result<String, String> {
|
||||||
|
let base_url = {
|
||||||
|
let handle = DB.borrow_data().unwrap();
|
||||||
|
|
||||||
|
if handle.base_url.is_empty() {
|
||||||
|
return Ok("".to_string());
|
||||||
|
};
|
||||||
|
|
||||||
|
Url::parse(&handle.base_url).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
let url = base_url.join(&path).unwrap();
|
||||||
|
|
||||||
|
return Ok(url.to_string());
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2.0.0",
|
"$schema": "https://schema.tauri.app/config/2.0.0",
|
||||||
"productName": "drop",
|
"productName": "Drop Desktop Client",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"identifier": "dev.drop.app",
|
"identifier": "dev.drop.app",
|
||||||
"build": {
|
"build": {
|
||||||
|
|||||||
Vendored
+19
-5
@@ -1,6 +1,20 @@
|
|||||||
|
export type AppState = {
|
||||||
|
status: AppStatus;
|
||||||
|
user?: User;
|
||||||
|
};
|
||||||
|
|
||||||
export enum AppStatus {
|
export enum AppStatus {
|
||||||
NotConfigured = "NotConfigured",
|
NotConfigured = "NotConfigured",
|
||||||
SignedOut = "SignedOut",
|
SignedOut = "SignedOut",
|
||||||
SignedIn = "SignedIn",
|
SignedIn = "SignedIn",
|
||||||
SignedInNeedsReauth = "SignedInNeedsReauth",
|
SignedInNeedsReauth = "SignedInNeedsReauth",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type User = {
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
admin: boolean;
|
||||||
|
email: string;
|
||||||
|
displayName: string;
|
||||||
|
profilePicture: string;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user