diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index c9bbcb3c..c0a8137b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -16,7 +16,8 @@ tauri-build = { version = "1.4", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.4", features = [ +tauri = { version = "1.4", features = [ "window-create", + "macos-private-api", "fs-read-dir", "fs-read-file", "window-start-dragging", diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index cf68e559..bcb2bb11 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -67,7 +67,10 @@ "center": true, "setResizable": true, "setSize": true, - "startDragging": true + "startDragging": true, + "create": true, + "close": true, + "print": true }, "clipboard": { "all": false, @@ -124,7 +127,15 @@ "security": { "csp": { "content-security-policy": "upgrade-insecure-requests" - } + }, + "dangerousRemoteDomainIpcAccess": [ + { + "scheme": "https", + "domain": "nwc.getalby.com", + "windows": ["alby"], + "enableTauriAPI": true + } + ] }, "macOSPrivateApi": true } diff --git a/src/shared/alby.tsx b/src/shared/alby.tsx new file mode 100644 index 00000000..7145bc1b --- /dev/null +++ b/src/shared/alby.tsx @@ -0,0 +1,135 @@ +import { webln } from '@getalby/sdk'; +import * as Dialog from '@radix-ui/react-dialog'; +import { message } from '@tauri-apps/api/dialog'; +import { WebviewWindow } from '@tauri-apps/api/window'; +import { useState } from 'react'; + +import { useStorage } from '@libs/storage/provider'; + +import { + AlbyIcon, + ArrowRightCircleIcon, + CancelIcon, + LoaderIcon, + StarsIcon, +} from '@shared/icons'; + +export function AlbyConnectButton() { + const { db } = useStorage(); + + const [isOpen, setIsOpen] = useState(false); + const [isLoading, setIsloading] = useState(false); + + const initAlby = async () => { + try { + setIsloading(true); + + const provider = webln.NostrWebLNProvider.withNewSecret(); + const walletConnectURL = provider.getNostrWalletConnectUrl(true); + + // get auth url + const authURL = provider.getAuthorizationUrl({ name: 'Lume' }); + + // open auth window + const webview = new WebviewWindow('alby', { + title: 'Connect Alby', + url: authURL.href, + center: true, + theme: 'light', + width: 400, + height: 650, + }); + + webview.listen('tauri://close-requested', async (e) => { + console.log(e); + await db.secureSave('wallet-connect-url', walletConnectURL); + setIsloading(false); + webview.close(); + }); + } catch (e) { + setIsloading(false); + await message(e.toString(), { title: 'Connect Alby', type: 'error' }); + } + }; + + return ( + +
+ +
+
+ +
+
+
+ New feature +
+

+ Send bitcoin tip with Alby +

+
+ + + +
+
+ + + +
+
+
+
+ + Alby integration (Beta) + + + + +
+
+
+
+
+

+ When you click "Connect", a new window will open in your + default browser. You will need to click the "Connect Wallet" + button to grant Lume permission to integrate with your Alby account. +

+

+ All information will be encrypted and stored on the local machine. +

+
+ +
+
+
+
+
+ ); +} diff --git a/src/shared/icons/alby.tsx b/src/shared/icons/alby.tsx new file mode 100644 index 00000000..7f6a6ed2 --- /dev/null +++ b/src/shared/icons/alby.tsx @@ -0,0 +1,74 @@ +import { SVGProps } from 'react'; + +export function AlbyIcon(props: JSX.IntrinsicAttributes & SVGProps) { + return ( + + + + + + + + + + + + + + + + ); +} diff --git a/src/shared/icons/index.ts b/src/shared/icons/index.ts index a582084b..6590a580 100644 --- a/src/shared/icons/index.ts +++ b/src/shared/icons/index.ts @@ -61,3 +61,5 @@ export * from './mention'; export * from './groupFeeds'; export * from './article'; export * from './follows'; +export * from './alby'; +export * from './stars'; diff --git a/src/shared/icons/stars.tsx b/src/shared/icons/stars.tsx new file mode 100644 index 00000000..5aa3bc08 --- /dev/null +++ b/src/shared/icons/stars.tsx @@ -0,0 +1,19 @@ +import { SVGProps } from 'react'; + +export function StarsIcon(props: JSX.IntrinsicAttributes & SVGProps) { + return ( + + + + ); +} diff --git a/src/shared/navigation.tsx b/src/shared/navigation.tsx index 0f0bfb30..845ad916 100644 --- a/src/shared/navigation.tsx +++ b/src/shared/navigation.tsx @@ -7,6 +7,7 @@ import { ChatsList } from '@app/chats/components/list'; import { useStorage } from '@libs/storage/provider'; import { ActiveAccount } from '@shared/accounts/active'; +import { AlbyConnectButton } from '@shared/alby'; import { ComposerModal } from '@shared/composer'; import { Frame } from '@shared/frame'; import { BellIcon, NavArrowDownIcon, SpaceIcon } from '@shared/icons'; @@ -97,7 +98,10 @@ export function Navigation() { -
+
+
+ +
diff --git a/src/utils/hooks/useNostr.ts b/src/utils/hooks/useNostr.ts index 35b42a4f..c7fdaf33 100644 --- a/src/utils/hooks/useNostr.ts +++ b/src/utils/hooks/useNostr.ts @@ -126,7 +126,7 @@ export function useNostr() { let since: number; if (dbEventsEmpty || db.account.last_login_at === 0) { - since = nHoursAgo(24); + since = db.account.network.length > 400 ? nHoursAgo(12) : nHoursAgo(24); } else { since = db.account.last_login_at; } @@ -164,10 +164,10 @@ export function useNostr() { ); } - return { status: 'ok', data: [], message: 'prefetch completed' }; + return { status: 'ok', message: 'prefetch completed' }; } catch (e) { console.error('prefetch events failed, error: ', e); - return { status: 'failed', data: [], message: e }; + return { status: 'failed', message: e }; } };