rework macos version

This commit is contained in:
Phong 2023-10-11 13:45:56 +07:00
parent c3f399ea0b
commit 2fcbf1987b
18 changed files with 394 additions and 445 deletions

View File

@ -33,6 +33,7 @@
"@radix-ui/react-tooltip": "^1.0.7", "@radix-ui/react-tooltip": "^1.0.7",
"@tanstack/react-query": "^4.36.1", "@tanstack/react-query": "^4.36.1",
"@tauri-apps/api": "2.0.0-alpha.8", "@tauri-apps/api": "2.0.0-alpha.8",
"@tauri-apps/cli": "2.0.0-alpha.15",
"@tauri-apps/plugin-app": "2.0.0-alpha.1", "@tauri-apps/plugin-app": "2.0.0-alpha.1",
"@tauri-apps/plugin-clipboard-manager": "2.0.0-alpha.1", "@tauri-apps/plugin-clipboard-manager": "2.0.0-alpha.1",
"@tauri-apps/plugin-dialog": "2.0.0-alpha.1", "@tauri-apps/plugin-dialog": "2.0.0-alpha.1",
@ -83,12 +84,11 @@
}, },
"devDependencies": { "devDependencies": {
"@tailwindcss/typography": "^0.5.10", "@tailwindcss/typography": "^0.5.10",
"@tauri-apps/cli": "2.0.0-alpha.14",
"@trivago/prettier-plugin-sort-imports": "^4.2.0", "@trivago/prettier-plugin-sort-imports": "^4.2.0",
"@types/html-to-text": "^9.0.2", "@types/html-to-text": "^9.0.2",
"@types/node": "^20.8.4", "@types/node": "^20.8.4",
"@types/react": "^18.2.27", "@types/react": "^18.2.28",
"@types/react-dom": "^18.2.12", "@types/react-dom": "^18.2.13",
"@types/youtube-player": "^5.5.8", "@types/youtube-player": "^5.5.8",
"@typescript-eslint/eslint-plugin": "^6.7.5", "@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5", "@typescript-eslint/parser": "^6.7.5",

File diff suppressed because it is too large Load Diff

10
src-tauri/Cargo.lock generated
View File

@ -2520,9 +2520,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]] [[package]]
name = "jobserver" name = "jobserver"
version = "0.1.26" version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@ -2724,8 +2724,6 @@ dependencies = [
name = "lume" name = "lume"
version = "1.2.6" version = "1.2.6"
dependencies = [ dependencies = [
"cocoa 0.25.0",
"objc",
"rust-argon2", "rust-argon2",
"serde", "serde",
"serde_json", "serde_json",
@ -6618,9 +6616,9 @@ dependencies = [
[[package]] [[package]]
name = "wry" name = "wry"
version = "0.33.0" version = "0.33.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf906b43b8042615c85a978dceb4d4b72214d27b850b54abc3edeb7c5a67abab" checksum = "2cb3bc6ed7e3d905a5a963a3e4e9ee5ede76408e50de42d68e523ee75ab1c78a"
dependencies = [ dependencies = [
"base64 0.21.4", "base64 0.21.4",
"block", "block",

View File

@ -8,15 +8,14 @@ repository = "https://github.com/luminous-devs/lume"
edition = "2021" edition = "2021"
rust-version = "1.66" rust-version = "1.66"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies] [build-dependencies]
tauri-build = { version = "2.0.0-alpha.8", features = [] } tauri-build = { version = "2.0.0-alpha", features = [] }
[dependencies] [dependencies]
serde_json = "1.0" serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
tauri = { version = "2.0.0-alpha", features = [ tauri = { version = "2.0.0-alpha", features = [
"macos-private-api",
"native-tls-vendored", "native-tls-vendored",
] } ] }
tauri-plugin-app = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } tauri-plugin-app = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
@ -45,10 +44,6 @@ sqlx-cli = { version = "0.7.0", default-features = false, features = [
rust-argon2 = "1.0" rust-argon2 = "1.0"
webpage = { version = "1.6.0", features = ["serde"] } webpage = { version = "1.6.0", features = ["serde"] }
[target.'cfg(any(target_os = "macos"))'.dependencies]
cocoa = "0.25.0"
objc = "0.2.7"
[features] [features]
# by default Tauri runs in production mode # by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL # when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL

View File

@ -4,7 +4,7 @@
)] )]
use std::time::Duration; use std::time::Duration;
use tauri::{Manager}; use tauri::Manager;
use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_sql::{Migration, MigrationKind}; use tauri_plugin_sql::{Migration, MigrationKind};
use webpage::{Webpage, WebpageOptions}; use webpage::{Webpage, WebpageOptions};
@ -92,6 +92,19 @@ async fn close_splashscreen(window: tauri::Window) {
fn main() { fn main() {
tauri::Builder::default() tauri::Builder::default()
/*
.setup(|app| {
let salt_path = app
.path()
.app_local_data_dir()
.expect("could not resolve app local data path")
.join(".salt.txt");
app
.handle()
.plugin(tauri_plugin_stronghold::Builder::with_argon2(&salt_path).build())?;
Ok(())
})
*/
.plugin(tauri_plugin_app::init()) .plugin(tauri_plugin_app::init())
.plugin(tauri_plugin_clipboard_manager::init()) .plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_dialog::init())

View File

@ -1,60 +0,0 @@
use tauri::{Runtime, Window};
pub trait TrafficLight {
#[cfg(target_os = "macos")]
fn set_transparent_titlebar(&self, transparent: bool);
fn position_traffic_lights(&self, x: f64, y: f64);
}
impl<R: Runtime> TrafficLight for Window<R> {
#[cfg(target_os = "macos")]
fn set_transparent_titlebar(&self, transparent: bool) {
use cocoa::appkit::{NSWindow, NSWindowTitleVisibility};
let window = self.ns_window().unwrap() as cocoa::base::id;
unsafe {
window.setTitleVisibility_(NSWindowTitleVisibility::NSWindowTitleHidden);
if transparent {
window.setTitlebarAppearsTransparent_(cocoa::base::YES);
} else {
window.setTitlebarAppearsTransparent_(cocoa::base::NO);
}
}
}
#[cfg(target_os = "macos")]
fn position_traffic_lights(&self, x: f64, y: f64) {
use cocoa::appkit::{NSView, NSWindow, NSWindowButton};
use cocoa::foundation::NSRect;
let window = self.ns_window().unwrap() as cocoa::base::id;
unsafe {
let close = window.standardWindowButton_(NSWindowButton::NSWindowCloseButton);
let miniaturize = window.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton);
let zoom = window.standardWindowButton_(NSWindowButton::NSWindowZoomButton);
let title_bar_container_view = close.superview().superview();
let close_rect: NSRect = msg_send![close, frame];
let button_height = close_rect.size.height;
let title_bar_frame_height = button_height + y;
let mut title_bar_rect = NSView::frame(title_bar_container_view);
title_bar_rect.size.height = title_bar_frame_height;
title_bar_rect.origin.y = NSView::frame(window).size.height - title_bar_frame_height;
let _: () = msg_send![title_bar_container_view, setFrame: title_bar_rect];
let window_buttons = vec![close, miniaturize, zoom];
let space_between = NSView::frame(miniaturize).origin.x - NSView::frame(close).origin.x;
for (i, button) in window_buttons.into_iter().enumerate() {
let mut rect: NSRect = NSView::frame(button);
rect.origin.x = x + (i as f64 * space_between);
button.setFrameOrigin(rect.origin);
}
}
}
}

View File

@ -83,6 +83,7 @@
} }
}, },
"security": { "security": {
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost",
"dangerousRemoteDomainIpcAccess": [ "dangerousRemoteDomainIpcAccess": [
{ {
"domain": "nwc.getalby.com", "domain": "nwc.getalby.com",
@ -92,6 +93,7 @@
] ]
} }
] ]
} },
"macOSPrivateApi": true
} }
} }

