mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-09 20:12:14 +10:00
reorganisation, cleanup and new nonce protocol
This commit is contained in:
4
app.vue
4
app.vue
@ -43,4 +43,8 @@ listen("auth/failed", () => {
|
||||
listen("auth/finished", () => {
|
||||
router.push("/");
|
||||
});
|
||||
|
||||
useHead({
|
||||
title: "Drop"
|
||||
})
|
||||
</script>
|
||||
|
||||
@ -1,15 +1,17 @@
|
||||
<template>
|
||||
<div class="h-16 cursor-pointer bg-gray-950 flex flex-row justify-between">
|
||||
<div
|
||||
@mousedown="() => window.startDragging()"
|
||||
class="flex flex-row grow items-center justify-between pl-5 pr-2 py-3"
|
||||
>
|
||||
<div
|
||||
@mousedown="() => window.startDragging()"
|
||||
class="h-16 cursor-pointer bg-zinc-950 flex flex-row justify-between"
|
||||
>
|
||||
<div class="flex flex-row grow items-center justify-between pl-5 pr-2 py-3">
|
||||
<div class="inline-flex items-center gap-x-10">
|
||||
<Wordmark class="h-8 mb-0.5" />
|
||||
<NuxtLink to="/">
|
||||
<Wordmark class="h-8 mb-0.5" />
|
||||
</NuxtLink>
|
||||
<nav class="inline-flex items-center mt-0.5">
|
||||
<ol class="inline-flex items-center gap-x-6">
|
||||
<li
|
||||
class="transition text-gray-300 hover:text-gray-100 uppercase font-display font-semibold text-md"
|
||||
class="transition text-zinc-300 hover:text-zinc-100 uppercase font-display font-semibold text-md"
|
||||
v-for="(nav, navIdx) in navigation"
|
||||
>
|
||||
{{ nav.label }}
|
||||
|
||||
@ -49,15 +49,16 @@
|
||||
Admin Dashboard
|
||||
</a>
|
||||
</MenuItem>
|
||||
<MenuItem v-for="(nav, navIdx) in navigation" v-slot="{ active }">
|
||||
<NuxtLink
|
||||
<MenuItem v-for="(nav, navIdx) in navigation" v-slot="{ active, close }">
|
||||
<button
|
||||
@click="() => navigate(close, nav)"
|
||||
:href="nav.route"
|
||||
:class="[
|
||||
active ? 'bg-zinc-800 text-zinc-100' : 'text-zinc-400',
|
||||
'transition block px-4 py-2 text-sm',
|
||||
'transition text-left block px-4 py-2 text-sm',
|
||||
]"
|
||||
>
|
||||
{{ nav.label }}</NuxtLink
|
||||
{{ nav.label }}</button
|
||||
>
|
||||
</MenuItem>
|
||||
</div>
|
||||
@ -75,6 +76,12 @@ import HeaderWidget from "./HeaderWidget.vue";
|
||||
import { useAppState } from "~/composables/app-state";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
const open = ref(false);
|
||||
const router = useRouter();
|
||||
router.afterEach(() => {
|
||||
open.value = false;
|
||||
})
|
||||
|
||||
const state = useAppState();
|
||||
const profilePictureUrl: string = await invoke("gen_drop_url", {
|
||||
path: `/api/v1/object/${state.value.user?.profilePicture}`,
|
||||
@ -83,16 +90,26 @@ const adminUrl: string = await invoke("gen_drop_url", {
|
||||
path: "/admin",
|
||||
});
|
||||
|
||||
function navigate(close: () => any, to: NavigationItem){
|
||||
close();
|
||||
router.push(to.route);
|
||||
}
|
||||
|
||||
const navigation: NavigationItem[] = [
|
||||
{
|
||||
label: "Account settings",
|
||||
route: "/account",
|
||||
prefix: "",
|
||||
},
|
||||
{
|
||||
label: "App settings",
|
||||
route: "/settings",
|
||||
prefix: "",
|
||||
},
|
||||
{
|
||||
label: "Sign out",
|
||||
route: "/signout",
|
||||
prefix: "",
|
||||
},
|
||||
].filter((e) => e !== undefined);
|
||||
]
|
||||
</script>
|
||||
|
||||
@ -14,9 +14,9 @@
|
||||
<slot />
|
||||
<div class="mt-10">
|
||||
<button
|
||||
@click="() => auth()"
|
||||
@click="() => authWrapper_wrapper()"
|
||||
:disabled="loading"
|
||||
class="text-sm font-semibold leading-7 text-blue-600"
|
||||
class="text-sm text-left font-semibold leading-7 text-blue-600"
|
||||
>
|
||||
<div v-if="loading" role="status">
|
||||
<svg
|
||||
@ -40,6 +40,22 @@
|
||||
<span v-else>
|
||||
Sign in with your browser <span aria-hidden="true">→</span>
|
||||
</span>
|
||||
|
||||
<div v-if="error" class="mt-5 rounded-md bg-red-600/10 p-4">
|
||||
<div class="flex">
|
||||
<div class="flex-shrink-0">
|
||||
<XCircleIcon
|
||||
class="h-5 w-5 text-red-600"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
<div class="ml-3">
|
||||
<h3 class="text-sm font-medium text-red-600">
|
||||
{{ error }}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -82,12 +98,21 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { XCircleIcon } from "@heroicons/vue/16/solid";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
const loading = ref(false);
|
||||
const error = ref<string | undefined>();
|
||||
|
||||
async function auth() {
|
||||
loading.value = true;
|
||||
await invoke("auth_initiate");
|
||||
}
|
||||
|
||||
function authWrapper_wrapper() {
|
||||
loading.value = true;
|
||||
auth().catch((e) => {
|
||||
loading.value = false;
|
||||
error.value = e;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
30
composables/current-page-engine.ts
Normal file
30
composables/current-page-engine.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import type { RouteLocationNormalized } from "vue-router";
|
||||
import type { NavigationItem } from "~/components/types";
|
||||
|
||||
export const useCurrentNavigationIndex = (
|
||||
navigation: Array<NavigationItem>
|
||||
) => {
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
const currentNavigation = ref(-1);
|
||||
|
||||
function calculateCurrentNavIndex(to: RouteLocationNormalized) {
|
||||
const validOptions = navigation
|
||||
.map((e, i) => ({ ...e, index: i }))
|
||||
.filter((e) => to.fullPath.startsWith(e.prefix));
|
||||
const bestOption = validOptions
|
||||
.sort((a, b) => b.route.length - a.route.length)
|
||||
.at(0);
|
||||
|
||||
return bestOption?.index ?? -1;
|
||||
}
|
||||
|
||||
currentNavigation.value = calculateCurrentNavIndex(route);
|
||||
|
||||
router.afterEach((to) => {
|
||||
currentNavigation.value = calculateCurrentNavIndex(to);
|
||||
});
|
||||
|
||||
return currentNavigation;
|
||||
};
|
||||
@ -16,6 +16,7 @@
|
||||
"@heroicons/vue": "^2.1.5",
|
||||
"@tauri-apps/api": ">=2.0.0",
|
||||
"@tauri-apps/plugin-deep-link": "~2",
|
||||
"@tauri-apps/plugin-dialog": "~2",
|
||||
"@tauri-apps/plugin-shell": ">=2.0.0",
|
||||
"nuxt": "^3.13.0",
|
||||
"scss": "^0.2.4",
|
||||
|
||||
74
pages/settings.vue
Normal file
74
pages/settings.vue
Normal file
@ -0,0 +1,74 @@
|
||||
<template>
|
||||
<div class="mx-auto max-w-7xl px-8">
|
||||
<div class="border-b border-zinc-700 py-5">
|
||||
<h3 class="text-base font-semibold font-display leading-6 text-zinc-100">
|
||||
Settings
|
||||
</h3>
|
||||
</div>
|
||||
<div class="mt-5 flex flex-row gap-12">
|
||||
<nav class="flex flex-col" aria-label="Sidebar">
|
||||
<ul role="list" class="-mx-2 space-y-1">
|
||||
<li v-for="(item, itemIdx) in navigation" :key="item.prefix">
|
||||
<NuxtLink
|
||||
:href="item.route"
|
||||
:class="[
|
||||
itemIdx === currentPageIndex
|
||||
? 'bg-zinc-800/50 text-blue-600'
|
||||
: 'text-zinc-400 hover:bg-zinc-800/30 hover:text-blue-600',
|
||||
'transition group flex gap-x-3 rounded-md p-2 pr-12 text-sm font-semibold leading-6',
|
||||
]"
|
||||
>
|
||||
<component
|
||||
:is="item.icon"
|
||||
:class="[
|
||||
itemIdx === currentPageIndex
|
||||
? 'text-blue-600'
|
||||
: 'text-zinc-400 group-hover:text-blue-600',
|
||||
'transition h-6 w-6 shrink-0',
|
||||
]"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
{{ item.label }}
|
||||
</NuxtLink>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div class="grow">
|
||||
<NuxtPage />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ArrowDownTrayIcon,
|
||||
HomeIcon,
|
||||
RectangleGroupIcon,
|
||||
} from "@heroicons/vue/16/solid";
|
||||
import type { Component } from "vue";
|
||||
import type { NavigationItem } from "~/components/types";
|
||||
|
||||
const navigation: Array<NavigationItem & { icon: Component }> = [
|
||||
{
|
||||
label: "Home",
|
||||
route: "/settings",
|
||||
prefix: "/settings",
|
||||
icon: HomeIcon,
|
||||
},
|
||||
{
|
||||
label: "Interface",
|
||||
route: "/settings/interface",
|
||||
prefix: "/settings/interface",
|
||||
icon: RectangleGroupIcon,
|
||||
},
|
||||
{
|
||||
label: "Downloads",
|
||||
route: "/settings/downloads",
|
||||
prefix: "/settings/downloads",
|
||||
icon: ArrowDownTrayIcon,
|
||||
},
|
||||
];
|
||||
|
||||
const currentPageIndex = useCurrentNavigationIndex(navigation);
|
||||
</script>
|
||||
3
pages/settings/downloads.vue
Normal file
3
pages/settings/downloads.vue
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
|
||||
</template>
|
||||
3
pages/settings/index.vue
Normal file
3
pages/settings/index.vue
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<h1>Home</h1>
|
||||
</template>
|
||||
3
pages/settings/interface.vue
Normal file
3
pages/settings/interface.vue
Normal file
@ -0,0 +1,3 @@
|
||||
<template>
|
||||
|
||||
</template>
|
||||
@ -60,7 +60,7 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<p class="mt-10 text-center text-sm text-gray-500">
|
||||
<p class="mt-10 text-center text-sm text-zinc-500">
|
||||
Don't have one?
|
||||
{{ " " }}
|
||||
<a
|
||||
|
||||
193
src-tauri/Cargo.lock
generated
193
src-tauri/Cargo.lock
generated
@ -62,6 +62,27 @@ version = "1.0.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
|
||||
|
||||
[[package]]
|
||||
name = "ashpd"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d43c03d9e36dd40cab48435be0b09646da362c278223ca535493877b2c1dee9"
|
||||
dependencies = [
|
||||
"enumflags2",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"rand 0.8.5",
|
||||
"raw-window-handle",
|
||||
"serde",
|
||||
"serde_repr",
|
||||
"tokio",
|
||||
"url",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-broadcast"
|
||||
version = "0.7.1"
|
||||
@ -882,6 +903,15 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b"
|
||||
|
||||
[[package]]
|
||||
name = "dlib"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412"
|
||||
dependencies = [
|
||||
"libloading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dlopen2"
|
||||
version = "0.7.0"
|
||||
@ -914,6 +944,12 @@ dependencies = [
|
||||
"const-random",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "downcast-rs"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
|
||||
|
||||
[[package]]
|
||||
name = "dpi"
|
||||
version = "0.1.1"
|
||||
@ -932,7 +968,6 @@ dependencies = [
|
||||
"hex",
|
||||
"log",
|
||||
"openssl",
|
||||
"os_info",
|
||||
"rayon",
|
||||
"reqwest",
|
||||
"rustbreak",
|
||||
@ -942,6 +977,7 @@ dependencies = [
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tauri-plugin-deep-link",
|
||||
"tauri-plugin-dialog",
|
||||
"tauri-plugin-shell",
|
||||
"tauri-plugin-single-instance",
|
||||
"url",
|
||||
@ -2382,6 +2418,7 @@ checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"block2",
|
||||
"dispatch",
|
||||
"libc",
|
||||
"objc2",
|
||||
]
|
||||
@ -2528,17 +2565,6 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_info"
|
||||
version = "3.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae99c7fa6dd38c7cafe1ec085e804f8f555a2f8659b0dbe03f1f9963a9b51092"
|
||||
dependencies = [
|
||||
"log",
|
||||
"serde",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_pipe"
|
||||
version = "1.2.1"
|
||||
@ -2786,7 +2812,7 @@ checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"indexmap 2.6.0",
|
||||
"quick-xml",
|
||||
"quick-xml 0.32.0",
|
||||
"serde",
|
||||
"time",
|
||||
]
|
||||
@ -2914,6 +2940,15 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.37"
|
||||
@ -3125,6 +3160,29 @@ dependencies = [
|
||||
"windows-registry 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rfd"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8af382a047821a08aa6bfc09ab0d80ff48d45d8726f7cd8e44891f7cb4a4278e"
|
||||
dependencies = [
|
||||
"ashpd",
|
||||
"block2",
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
"gtk-sys",
|
||||
"js-sys",
|
||||
"log",
|
||||
"objc2",
|
||||
"objc2-app-kit",
|
||||
"objc2-foundation",
|
||||
"raw-window-handle",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.17.8"
|
||||
@ -3282,6 +3340,12 @@ dependencies = [
|
||||
"syn 2.0.79",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scoped-tls"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
@ -4058,6 +4122,45 @@ dependencies = [
|
||||
"windows-result",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-dialog"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddb2fe88b602461c118722c574e2775ab26a4e68886680583874b2f6520608b7"
|
||||
dependencies = [
|
||||
"log",
|
||||
"raw-window-handle",
|
||||
"rfd",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
"tauri-plugin",
|
||||
"tauri-plugin-fs",
|
||||
"thiserror",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-fs"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab300488ebec3487ca5f56289692e7e45feb07eea8d5e1dba497f7dc9dd9c407"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"dunce",
|
||||
"glob",
|
||||
"percent-encoding",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"tauri",
|
||||
"tauri-plugin",
|
||||
"thiserror",
|
||||
"url",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-shell"
|
||||
version = "2.0.1"
|
||||
@ -4303,7 +4406,9 @@ dependencies = [
|
||||
"mio",
|
||||
"parking_lot",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
"tracing",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
@ -4805,6 +4910,66 @@ dependencies = [
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-backend"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "056535ced7a150d45159d3a8dc30f91a2e2d588ca0b23f70e56033622b8016f6"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"downcast-rs",
|
||||
"rustix",
|
||||
"scoped-tls",
|
||||
"smallvec",
|
||||
"wayland-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-client"
|
||||
version = "0.31.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3f45d1222915ef1fd2057220c1d9d9624b7654443ea35c3877f7a52bd0a5a2d"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"rustix",
|
||||
"wayland-backend",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols"
|
||||
version = "0.32.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b5755d77ae9040bb872a25026555ce4cb0ae75fd923e90d25fba07d81057de0"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-scanner"
|
||||
version = "0.31.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "597f2001b2e5fc1121e3d5b9791d3e78f05ba6bfa4641053846248e3a13661c3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quick-xml 0.36.2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-sys"
|
||||
version = "0.31.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "efa8ac0d8e8ed3e3b5c9fc92c7881406a268e11555abe36493efabe649a29e09"
|
||||
dependencies = [
|
||||
"dlib",
|
||||
"log",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.70"
|
||||
@ -5405,6 +5570,7 @@ dependencies = [
|
||||
"serde_repr",
|
||||
"sha1",
|
||||
"static_assertions",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"uds_windows",
|
||||
"windows-sys 0.52.0",
|
||||
@ -5476,6 +5642,7 @@ dependencies = [
|
||||
"enumflags2",
|
||||
"serde",
|
||||
"static_assertions",
|
||||
"url",
|
||||
"zvariant_derive",
|
||||
]
|
||||
|
||||
|
||||
@ -30,11 +30,11 @@ rayon = "1.10.0"
|
||||
directories = "5.0.1"
|
||||
webbrowser = "1.0.2"
|
||||
url = "2.5.2"
|
||||
os_info = "3.8.2"
|
||||
tauri-plugin-deep-link = "2"
|
||||
log = "0.4.22"
|
||||
structured-logger = "1.0.3"
|
||||
hex = "0.4.3"
|
||||
tauri-plugin-dialog = "2"
|
||||
|
||||
[dependencies.uuid]
|
||||
version = "1.10.0"
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
"core:window:allow-minimize",
|
||||
"core:window:allow-maximize",
|
||||
"core:window:allow-close",
|
||||
"deep-link:default"
|
||||
"deep-link:default",
|
||||
"dialog:default"
|
||||
]
|
||||
}
|
||||
@ -1,10 +1,11 @@
|
||||
use std::{
|
||||
borrow::{Borrow, BorrowMut},
|
||||
env,
|
||||
fmt::format,
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
use log::info;
|
||||
use log::{info, warn};
|
||||
use openssl::{
|
||||
ec::EcKey,
|
||||
hash::MessageDigest,
|
||||
@ -12,11 +13,11 @@ use openssl::{
|
||||
sign::{self, Signer},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::{App, AppHandle, Emitter, Error, EventLoopMessage, Manager, Wry};
|
||||
use tauri::{http::response, App, AppHandle, Emitter, EventLoopMessage, Manager, Wry};
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{data::DatabaseAuth, AppState, AppStatus, User, DB};
|
||||
use crate::{db::DatabaseAuth, AppState, AppStatus, User, DB};
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct InitiateRequestBody {
|
||||
@ -49,7 +50,7 @@ macro_rules! unwrap_or_return {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn sign_nonce(private_key: String, nonce: String) -> Result<String, Error> {
|
||||
pub fn sign_nonce(private_key: String, nonce: String) -> Result<String, ()> {
|
||||
let client_private_key = EcKey::private_key_from_pem(private_key.as_bytes()).unwrap();
|
||||
let pkey_private_key = PKey::from_ec_key(client_private_key).unwrap();
|
||||
|
||||
@ -74,7 +75,7 @@ pub fn generate_authorization_header() -> String {
|
||||
return format!("Nonce {} {} {}", certs.clientId, nonce, signature);
|
||||
}
|
||||
|
||||
pub fn fetch_user() -> Result<User, Error> {
|
||||
pub fn fetch_user() -> Result<User, ()> {
|
||||
let base_url = {
|
||||
let handle = DB.borrow_data().unwrap();
|
||||
Url::parse(&handle.base_url).unwrap()
|
||||
@ -90,6 +91,11 @@ pub fn fetch_user() -> Result<User, Error> {
|
||||
.send()
|
||||
.unwrap();
|
||||
|
||||
if response.status() != 200 {
|
||||
warn!("Failed to fetch user: {}", response.status());
|
||||
return Err(());
|
||||
}
|
||||
|
||||
let user = response.json::<User>().unwrap();
|
||||
|
||||
return Ok(user);
|
||||
@ -138,11 +144,10 @@ pub fn recieve_handshake(app: AppHandle, path: String) {
|
||||
let app_state = app.state::<Mutex<AppState>>();
|
||||
let mut app_state_handle = app_state.lock().unwrap();
|
||||
app_state_handle.status = AppStatus::SignedIn;
|
||||
app_state_handle.user = Some(fetch_user().unwrap());
|
||||
}
|
||||
|
||||
app.emit("auth/finished", ()).unwrap();
|
||||
|
||||
fetch_user().unwrap();
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@ -152,12 +157,10 @@ pub async fn auth_initiate<'a>() -> Result<(), String> {
|
||||
Url::parse(&db_lock.base_url.clone()).unwrap()
|
||||
};
|
||||
|
||||
let current_os_info = os_info::get();
|
||||
|
||||
let endpoint = base_url.join("/api/v1/client/auth/initiate").unwrap();
|
||||
let body = InitiateRequestBody {
|
||||
name: format!("Drop Desktop Client"),
|
||||
platform: current_os_info.os_type().to_string(),
|
||||
platform: env::consts::OS.to_string(),
|
||||
};
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
@ -168,6 +171,10 @@ pub async fn auth_initiate<'a>() -> Result<(), String> {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if response.status() != 200 {
|
||||
return Err("Failed to create redirect URL. Please try again later.".to_string());
|
||||
}
|
||||
|
||||
let redir_url = response.text().await.unwrap();
|
||||
let complete_redir_url = base_url.join(&redir_url).unwrap();
|
||||
|
||||
@ -177,7 +184,7 @@ pub async fn auth_initiate<'a>() -> Result<(), String> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn setup() -> Result<(AppStatus, Option<User>), Error> {
|
||||
pub fn setup() -> Result<(AppStatus, Option<User>), ()> {
|
||||
let data = DB.borrow_data().unwrap();
|
||||
|
||||
// If we have certs, exit for now
|
||||
@ -186,7 +193,7 @@ pub fn setup() -> Result<(AppStatus, Option<User>), Error> {
|
||||
if user_result.is_err() {
|
||||
return Ok((AppStatus::SignedInNeedsReauth, None));
|
||||
}
|
||||
return Ok((AppStatus::SignedIn, Some(user_result.unwrap())))
|
||||
return Ok((AppStatus::SignedIn, Some(user_result.unwrap())));
|
||||
}
|
||||
|
||||
drop(data);
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
use std::fs;
|
||||
use std::{
|
||||
fs::{self, create_dir_all},
|
||||
path::PathBuf,
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use directories::BaseDirs;
|
||||
use rustbreak::{deser::Bincode, PathDatabase};
|
||||
@ -13,20 +17,37 @@ pub struct DatabaseAuth {
|
||||
pub clientId: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Clone, Deserialize)]
|
||||
pub struct DatabaseApps {
|
||||
pub apps_base_dir: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, Clone, Deserialize)]
|
||||
pub struct Database {
|
||||
pub auth: Option<DatabaseAuth>,
|
||||
pub base_url: String,
|
||||
pub downloads: DatabaseApps,
|
||||
}
|
||||
|
||||
pub type DatabaseInterface =
|
||||
rustbreak::Database<Database, rustbreak::backend::PathBackend, Bincode>;
|
||||
|
||||
pub static DATA_ROOT_DIR: LazyLock<PathBuf> =
|
||||
LazyLock::new(|| BaseDirs::new().unwrap().data_dir().join("drop"));
|
||||
|
||||
pub fn setup() -> DatabaseInterface {
|
||||
let db_path = BaseDirs::new().unwrap().data_dir().join("drop");
|
||||
let db_path = DATA_ROOT_DIR.join("drop.db");
|
||||
let apps_base_dir = DATA_ROOT_DIR.join("apps");
|
||||
|
||||
create_dir_all(DATA_ROOT_DIR.clone()).unwrap();
|
||||
create_dir_all(apps_base_dir.clone()).unwrap();
|
||||
|
||||
let default = Database {
|
||||
auth: None,
|
||||
base_url: "".to_string(),
|
||||
downloads: DatabaseApps {
|
||||
apps_base_dir: apps_base_dir.to_str().unwrap().to_string(),
|
||||
},
|
||||
};
|
||||
let db = match fs::exists(db_path.clone()).unwrap() {
|
||||
true => PathDatabase::load_from_path(db_path).expect("Database loading failed"),
|
||||
@ -1,5 +1,5 @@
|
||||
mod auth;
|
||||
mod data;
|
||||
mod db;
|
||||
mod remote;
|
||||
mod unpacker;
|
||||
|
||||
@ -10,7 +10,7 @@ use std::{
|
||||
};
|
||||
|
||||
use auth::{auth_initiate, recieve_handshake};
|
||||
use data::DatabaseInterface;
|
||||
use db::{DatabaseInterface, DATA_ROOT_DIR};
|
||||
use log::info;
|
||||
use remote::{gen_drop_url, use_remote};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -52,7 +52,7 @@ fn setup<'a>() -> AppState {
|
||||
.with_target_writer("*", new_writer(io::stdout()))
|
||||
.init();
|
||||
|
||||
let is_set_up = data::is_set_up();
|
||||
let is_set_up = db::is_set_up();
|
||||
if !is_set_up {
|
||||
return AppState {
|
||||
status: AppStatus::NotConfigured,
|
||||
@ -67,14 +67,14 @@ fn setup<'a>() -> AppState {
|
||||
};
|
||||
}
|
||||
|
||||
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(|| data::setup());
|
||||
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(|| db::setup());
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let state = setup();
|
||||
info!("Initialized drop client");
|
||||
|
||||
let mut builder = tauri::Builder::default();
|
||||
let mut builder = tauri::Builder::default().plugin(tauri_plugin_dialog::init());
|
||||
|
||||
#[cfg(desktop)]
|
||||
{
|
||||
@ -103,6 +103,19 @@ pub fn run() {
|
||||
|
||||
let handle = app.handle().clone();
|
||||
|
||||
let main_window = tauri::WebviewWindowBuilder::new(
|
||||
&handle,
|
||||
"main", // BTW this is not the name of the window, just the label. Keep this 'main', there are permissions & configs that depend on it
|
||||
tauri::WebviewUrl::App("index.html".into()),
|
||||
)
|
||||
.title("Drop Desktop App")
|
||||
.min_inner_size(900.0, 900.0)
|
||||
.inner_size(1536.0, 864.0)
|
||||
.decorations(false)
|
||||
.data_directory(DATA_ROOT_DIR.join(".webview"))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
app.deep_link().on_open_url(move |event| {
|
||||
info!("handling drop:// url");
|
||||
let binding = event.urls();
|
||||
@ -112,6 +125,7 @@ pub fn run() {
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
|
||||
@ -10,16 +10,6 @@
|
||||
"frontendDist": "../.output/public"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"title": "Drop",
|
||||
"width": 1536,
|
||||
"height": 864,
|
||||
"minWidth": 820,
|
||||
"minHeight": 600,
|
||||
"decorations": false
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
|
||||
@ -1335,6 +1335,13 @@
|
||||
dependencies:
|
||||
"@tauri-apps/api" "^2.0.0"
|
||||
|
||||
"@tauri-apps/plugin-dialog@~2":
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-dialog/-/plugin-dialog-2.0.0.tgz#f1e2840c7f824572a76b375fd1b538a36f28de14"
|
||||
integrity sha512-ApNkejXP2jpPBSifznPPcHTXxu9/YaRW+eJ+8+nYwqp0lLUtebFHG4QhxitM43wwReHE81WAV1DQ/b+2VBftOA==
|
||||
dependencies:
|
||||
"@tauri-apps/api" "^2.0.0"
|
||||
|
||||
"@tauri-apps/plugin-shell@>=2.0.0":
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-shell/-/plugin-shell-2.0.0.tgz#b6fc88ab070fd5f620e46405715779aa44eb8428"
|
||||
|
||||
Reference in New Issue
Block a user