View File

@ -5,7 +5,7 @@
{ {
"width": 300, "width": 300,
"height": 300, "height": 300,
"decorations": false, "decorations": true,
"title": "Lume", "title": "Lume",
"titleBarStyle": "Overlay", "titleBarStyle": "Overlay",
"hiddenTitle": true, "hiddenTitle": true,
@ -27,7 +27,7 @@
"hiddenTitle": true, "hiddenTitle": true,
"visible": false, "visible": false,
"fileDropEnabled": true, "fileDropEnabled": true,
"decorations": false, "decorations": true,
"transparent": true, "transparent": true,
"windowEffects": { "windowEffects": {
"effects": ["hudWindow"] "effects": ["hudWindow"]

View File

@ -61,7 +61,7 @@ export function ImportStep2Screen() {
setLoading(true); setLoading(true);
if (data.password.length > 3) { if (data.password.length > 3) {
const dir = await appConfigDir(); const dir = await appConfigDir();
const stronghold = await Stronghold.load(`${dir}lume.stronghold`, data.password); const stronghold = await Stronghold.load(`${dir}/lume.stronghold`, data.password);
if (!db.secureDB) db.secureDB = stronghold; if (!db.secureDB) db.secureDB = stronghold;

View File

@ -2,7 +2,7 @@ import { appConfigDir } from '@tauri-apps/api/path';
import { Stronghold } from '@tauri-apps/plugin-stronghold'; import { Stronghold } from '@tauri-apps/plugin-stronghold';
import { useState } from 'react'; import { useState } from 'react';
import { Resolver, useForm } from 'react-hook-form'; import { Resolver, useForm } from 'react-hook-form';
import { Link, useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { useStorage } from '@libs/storage/provider'; import { useStorage } from '@libs/storage/provider';
@ -33,7 +33,6 @@ export function UnlockScreen() {
const navigate = useNavigate(); const navigate = useNavigate();
const setPrivkey = useStronghold((state) => state.setPrivkey); const setPrivkey = useStronghold((state) => state.setPrivkey);
const setWalletConnectURL = useStronghold((state) => state.setWalletConnectURL); const setWalletConnectURL = useStronghold((state) => state.setWalletConnectURL);
const resetStronghold = useStronghold((state) => state.reset);
const [showPassword, setShowPassword] = useState<boolean>(false); const [showPassword, setShowPassword] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
@ -43,7 +42,7 @@ export function UnlockScreen() {
register, register,
setError, setError,
handleSubmit, handleSubmit,
formState: { errors, isDirty, isValid }, formState: { isDirty, isValid },
} = useForm<FormValues>({ resolver }); } = useForm<FormValues>({ resolver });
const onSubmit = async (data: { [x: string]: string }) => { const onSubmit = async (data: { [x: string]: string }) => {
@ -71,15 +70,6 @@ export function UnlockScreen() {
} }
}; };
const logout = async () => {
// remove account
db.accountLogout();
// reset stronghold
resetStronghold();
// redirect to welcome screen
navigate('/auth/welcome');
};
return ( return (
<div className="flex h-full w-full items-center justify-center"> <div className="flex h-full w-full items-center justify-center">
<div className="mx-auto w-full max-w-md"> <div className="mx-auto w-full max-w-md">

View File

@ -110,7 +110,7 @@ export function RelayScreen() {
href={`https://nips.be/${item}`} href={`https://nips.be/${item}`}
target="_blank" target="_blank"
rel="noreferrer" rel="noreferrer"
className="inline-flex aspect-square h-full w-full items-center justify-center rounded-lg bg-white/10 text-sm font-medium hover:bg-blue-600" className="inline-flex aspect-square h-auto w-full items-center justify-center rounded-lg bg-white/10 text-sm font-medium hover:bg-blue-600"
> >
{item} {item}
</a> </a>

View File

@ -14,37 +14,39 @@ export class LumeStorage {
public account: Account | null; public account: Account | null;
public platform: Platform | null; public platform: Platform | null;
constructor(sqlite: Database, platform?: Platform, stronghold?: Stronghold) { constructor(sqlite: Database, platform: Platform, stronghold?: Stronghold) {
this.db = sqlite; this.db = sqlite;
this.secureDB = stronghold ?? undefined; this.secureDB = stronghold ?? undefined;
this.account = null; this.account = null;
this.platform = platform ?? undefined; this.platform = platform;
} }
private async getSecureClient(key?: string) { private async getSecureClient() {
try { try {
return await this.secureDB.loadClient(key ?? 'lume'); return await this.secureDB.loadClient('lume');
} catch { } catch {
return await this.secureDB.createClient(key ?? 'lume'); return await this.secureDB.createClient('lume');
} }
} }
public async secureSave(key: string, value: string, clientKey?: string) { public async secureSave(key: string, value: string) {
if (!this.secureDB) throw new Error("Stronghold isn't initialize"); if (!this.secureDB) throw new Error("Stronghold isn't initialize");
const client = await this.getSecureClient(clientKey); const client = await this.getSecureClient();
const store = client.getStore(); if (!client) throw new Error('Cannot get stronghold client');
const store = client.getStore();
await store.insert(key, Array.from(new TextEncoder().encode(value))); await store.insert(key, Array.from(new TextEncoder().encode(value)));
await this.secureDB.save(); await this.secureDB.save();
} }
public async secureLoad(key: string, clientKey?: string) { public async secureLoad(key: string) {
if (!this.secureDB) throw new Error("Stronghold isn't initialize"); if (!this.secureDB) throw new Error("Stronghold isn't initialize");
const client = await this.getSecureClient(clientKey); const client = await this.getSecureClient();
const store = client.getStore(); if (!client) throw new Error('Cannot get stronghold client');
const store = client.getStore();
const value = await store.get(key); const value = await store.get(key);
if (!value) return null; if (!value) return null;

View File

@ -50,7 +50,7 @@ export function ActiveAccount() {
if (status === 'loading') { if (status === 'loading') {
return ( return (
<div className="aspect-square h-full w-full animate-pulse rounded-lg bg-white/10" /> <div className="aspect-square h-auto w-full animate-pulse rounded-lg bg-white/10" />
); );
} }
@ -60,7 +60,7 @@ export function ActiveAccount() {
<Image <Image
src={user?.picture || user?.image} src={user?.picture || user?.image}
alt={db.account.npub} alt={db.account.npub}
className="aspect-square h-full w-full rounded-md" className="aspect-square h-auto w-full rounded-md"
/> />
<span className="absolute bottom-0 right-0 block h-2 w-2 rounded-full bg-emerald-500 ring-2 ring-neutral-100 dark:ring-neutral-900" /> <span className="absolute bottom-0 right-0 block h-2 w-2 rounded-full bg-emerald-500 ring-2 ring-neutral-100 dark:ring-neutral-900" />
</Link> </Link>

View File

@ -28,7 +28,7 @@ export function ComposerModal() {
<Dialog.Trigger asChild> <Dialog.Trigger asChild>
<button <button
type="button" type="button"
className="flex aspect-square h-full w-full items-center justify-center rounded-lg bg-neutral-300 hover:bg-blue-600 dark:bg-neutral-700 dark:hover:bg-blue-600" className="flex aspect-square h-auto w-full items-center justify-center rounded-lg bg-neutral-300 hover:bg-blue-600 dark:bg-neutral-700 dark:hover:bg-blue-600"
> >
<ComposeIcon className="h-5 w-5 text-black dark:text-white" /> <ComposeIcon className="h-5 w-5 text-black dark:text-white" />
</button> </button>

View File

@ -1,14 +1,25 @@
import { Outlet, ScrollRestoration } from 'react-router-dom'; import { Outlet, ScrollRestoration } from 'react-router-dom';
import { twMerge } from 'tailwind-merge';
import { WindowTitlebar } from 'tauri-controls'; import { WindowTitlebar } from 'tauri-controls';
import { useStorage } from '@libs/storage/provider';
import { Navigation } from '@shared/navigation'; import { Navigation } from '@shared/navigation';
export function AppLayout() { export function AppLayout() {
const { db } = useStorage();
return ( return (
<div className="flex h-screen w-screen flex-col bg-neutral-50 dark:bg-neutral-950"> <div className="flex h-screen w-screen flex-col bg-neutral-50 dark:bg-neutral-950">
<WindowTitlebar /> {db.platform !== 'macos' ? <WindowTitlebar /> : <div className="h-11" />}
<div className="flex h-full min-h-0 w-full"> <div className="flex h-full min-h-0 w-full">
<div data-tauri-drag-region className="h-full w-[64px] shrink-0 pt-2"> <div
data-tauri-drag-region
className={twMerge(
'h-full w-[64px] shrink-0',
db.platform !== 'macos' ? 'pt-2' : 'pt-16'
)}
>
<Navigation /> <Navigation />
</div> </div>
<div className="flex h-full min-h-0 flex-1 rounded-tl-lg bg-white shadow-[rgba(50,_50,_105,_0.15)_0px_2px_5px_0px,_rgba(0,_0,_0,_0.05)_0px_1px_1px_0px] dark:bg-black dark:shadow-[inset_0_0_0.5px_1px_hsla(0,0%,100%,0.075),0_0_0_1px_hsla(0,0%,0%,0.05),0_0.3px_0.4px_hsla(0,0%,0%,0.02),0_0.9px_1.5px_hsla(0,0%,0%,0.045),0_3.5px_6px_hsla(0,0%,0%,0.09)]"> <div className="flex h-full min-h-0 flex-1 rounded-tl-lg bg-white shadow-[rgba(50,_50,_105,_0.15)_0px_2px_5px_0px,_rgba(0,_0,_0,_0.05)_0px_1px_1px_0px] dark:bg-black dark:shadow-[inset_0_0_0.5px_1px_hsla(0,0%,100%,0.075),0_0_0_1px_hsla(0,0%,0%,0.05),0_0.3px_0.4px_hsla(0,0%,0%,0.02),0_0.9px_1.5px_hsla(0,0%,0%,0.045),0_3.5px_6px_hsla(0,0%,0%,0.09)]">

View File

@ -1,10 +1,14 @@
import { Outlet } from 'react-router-dom'; import { Outlet } from 'react-router-dom';
import { WindowTitlebar } from 'tauri-controls'; import { WindowTitlebar } from 'tauri-controls';
import { useStorage } from '@libs/storage/provider';
export function AuthLayout() { export function AuthLayout() {
const { db } = useStorage();
return ( return (
<div className="relative h-screen w-screen bg-neutral-50 dark:bg-neutral-950"> <div className="relative h-screen w-screen bg-neutral-50 dark:bg-neutral-950">
<WindowTitlebar /> {db.platform !== 'macos' ? <WindowTitlebar /> : null}
<div className="bg-neutral-50 dark:bg-neutral-950"> <div className="bg-neutral-50 dark:bg-neutral-950">
<Outlet /> <Outlet />
</div> </div>

View File

@ -25,7 +25,7 @@ export function Navigation() {
<> <>
<div <div
className={twMerge( className={twMerge(
'inline-flex aspect-square h-full w-full items-center justify-center rounded-lg', 'inline-flex aspect-square h-auto w-full items-center justify-center rounded-lg',
isActive isActive
? 'bg-black/10 text-black dark:bg-white/10 dark:text-white' ? 'bg-black/10 text-black dark:bg-white/10 dark:text-white'
: 'text-black/50 dark:text-white/50' : 'text-black/50 dark:text-white/50'
@ -46,7 +46,7 @@ export function Navigation() {
<> <>
<div <div
className={twMerge( className={twMerge(
'inline-flex aspect-square h-full w-full items-center justify-center rounded-lg', 'inline-flex aspect-square h-auto w-full items-center justify-center rounded-lg',
isActive isActive
? 'bg-black/10 text-black dark:bg-white/10 dark:text-white' ? 'bg-black/10 text-black dark:bg-white/10 dark:text-white'
: 'text-black/50 dark:text-white/50' : 'text-black/50 dark:text-white/50'
@ -67,7 +67,7 @@ export function Navigation() {
<> <>
<div <div
className={twMerge( className={twMerge(
'inline-flex aspect-square h-full w-full items-center justify-center rounded-lg', 'inline-flex aspect-square h-auto w-full items-center justify-center rounded-lg',
isActive isActive
? 'bg-black/10 text-black dark:bg-white/10 dark:text-white' ? 'bg-black/10 text-black dark:bg-white/10 dark:text-white'
: 'text-black/50 dark:text-white/50' : 'text-black/50 dark:text-white/50'
@ -88,7 +88,7 @@ export function Navigation() {
<> <>
<div <div
className={twMerge( className={twMerge(
'inline-flex aspect-square h-full w-full items-center justify-center rounded-lg', 'inline-flex aspect-square h-auto w-full items-center justify-center rounded-lg',
isActive isActive
? 'bg-black/10 text-black dark:bg-white/10 dark:text-white' ? 'bg-black/10 text-black dark:bg-white/10 dark:text-white'
: 'text-black/50 dark:text-white/50' : 'text-black/50 dark:text-white/50'
@ -109,7 +109,7 @@ export function Navigation() {
<> <>
<div <div
className={twMerge( className={twMerge(
'inline-flex aspect-square h-full w-full items-center justify-center rounded-lg', 'inline-flex aspect-square h-auto w-full items-center justify-center rounded-lg',
isActive isActive
? 'bg-black/10 text-black dark:bg-white/10 dark:text-white' ? 'bg-black/10 text-black dark:bg-white/10 dark:text-white'
: 'text-black/50 dark:text-white/50' : 'text-black/50 dark:text-white/50'
@ -126,7 +126,7 @@ export function Navigation() {
<ComposerModal /> <ComposerModal />
<Link <Link
to="/nwc" to="/nwc"
className="flex aspect-square h-full w-full items-center justify-center rounded-lg bg-neutral-100 hover:bg-blue-600 dark:bg-neutral-900 dark:hover:bg-blue-600" className="flex aspect-square h-auto w-full items-center justify-center rounded-lg bg-neutral-100 hover:bg-blue-600 dark:bg-neutral-900 dark:hover:bg-blue-600"
> >
<NwcIcon className="h-5 w-5" /> <NwcIcon className="h-5 w-5" />
</Link> </Link>

10
src/utils/types.d.ts vendored
View File

@ -1,5 +1,5 @@
import { NDKEvent, NDKUserProfile } from '@nostr-dev-kit/ndk'; import { type NDKEvent, type NDKUserProfile } from '@nostr-dev-kit/ndk';
import { Response } from '@tauri-apps/plugin-http'; import { type Response } from '@tauri-apps/plugin-http';
export interface RichContent { export interface RichContent {
parsed: string; parsed: string;
@ -68,12 +68,6 @@ export interface Chats {
new_messages?: number; new_messages?: number;
} }
export interface Settings {
id: string;
key: string;
value: string;
}
export interface Relays { export interface Relays {
id?: string; id?: string;
account_id?: number; account_id?: number;