Compare commits
64 Commits
4c0beb2a2a
...
v1.0.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fef2ae1c6 | ||
|
|
c2a723faa8 | ||
|
|
6b872527ad | ||
|
|
d9b16aea9a | ||
|
|
8345def015 | ||
|
|
b0ba2549d7 | ||
|
|
c8034642c5 | ||
|
|
8205c69e19 | ||
|
|
d36364d60d | ||
|
|
99363475e0 | ||
|
|
a52e1877fe | ||
|
|
b41de00c95 | ||
|
|
94cbb4aa0e | ||
|
|
40e7ca368b | ||
|
|
b91697defc | ||
|
|
1d57a2deab | ||
|
|
aa26c9ccba | ||
|
|
ff61c28a76 | ||
|
|
069eae8145 | ||
|
|
ccbcc644db | ||
|
|
15c5ce7677 | ||
|
|
40d726c986 | ||
|
|
fe4eb7df74 | ||
|
|
b5d6d91851 | ||
|
|
d475d03d0c | ||
|
|
0f00fed122 | ||
|
|
ef73b3c629 | ||
|
|
bbf31baee5 | ||
|
|
80227b3ed3 | ||
|
|
d00c5a1982 | ||
|
|
c054017d7e | ||
|
|
d065e70cd1 | ||
|
|
7a6b6feacc | ||
|
|
55c5ebbf17 | ||
|
|
3fecda175b | ||
|
|
2423cdca19 | ||
|
|
4b021bef01 | ||
|
|
dcf28e2b60 | ||
|
|
624140c061 | ||
|
|
fcb2b671e7 | ||
|
|
a86219dcb0 | ||
|
|
c22a7291c7 | ||
|
|
d7996bf32e | ||
|
|
2dcf825105 | ||
|
|
3debfa81d7 | ||
|
|
4ba2049756 | ||
|
|
b7ffdc8431 | ||
|
|
e152154c3b | ||
|
|
ff5ae8280c | ||
|
|
41cc8f4032 | ||
|
|
8ebd1c3525 | ||
|
|
bd1910ce03 | ||
|
|
cba3f976c6 | ||
|
|
971a82df1b | ||
|
|
6d863d8bbe | ||
|
|
10ded51d2f | ||
|
|
e44ce7e3f6 | ||
|
|
a7f9a7ceeb | ||
|
|
ebf0e86828 | ||
|
|
2ec98e14d0 | ||
|
|
31df6d7937 | ||
|
|
67ccfcb132 | ||
|
|
e3141aba19 | ||
|
|
bc588114c4 |
6
.github/workflows/release.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
|||||||
os: windows-11-arm
|
os: windows-11-arm
|
||||||
target: aarch64-pc-windows-msvc
|
target: aarch64-pc-windows-msvc
|
||||||
- platform: macos-x64
|
- platform: macos-x64
|
||||||
os: macos-13
|
os: macos-15-intel
|
||||||
target: x86_64-apple-darwin
|
target: x86_64-apple-darwin
|
||||||
- platform: macos-arm64
|
- platform: macos-arm64
|
||||||
os: macos-latest
|
os: macos-latest
|
||||||
@@ -130,7 +130,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Make get-crate-version executable
|
- name: Make get-crate-version executable
|
||||||
run: chmod +x script/get-crate-version
|
run: chmod +x script/get-crate-version
|
||||||
@@ -163,8 +163,6 @@ jobs:
|
|||||||
generate_release_notes: true
|
generate_release_notes: true
|
||||||
files: |
|
files: |
|
||||||
artifacts/**/*
|
artifacts/**/*
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Output release info
|
- name: Output release info
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
3
.gitignore
vendored
@@ -21,3 +21,6 @@ dist/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
# Added by goreleaser init:
|
# Added by goreleaser init:
|
||||||
.intentionally-empty-file.o
|
.intentionally-empty-file.o
|
||||||
|
|
||||||
|
.cargo/
|
||||||
|
vendor/
|
||||||
|
|||||||
2281
Cargo.lock
generated
10
Cargo.toml
@@ -4,15 +4,14 @@ members = ["crates/*"]
|
|||||||
default-members = ["crates/coop"]
|
default-members = ["crates/coop"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.3.0"
|
version = "1.0.0-beta3"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
|
||||||
# GPUI
|
# GPUI
|
||||||
gpui = { git = "https://github.com/zed-industries/zed" }
|
gpui = { git = "https://github.com/zed-industries/zed" }
|
||||||
gpui_platform = { git = "https://github.com/zed-industries/zed" }
|
gpui_platform = { git = "https://github.com/zed-industries/zed", features = ["font-kit", "x11", "wayland"] }
|
||||||
gpui_linux = { git = "https://github.com/zed-industries/zed" }
|
gpui_linux = { git = "https://github.com/zed-industries/zed" }
|
||||||
gpui_windows = { git = "https://github.com/zed-industries/zed" }
|
gpui_windows = { git = "https://github.com/zed-industries/zed" }
|
||||||
gpui_macos = { git = "https://github.com/zed-industries/zed" }
|
gpui_macos = { git = "https://github.com/zed-industries/zed" }
|
||||||
@@ -22,6 +21,8 @@ reqwest_client = { git = "https://github.com/zed-industries/zed" }
|
|||||||
# Nostr
|
# Nostr
|
||||||
nostr-lmdb = { git = "https://github.com/rust-nostr/nostr" }
|
nostr-lmdb = { git = "https://github.com/rust-nostr/nostr" }
|
||||||
nostr-connect = { git = "https://github.com/rust-nostr/nostr" }
|
nostr-connect = { git = "https://github.com/rust-nostr/nostr" }
|
||||||
|
nostr-blossom = { git = "https://github.com/rust-nostr/nostr" }
|
||||||
|
nostr-gossip-memory = { git = "https://github.com/rust-nostr/nostr" }
|
||||||
nostr-sdk = { git = "https://github.com/rust-nostr/nostr" }
|
nostr-sdk = { git = "https://github.com/rust-nostr/nostr" }
|
||||||
nostr = { git = "https://github.com/rust-nostr/nostr", features = [ "nip96", "nip59", "nip49", "nip44" ] }
|
nostr = { git = "https://github.com/rust-nostr/nostr", features = [ "nip96", "nip59", "nip49", "nip44" ] }
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ smallvec = "1.14.0"
|
|||||||
smol = "2"
|
smol = "2"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
webbrowser = "1.0.4"
|
webbrowser = "1.0.4"
|
||||||
|
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = true
|
strip = true
|
||||||
|
|||||||
3
assets/icons/book.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M4.75 20V4.75C4.75 3.64543 5.64543 2.75 6.75 2.75H19.25V18.75H6C5.30964 18.75 4.75 19.3096 4.75 20ZM4.75 20C4.75 20.6904 5.30964 21.25 6 21.25H19.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M12 12.25C9.75 12.25 9.75 13.75 9.75 13.75H14.25C14.25 13.75 14.25 12.25 12 12.25Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M13 9.25C13 9.80228 12.5523 10.25 12 10.25C11.4477 10.25 11 9.80228 11 9.25C11 8.69772 11.4477 8.25 12 8.25C12.5523 8.25 13 8.69772 13 9.25Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M11.5 9.25H12.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 866 B |
@@ -1,3 +1,3 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.10352 4C7.42998 2.84575 8.49122 2 9.75 2H14.25C15.5088 2 16.57 2.84575 16.8965 4H18.25C19.7688 4 21 5.23122 21 6.75V19.25C21 20.7688 19.7688 22 18.25 22H5.75C4.23122 22 3 20.7688 3 19.25V6.75C3 5.23122 4.23122 4 5.75 4H7.10352ZM8.5 4.75V6.25C8.5 6.38807 8.61193 6.5 8.75 6.5H15.25C15.3881 6.5 15.5 6.38807 15.5 6.25V4.75C15.5 4.05964 14.9404 3.5 14.25 3.5H9.75C9.05964 3.5 8.5 4.05964 8.5 4.75Z" fill="currentColor"/>
|
<path d="M8.75 8.75V4C8.75 3.30964 9.30964 2.75 10 2.75H20C20.6904 2.75 21.25 3.30964 21.25 4V14C21.25 14.6904 20.6904 15.25 20 15.25H15.25M14 8.75H4C3.30964 8.75 2.75 9.30964 2.75 10V20C2.75 20.6904 3.30964 21.25 4 21.25H14C14.6904 21.25 15.25 20.6904 15.25 20V10C15.25 9.30964 14.6904 8.75 14 8.75Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 550 B After Width: | Height: | Size: 472 B |
3
assets/icons/device.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M14.25 10.75C14.25 9.64543 15.1454 8.75 16.25 8.75H20.25C21.3546 8.75 22.25 9.64543 22.25 10.75V19.25C22.25 20.3546 21.3546 21.25 20.25 21.25H16.25C15.1454 21.25 14.25 20.3546 14.25 19.25V10.75Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M17.25 18.25H19.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M20.25 8.75V5.75C20.25 4.64543 19.3546 3.75 18.25 3.75H5.75C4.64543 3.75 3.75 4.64543 3.75 5.75V14.75C3.75 15.8546 2.85457 16.75 1.75 16.75V18.25C1.75 19.3546 2.64543 20.25 3.75 20.25H14.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M3.75 16.75H14.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 898 B |
3
assets/icons/group.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<circle cx="12" cy="8.75" r="3" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><circle cx="4" cy="9.80005" r="2" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><circle cx="20" cy="9.80005" r="2" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M7.25 16.625V16.5C7.25 13.8766 9.37665 11.75 12 11.75C14.6234 11.75 16.75 13.8766 16.75 16.5V16.625C16.75 17.5225 16.0225 18.25 15.125 18.25H8.875C7.97754 18.25 7.25 17.5225 7.25 16.625Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M4.25 17.2602H2.75C1.64543 17.2602 0.706551 16.3538 0.919944 15.2701C1.25877 13.5493 2.15049 12.3257 4 11.8301" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M19.75 17.2601H21.25C22.3546 17.2601 23.2935 16.3538 23.08 15.27C22.7412 13.5493 21.8495 12.3257 20 11.8301" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.1 KiB |
3
assets/icons/input.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M11.75 6.75H19.25C20.3546 6.75 21.25 7.64543 21.25 8.75V15.25C21.25 16.3546 20.3546 17.25 19.25 17.25H11.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M5.75 6.75H4.75C3.64543 6.75 2.75 7.64543 2.75 8.75V15.25C2.75 16.3546 3.64543 17.25 4.75 17.25H5.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M8.75 3.75V20.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 604 B |
@@ -1,3 +1,3 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.25 4C20.7688 4 22 5.23122 22 6.75V17.25C22 18.7688 20.7688 20 19.25 20H4.75C3.23122 20 2 18.7688 2 17.25V6.75C2 5.23122 3.23122 4 4.75 4H19.25ZM6.25 7.5C5.83579 7.5 5.5 7.83579 5.5 8.25V15.75C5.5 16.1642 5.83579 16.5 6.25 16.5C6.66421 16.5 7 16.1642 7 15.75V8.25C7 7.83579 6.66421 7.5 6.25 7.5Z" fill="currentColor"/>
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M9 5.5V18.5H19.25C19.9404 18.5 20.5 17.9404 20.5 17.25V6.75C20.5 6.05964 19.9404 5.5 19.25 5.5H9ZM2 6.75C2 5.23122 3.23122 4 4.75 4H19.25C20.7688 4 22 5.23122 22 6.75V17.25C22 18.7688 20.7688 20 19.25 20H4.75C3.23122 20 2 18.7688 2 17.25V6.75Z" fill="currentColor"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 451 B After Width: | Height: | Size: 396 B |
@@ -1,3 +1,3 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
<path d="M2.75 6.75C2.75 5.64543 3.64543 4.75 4.75 4.75H19.25C20.3546 4.75 21.25 5.64543 21.25 6.75V17.25C21.25 18.3546 20.3546 19.25 19.25 19.25H4.75C3.64543 19.25 2.75 18.3546 2.75 17.25V6.75Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/><path d="M6.25 8.25V15.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
|
<path d="M2.75 6.75C2.75 5.64543 3.64543 4.75 4.75 4.75H19.25C20.3546 4.75 21.25 5.64543 21.25 6.75V17.25C21.25 18.3546 20.3546 19.25 19.25 19.25H4.75C3.64543 19.25 2.75 18.3546 2.75 17.25V6.75Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/><path d="M8.25 5V12V19" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 435 B After Width: | Height: | Size: 433 B |
@@ -1,3 +1,3 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.75 4C3.23122 4 2 5.23122 2 6.75V17.25C2 18.7688 3.23122 20 4.75 20H19.25C20.7688 20 22 18.7688 22 17.25V6.75C22 5.23122 20.7688 4 19.25 4H4.75ZM17.75 7.5C18.1642 7.5 18.5 7.83579 18.5 8.25V15.75C18.5 16.1642 18.1642 16.5 17.75 16.5C17.3358 16.5 17 16.1642 17 15.75V8.25C17 7.83579 17.3358 7.5 17.75 7.5Z" fill="currentColor"/>
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 5.5V18.5H4.75C4.05964 18.5 3.5 17.9404 3.5 17.25V6.75C3.5 6.05964 4.05964 5.5 4.75 5.5H15ZM22 6.75C22 5.23122 20.7688 4 19.25 4H4.75C3.23122 4 2 5.23122 2 6.75V17.25C2 18.7688 3.23122 20 4.75 20H19.25C20.7688 20 22 18.7688 22 17.25V6.75Z" fill="currentColor"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 459 B After Width: | Height: | Size: 394 B |
@@ -1,3 +1,3 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
<path d="M2.75 6.75C2.75 5.64543 3.64543 4.75 4.75 4.75H19.25C20.3546 4.75 21.25 5.64543 21.25 6.75V17.25C21.25 18.3546 20.3546 19.25 19.25 19.25H4.75C3.64543 19.25 2.75 18.3546 2.75 17.25V6.75Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/><path d="M17.75 8.25V15.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
|
<path d="M15.75 5V19" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/><path d="M2.75 6.75C2.75 5.64543 3.64543 4.75 4.75 4.75H19.25C20.3546 4.75 21.25 5.64543 21.25 6.75V17.25C21.25 18.3546 20.3546 19.25 19.25 19.25H4.75C3.64543 19.25 2.75 18.3546 2.75 17.25V6.75Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 436 B After Width: | Height: | Size: 431 B |
3
assets/icons/refresh.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M13 21C13.5523 21 14 20.5523 14 20C14 19.4477 13.5523 19 13 19C12.4477 19 12 19.4477 12 20C12 20.5523 12.4477 21 13 21Z" fill="currentColor"/><path d="M21 11C21 10.4477 20.5523 9.99999 20 9.99999C19.4477 9.99999 19 10.4477 19 11C19 11.5523 19.4477 12 20 12C20.5523 12 21 11.5523 21 11Z" fill="currentColor"/><path d="M19.9295 14.2679C20.4078 14.5441 20.5716 15.1557 20.2955 15.634C20.0193 16.1123 19.4078 16.2761 18.9295 16C18.4512 15.7238 18.2873 15.1123 18.5634 14.634C18.8396 14.1557 19.4512 13.9918 19.9295 14.2679Z" fill="currentColor"/><path d="M17.3676 19.2942C17.8459 19.0181 18.0098 18.4065 17.7336 17.9282C17.4575 17.4499 16.8459 17.286 16.3676 17.5621C15.8893 17.8383 15.7254 18.4499 16.0016 18.9282C16.2777 19.4065 16.8893 19.5703 17.3676 19.2942Z" fill="currentColor"/><path d="M18.9269 7.99998C18.4487 8.27612 17.8371 8.11225 17.5609 7.63396C17.2848 7.15566 17.4487 6.54407 17.9269 6.26793C18.4052 5.99179 19.0168 6.15566 19.293 6.63396C19.5691 7.11225 19.4052 7.72384 18.9269 7.99998Z" fill="currentColor"/><path d="M9.25 14.75V20.25H3.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M15.2493 4.41452C14.2521 3.98683 13.1537 3.75 12 3.75C7.44365 3.75 3.75 7.44365 3.75 12C3.75 15.498 5.92698 18.4875 9 19.6876" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.4 KiB |
3
assets/icons/reset.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M13 17.25C16.4518 17.25 19.25 14.4518 19.25 11V10.5C19.25 6.77208 16.2279 3.75 12.5 3.75C8.77208 3.75 5.75 6.77208 5.75 10.5V20" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M2 16.5L5.75 20.25L9.5 16.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 435 B |
3
assets/icons/scan.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M7.25 4.75H4.75C3.64543 4.75 2.75 5.64543 2.75 6.75V9.25M16.75 4.75H19.25C20.3546 4.75 21.25 5.64543 21.25 6.75V9.25M21.25 14.75V17.25C21.25 18.3546 20.3546 19.25 19.25 19.25H16.75M7.25 19.25H4.75C3.64543 19.25 2.75 18.3546 2.75 17.25V14.75M7.75 9.75V14.25M16.25 9.75V14.25M12 9.75V12.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 468 B |
3
assets/icons/settings2.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M13 19.25H5.95C4.82989 19.25 4.26984 19.25 3.84202 19.032C3.46569 18.8403 3.15973 18.5343 2.96799 18.158C2.75 17.7302 2.75 17.1701 2.75 16.05V7.95C2.75 6.82989 2.75 6.26984 2.96799 5.84202C3.15973 5.46569 3.46569 5.15973 3.84202 4.96799C4.26984 4.75 4.8299 4.75 5.95 4.75H18.05C19.1701 4.75 19.7302 4.75 20.158 4.96799C20.5343 5.15973 20.8403 5.46569 21.032 5.84202C21.25 6.26984 21.25 6.8299 21.25 7.95V11" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/><path d="M3 5.63635L10.9761 10.3898C11.6069 10.7657 12.3931 10.7657 13.0239 10.3898L21 5.63635" stroke="currentColor" stroke-width="1.5"/><path d="M21.8148 15.375L21.1669 15.7491M16.1856 18.625L16.8335 18.2509M21.8147 18.625L21.1669 18.251M16.1855 15.375L16.8335 15.7491M19.0002 20.25L19.0002 19.4375M19.0002 13.75V14.5625M21.1669 17C21.1669 16.6053 21.0613 16.2352 20.8769 15.9165C20.5022 15.269 19.8021 14.8333 19.0002 14.8333C18.1983 14.8333 17.4981 15.269 17.1235 15.9165C16.9391 16.2352 16.8335 16.6053 16.8335 17C16.8335 17.3947 16.9391 17.7648 17.1235 18.0835C17.4982 18.731 18.1983 19.1667 19.0002 19.1667C19.8021 19.1667 20.5022 18.731 20.8769 18.0835C21.0613 17.7648 21.1669 17.3947 21.1669 17Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.3 KiB |
3
assets/icons/user-key.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M12.9996 12.8145C12.675 12.7719 12.3415 12.75 11.9996 12.75C8.55174 12.75 5.94978 14.981 4.9305 18.114C4.56744 19.23 5.50919 20.25 6.68275 20.25H13.9996M15.7496 6.5C15.7496 8.57107 14.0706 10.25 11.9996 10.25C9.92851 10.25 8.24958 8.57107 8.24958 6.5C8.24958 4.42893 9.92851 2.75 11.9996 2.75C14.0706 2.75 15.7496 4.42893 15.7496 6.5ZM15.7496 14C15.7496 12.7574 16.7569 11.75 17.9996 11.75C19.2422 11.75 20.2496 12.7574 20.2496 14C20.2496 14.7801 19.8526 15.4675 19.2496 15.8711V17L18.7496 17.9356L19.2496 18.9678V20L17.9996 21L16.7496 20V15.8711C16.1466 15.4675 15.7496 14.7801 15.7496 14Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 771 B |
144
assets/themes/aurora.json
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
{
|
||||||
|
"id": "aurora",
|
||||||
|
"name": "Aurora",
|
||||||
|
"author": "Coop",
|
||||||
|
"url": "https://github.com/lumehq/coop",
|
||||||
|
"light": {
|
||||||
|
"background": "#fdfcfeff",
|
||||||
|
"surface_background": "#f8f8ffff",
|
||||||
|
"elevated_surface_background": "#f0f1feff",
|
||||||
|
"panel_background": "#fdfcfeff",
|
||||||
|
"overlay": "#211f4300",
|
||||||
|
"title_bar": "#f0f1feff",
|
||||||
|
"title_bar_inactive": "#fdfcfeff",
|
||||||
|
"window_border": "#dadcffff",
|
||||||
|
"border": "#dadcffff",
|
||||||
|
"border_variant": "#cbcdffff",
|
||||||
|
"border_focused": "#5b5bd6ff",
|
||||||
|
"border_selected": "#5b5bd6ff",
|
||||||
|
"border_transparent": "#00000000",
|
||||||
|
"border_disabled": "#e6e7ffff",
|
||||||
|
"ring": "#5151cdff",
|
||||||
|
"text": "#1f2d5cff",
|
||||||
|
"text_muted": "#5753c6ff",
|
||||||
|
"text_placeholder": "#9b9ef0ff",
|
||||||
|
"text_accent": "#5b5bd6ff",
|
||||||
|
"text_danger": "#e54d2eff",
|
||||||
|
"text_warning": "#f76b15ff",
|
||||||
|
"icon": "#5753c6ff",
|
||||||
|
"icon_muted": "#9b9ef0ff",
|
||||||
|
"icon_accent": "#5151cdff",
|
||||||
|
"element_foreground": "#ffffffff",
|
||||||
|
"element_background": "#5b5bd6ff",
|
||||||
|
"element_hover": "#5151cdff",
|
||||||
|
"element_active": "#6e56cfff",
|
||||||
|
"element_selected": "#654dc4ff",
|
||||||
|
"element_disabled": "#5b5bd64d",
|
||||||
|
"secondary_foreground": "#1f2d5cff",
|
||||||
|
"secondary_background": "#f0f1feff",
|
||||||
|
"secondary_hover": "#e6e7ffff",
|
||||||
|
"secondary_active": "#dadcffff",
|
||||||
|
"secondary_selected": "#dadcffff",
|
||||||
|
"secondary_disabled": "#5b5bd64d",
|
||||||
|
"danger_foreground": "#ffffffff",
|
||||||
|
"danger_background": "#feebe7ff",
|
||||||
|
"danger_hover": "#ffcdc2ff",
|
||||||
|
"danger_active": "#fdbdafff",
|
||||||
|
"danger_selected": "#fdbdafff",
|
||||||
|
"danger_disabled": "#e54d2e4d",
|
||||||
|
"warning_foreground": "#ffffffff",
|
||||||
|
"warning_background": "#fff7edff",
|
||||||
|
"warning_hover": "#ffd19aff",
|
||||||
|
"warning_active": "#ffc182ff",
|
||||||
|
"warning_selected": "#ffc182ff",
|
||||||
|
"warning_disabled": "#f76b154d",
|
||||||
|
"ghost_element_background": "#00000000",
|
||||||
|
"ghost_element_background_alt": "#f0f1feff",
|
||||||
|
"ghost_element_hover": "#211f430d",
|
||||||
|
"ghost_element_active": "#211f431a",
|
||||||
|
"ghost_element_selected": "#211f431a",
|
||||||
|
"ghost_element_disabled": "#211f4305",
|
||||||
|
"tab_background": "#f0f1feff",
|
||||||
|
"tab_foreground": "#5753c6ff",
|
||||||
|
"tab_hover_background": "#211f430d",
|
||||||
|
"tab_active_background": "#fdfcfeff",
|
||||||
|
"tab_active_foreground": "#1f2d5cff",
|
||||||
|
"scrollbar_thumb_background": "#211f431a",
|
||||||
|
"scrollbar_thumb_hover_background": "#211f4326",
|
||||||
|
"scrollbar_thumb_border": "#00000000",
|
||||||
|
"scrollbar_track_background": "#00000000",
|
||||||
|
"scrollbar_track_border": "#00000000",
|
||||||
|
"drop_target_background": "#5b5bd61a",
|
||||||
|
"cursor": "#5b5bd6ff",
|
||||||
|
"selection": "#5b5bd640"
|
||||||
|
},
|
||||||
|
"dark": {
|
||||||
|
"background": "#14121fff",
|
||||||
|
"surface_background": "#1b1525ff",
|
||||||
|
"elevated_surface_background": "#291f43ff",
|
||||||
|
"panel_background": "#14121fff",
|
||||||
|
"overlay": "#baa7ff1a",
|
||||||
|
"title_bar": "#291f43ff",
|
||||||
|
"title_bar_inactive": "#14121fff",
|
||||||
|
"window_border": "#473876ff",
|
||||||
|
"border": "#473876ff",
|
||||||
|
"border_variant": "#3c2e69ff",
|
||||||
|
"border_focused": "#7d66d9ff",
|
||||||
|
"border_selected": "#7d66d9ff",
|
||||||
|
"border_transparent": "#00000000",
|
||||||
|
"border_disabled": "#33255bff",
|
||||||
|
"ring": "#6e56cfff",
|
||||||
|
"text": "#e2ddfeff",
|
||||||
|
"text_muted": "#baa7ffff",
|
||||||
|
"text_placeholder": "#6958adff",
|
||||||
|
"text_accent": "#baa7ffff",
|
||||||
|
"text_danger": "#ff977dff",
|
||||||
|
"text_warning": "#ffa057ff",
|
||||||
|
"icon": "#baa7ffff",
|
||||||
|
"icon_muted": "#6958adff",
|
||||||
|
"icon_accent": "#6e56cfff",
|
||||||
|
"element_foreground": "#14121fff",
|
||||||
|
"element_background": "#7d66d9ff",
|
||||||
|
"element_hover": "#baa7ffff",
|
||||||
|
"element_active": "#6e56cfff",
|
||||||
|
"element_selected": "#654dc4ff",
|
||||||
|
"element_disabled": "#7d66d94d",
|
||||||
|
"secondary_foreground": "#e2ddfeff",
|
||||||
|
"secondary_background": "#291f43ff",
|
||||||
|
"secondary_hover": "#33255bff",
|
||||||
|
"secondary_active": "#3c2e69ff",
|
||||||
|
"secondary_selected": "#3c2e69ff",
|
||||||
|
"secondary_disabled": "#7d66d94d",
|
||||||
|
"danger_foreground": "#181111ff",
|
||||||
|
"danger_background": "#391714ff",
|
||||||
|
"danger_hover": "#5e1c16ff",
|
||||||
|
"danger_active": "#6e2920ff",
|
||||||
|
"danger_selected": "#6e2920ff",
|
||||||
|
"danger_disabled": "#ff977d4d",
|
||||||
|
"warning_foreground": "#17120eff",
|
||||||
|
"warning_background": "#331e0bff",
|
||||||
|
"warning_hover": "#562800ff",
|
||||||
|
"warning_active": "#66350cff",
|
||||||
|
"warning_selected": "#66350cff",
|
||||||
|
"warning_disabled": "#ffa0574d",
|
||||||
|
"ghost_element_background": "#00000000",
|
||||||
|
"ghost_element_background_alt": "#291f43ff",
|
||||||
|
"ghost_element_hover": "#baa7ff0d",
|
||||||
|
"ghost_element_active": "#baa7ff1a",
|
||||||
|
"ghost_element_selected": "#baa7ff1a",
|
||||||
|
"ghost_element_disabled": "#baa7ff05",
|
||||||
|
"tab_background": "#291f43ff",
|
||||||
|
"tab_foreground": "#baa7ffff",
|
||||||
|
"tab_hover_background": "#baa7ff0d",
|
||||||
|
"tab_active_background": "#14121fff",
|
||||||
|
"tab_active_foreground": "#e2ddfeff",
|
||||||
|
"scrollbar_thumb_background": "#baa7ff1a",
|
||||||
|
"scrollbar_thumb_hover_background": "#baa7ff26",
|
||||||
|
"scrollbar_thumb_border": "#00000000",
|
||||||
|
"scrollbar_track_background": "#00000000",
|
||||||
|
"scrollbar_track_border": "#00000000",
|
||||||
|
"drop_target_background": "#baa7ff1a",
|
||||||
|
"cursor": "#baa7ffff",
|
||||||
|
"selection": "#baa7ff40"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,72 +1,76 @@
|
|||||||
{
|
{
|
||||||
"id": "catppuccin-frappe",
|
"id": "catppuccin-frappe",
|
||||||
"name": "Catppuccin Frappé",
|
"name": "Catppuccin Frappé",
|
||||||
"author": "Catppuccin",
|
"author": "Catppuccin Org (ported by Coop)",
|
||||||
"url": "https://github.com/catppuccin/catppuccin",
|
"url": "https://catppuccin.com",
|
||||||
"light": {
|
"light": {
|
||||||
"background": "#303446",
|
"background": "#303446",
|
||||||
"surface_background": "#292c3c",
|
"surface_background": "#292c3c",
|
||||||
"elevated_surface_background": "#232634",
|
"elevated_surface_background": "#232634",
|
||||||
"panel_background": "#303446",
|
"panel_background": "#303446",
|
||||||
"overlay": "#c6d0f51a",
|
"overlay": "#c6d0f51a",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#232634",
|
||||||
"title_bar_inactive": "#303446",
|
"title_bar_inactive": "#303446",
|
||||||
"window_border": "#626880",
|
"window_border": "#51576d",
|
||||||
"border": "#626880",
|
"border": "#51576d",
|
||||||
"border_variant": "#51576d",
|
"border_variant": "#414559",
|
||||||
"border_focused": "#8caaee",
|
"border_focused": "#8caaee",
|
||||||
"border_selected": "#8caaee",
|
"border_selected": "#8caaee",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#c6d0f500",
|
||||||
"border_disabled": "#414559",
|
"border_disabled": "#292c3c",
|
||||||
"ring": "#8caaee",
|
"ring": "#babbf1",
|
||||||
"text": "#c6d0f5",
|
"text": "#c6d0f5",
|
||||||
"text_muted": "#b5bfe2",
|
"text_muted": "#a5adce",
|
||||||
"text_placeholder": "#a5adce",
|
"text_placeholder": "#838ba7",
|
||||||
"text_accent": "#8caaee",
|
"text_accent": "#8caaee",
|
||||||
"icon": "#c6d0f5",
|
"text_danger": "#e78284",
|
||||||
"icon_muted": "#b5bfe2",
|
"text_warning": "#ef9f76",
|
||||||
"icon_accent": "#8caaee",
|
"icon": "#a5adce",
|
||||||
|
"icon_muted": "#838ba7",
|
||||||
|
"icon_accent": "#babbf1",
|
||||||
"element_foreground": "#303446",
|
"element_foreground": "#303446",
|
||||||
"element_background": "#8caaee",
|
"element_background": "#8caaee",
|
||||||
"element_hover": "#8caaeee6",
|
"element_hover": "#babbf1",
|
||||||
"element_active": "#7e99d6",
|
"element_active": "#99d1db",
|
||||||
"element_selected": "#7088be",
|
"element_selected": "#85c1dc",
|
||||||
"element_disabled": "#8caaee4d",
|
"element_disabled": "#8caaee4d",
|
||||||
"secondary_foreground": "#8caaee",
|
"secondary_foreground": "#c6d0f5",
|
||||||
"secondary_background": "#414559",
|
"secondary_background": "#414559",
|
||||||
"secondary_hover": "#8caaee1a",
|
"secondary_hover": "#51576d",
|
||||||
"secondary_active": "#51576d",
|
"secondary_active": "#626880",
|
||||||
"secondary_selected": "#51576d",
|
"secondary_selected": "#626880",
|
||||||
"secondary_disabled": "#8caaee4d",
|
"secondary_disabled": "#8caaee4d",
|
||||||
"danger_foreground": "#303446",
|
"danger_foreground": "#303446",
|
||||||
"danger_background": "#e78284",
|
"danger_background": "#e78284",
|
||||||
"danger_hover": "#e78284e6",
|
"danger_hover": "#ea999c",
|
||||||
"danger_active": "#d07576",
|
"danger_active": "#ef9f76",
|
||||||
"danger_selected": "#b96869",
|
"danger_selected": "#e5c890",
|
||||||
"danger_disabled": "#e782844d",
|
"danger_disabled": "#e782844d",
|
||||||
"warning_foreground": "#303446",
|
"warning_foreground": "#303446",
|
||||||
"warning_background": "#e5c890",
|
"warning_background": "#ef9f76",
|
||||||
"warning_hover": "#e5c890e6",
|
"warning_hover": "#e5c890",
|
||||||
"warning_active": "#ceb481",
|
"warning_active": "#a6d189",
|
||||||
"warning_selected": "#b7a072",
|
"warning_selected": "#81c8be",
|
||||||
"warning_disabled": "#e5c8904d",
|
"warning_disabled": "#ef9f764d",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#c6d0f500",
|
||||||
"ghost_element_background_alt": "#414559",
|
"ghost_element_background_alt": "#292c3c",
|
||||||
"ghost_element_hover": "#c6d0f51a",
|
"ghost_element_hover": "#c6d0f50d",
|
||||||
"ghost_element_active": "#51576d",
|
"ghost_element_active": "#c6d0f51a",
|
||||||
"ghost_element_selected": "#51576d",
|
"ghost_element_selected": "#c6d0f51a",
|
||||||
"ghost_element_disabled": "#c6d0f50d",
|
"ghost_element_disabled": "#c6d0f505",
|
||||||
"tab_inactive_background": "#414559",
|
"tab_background": "#232634",
|
||||||
"tab_hover_background": "#51576d",
|
"tab_foreground": "#a5adce",
|
||||||
"tab_active_background": "#626880",
|
"tab_hover_background": "#c6d0f50d",
|
||||||
"scrollbar_thumb_background": "#c6d0f533",
|
"tab_active_background": "#303446",
|
||||||
"scrollbar_thumb_hover_background": "#c6d0f54d",
|
"tab_active_foreground": "#c6d0f5",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#c6d0f51a",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#c6d0f526",
|
||||||
"scrollbar_track_border": "#51576d",
|
"scrollbar_thumb_border": "#c6d0f500",
|
||||||
|
"scrollbar_track_background": "#c6d0f500",
|
||||||
|
"scrollbar_track_border": "#c6d0f500",
|
||||||
"drop_target_background": "#8caaee1a",
|
"drop_target_background": "#8caaee1a",
|
||||||
"cursor": "#99d1db",
|
"cursor": "#8caaee",
|
||||||
"selection": "#99d1db40"
|
"selection": "#8caaee40"
|
||||||
},
|
},
|
||||||
"dark": {
|
"dark": {
|
||||||
"background": "#303446",
|
"background": "#303446",
|
||||||
@@ -74,63 +78,67 @@
|
|||||||
"elevated_surface_background": "#232634",
|
"elevated_surface_background": "#232634",
|
||||||
"panel_background": "#303446",
|
"panel_background": "#303446",
|
||||||
"overlay": "#c6d0f51a",
|
"overlay": "#c6d0f51a",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#232634",
|
||||||
"title_bar_inactive": "#303446",
|
"title_bar_inactive": "#303446",
|
||||||
"window_border": "#626880",
|
"window_border": "#51576d",
|
||||||
"border": "#626880",
|
"border": "#51576d",
|
||||||
"border_variant": "#51576d",
|
"border_variant": "#414559",
|
||||||
"border_focused": "#8caaee",
|
"border_focused": "#8caaee",
|
||||||
"border_selected": "#8caaee",
|
"border_selected": "#8caaee",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#c6d0f500",
|
||||||
"border_disabled": "#414559",
|
"border_disabled": "#292c3c",
|
||||||
"ring": "#8caaee",
|
"ring": "#babbf1",
|
||||||
"text": "#c6d0f5",
|
"text": "#c6d0f5",
|
||||||
"text_muted": "#b5bfe2",
|
"text_muted": "#a5adce",
|
||||||
"text_placeholder": "#a5adce",
|
"text_placeholder": "#838ba7",
|
||||||
"text_accent": "#8caaee",
|
"text_accent": "#8caaee",
|
||||||
"icon": "#c6d0f5",
|
"text_danger": "#e78284",
|
||||||
"icon_muted": "#b5bfe2",
|
"text_warning": "#ef9f76",
|
||||||
"icon_accent": "#8caaee",
|
"icon": "#a5adce",
|
||||||
|
"icon_muted": "#838ba7",
|
||||||
|
"icon_accent": "#babbf1",
|
||||||
"element_foreground": "#303446",
|
"element_foreground": "#303446",
|
||||||
"element_background": "#8caaee",
|
"element_background": "#8caaee",
|
||||||
"element_hover": "#8caaeee6",
|
"element_hover": "#babbf1",
|
||||||
"element_active": "#7e99d6",
|
"element_active": "#99d1db",
|
||||||
"element_selected": "#7088be",
|
"element_selected": "#85c1dc",
|
||||||
"element_disabled": "#8caaee4d",
|
"element_disabled": "#8caaee4d",
|
||||||
"secondary_foreground": "#8caaee",
|
"secondary_foreground": "#c6d0f5",
|
||||||
"secondary_background": "#414559",
|
"secondary_background": "#414559",
|
||||||
"secondary_hover": "#8caaee1a",
|
"secondary_hover": "#51576d",
|
||||||
"secondary_active": "#51576d",
|
"secondary_active": "#626880",
|
||||||
"secondary_selected": "#51576d",
|
"secondary_selected": "#626880",
|
||||||
"secondary_disabled": "#8caaee4d",
|
"secondary_disabled": "#8caaee4d",
|
||||||
"danger_foreground": "#303446",
|
"danger_foreground": "#303446",
|
||||||
"danger_background": "#e78284",
|
"danger_background": "#e78284",
|
||||||
"danger_hover": "#e78284e6",
|
"danger_hover": "#ea999c",
|
||||||
"danger_active": "#d07576",
|
"danger_active": "#ef9f76",
|
||||||
"danger_selected": "#b96869",
|
"danger_selected": "#e5c890",
|
||||||
"danger_disabled": "#e782844d",
|
"danger_disabled": "#e782844d",
|
||||||
"warning_foreground": "#303446",
|
"warning_foreground": "#303446",
|
||||||
"warning_background": "#e5c890",
|
"warning_background": "#ef9f76",
|
||||||
"warning_hover": "#e5c890e6",
|
"warning_hover": "#e5c890",
|
||||||
"warning_active": "#ceb481",
|
"warning_active": "#a6d189",
|
||||||
"warning_selected": "#b7a072",
|
"warning_selected": "#81c8be",
|
||||||
"warning_disabled": "#e5c8904d",
|
"warning_disabled": "#ef9f764d",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#c6d0f500",
|
||||||
"ghost_element_background_alt": "#414559",
|
"ghost_element_background_alt": "#292c3c",
|
||||||
"ghost_element_hover": "#c6d0f51a",
|
"ghost_element_hover": "#c6d0f50d",
|
||||||
"ghost_element_active": "#51576d",
|
"ghost_element_active": "#c6d0f51a",
|
||||||
"ghost_element_selected": "#51576d",
|
"ghost_element_selected": "#c6d0f51a",
|
||||||
"ghost_element_disabled": "#c6d0f50d",
|
"ghost_element_disabled": "#c6d0f505",
|
||||||
"tab_inactive_background": "#414559",
|
"tab_background": "#232634",
|
||||||
"tab_hover_background": "#51576d",
|
"tab_foreground": "#a5adce",
|
||||||
"tab_active_background": "#626880",
|
"tab_hover_background": "#c6d0f50d",
|
||||||
"scrollbar_thumb_background": "#c6d0f533",
|
"tab_active_background": "#303446",
|
||||||
"scrollbar_thumb_hover_background": "#c6d0f54d",
|
"tab_active_foreground": "#c6d0f5",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#c6d0f51a",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#c6d0f526",
|
||||||
"scrollbar_track_border": "#51576d",
|
"scrollbar_thumb_border": "#c6d0f500",
|
||||||
|
"scrollbar_track_background": "#c6d0f500",
|
||||||
|
"scrollbar_track_border": "#c6d0f500",
|
||||||
"drop_target_background": "#8caaee1a",
|
"drop_target_background": "#8caaee1a",
|
||||||
"cursor": "#99d1db",
|
"cursor": "#8caaee",
|
||||||
"selection": "#99d1db40"
|
"selection": "#8caaee40"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +1,76 @@
|
|||||||
{
|
{
|
||||||
"id": "catppuccin-latte",
|
"id": "catppuccin-latte",
|
||||||
"name": "Catppuccin Latte",
|
"name": "Catppuccin Latte",
|
||||||
"author": "Catppuccin",
|
"author": "Catppuccin Org (ported by Coop)",
|
||||||
"url": "https://github.com/catppuccin/catppuccin",
|
"url": "https://catppuccin.com",
|
||||||
"light": {
|
"light": {
|
||||||
"background": "#eff1f5",
|
"background": "#eff1f5",
|
||||||
"surface_background": "#e6e9ef",
|
"surface_background": "#e6e9ef",
|
||||||
"elevated_surface_background": "#dce0e8",
|
"elevated_surface_background": "#dce0e8",
|
||||||
"panel_background": "#eff1f5",
|
"panel_background": "#eff1f5",
|
||||||
"overlay": "#4c4f691a",
|
"overlay": "#4c4f691a",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#dce0e8",
|
||||||
"title_bar_inactive": "#eff1f5",
|
"title_bar_inactive": "#eff1f5",
|
||||||
"window_border": "#acb0be",
|
"window_border": "#bcc0cc",
|
||||||
"border": "#acb0be",
|
"border": "#bcc0cc",
|
||||||
"border_variant": "#bcc0cc",
|
"border_variant": "#ccd0da",
|
||||||
"border_focused": "#1e66f5",
|
"border_focused": "#1e66f5",
|
||||||
"border_selected": "#1e66f5",
|
"border_selected": "#1e66f5",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#4c4f6900",
|
||||||
"border_disabled": "#ccd0da",
|
"border_disabled": "#e6e9ef",
|
||||||
"ring": "#1e66f5",
|
"ring": "#7287fd",
|
||||||
"text": "#4c4f69",
|
"text": "#4c4f69",
|
||||||
"text_muted": "#5c5f77",
|
"text_muted": "#6c6f85",
|
||||||
"text_placeholder": "#6c6f85",
|
"text_placeholder": "#8c8fa1",
|
||||||
"text_accent": "#1e66f5",
|
"text_accent": "#1e66f5",
|
||||||
"icon": "#4c4f69",
|
"text_danger": "#d20f39",
|
||||||
"icon_muted": "#5c5f77",
|
"text_warning": "#fe640b",
|
||||||
"icon_accent": "#1e66f5",
|
"icon": "#6c6f85",
|
||||||
|
"icon_muted": "#8c8fa1",
|
||||||
|
"icon_accent": "#7287fd",
|
||||||
"element_foreground": "#eff1f5",
|
"element_foreground": "#eff1f5",
|
||||||
"element_background": "#1e66f5",
|
"element_background": "#1e66f5",
|
||||||
"element_hover": "#1e66f5e6",
|
"element_hover": "#7287fd",
|
||||||
"element_active": "#1b5cdc",
|
"element_active": "#04a5e5",
|
||||||
"element_selected": "#1852c3",
|
"element_selected": "#209fb5",
|
||||||
"element_disabled": "#1e66f54d",
|
"element_disabled": "#1e66f54d",
|
||||||
"secondary_foreground": "#1e66f5",
|
"secondary_foreground": "#4c4f69",
|
||||||
"secondary_background": "#e6e9ef",
|
"secondary_background": "#ccd0da",
|
||||||
"secondary_hover": "#1e66f51a",
|
"secondary_hover": "#bcc0cc",
|
||||||
"secondary_active": "#dce0e8",
|
"secondary_active": "#acb0be",
|
||||||
"secondary_selected": "#dce0e8",
|
"secondary_selected": "#acb0be",
|
||||||
"secondary_disabled": "#1e66f54d",
|
"secondary_disabled": "#1e66f54d",
|
||||||
"danger_foreground": "#eff1f5",
|
"danger_foreground": "#eff1f5",
|
||||||
"danger_background": "#d20f39",
|
"danger_background": "#d20f39",
|
||||||
"danger_hover": "#d20f39e6",
|
"danger_hover": "#e64553",
|
||||||
"danger_active": "#bc0e33",
|
"danger_active": "#fe640b",
|
||||||
"danger_selected": "#a60c2d",
|
"danger_selected": "#df8e1d",
|
||||||
"danger_disabled": "#d20f394d",
|
"danger_disabled": "#d20f394d",
|
||||||
"warning_foreground": "#4c4f69",
|
"warning_foreground": "#eff1f5",
|
||||||
"warning_background": "#df8e1d",
|
"warning_background": "#fe640b",
|
||||||
"warning_hover": "#df8e1de6",
|
"warning_hover": "#df8e1d",
|
||||||
"warning_active": "#c9801a",
|
"warning_active": "#40a02b",
|
||||||
"warning_selected": "#b47217",
|
"warning_selected": "#179299",
|
||||||
"warning_disabled": "#df8e1d4d",
|
"warning_disabled": "#fe640b4d",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#4c4f6900",
|
||||||
"ghost_element_background_alt": "#e6e9ef",
|
"ghost_element_background_alt": "#e6e9ef",
|
||||||
"ghost_element_hover": "#4c4f691a",
|
"ghost_element_hover": "#4c4f690d",
|
||||||
"ghost_element_active": "#dce0e8",
|
"ghost_element_active": "#4c4f691a",
|
||||||
"ghost_element_selected": "#dce0e8",
|
"ghost_element_selected": "#4c4f691a",
|
||||||
"ghost_element_disabled": "#4c4f690d",
|
"ghost_element_disabled": "#4c4f6905",
|
||||||
"tab_inactive_background": "#e6e9ef",
|
"tab_background": "#e6e9ef",
|
||||||
"tab_hover_background": "#dce0e8",
|
"tab_foreground": "#6c6f85",
|
||||||
"tab_active_background": "#ccd0da",
|
"tab_hover_background": "#4c4f690d",
|
||||||
"scrollbar_thumb_background": "#4c4f6933",
|
"tab_active_background": "#eff1f5",
|
||||||
"scrollbar_thumb_hover_background": "#4c4f694d",
|
"tab_active_foreground": "#4c4f69",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#4c4f691a",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#4c4f6926",
|
||||||
"scrollbar_track_border": "#dce0e8",
|
"scrollbar_thumb_border": "#4c4f6900",
|
||||||
|
"scrollbar_track_background": "#4c4f6900",
|
||||||
|
"scrollbar_track_border": "#4c4f6900",
|
||||||
"drop_target_background": "#1e66f51a",
|
"drop_target_background": "#1e66f51a",
|
||||||
"cursor": "#04a5e5",
|
"cursor": "#1e66f5",
|
||||||
"selection": "#04a5e540"
|
"selection": "#1e66f540"
|
||||||
},
|
},
|
||||||
"dark": {
|
"dark": {
|
||||||
"background": "#eff1f5",
|
"background": "#eff1f5",
|
||||||
@@ -74,63 +78,67 @@
|
|||||||
"elevated_surface_background": "#dce0e8",
|
"elevated_surface_background": "#dce0e8",
|
||||||
"panel_background": "#eff1f5",
|
"panel_background": "#eff1f5",
|
||||||
"overlay": "#4c4f691a",
|
"overlay": "#4c4f691a",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#dce0e8",
|
||||||
"title_bar_inactive": "#eff1f5",
|
"title_bar_inactive": "#eff1f5",
|
||||||
"window_border": "#acb0be",
|
"window_border": "#bcc0cc",
|
||||||
"border": "#acb0be",
|
"border": "#bcc0cc",
|
||||||
"border_variant": "#bcc0cc",
|
"border_variant": "#ccd0da",
|
||||||
"border_focused": "#1e66f5",
|
"border_focused": "#1e66f5",
|
||||||
"border_selected": "#1e66f5",
|
"border_selected": "#1e66f5",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#4c4f6900",
|
||||||
"border_disabled": "#ccd0da",
|
"border_disabled": "#e6e9ef",
|
||||||
"ring": "#1e66f5",
|
"ring": "#7287fd",
|
||||||
"text": "#4c4f69",
|
"text": "#4c4f69",
|
||||||
"text_muted": "#5c5f77",
|
"text_muted": "#6c6f85",
|
||||||
"text_placeholder": "#6c6f85",
|
"text_placeholder": "#8c8fa1",
|
||||||
"text_accent": "#1e66f5",
|
"text_accent": "#1e66f5",
|
||||||
"icon": "#4c4f69",
|
"text_danger": "#d20f39",
|
||||||
"icon_muted": "#5c5f77",
|
"text_warning": "#fe640b",
|
||||||
"icon_accent": "#1e66f5",
|
"icon": "#6c6f85",
|
||||||
|
"icon_muted": "#8c8fa1",
|
||||||
|
"icon_accent": "#7287fd",
|
||||||
"element_foreground": "#eff1f5",
|
"element_foreground": "#eff1f5",
|
||||||
"element_background": "#1e66f5",
|
"element_background": "#1e66f5",
|
||||||
"element_hover": "#1e66f5e6",
|
"element_hover": "#7287fd",
|
||||||
"element_active": "#1b5cdc",
|
"element_active": "#04a5e5",
|
||||||
"element_selected": "#1852c3",
|
"element_selected": "#209fb5",
|
||||||
"element_disabled": "#1e66f54d",
|
"element_disabled": "#1e66f54d",
|
||||||
"secondary_foreground": "#1e66f5",
|
"secondary_foreground": "#4c4f69",
|
||||||
"secondary_background": "#e6e9ef",
|
"secondary_background": "#ccd0da",
|
||||||
"secondary_hover": "#1e66f51a",
|
"secondary_hover": "#bcc0cc",
|
||||||
"secondary_active": "#dce0e8",
|
"secondary_active": "#acb0be",
|
||||||
"secondary_selected": "#dce0e8",
|
"secondary_selected": "#acb0be",
|
||||||
"secondary_disabled": "#1e66f54d",
|
"secondary_disabled": "#1e66f54d",
|
||||||
"danger_foreground": "#eff1f5",
|
"danger_foreground": "#eff1f5",
|
||||||
"danger_background": "#d20f39",
|
"danger_background": "#d20f39",
|
||||||
"danger_hover": "#d20f39e6",
|
"danger_hover": "#e64553",
|
||||||
"danger_active": "#bc0e33",
|
"danger_active": "#fe640b",
|
||||||
"danger_selected": "#a60c2d",
|
"danger_selected": "#df8e1d",
|
||||||
"danger_disabled": "#d20f394d",
|
"danger_disabled": "#d20f394d",
|
||||||
"warning_foreground": "#4c4f69",
|
"warning_foreground": "#eff1f5",
|
||||||
"warning_background": "#df8e1d",
|
"warning_background": "#fe640b",
|
||||||
"warning_hover": "#df8e1de6",
|
"warning_hover": "#df8e1d",
|
||||||
"warning_active": "#c9801a",
|
"warning_active": "#40a02b",
|
||||||
"warning_selected": "#b47217",
|
"warning_selected": "#179299",
|
||||||
"warning_disabled": "#df8e1d4d",
|
"warning_disabled": "#fe640b4d",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#4c4f6900",
|
||||||
"ghost_element_background_alt": "#e6e9ef",
|
"ghost_element_background_alt": "#e6e9ef",
|
||||||
"ghost_element_hover": "#4c4f691a",
|
"ghost_element_hover": "#4c4f690d",
|
||||||
"ghost_element_active": "#dce0e8",
|
"ghost_element_active": "#4c4f691a",
|
||||||
"ghost_element_selected": "#dce0e8",
|
"ghost_element_selected": "#4c4f691a",
|
||||||
"ghost_element_disabled": "#4c4f690d",
|
"ghost_element_disabled": "#4c4f6905",
|
||||||
"tab_inactive_background": "#e6e9ef",
|
"tab_background": "#e6e9ef",
|
||||||
"tab_hover_background": "#dce0e8",
|
"tab_foreground": "#6c6f85",
|
||||||
"tab_active_background": "#ccd0da",
|
"tab_hover_background": "#4c4f690d",
|
||||||
"scrollbar_thumb_background": "#4c4f6933",
|
"tab_active_background": "#eff1f5",
|
||||||
"scrollbar_thumb_hover_background": "#4c4f694d",
|
"tab_active_foreground": "#4c4f69",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#4c4f691a",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#4c4f6926",
|
||||||
"scrollbar_track_border": "#dce0e8",
|
"scrollbar_thumb_border": "#4c4f6900",
|
||||||
|
"scrollbar_track_background": "#4c4f6900",
|
||||||
|
"scrollbar_track_border": "#4c4f6900",
|
||||||
"drop_target_background": "#1e66f51a",
|
"drop_target_background": "#1e66f51a",
|
||||||
"cursor": "#04a5e5",
|
"cursor": "#1e66f5",
|
||||||
"selection": "#04a5e540"
|
"selection": "#1e66f540"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +1,76 @@
|
|||||||
{
|
{
|
||||||
"id": "catppuccin-macchiato",
|
"id": "catppuccin-macchiato",
|
||||||
"name": "Catppuccin Macchiato",
|
"name": "Catppuccin Macchiato",
|
||||||
"author": "Catppuccin",
|
"author": "Catppuccin Org (ported by Coop)",
|
||||||
"url": "https://github.com/catppuccin/catppuccin",
|
"url": "https://catppuccin.com",
|
||||||
"light": {
|
"light": {
|
||||||
"background": "#24273a",
|
"background": "#24273a",
|
||||||
"surface_background": "#1e2030",
|
"surface_background": "#1e2030",
|
||||||
"elevated_surface_background": "#181926",
|
"elevated_surface_background": "#181926",
|
||||||
"panel_background": "#24273a",
|
"panel_background": "#24273a",
|
||||||
"overlay": "#cad3f51a",
|
"overlay": "#cad3f51a",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#181926",
|
||||||
"title_bar_inactive": "#24273a",
|
"title_bar_inactive": "#24273a",
|
||||||
"window_border": "#5b6078",
|
"window_border": "#494d64",
|
||||||
"border": "#5b6078",
|
"border": "#494d64",
|
||||||
"border_variant": "#494d64",
|
"border_variant": "#363a4f",
|
||||||
"border_focused": "#8aadf4",
|
"border_focused": "#8aadf4",
|
||||||
"border_selected": "#8aadf4",
|
"border_selected": "#8aadf4",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#cad3f500",
|
||||||
"border_disabled": "#363a4f",
|
"border_disabled": "#1e2030",
|
||||||
"ring": "#8aadf4",
|
"ring": "#b7bdf8",
|
||||||
"text": "#cad3f5",
|
"text": "#cad3f5",
|
||||||
"text_muted": "#b8c0e0",
|
"text_muted": "#a5adcb",
|
||||||
"text_placeholder": "#a5adcb",
|
"text_placeholder": "#8087a2",
|
||||||
"text_accent": "#8aadf4",
|
"text_accent": "#8aadf4",
|
||||||
"icon": "#cad3f5",
|
"text_danger": "#ed8796",
|
||||||
"icon_muted": "#b8c0e0",
|
"text_warning": "#f5a97f",
|
||||||
"icon_accent": "#8aadf4",
|
"icon": "#a5adcb",
|
||||||
|
"icon_muted": "#8087a2",
|
||||||
|
"icon_accent": "#b7bdf8",
|
||||||
"element_foreground": "#24273a",
|
"element_foreground": "#24273a",
|
||||||
"element_background": "#8aadf4",
|
"element_background": "#8aadf4",
|
||||||
"element_hover": "#8aadf4e6",
|
"element_hover": "#b7bdf8",
|
||||||
"element_active": "#7c9cdc",
|
"element_active": "#91d7e3",
|
||||||
"element_selected": "#6e8bc4",
|
"element_selected": "#7dc4e4",
|
||||||
"element_disabled": "#8aadf44d",
|
"element_disabled": "#8aadf44d",
|
||||||
"secondary_foreground": "#8aadf4",
|
"secondary_foreground": "#cad3f5",
|
||||||
"secondary_background": "#363a4f",
|
"secondary_background": "#363a4f",
|
||||||
"secondary_hover": "#8aadf41a",
|
"secondary_hover": "#494d64",
|
||||||
"secondary_active": "#494d64",
|
"secondary_active": "#5b6078",
|
||||||
"secondary_selected": "#494d64",
|
"secondary_selected": "#5b6078",
|
||||||
"secondary_disabled": "#8aadf44d",
|
"secondary_disabled": "#8aadf44d",
|
||||||
"danger_foreground": "#24273a",
|
"danger_foreground": "#24273a",
|
||||||
"danger_background": "#ed8796",
|
"danger_background": "#ed8796",
|
||||||
"danger_hover": "#ed8796e6",
|
"danger_hover": "#ee99a0",
|
||||||
"danger_active": "#d57a87",
|
"danger_active": "#f5a97f",
|
||||||
"danger_selected": "#bd6d78",
|
"danger_selected": "#eed49f",
|
||||||
"danger_disabled": "#ed87964d",
|
"danger_disabled": "#ed87964d",
|
||||||
"warning_foreground": "#24273a",
|
"warning_foreground": "#24273a",
|
||||||
"warning_background": "#eed49f",
|
"warning_background": "#f5a97f",
|
||||||
"warning_hover": "#eed49fe6",
|
"warning_hover": "#eed49f",
|
||||||
"warning_active": "#d6bf8f",
|
"warning_active": "#a6da95",
|
||||||
"warning_selected": "#beaa7f",
|
"warning_selected": "#8bd5ca",
|
||||||
"warning_disabled": "#eed49f4d",
|
"warning_disabled": "#f5a97f4d",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#cad3f500",
|
||||||
"ghost_element_background_alt": "#363a4f",
|
"ghost_element_background_alt": "#1e2030",
|
||||||
"ghost_element_hover": "#cad3f51a",
|
"ghost_element_hover": "#cad3f50d",
|
||||||
"ghost_element_active": "#494d64",
|
"ghost_element_active": "#cad3f51a",
|
||||||
"ghost_element_selected": "#494d64",
|
"ghost_element_selected": "#cad3f51a",
|
||||||
"ghost_element_disabled": "#cad3f50d",
|
"ghost_element_disabled": "#cad3f505",
|
||||||
"tab_inactive_background": "#363a4f",
|
"tab_background": "#181926",
|
||||||
"tab_hover_background": "#494d64",
|
"tab_foreground": "#a5adcb",
|
||||||
"tab_active_background": "#5b6078",
|
"tab_hover_background": "#cad3f50d",
|
||||||
"scrollbar_thumb_background": "#cad3f533",
|
"tab_active_background": "#24273a",
|
||||||
"scrollbar_thumb_hover_background": "#cad3f54d",
|
"tab_active_foreground": "#cad3f5",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#cad3f51a",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#cad3f526",
|
||||||
"scrollbar_track_border": "#494d64",
|
"scrollbar_thumb_border": "#cad3f500",
|
||||||
|
"scrollbar_track_background": "#cad3f500",
|
||||||
|
"scrollbar_track_border": "#cad3f500",
|
||||||
"drop_target_background": "#8aadf41a",
|
"drop_target_background": "#8aadf41a",
|
||||||
"cursor": "#91d7e3",
|
"cursor": "#8aadf4",
|
||||||
"selection": "#91d7e340"
|
"selection": "#8aadf440"
|
||||||
},
|
},
|
||||||
"dark": {
|
"dark": {
|
||||||
"background": "#24273a",
|
"background": "#24273a",
|
||||||
@@ -74,63 +78,67 @@
|
|||||||
"elevated_surface_background": "#181926",
|
"elevated_surface_background": "#181926",
|
||||||
"panel_background": "#24273a",
|
"panel_background": "#24273a",
|
||||||
"overlay": "#cad3f51a",
|
"overlay": "#cad3f51a",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#181926",
|
||||||
"title_bar_inactive": "#24273a",
|
"title_bar_inactive": "#24273a",
|
||||||
"window_border": "#5b6078",
|
"window_border": "#494d64",
|
||||||
"border": "#5b6078",
|
"border": "#494d64",
|
||||||
"border_variant": "#494d64",
|
"border_variant": "#363a4f",
|
||||||
"border_focused": "#8aadf4",
|
"border_focused": "#8aadf4",
|
||||||
"border_selected": "#8aadf4",
|
"border_selected": "#8aadf4",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#cad3f500",
|
||||||
"border_disabled": "#363a4f",
|
"border_disabled": "#1e2030",
|
||||||
"ring": "#8aadf4",
|
"ring": "#b7bdf8",
|
||||||
"text": "#cad3f5",
|
"text": "#cad3f5",
|
||||||
"text_muted": "#b8c0e0",
|
"text_muted": "#a5adcb",
|
||||||
"text_placeholder": "#a5adcb",
|
"text_placeholder": "#8087a2",
|
||||||
"text_accent": "#8aadf4",
|
"text_accent": "#8aadf4",
|
||||||
"icon": "#cad3f5",
|
"text_danger": "#ed8796",
|
||||||
"icon_muted": "#b8c0e0",
|
"text_warning": "#f5a97f",
|
||||||
"icon_accent": "#8aadf4",
|
"icon": "#a5adcb",
|
||||||
|
"icon_muted": "#8087a2",
|
||||||
|
"icon_accent": "#b7bdf8",
|
||||||
"element_foreground": "#24273a",
|
"element_foreground": "#24273a",
|
||||||
"element_background": "#8aadf4",
|
"element_background": "#8aadf4",
|
||||||
"element_hover": "#8aadf4e6",
|
"element_hover": "#b7bdf8",
|
||||||
"element_active": "#7c9cdc",
|
"element_active": "#91d7e3",
|
||||||
"element_selected": "#6e8bc4",
|
"element_selected": "#7dc4e4",
|
||||||
"element_disabled": "#8aadf44d",
|
"element_disabled": "#8aadf44d",
|
||||||
"secondary_foreground": "#8aadf4",
|
"secondary_foreground": "#cad3f5",
|
||||||
"secondary_background": "#363a4f",
|
"secondary_background": "#363a4f",
|
||||||
"secondary_hover": "#8aadf41a",
|
"secondary_hover": "#494d64",
|
||||||
"secondary_active": "#494d64",
|
"secondary_active": "#5b6078",
|
||||||
"secondary_selected": "#494d64",
|
"secondary_selected": "#5b6078",
|
||||||
"secondary_disabled": "#8aadf44d",
|
"secondary_disabled": "#8aadf44d",
|
||||||
"danger_foreground": "#24273a",
|
"danger_foreground": "#24273a",
|
||||||
"danger_background": "#ed8796",
|
"danger_background": "#ed8796",
|
||||||
"danger_hover": "#ed8796e6",
|
"danger_hover": "#ee99a0",
|
||||||
"danger_active": "#d57a87",
|
"danger_active": "#f5a97f",
|
||||||
"danger_selected": "#bd6d78",
|
"danger_selected": "#eed49f",
|
||||||
"danger_disabled": "#ed87964d",
|
"danger_disabled": "#ed87964d",
|
||||||
"warning_foreground": "#24273a",
|
"warning_foreground": "#24273a",
|
||||||
"warning_background": "#eed49f",
|
"warning_background": "#f5a97f",
|
||||||
"warning_hover": "#eed49fe6",
|
"warning_hover": "#eed49f",
|
||||||
"warning_active": "#d6bf8f",
|
"warning_active": "#a6da95",
|
||||||
"warning_selected": "#beaa7f",
|
"warning_selected": "#8bd5ca",
|
||||||
"warning_disabled": "#eed49f4d",
|
"warning_disabled": "#f5a97f4d",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#cad3f500",
|
||||||
"ghost_element_background_alt": "#363a4f",
|
"ghost_element_background_alt": "#1e2030",
|
||||||
"ghost_element_hover": "#cad3f51a",
|
"ghost_element_hover": "#cad3f50d",
|
||||||
"ghost_element_active": "#494d64",
|
"ghost_element_active": "#cad3f51a",
|
||||||
"ghost_element_selected": "#494d64",
|
"ghost_element_selected": "#cad3f51a",
|
||||||
"ghost_element_disabled": "#cad3f50d",
|
"ghost_element_disabled": "#cad3f505",
|
||||||
"tab_inactive_background": "#363a4f",
|
"tab_background": "#181926",
|
||||||
"tab_hover_background": "#494d64",
|
"tab_foreground": "#a5adcb",
|
||||||
"tab_active_background": "#5b6078",
|
"tab_hover_background": "#cad3f50d",
|
||||||
"scrollbar_thumb_background": "#cad3f533",
|
"tab_active_background": "#24273a",
|
||||||
"scrollbar_thumb_hover_background": "#cad3f54d",
|
"tab_active_foreground": "#cad3f5",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#cad3f51a",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#cad3f526",
|
||||||
"scrollbar_track_border": "#494d64",
|
"scrollbar_thumb_border": "#cad3f500",
|
||||||
|
"scrollbar_track_background": "#cad3f500",
|
||||||
|
"scrollbar_track_border": "#cad3f500",
|
||||||
"drop_target_background": "#8aadf41a",
|
"drop_target_background": "#8aadf41a",
|
||||||
"cursor": "#91d7e3",
|
"cursor": "#8aadf4",
|
||||||
"selection": "#91d7e340"
|
"selection": "#8aadf440"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +1,76 @@
|
|||||||
{
|
{
|
||||||
"id": "catppuccin-mocha",
|
"id": "catppuccin-mocha",
|
||||||
"name": "Catppuccin Mocha",
|
"name": "Catppuccin Mocha",
|
||||||
"author": "Catppuccin",
|
"author": "Catppuccin Org (ported by Coop)",
|
||||||
"url": "https://github.com/catppuccin/catppuccin",
|
"url": "https://catppuccin.com",
|
||||||
"light": {
|
"light": {
|
||||||
"background": "#1e1e2e",
|
"background": "#1e1e2e",
|
||||||
"surface_background": "#181825",
|
"surface_background": "#181825",
|
||||||
"elevated_surface_background": "#11111b",
|
"elevated_surface_background": "#11111b",
|
||||||
"panel_background": "#1e1e2e",
|
"panel_background": "#1e1e2e",
|
||||||
"overlay": "#cdd6f41a",
|
"overlay": "#cdd6f41a",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#11111b",
|
||||||
"title_bar_inactive": "#1e1e2e",
|
"title_bar_inactive": "#1e1e2e",
|
||||||
"window_border": "#585b70",
|
"window_border": "#45475a",
|
||||||
"border": "#585b70",
|
"border": "#45475a",
|
||||||
"border_variant": "#45475a",
|
"border_variant": "#313244",
|
||||||
"border_focused": "#89b4fa",
|
"border_focused": "#89b4fa",
|
||||||
"border_selected": "#89b4fa",
|
"border_selected": "#89b4fa",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#cdd6f400",
|
||||||
"border_disabled": "#313244",
|
"border_disabled": "#181825",
|
||||||
"ring": "#89b4fa",
|
"ring": "#b4befe",
|
||||||
"text": "#cdd6f4",
|
"text": "#cdd6f4",
|
||||||
"text_muted": "#bac2de",
|
"text_muted": "#a6adc8",
|
||||||
"text_placeholder": "#a6adc8",
|
"text_placeholder": "#7f849c",
|
||||||
"text_accent": "#89b4fa",
|
"text_accent": "#89b4fa",
|
||||||
"icon": "#cdd6f4",
|
"text_danger": "#f38ba8",
|
||||||
"icon_muted": "#bac2de",
|
"text_warning": "#fab387",
|
||||||
"icon_accent": "#89b4fa",
|
"icon": "#a6adc8",
|
||||||
|
"icon_muted": "#7f849c",
|
||||||
|
"icon_accent": "#b4befe",
|
||||||
"element_foreground": "#1e1e2e",
|
"element_foreground": "#1e1e2e",
|
||||||
"element_background": "#89b4fa",
|
"element_background": "#89b4fa",
|
||||||
"element_hover": "#89b4fae6",
|
"element_hover": "#b4befe",
|
||||||
"element_active": "#7ba2e1",
|
"element_active": "#89dceb",
|
||||||
"element_selected": "#6d90c8",
|
"element_selected": "#74c7ec",
|
||||||
"element_disabled": "#89b4fa4d",
|
"element_disabled": "#89b4fa4d",
|
||||||
"secondary_foreground": "#89b4fa",
|
"secondary_foreground": "#cdd6f4",
|
||||||
"secondary_background": "#313244",
|
"secondary_background": "#313244",
|
||||||
"secondary_hover": "#89b4fa1a",
|
"secondary_hover": "#45475a",
|
||||||
"secondary_active": "#45475a",
|
"secondary_active": "#585b70",
|
||||||
"secondary_selected": "#45475a",
|
"secondary_selected": "#585b70",
|
||||||
"secondary_disabled": "#89b4fa4d",
|
"secondary_disabled": "#89b4fa4d",
|
||||||
"danger_foreground": "#1e1e2e",
|
"danger_foreground": "#1e1e2e",
|
||||||
"danger_background": "#f38ba8",
|
"danger_background": "#f38ba8",
|
||||||
"danger_hover": "#f38ba8e6",
|
"danger_hover": "#eba0ac",
|
||||||
"danger_active": "#db7d97",
|
"danger_active": "#fab387",
|
||||||
"danger_selected": "#c36f86",
|
"danger_selected": "#f9e2af",
|
||||||
"danger_disabled": "#f38ba84d",
|
"danger_disabled": "#f38ba84d",
|
||||||
"warning_foreground": "#1e1e2e",
|
"warning_foreground": "#1e1e2e",
|
||||||
"warning_background": "#f9e2af",
|
"warning_background": "#fab387",
|
||||||
"warning_hover": "#f9e2afe6",
|
"warning_hover": "#f9e2af",
|
||||||
"warning_active": "#e0cb9e",
|
"warning_active": "#a6e3a1",
|
||||||
"warning_selected": "#c7b48d",
|
"warning_selected": "#94e2d5",
|
||||||
"warning_disabled": "#f9e2af4d",
|
"warning_disabled": "#fab3874d",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#cdd6f400",
|
||||||
"ghost_element_background_alt": "#313244",
|
"ghost_element_background_alt": "#181825",
|
||||||
"ghost_element_hover": "#cdd6f41a",
|
"ghost_element_hover": "#cdd6f40d",
|
||||||
"ghost_element_active": "#45475a",
|
"ghost_element_active": "#cdd6f41a",
|
||||||
"ghost_element_selected": "#45475a",
|
"ghost_element_selected": "#cdd6f41a",
|
||||||
"ghost_element_disabled": "#cdd6f50d",
|
"ghost_element_disabled": "#cdd6f405",
|
||||||
"tab_inactive_background": "#313244",
|
"tab_background": "#11111b",
|
||||||
"tab_hover_background": "#45475a",
|
"tab_foreground": "#a6adc8",
|
||||||
"tab_active_background": "#585b70",
|
"tab_hover_background": "#cdd6f40d",
|
||||||
"scrollbar_thumb_background": "#cdd6f533",
|
"tab_active_background": "#1e1e2e",
|
||||||
"scrollbar_thumb_hover_background": "#cdd6f54d",
|
"tab_active_foreground": "#cdd6f4",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#cdd6f41a",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#cdd6f426",
|
||||||
"scrollbar_track_border": "#45475a",
|
"scrollbar_thumb_border": "#cdd6f400",
|
||||||
|
"scrollbar_track_background": "#cdd6f400",
|
||||||
|
"scrollbar_track_border": "#cdd6f400",
|
||||||
"drop_target_background": "#89b4fa1a",
|
"drop_target_background": "#89b4fa1a",
|
||||||
"cursor": "#89dceb",
|
"cursor": "#89b4fa",
|
||||||
"selection": "#89dceb40"
|
"selection": "#89b4fa40"
|
||||||
},
|
},
|
||||||
"dark": {
|
"dark": {
|
||||||
"background": "#1e1e2e",
|
"background": "#1e1e2e",
|
||||||
@@ -74,63 +78,67 @@
|
|||||||
"elevated_surface_background": "#11111b",
|
"elevated_surface_background": "#11111b",
|
||||||
"panel_background": "#1e1e2e",
|
"panel_background": "#1e1e2e",
|
||||||
"overlay": "#cdd6f41a",
|
"overlay": "#cdd6f41a",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#11111b",
|
||||||
"title_bar_inactive": "#1e1e2e",
|
"title_bar_inactive": "#1e1e2e",
|
||||||
"window_border": "#585b70",
|
"window_border": "#45475a",
|
||||||
"border": "#585b70",
|
"border": "#45475a",
|
||||||
"border_variant": "#45475a",
|
"border_variant": "#313244",
|
||||||
"border_focused": "#89b4fa",
|
"border_focused": "#89b4fa",
|
||||||
"border_selected": "#89b4fa",
|
"border_selected": "#89b4fa",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#cdd6f400",
|
||||||
"border_disabled": "#313244",
|
"border_disabled": "#181825",
|
||||||
"ring": "#89b4fa",
|
"ring": "#b4befe",
|
||||||
"text": "#cdd6f4",
|
"text": "#cdd6f4",
|
||||||
"text_muted": "#bac2de",
|
"text_muted": "#a6adc8",
|
||||||
"text_placeholder": "#a6adc8",
|
"text_placeholder": "#7f849c",
|
||||||
"text_accent": "#89b4fa",
|
"text_accent": "#89b4fa",
|
||||||
"icon": "#cdd6f4",
|
"text_danger": "#f38ba8",
|
||||||
"icon_muted": "#bac2de",
|
"text_warning": "#fab387",
|
||||||
"icon_accent": "#89b4fa",
|
"icon": "#a6adc8",
|
||||||
|
"icon_muted": "#7f849c",
|
||||||
|
"icon_accent": "#b4befe",
|
||||||
"element_foreground": "#1e1e2e",
|
"element_foreground": "#1e1e2e",
|
||||||
"element_background": "#89b4fa",
|
"element_background": "#89b4fa",
|
||||||
"element_hover": "#89b4fae6",
|
"element_hover": "#b4befe",
|
||||||
"element_active": "#7ba2e1",
|
"element_active": "#89dceb",
|
||||||
"element_selected": "#6d90c8",
|
"element_selected": "#74c7ec",
|
||||||
"element_disabled": "#89b4fa4d",
|
"element_disabled": "#89b4fa4d",
|
||||||
"secondary_foreground": "#89b4fa",
|
"secondary_foreground": "#cdd6f4",
|
||||||
"secondary_background": "#313244",
|
"secondary_background": "#313244",
|
||||||
"secondary_hover": "#89b4fa1a",
|
"secondary_hover": "#45475a",
|
||||||
"secondary_active": "#45475a",
|
"secondary_active": "#585b70",
|
||||||
"secondary_selected": "#45475a",
|
"secondary_selected": "#585b70",
|
||||||
"secondary_disabled": "#89b4fa4d",
|
"secondary_disabled": "#89b4fa4d",
|
||||||
"danger_foreground": "#1e1e2e",
|
"danger_foreground": "#1e1e2e",
|
||||||
"danger_background": "#f38ba8",
|
"danger_background": "#f38ba8",
|
||||||
"danger_hover": "#f38ba8e6",
|
"danger_hover": "#eba0ac",
|
||||||
"danger_active": "#db7d97",
|
"danger_active": "#fab387",
|
||||||
"danger_selected": "#c36f86",
|
"danger_selected": "#f9e2af",
|
||||||
"danger_disabled": "#f38ba84d",
|
"danger_disabled": "#f38ba84d",
|
||||||
"warning_foreground": "#1e1e2e",
|
"warning_foreground": "#1e1e2e",
|
||||||
"warning_background": "#f9e2af",
|
"warning_background": "#fab387",
|
||||||
"warning_hover": "#f9e2afe6",
|
"warning_hover": "#f9e2af",
|
||||||
"warning_active": "#e0cb9e",
|
"warning_active": "#a6e3a1",
|
||||||
"warning_selected": "#c7b48d",
|
"warning_selected": "#94e2d5",
|
||||||
"warning_disabled": "#f9e2af4d",
|
"warning_disabled": "#fab3874d",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#cdd6f400",
|
||||||
"ghost_element_background_alt": "#313244",
|
"ghost_element_background_alt": "#181825",
|
||||||
"ghost_element_hover": "#cdd6f41a",
|
"ghost_element_hover": "#cdd6f40d",
|
||||||
"ghost_element_active": "#45475a",
|
"ghost_element_active": "#cdd6f41a",
|
||||||
"ghost_element_selected": "#45475a",
|
"ghost_element_selected": "#cdd6f41a",
|
||||||
"ghost_element_disabled": "#cdd6f50d",
|
"ghost_element_disabled": "#cdd6f405",
|
||||||
"tab_inactive_background": "#313244",
|
"tab_background": "#11111b",
|
||||||
"tab_hover_background": "#45475a",
|
"tab_foreground": "#a6adc8",
|
||||||
"tab_active_background": "#585b70",
|
"tab_hover_background": "#cdd6f40d",
|
||||||
"scrollbar_thumb_background": "#cdd6f533",
|
"tab_active_background": "#1e1e2e",
|
||||||
"scrollbar_thumb_hover_background": "#cdd6f54d",
|
"tab_active_foreground": "#cdd6f4",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#cdd6f41a",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#cdd6f426",
|
||||||
"scrollbar_track_border": "#45475a",
|
"scrollbar_thumb_border": "#cdd6f400",
|
||||||
|
"scrollbar_track_background": "#cdd6f400",
|
||||||
|
"scrollbar_track_border": "#cdd6f400",
|
||||||
"drop_target_background": "#89b4fa1a",
|
"drop_target_background": "#89b4fa1a",
|
||||||
"cursor": "#89dceb",
|
"cursor": "#89b4fa",
|
||||||
"selection": "#89dceb40"
|
"selection": "#89b4fa40"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,71 +1,75 @@
|
|||||||
{
|
{
|
||||||
"id": "flexoki",
|
"id": "flexoki",
|
||||||
"name": "Flexoki",
|
"name": "Flexoki",
|
||||||
"author": "Steph Ango",
|
"author": "Steph Ango (ported by Coop)",
|
||||||
"url": "https://stephango.com/flexoki",
|
"url": "https://stephango.com/flexoki",
|
||||||
"light": {
|
"light": {
|
||||||
"background": "#FFFCF0",
|
"background": "#FFFCF0",
|
||||||
"surface_background": "#F2F0E5",
|
"surface_background": "#F2F0E5",
|
||||||
"elevated_surface_background": "#E6E4D9",
|
"elevated_surface_background": "#E6E4D9",
|
||||||
"panel_background": "#FFFCF0",
|
"panel_background": "#FFFCF0",
|
||||||
"overlay": "#100F0F1a",
|
"overlay": "#100F0F1A",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#E6E4D9",
|
||||||
"title_bar_inactive": "#FFFCF0",
|
"title_bar_inactive": "#FFFCF0",
|
||||||
"window_border": "#CECDC3",
|
"window_border": "#CECDC3",
|
||||||
"border": "#CECDC3",
|
"border": "#CECDC3",
|
||||||
"border_variant": "#DAD8CE",
|
"border_variant": "#DAD8CE",
|
||||||
"border_focused": "#24837B",
|
"border_focused": "#24837B",
|
||||||
"border_selected": "#24837B",
|
"border_selected": "#24837B",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#100F0F00",
|
||||||
"border_disabled": "#E6E4D9",
|
"border_disabled": "#E6E4D9",
|
||||||
"ring": "#24837B",
|
"ring": "#3AA99F",
|
||||||
"text": "#100F0F",
|
"text": "#100F0F",
|
||||||
"text_muted": "#6F6E69",
|
"text_muted": "#6F6E69",
|
||||||
"text_placeholder": "#878580",
|
"text_placeholder": "#B7B5AC",
|
||||||
"text_accent": "#24837B",
|
"text_accent": "#24837B",
|
||||||
"icon": "#100F0F",
|
"text_danger": "#AF3029",
|
||||||
"icon_muted": "#6F6E69",
|
"text_warning": "#BC5215",
|
||||||
"icon_accent": "#24837B",
|
"icon": "#6F6E69",
|
||||||
"element_foreground": "#DDF1E4",
|
"icon_muted": "#B7B5AC",
|
||||||
|
"icon_accent": "#3AA99F",
|
||||||
|
"element_foreground": "#FFFCF0",
|
||||||
"element_background": "#24837B",
|
"element_background": "#24837B",
|
||||||
"element_hover": "#24837Be5",
|
"element_hover": "#3AA99F",
|
||||||
"element_active": "#20756E",
|
"element_active": "#1C1B1A",
|
||||||
"element_selected": "#1C6861",
|
"element_selected": "#100F0F",
|
||||||
"element_disabled": "#24837B4c",
|
"element_disabled": "#24837B4D",
|
||||||
"secondary_foreground": "#24837B",
|
"secondary_foreground": "#100F0F",
|
||||||
"secondary_background": "#E6E4D9",
|
"secondary_background": "#E6E4D9",
|
||||||
"secondary_hover": "#24837B1a",
|
"secondary_hover": "#DAD8CE",
|
||||||
"secondary_active": "#DAD8CE",
|
"secondary_active": "#CECDC3",
|
||||||
"secondary_selected": "#DAD8CE",
|
"secondary_selected": "#CECDC3",
|
||||||
"secondary_disabled": "#24837B4c",
|
"secondary_disabled": "#24837B4D",
|
||||||
"danger_foreground": "#FFE1D5",
|
"danger_foreground": "#FFFCF0",
|
||||||
"danger_background": "#AF3029",
|
"danger_background": "#AF3029",
|
||||||
"danger_hover": "#AF3029e5",
|
"danger_hover": "#D14D41",
|
||||||
"danger_active": "#9E2B25",
|
"danger_active": "#1C1B1A",
|
||||||
"danger_selected": "#8D2620",
|
"danger_selected": "#100F0F",
|
||||||
"danger_disabled": "#AF30294c",
|
"danger_disabled": "#AF30294D",
|
||||||
"warning_foreground": "#FFE7CE",
|
"warning_foreground": "#FFFCF0",
|
||||||
"warning_background": "#BC5215",
|
"warning_background": "#BC5215",
|
||||||
"warning_hover": "#BC5215e5",
|
"warning_hover": "#DA702C",
|
||||||
"warning_active": "#A94913",
|
"warning_active": "#1C1B1A",
|
||||||
"warning_selected": "#964011",
|
"warning_selected": "#100F0F",
|
||||||
"warning_disabled": "#BC52154c",
|
"warning_disabled": "#BC52154D",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#100F0F00",
|
||||||
"ghost_element_background_alt": "#E6E4D9",
|
"ghost_element_background_alt": "#F2F0E5",
|
||||||
"ghost_element_hover": "#100F0F1a",
|
"ghost_element_hover": "#100F0F0D",
|
||||||
"ghost_element_active": "#DAD8CE",
|
"ghost_element_active": "#100F0F1A",
|
||||||
"ghost_element_selected": "#DAD8CE",
|
"ghost_element_selected": "#100F0F1A",
|
||||||
"ghost_element_disabled": "#100F0F0d",
|
"ghost_element_disabled": "#100F0F05",
|
||||||
"tab_inactive_background": "#E6E4D9",
|
"tab_background": "#E6E4D9",
|
||||||
"tab_hover_background": "#DAD8CE",
|
"tab_foreground": "#6F6E69",
|
||||||
"tab_active_background": "#CECDC3",
|
"tab_hover_background": "#100F0F0D",
|
||||||
"scrollbar_thumb_background": "#100F0F33",
|
"tab_active_background": "#FFFCF0",
|
||||||
"scrollbar_thumb_hover_background": "#100F0F4d",
|
"tab_active_foreground": "#100F0F",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#100F0F1A",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#100F0F26",
|
||||||
"scrollbar_track_border": "#DAD8CE",
|
"scrollbar_thumb_border": "#100F0F00",
|
||||||
"drop_target_background": "#24837B1a",
|
"scrollbar_track_background": "#100F0F00",
|
||||||
"cursor": "#205EA6",
|
"scrollbar_track_border": "#100F0F00",
|
||||||
|
"drop_target_background": "#24837B1A",
|
||||||
|
"cursor": "#24837B",
|
||||||
"selection": "#24837B40"
|
"selection": "#24837B40"
|
||||||
},
|
},
|
||||||
"dark": {
|
"dark": {
|
||||||
@@ -73,64 +77,68 @@
|
|||||||
"surface_background": "#1C1B1A",
|
"surface_background": "#1C1B1A",
|
||||||
"elevated_surface_background": "#282726",
|
"elevated_surface_background": "#282726",
|
||||||
"panel_background": "#100F0F",
|
"panel_background": "#100F0F",
|
||||||
"overlay": "#FFFCF01a",
|
"overlay": "#FFFCF01A",
|
||||||
"title_bar": "#00000000",
|
"title_bar": "#282726",
|
||||||
"title_bar_inactive": "#100F0F",
|
"title_bar_inactive": "#100F0F",
|
||||||
"window_border": "#403E3C",
|
"window_border": "#403E3C",
|
||||||
"border": "#403E3C",
|
"border": "#403E3C",
|
||||||
"border_variant": "#343331",
|
"border_variant": "#343331",
|
||||||
"border_focused": "#3AA99F",
|
"border_focused": "#3AA99F",
|
||||||
"border_selected": "#3AA99F",
|
"border_selected": "#3AA99F",
|
||||||
"border_transparent": "#00000000",
|
"border_transparent": "#100F0F00",
|
||||||
"border_disabled": "#282726",
|
"border_disabled": "#282726",
|
||||||
"ring": "#3AA99F",
|
"ring": "#24837B",
|
||||||
"text": "#FFFCF0",
|
"text": "#CECDC3",
|
||||||
"text_muted": "#878580",
|
"text_muted": "#878580",
|
||||||
"text_placeholder": "#575653",
|
"text_placeholder": "#575653",
|
||||||
"text_accent": "#3AA99F",
|
"text_accent": "#3AA99F",
|
||||||
"icon": "#FFFCF0",
|
"text_danger": "#D14D41",
|
||||||
"icon_muted": "#878580",
|
"text_warning": "#DA702C",
|
||||||
"icon_accent": "#3AA99F",
|
"icon": "#878580",
|
||||||
"element_foreground": "#101F1D",
|
"icon_muted": "#575653",
|
||||||
|
"icon_accent": "#24837B",
|
||||||
|
"element_foreground": "#100F0F",
|
||||||
"element_background": "#3AA99F",
|
"element_background": "#3AA99F",
|
||||||
"element_hover": "#3AA99Fe5",
|
"element_hover": "#24837B",
|
||||||
"element_active": "#34988F",
|
"element_active": "#CECDC3",
|
||||||
"element_selected": "#2F877F",
|
"element_selected": "#F2F0E5",
|
||||||
"element_disabled": "#3AA99F4c",
|
"element_disabled": "#3AA99F4D",
|
||||||
"secondary_foreground": "#3AA99F",
|
"secondary_foreground": "#CECDC3",
|
||||||
"secondary_background": "#282726",
|
"secondary_background": "#1C1B1A",
|
||||||
"secondary_hover": "#3AA99F1a",
|
"secondary_hover": "#282726",
|
||||||
"secondary_active": "#343331",
|
"secondary_active": "#343331",
|
||||||
"secondary_selected": "#343331",
|
"secondary_selected": "#343331",
|
||||||
"secondary_disabled": "#3AA99F4c",
|
"secondary_disabled": "#3AA99F4D",
|
||||||
"danger_foreground": "#261312",
|
"danger_foreground": "#100F0F",
|
||||||
"danger_background": "#D14D41",
|
"danger_background": "#D14D41",
|
||||||
"danger_hover": "#D14D41e5",
|
"danger_hover": "#AF3029",
|
||||||
"danger_active": "#BC453A",
|
"danger_active": "#CECDC3",
|
||||||
"danger_selected": "#A73D33",
|
"danger_selected": "#F2F0E5",
|
||||||
"danger_disabled": "#D14D414c",
|
"danger_disabled": "#D14D414D",
|
||||||
"warning_foreground": "#27180E",
|
"warning_foreground": "#100F0F",
|
||||||
"warning_background": "#DA702C",
|
"warning_background": "#DA702C",
|
||||||
"warning_hover": "#DA702Ce5",
|
"warning_hover": "#BC5215",
|
||||||
"warning_active": "#C46527",
|
"warning_active": "#CECDC3",
|
||||||
"warning_selected": "#AF5A22",
|
"warning_selected": "#F2F0E5",
|
||||||
"warning_disabled": "#DA702C4c",
|
"warning_disabled": "#DA702C4D",
|
||||||
"ghost_element_background": "#00000000",
|
"ghost_element_background": "#100F0F00",
|
||||||
"ghost_element_background_alt": "#282726",
|
"ghost_element_background_alt": "#1C1B1A",
|
||||||
"ghost_element_hover": "#FFFCF01a",
|
"ghost_element_hover": "#FFFCF00D",
|
||||||
"ghost_element_active": "#343331",
|
"ghost_element_active": "#FFFCF01A",
|
||||||
"ghost_element_selected": "#343331",
|
"ghost_element_selected": "#FFFCF01A",
|
||||||
"ghost_element_disabled": "#FFFCF00d",
|
"ghost_element_disabled": "#FFFCF005",
|
||||||
"tab_inactive_background": "#282726",
|
"tab_background": "#282726",
|
||||||
"tab_hover_background": "#343331",
|
"tab_foreground": "#878580",
|
||||||
"tab_active_background": "#403E3C",
|
"tab_hover_background": "#FFFCF00D",
|
||||||
"scrollbar_thumb_background": "#FFFCF033",
|
"tab_active_background": "#100F0F",
|
||||||
"scrollbar_thumb_hover_background": "#FFFCF04d",
|
"tab_active_foreground": "#CECDC3",
|
||||||
"scrollbar_thumb_border": "#00000000",
|
"scrollbar_thumb_background": "#FFFCF01A",
|
||||||
"scrollbar_track_background": "#00000000",
|
"scrollbar_thumb_hover_background": "#FFFCF026",
|
||||||
"scrollbar_track_border": "#343331",
|
"scrollbar_thumb_border": "#100F0F00",
|
||||||
"drop_target_background": "#3AA99F1a",
|
"scrollbar_track_background": "#100F0F00",
|
||||||
"cursor": "#4385BE",
|
"scrollbar_track_border": "#100F0F00",
|
||||||
|
"drop_target_background": "#3AA99F1A",
|
||||||
|
"cursor": "#3AA99F",
|
||||||
"selection": "#3AA99F40"
|
"selection": "#3AA99F40"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
144
assets/themes/forest.json
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
{
|
||||||
|
"id": "forest",
|
||||||
|
"name": "Forest",
|
||||||
|
"author": "Coop",
|
||||||
|
"url": "https://github.com/lumehq/coop",
|
||||||
|
"light": {
|
||||||
|
"background": "#fbfefcff",
|
||||||
|
"surface_background": "#f4fbf6ff",
|
||||||
|
"elevated_surface_background": "#e9f6e9ff",
|
||||||
|
"panel_background": "#fbfefcff",
|
||||||
|
"overlay": "#193b2d1a",
|
||||||
|
"title_bar": "#e9f6e9ff",
|
||||||
|
"title_bar_inactive": "#fbfefcff",
|
||||||
|
"window_border": "#c4e8d1ff",
|
||||||
|
"border": "#c4e8d1ff",
|
||||||
|
"border_variant": "#b2ddb5ff",
|
||||||
|
"border_focused": "#30a46cff",
|
||||||
|
"border_selected": "#30a46cff",
|
||||||
|
"border_transparent": "#00000000",
|
||||||
|
"border_disabled": "#e0f3e6ff",
|
||||||
|
"ring": "#2b9a66ff",
|
||||||
|
"text": "#193b2dff",
|
||||||
|
"text_muted": "#2f7c57ff",
|
||||||
|
"text_placeholder": "#8eceaaff",
|
||||||
|
"text_accent": "#30a46cff",
|
||||||
|
"text_danger": "#e54d2eff",
|
||||||
|
"text_warning": "#f76b15ff",
|
||||||
|
"icon": "#2f7c57ff",
|
||||||
|
"icon_muted": "#8eceaaff",
|
||||||
|
"icon_accent": "#2b9a66ff",
|
||||||
|
"element_foreground": "#ffffffff",
|
||||||
|
"element_background": "#30a46cff",
|
||||||
|
"element_hover": "#2b9a66ff",
|
||||||
|
"element_active": "#2a7e3bff",
|
||||||
|
"element_selected": "#218358ff",
|
||||||
|
"element_disabled": "#30a46c4d",
|
||||||
|
"secondary_foreground": "#193b2dff",
|
||||||
|
"secondary_background": "#e9f6e9ff",
|
||||||
|
"secondary_hover": "#daf1dbff",
|
||||||
|
"secondary_active": "#c4e8d1ff",
|
||||||
|
"secondary_selected": "#c4e8d1ff",
|
||||||
|
"secondary_disabled": "#30a46c4d",
|
||||||
|
"danger_foreground": "#ffffffff",
|
||||||
|
"danger_background": "#feebe7ff",
|
||||||
|
"danger_hover": "#ffcdc2ff",
|
||||||
|
"danger_active": "#fdbdafff",
|
||||||
|
"danger_selected": "#fdbdafff",
|
||||||
|
"danger_disabled": "#e54d2e4d",
|
||||||
|
"warning_foreground": "#ffffffff",
|
||||||
|
"warning_background": "#fff7edff",
|
||||||
|
"warning_hover": "#ffd19aff",
|
||||||
|
"warning_active": "#ffc182ff",
|
||||||
|
"warning_selected": "#ffc182ff",
|
||||||
|
"warning_disabled": "#f76b154d",
|
||||||
|
"ghost_element_background": "#00000000",
|
||||||
|
"ghost_element_background_alt": "#e9f6e9ff",
|
||||||
|
"ghost_element_hover": "#193b2d0d",
|
||||||
|
"ghost_element_active": "#193b2d1a",
|
||||||
|
"ghost_element_selected": "#193b2d1a",
|
||||||
|
"ghost_element_disabled": "#193b2d05",
|
||||||
|
"tab_background": "#e9f6e9ff",
|
||||||
|
"tab_foreground": "#2f7c57ff",
|
||||||
|
"tab_hover_background": "#193b2d0d",
|
||||||
|
"tab_active_background": "#fbfefcff",
|
||||||
|
"tab_active_foreground": "#193b2dff",
|
||||||
|
"scrollbar_thumb_background": "#193b2d1a",
|
||||||
|
"scrollbar_thumb_hover_background": "#193b2d26",
|
||||||
|
"scrollbar_thumb_border": "#00000000",
|
||||||
|
"scrollbar_track_background": "#00000000",
|
||||||
|
"scrollbar_track_border": "#00000000",
|
||||||
|
"drop_target_background": "#30a46c1a",
|
||||||
|
"cursor": "#30a46cff",
|
||||||
|
"selection": "#30a46c40"
|
||||||
|
},
|
||||||
|
"dark": {
|
||||||
|
"background": "#0e1512ff",
|
||||||
|
"surface_background": "#121b17ff",
|
||||||
|
"elevated_surface_background": "#132d21ff",
|
||||||
|
"panel_background": "#0e1512ff",
|
||||||
|
"overlay": "#b1f1cb1a",
|
||||||
|
"title_bar": "#132d21ff",
|
||||||
|
"title_bar_inactive": "#0e1512ff",
|
||||||
|
"window_border": "#20573eff",
|
||||||
|
"border": "#20573eff",
|
||||||
|
"border_variant": "#174933ff",
|
||||||
|
"border_focused": "#33b074ff",
|
||||||
|
"border_selected": "#33b074ff",
|
||||||
|
"border_transparent": "#00000000",
|
||||||
|
"border_disabled": "#113b29ff",
|
||||||
|
"ring": "#33b074ff",
|
||||||
|
"text": "#b1f1cbff",
|
||||||
|
"text_muted": "#71d083ff",
|
||||||
|
"text_placeholder": "#2f7c57ff",
|
||||||
|
"text_accent": "#3dd68cff",
|
||||||
|
"text_danger": "#ff977dff",
|
||||||
|
"text_warning": "#ffa057ff",
|
||||||
|
"icon": "#71d083ff",
|
||||||
|
"icon_muted": "#2f7c57ff",
|
||||||
|
"icon_accent": "#33b074ff",
|
||||||
|
"element_foreground": "#0e1512ff",
|
||||||
|
"element_background": "#3dd68cff",
|
||||||
|
"element_hover": "#71d083ff",
|
||||||
|
"element_active": "#33b074ff",
|
||||||
|
"element_selected": "#30a46cff",
|
||||||
|
"element_disabled": "#3dd68c4d",
|
||||||
|
"secondary_foreground": "#b1f1cbff",
|
||||||
|
"secondary_background": "#132d21ff",
|
||||||
|
"secondary_hover": "#113b29ff",
|
||||||
|
"secondary_active": "#174933ff",
|
||||||
|
"secondary_selected": "#174933ff",
|
||||||
|
"secondary_disabled": "#3dd68c4d",
|
||||||
|
"danger_foreground": "#181111ff",
|
||||||
|
"danger_background": "#391714ff",
|
||||||
|
"danger_hover": "#5e1c16ff",
|
||||||
|
"danger_active": "#6e2920ff",
|
||||||
|
"danger_selected": "#6e2920ff",
|
||||||
|
"danger_disabled": "#ff977d4d",
|
||||||
|
"warning_foreground": "#17120eff",
|
||||||
|
"warning_background": "#331e0bff",
|
||||||
|
"warning_hover": "#562800ff",
|
||||||
|
"warning_active": "#66350cff",
|
||||||
|
"warning_selected": "#66350cff",
|
||||||
|
"warning_disabled": "#ffa0574d",
|
||||||
|
"ghost_element_background": "#00000000",
|
||||||
|
"ghost_element_background_alt": "#132d21ff",
|
||||||
|
"ghost_element_hover": "#b1f1cb0d",
|
||||||
|
"ghost_element_active": "#b1f1cb1a",
|
||||||
|
"ghost_element_selected": "#b1f1cb1a",
|
||||||
|
"ghost_element_disabled": "#b1f1cb05",
|
||||||
|
"tab_background": "#132d21ff",
|
||||||
|
"tab_foreground": "#71d083ff",
|
||||||
|
"tab_hover_background": "#b1f1cb0d",
|
||||||
|
"tab_active_background": "#0e1512ff",
|
||||||
|
"tab_active_foreground": "#b1f1cbff",
|
||||||
|
"scrollbar_thumb_background": "#b1f1cb1a",
|
||||||
|
"scrollbar_thumb_hover_background": "#b1f1cb26",
|
||||||
|
"scrollbar_thumb_border": "#00000000",
|
||||||
|
"scrollbar_track_background": "#00000000",
|
||||||
|
"scrollbar_track_border": "#00000000",
|
||||||
|
"drop_target_background": "#3dd68c1a",
|
||||||
|
"cursor": "#3dd68cff",
|
||||||
|
"selection": "#3dd68c40"
|
||||||
|
}
|
||||||
|
}
|
||||||
144
assets/themes/ocean.json
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
{
|
||||||
|
"id": "ocean",
|
||||||
|
"name": "Ocean",
|
||||||
|
"author": "Coop",
|
||||||
|
"url": "https://github.com/lumehq/coop",
|
||||||
|
"light": {
|
||||||
|
"background": "#fafefeff",
|
||||||
|
"surface_background": "#f2fbfaff",
|
||||||
|
"elevated_surface_background": "#e6f7f7ff",
|
||||||
|
"panel_background": "#fafefeff",
|
||||||
|
"overlay": "#00333f1a",
|
||||||
|
"title_bar": "#e6f7f7ff",
|
||||||
|
"title_bar_inactive": "#fafefeff",
|
||||||
|
"window_border": "#cce5e9ff",
|
||||||
|
"border": "#cce5e9ff",
|
||||||
|
"border_variant": "#b8dde3ff",
|
||||||
|
"border_focused": "#00a2c7ff",
|
||||||
|
"border_selected": "#00a2c7ff",
|
||||||
|
"border_transparent": "#00000000",
|
||||||
|
"border_disabled": "#e0f0f2ff",
|
||||||
|
"ring": "#0797b9ff",
|
||||||
|
"text": "#0d3c48ff",
|
||||||
|
"text_muted": "#107d98ff",
|
||||||
|
"text_placeholder": "#60b3d7ff",
|
||||||
|
"text_accent": "#00a2c7ff",
|
||||||
|
"text_danger": "#e54d2eff",
|
||||||
|
"text_warning": "#f76b15ff",
|
||||||
|
"icon": "#107d98ff",
|
||||||
|
"icon_muted": "#60b3d7ff",
|
||||||
|
"icon_accent": "#0797b9ff",
|
||||||
|
"element_foreground": "#ffffffff",
|
||||||
|
"element_background": "#00a2c7ff",
|
||||||
|
"element_hover": "#0797b9ff",
|
||||||
|
"element_active": "#12667eff",
|
||||||
|
"element_selected": "#0d4a5cff",
|
||||||
|
"element_disabled": "#00a2c74d",
|
||||||
|
"secondary_foreground": "#0d4a5cff",
|
||||||
|
"secondary_background": "#ddf9f2ff",
|
||||||
|
"secondary_hover": "#c8f4e9ff",
|
||||||
|
"secondary_active": "#b3ecdeff",
|
||||||
|
"secondary_selected": "#b3ecdeff",
|
||||||
|
"secondary_disabled": "#00a2c74d",
|
||||||
|
"danger_foreground": "#ffffffff",
|
||||||
|
"danger_background": "#feebe7ff",
|
||||||
|
"danger_hover": "#ffcdc2ff",
|
||||||
|
"danger_active": "#fdbdafff",
|
||||||
|
"danger_selected": "#fdbdafff",
|
||||||
|
"danger_disabled": "#e54d2e4d",
|
||||||
|
"warning_foreground": "#ffffffff",
|
||||||
|
"warning_background": "#fff7edff",
|
||||||
|
"warning_hover": "#ffd19aff",
|
||||||
|
"warning_active": "#ffc182ff",
|
||||||
|
"warning_selected": "#ffc182ff",
|
||||||
|
"warning_disabled": "#f76b154d",
|
||||||
|
"ghost_element_background": "#00000000",
|
||||||
|
"ghost_element_background_alt": "#e6f7f7ff",
|
||||||
|
"ghost_element_hover": "#00333f0d",
|
||||||
|
"ghost_element_active": "#00333f1a",
|
||||||
|
"ghost_element_selected": "#00333f1a",
|
||||||
|
"ghost_element_disabled": "#00333f05",
|
||||||
|
"tab_background": "#e6f7f7ff",
|
||||||
|
"tab_foreground": "#107d98ff",
|
||||||
|
"tab_hover_background": "#00333f0d",
|
||||||
|
"tab_active_background": "#fafefeff",
|
||||||
|
"tab_active_foreground": "#0d3c48ff",
|
||||||
|
"scrollbar_thumb_background": "#00333f1a",
|
||||||
|
"scrollbar_thumb_hover_background": "#00333f26",
|
||||||
|
"scrollbar_thumb_border": "#00000000",
|
||||||
|
"scrollbar_track_background": "#00000000",
|
||||||
|
"scrollbar_track_border": "#00000000",
|
||||||
|
"drop_target_background": "#00a2c71a",
|
||||||
|
"cursor": "#00a2c7ff",
|
||||||
|
"selection": "#00a2c740"
|
||||||
|
},
|
||||||
|
"dark": {
|
||||||
|
"background": "#0b161aff",
|
||||||
|
"surface_background": "#101b20ff",
|
||||||
|
"elevated_surface_background": "#082c36ff",
|
||||||
|
"panel_background": "#0b161aff",
|
||||||
|
"overlay": "#c2f3ff1a",
|
||||||
|
"title_bar": "#082c36ff",
|
||||||
|
"title_bar_inactive": "#0b161aff",
|
||||||
|
"window_border": "#1b537bff",
|
||||||
|
"border": "#1b537bff",
|
||||||
|
"border_variant": "#154467ff",
|
||||||
|
"border_focused": "#00a2c7ff",
|
||||||
|
"border_selected": "#00a2c7ff",
|
||||||
|
"border_transparent": "#00000000",
|
||||||
|
"border_disabled": "#112840ff",
|
||||||
|
"ring": "#23afd0ff",
|
||||||
|
"text": "#b6ecf7ff",
|
||||||
|
"text_muted": "#4ccce6ff",
|
||||||
|
"text_placeholder": "#197caeff",
|
||||||
|
"text_accent": "#7ce2feff",
|
||||||
|
"text_danger": "#ff977dff",
|
||||||
|
"text_warning": "#ffa057ff",
|
||||||
|
"icon": "#4ccce6ff",
|
||||||
|
"icon_muted": "#197caeff",
|
||||||
|
"icon_accent": "#23afd0ff",
|
||||||
|
"element_foreground": "#0b161aff",
|
||||||
|
"element_background": "#7ce2feff",
|
||||||
|
"element_hover": "#a8eeffff",
|
||||||
|
"element_active": "#23afd0ff",
|
||||||
|
"element_selected": "#00a2c7ff",
|
||||||
|
"element_disabled": "#7ce2fe4d",
|
||||||
|
"secondary_foreground": "#adf0ddff",
|
||||||
|
"secondary_background": "#0d2d2aff",
|
||||||
|
"secondary_hover": "#023b37ff",
|
||||||
|
"secondary_active": "#084843ff",
|
||||||
|
"secondary_selected": "#084843ff",
|
||||||
|
"secondary_disabled": "#7ce2fe4d",
|
||||||
|
"danger_foreground": "#181111ff",
|
||||||
|
"danger_background": "#391714ff",
|
||||||
|
"danger_hover": "#5e1c16ff",
|
||||||
|
"danger_active": "#6e2920ff",
|
||||||
|
"danger_selected": "#6e2920ff",
|
||||||
|
"danger_disabled": "#ff977d4d",
|
||||||
|
"warning_foreground": "#17120eff",
|
||||||
|
"warning_background": "#331e0bff",
|
||||||
|
"warning_hover": "#562800ff",
|
||||||
|
"warning_active": "#66350cff",
|
||||||
|
"warning_selected": "#66350cff",
|
||||||
|
"warning_disabled": "#ffa0574d",
|
||||||
|
"ghost_element_background": "#00000000",
|
||||||
|
"ghost_element_background_alt": "#082c36ff",
|
||||||
|
"ghost_element_hover": "#c2f3ff0d",
|
||||||
|
"ghost_element_active": "#c2f3ff1a",
|
||||||
|
"ghost_element_selected": "#c2f3ff1a",
|
||||||
|
"ghost_element_disabled": "#c2f3ff05",
|
||||||
|
"tab_background": "#082c36ff",
|
||||||
|
"tab_foreground": "#4ccce6ff",
|
||||||
|
"tab_hover_background": "#c2f3ff0d",
|
||||||
|
"tab_active_background": "#0b161aff",
|
||||||
|
"tab_active_foreground": "#b6ecf7ff",
|
||||||
|
"scrollbar_thumb_background": "#c2f3ff1a",
|
||||||
|
"scrollbar_thumb_hover_background": "#c2f3ff26",
|
||||||
|
"scrollbar_thumb_border": "#00000000",
|
||||||
|
"scrollbar_track_background": "#00000000",
|
||||||
|
"scrollbar_track_border": "#00000000",
|
||||||
|
"drop_target_background": "#7ce2fe1a",
|
||||||
|
"cursor": "#7ce2feff",
|
||||||
|
"selection": "#7ce2fe40"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "rose-pine-dawn",
|
|
||||||
"name": "Rosé Pine Dawn",
|
|
||||||
"author": "Rosé Pine",
|
|
||||||
"url": "https://rosepinetheme.com/",
|
|
||||||
"light": {
|
|
||||||
"background": "#faf4ed",
|
|
||||||
"surface_background": "#fffaf3",
|
|
||||||
"elevated_surface_background": "#f2e9e1",
|
|
||||||
"panel_background": "#fffaf3",
|
|
||||||
"overlay": "#5752791a",
|
|
||||||
"title_bar": "#00000000",
|
|
||||||
"title_bar_inactive": "#faf4ed",
|
|
||||||
"window_border": "#cecacd",
|
|
||||||
"border": "#cecacd",
|
|
||||||
"border_variant": "#dfdad9",
|
|
||||||
"border_focused": "#286983",
|
|
||||||
"border_selected": "#286983",
|
|
||||||
"border_transparent": "#00000000",
|
|
||||||
"border_disabled": "#f4ede8",
|
|
||||||
"ring": "#286983",
|
|
||||||
"text": "#575279",
|
|
||||||
"text_muted": "#797593",
|
|
||||||
"text_placeholder": "#9893a5",
|
|
||||||
"text_accent": "#907aa9",
|
|
||||||
"icon": "#575279",
|
|
||||||
"icon_muted": "#797593",
|
|
||||||
"icon_accent": "#907aa9",
|
|
||||||
"element_foreground": "#faf4ed",
|
|
||||||
"element_background": "#286983",
|
|
||||||
"element_hover": "#286983e6",
|
|
||||||
"element_active": "#245f76",
|
|
||||||
"element_selected": "#205569",
|
|
||||||
"element_disabled": "#2869834d",
|
|
||||||
"secondary_foreground": "#286983",
|
|
||||||
"secondary_background": "#f4ede8",
|
|
||||||
"secondary_hover": "#2869831a",
|
|
||||||
"secondary_active": "#dfdad9",
|
|
||||||
"secondary_selected": "#dfdad9",
|
|
||||||
"secondary_disabled": "#2869834d",
|
|
||||||
"danger_foreground": "#faf4ed",
|
|
||||||
"danger_background": "#b4637a",
|
|
||||||
"danger_hover": "#b4637ae6",
|
|
||||||
"danger_active": "#a2596e",
|
|
||||||
"danger_selected": "#904f62",
|
|
||||||
"danger_disabled": "#b4637a4d",
|
|
||||||
"warning_foreground": "#faf4ed",
|
|
||||||
"warning_background": "#ea9d34",
|
|
||||||
"warning_hover": "#ea9d34e6",
|
|
||||||
"warning_active": "#d38d2f",
|
|
||||||
"warning_selected": "#bc7d2a",
|
|
||||||
"warning_disabled": "#ea9d344d",
|
|
||||||
"ghost_element_background": "#00000000",
|
|
||||||
"ghost_element_background_alt": "#f4ede8",
|
|
||||||
"ghost_element_hover": "#5752791a",
|
|
||||||
"ghost_element_active": "#dfdad9",
|
|
||||||
"ghost_element_selected": "#dfdad9",
|
|
||||||
"ghost_element_disabled": "#5752790d",
|
|
||||||
"tab_inactive_background": "#f4ede8",
|
|
||||||
"tab_hover_background": "#dfdad9",
|
|
||||||
"tab_active_background": "#cecacd",
|
|
||||||
"scrollbar_thumb_background": "#57527933",
|
|
||||||
"scrollbar_thumb_hover_background": "#5752794d",
|
|
||||||
"scrollbar_thumb_border": "#00000000",
|
|
||||||
"scrollbar_track_background": "#00000000",
|
|
||||||
"scrollbar_track_border": "#dfdad9",
|
|
||||||
"drop_target_background": "#2869831a",
|
|
||||||
"cursor": "#56949f",
|
|
||||||
"selection": "#56949f40"
|
|
||||||
},
|
|
||||||
"dark": {
|
|
||||||
"background": "#faf4ed",
|
|
||||||
"surface_background": "#fffaf3",
|
|
||||||
"elevated_surface_background": "#f2e9e1",
|
|
||||||
"panel_background": "#fffaf3",
|
|
||||||
"overlay": "#5752791a",
|
|
||||||
"title_bar": "#00000000",
|
|
||||||
"title_bar_inactive": "#faf4ed",
|
|
||||||
"window_border": "#cecacd",
|
|
||||||
"border": "#cecacd",
|
|
||||||
"border_variant": "#dfdad9",
|
|
||||||
"border_focused": "#286983",
|
|
||||||
"border_selected": "#286983",
|
|
||||||
"border_transparent": "#00000000",
|
|
||||||
"border_disabled": "#f4ede8",
|
|
||||||
"ring": "#286983",
|
|
||||||
"text": "#575279",
|
|
||||||
"text_muted": "#797593",
|
|
||||||
"text_placeholder": "#9893a5",
|
|
||||||
"text_accent": "#907aa9",
|
|
||||||
"icon": "#575279",
|
|
||||||
"icon_muted": "#797593",
|
|
||||||
"icon_accent": "#907aa9",
|
|
||||||
"element_foreground": "#faf4ed",
|
|
||||||
"element_background": "#286983",
|
|
||||||
"element_hover": "#286983e6",
|
|
||||||
"element_active": "#245f76",
|
|
||||||
"element_selected": "#205569",
|
|
||||||
"element_disabled": "#2869834d",
|
|
||||||
"secondary_foreground": "#286983",
|
|
||||||
"secondary_background": "#f4ede8",
|
|
||||||
"secondary_hover": "#2869831a",
|
|
||||||
"secondary_active": "#dfdad9",
|
|
||||||
"secondary_selected": "#dfdad9",
|
|
||||||
"secondary_disabled": "#2869834d",
|
|
||||||
"danger_foreground": "#faf4ed",
|
|
||||||
"danger_background": "#b4637a",
|
|
||||||
"danger_hover": "#b4637ae6",
|
|
||||||
"danger_active": "#a2596e",
|
|
||||||
"danger_selected": "#904f62",
|
|
||||||
"danger_disabled": "#b4637a4d",
|
|
||||||
"warning_foreground": "#faf4ed",
|
|
||||||
"warning_background": "#ea9d34",
|
|
||||||
"warning_hover": "#ea9d34e6",
|
|
||||||
"warning_active": "#d38d2f",
|
|
||||||
"warning_selected": "#bc7d2a",
|
|
||||||
"warning_disabled": "#ea9d344d",
|
|
||||||
"ghost_element_background": "#00000000",
|
|
||||||
"ghost_element_background_alt": "#f4ede8",
|
|
||||||
"ghost_element_hover": "#5752791a",
|
|
||||||
"ghost_element_active": "#dfdad9",
|
|
||||||
"ghost_element_selected": "#dfdad9",
|
|
||||||
"ghost_element_disabled": "#5752790d",
|
|
||||||
"tab_inactive_background": "#f4ede8",
|
|
||||||
"tab_hover_background": "#dfdad9",
|
|
||||||
"tab_active_background": "#cecacd",
|
|
||||||
"scrollbar_thumb_background": "#57527933",
|
|
||||||
"scrollbar_thumb_hover_background": "#5752794d",
|
|
||||||
"scrollbar_thumb_border": "#00000000",
|
|
||||||
"scrollbar_track_background": "#00000000",
|
|
||||||
"scrollbar_track_border": "#dfdad9",
|
|
||||||
"drop_target_background": "#2869831a",
|
|
||||||
"cursor": "#56949f",
|
|
||||||
"selection": "#56949f40"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "rose-pine-moon",
|
|
||||||
"name": "Rosé Pine Moon",
|
|
||||||
"author": "Rosé Pine",
|
|
||||||
"url": "https://rosepinetheme.com/",
|
|
||||||
"light": {
|
|
||||||
"background": "#232136",
|
|
||||||
"surface_background": "#2a273f",
|
|
||||||
"elevated_surface_background": "#393552",
|
|
||||||
"panel_background": "#2a273f",
|
|
||||||
"overlay": "#e0def41a",
|
|
||||||
"title_bar": "#00000000",
|
|
||||||
"title_bar_inactive": "#232136",
|
|
||||||
"window_border": "#56526e",
|
|
||||||
"border": "#56526e",
|
|
||||||
"border_variant": "#44415a",
|
|
||||||
"border_focused": "#3e8fb0",
|
|
||||||
"border_selected": "#3e8fb0",
|
|
||||||
"border_transparent": "#00000000",
|
|
||||||
"border_disabled": "#2a283e",
|
|
||||||
"ring": "#3e8fb0",
|
|
||||||
"text": "#e0def4",
|
|
||||||
"text_muted": "#908caa",
|
|
||||||
"text_placeholder": "#6e6a86",
|
|
||||||
"text_accent": "#c4a7e7",
|
|
||||||
"icon": "#e0def4",
|
|
||||||
"icon_muted": "#908caa",
|
|
||||||
"icon_accent": "#c4a7e7",
|
|
||||||
"element_foreground": "#232136",
|
|
||||||
"element_background": "#3e8fb0",
|
|
||||||
"element_hover": "#3e8fb0e6",
|
|
||||||
"element_active": "#38809d",
|
|
||||||
"element_selected": "#32718a",
|
|
||||||
"element_disabled": "#3e8fb04d",
|
|
||||||
"secondary_foreground": "#3e8fb0",
|
|
||||||
"secondary_background": "#2a283e",
|
|
||||||
"secondary_hover": "#3e8fb01a",
|
|
||||||
"secondary_active": "#44415a",
|
|
||||||
"secondary_selected": "#44415a",
|
|
||||||
"secondary_disabled": "#3e8fb04d",
|
|
||||||
"danger_foreground": "#232136",
|
|
||||||
"danger_background": "#eb6f92",
|
|
||||||
"danger_hover": "#eb6f92e6",
|
|
||||||
"danger_active": "#d46483",
|
|
||||||
"danger_selected": "#bd5974",
|
|
||||||
"danger_disabled": "#eb6f924d",
|
|
||||||
"warning_foreground": "#232136",
|
|
||||||
"warning_background": "#f6c177",
|
|
||||||
"warning_hover": "#f6c177e6",
|
|
||||||
"warning_active": "#ddae6b",
|
|
||||||
"warning_selected": "#c49b5f",
|
|
||||||
"warning_disabled": "#f6c1774d",
|
|
||||||
"ghost_element_background": "#00000000",
|
|
||||||
"ghost_element_background_alt": "#2a283e",
|
|
||||||
"ghost_element_hover": "#e0def41a",
|
|
||||||
"ghost_element_active": "#44415a",
|
|
||||||
"ghost_element_selected": "#44415a",
|
|
||||||
"ghost_element_disabled": "#e0def40d",
|
|
||||||
"tab_inactive_background": "#2a283e",
|
|
||||||
"tab_hover_background": "#44415a",
|
|
||||||
"tab_active_background": "#56526e",
|
|
||||||
"scrollbar_thumb_background": "#e0def433",
|
|
||||||
"scrollbar_thumb_hover_background": "#e0def44d",
|
|
||||||
"scrollbar_thumb_border": "#00000000",
|
|
||||||
"scrollbar_track_background": "#00000000",
|
|
||||||
"scrollbar_track_border": "#44415a",
|
|
||||||
"drop_target_background": "#3e8fb01a",
|
|
||||||
"cursor": "#9ccfd8",
|
|
||||||
"selection": "#9ccfd840"
|
|
||||||
},
|
|
||||||
"dark": {
|
|
||||||
"background": "#232136",
|
|
||||||
"surface_background": "#2a273f",
|
|
||||||
"elevated_surface_background": "#393552",
|
|
||||||
"panel_background": "#2a273f",
|
|
||||||
"overlay": "#e0def41a",
|
|
||||||
"title_bar": "#00000000",
|
|
||||||
"title_bar_inactive": "#232136",
|
|
||||||
"window_border": "#56526e",
|
|
||||||
"border": "#56526e",
|
|
||||||
"border_variant": "#44415a",
|
|
||||||
"border_focused": "#3e8fb0",
|
|
||||||
"border_selected": "#3e8fb0",
|
|
||||||
"border_transparent": "#00000000",
|
|
||||||
"border_disabled": "#2a283e",
|
|
||||||
"ring": "#3e8fb0",
|
|
||||||
"text": "#e0def4",
|
|
||||||
"text_muted": "#908caa",
|
|
||||||
"text_placeholder": "#6e6a86",
|
|
||||||
"text_accent": "#c4a7e7",
|
|
||||||
"icon": "#e0def4",
|
|
||||||
"icon_muted": "#908caa",
|
|
||||||
"icon_accent": "#c4a7e7",
|
|
||||||
"element_foreground": "#232136",
|
|
||||||
"element_background": "#3e8fb0",
|
|
||||||
"element_hover": "#3e8fb0e6",
|
|
||||||
"element_active": "#38809d",
|
|
||||||
"element_selected": "#32718a",
|
|
||||||
"element_disabled": "#3e8fb04d",
|
|
||||||
"secondary_foreground": "#3e8fb0",
|
|
||||||
"secondary_background": "#2a283e",
|
|
||||||
"secondary_hover": "#3e8fb01a",
|
|
||||||
"secondary_active": "#44415a",
|
|
||||||
"secondary_selected": "#44415a",
|
|
||||||
"secondary_disabled": "#3e8fb04d",
|
|
||||||
"danger_foreground": "#232136",
|
|
||||||
"danger_background": "#eb6f92",
|
|
||||||
"danger_hover": "#eb6f92e6",
|
|
||||||
"danger_active": "#d46483",
|
|
||||||
"danger_selected": "#bd5974",
|
|
||||||
"danger_disabled": "#eb6f924d",
|
|
||||||
"warning_foreground": "#232136",
|
|
||||||
"warning_background": "#f6c177",
|
|
||||||
"warning_hover": "#f6c177e6",
|
|
||||||
"warning_active": "#ddae6b",
|
|
||||||
"warning_selected": "#c49b5f",
|
|
||||||
"warning_disabled": "#f6c1774d",
|
|
||||||
"ghost_element_background": "#00000000",
|
|
||||||
"ghost_element_background_alt": "#2a283e",
|
|
||||||
"ghost_element_hover": "#e0def41a",
|
|
||||||
"ghost_element_active": "#44415a",
|
|
||||||
"ghost_element_selected": "#44415a",
|
|
||||||
"ghost_element_disabled": "#e0def40d",
|
|
||||||
"tab_inactive_background": "#2a283e",
|
|
||||||
"tab_hover_background": "#44415a",
|
|
||||||
"tab_active_background": "#56526e",
|
|
||||||
"scrollbar_thumb_background": "#e0def433",
|
|
||||||
"scrollbar_thumb_hover_background": "#e0def44d",
|
|
||||||
"scrollbar_thumb_border": "#00000000",
|
|
||||||
"scrollbar_track_background": "#00000000",
|
|
||||||
"scrollbar_track_border": "#44415a",
|
|
||||||
"drop_target_background": "#3e8fb01a",
|
|
||||||
"cursor": "#9ccfd8",
|
|
||||||
"selection": "#9ccfd840"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "rose-pine",
|
|
||||||
"name": "Rosé Pine",
|
|
||||||
"author": "Rosé Pine",
|
|
||||||
"url": "https://rosepinetheme.com/",
|
|
||||||
"light": {
|
|
||||||
"background": "#191724",
|
|
||||||
"surface_background": "#1f1d2e",
|
|
||||||
"elevated_surface_background": "#26233a",
|
|
||||||
"panel_background": "#1f1d2e",
|
|
||||||
"overlay": "#e0def41a",
|
|
||||||
"title_bar": "#00000000",
|
|
||||||
"title_bar_inactive": "#191724",
|
|
||||||
"window_border": "#524f67",
|
|
||||||
"border": "#524f67",
|
|
||||||
"border_variant": "#403d52",
|
|
||||||
"border_focused": "#31748f",
|
|
||||||
"border_selected": "#31748f",
|
|
||||||
"border_transparent": "#00000000",
|
|
||||||
"border_disabled": "#21202e",
|
|
||||||
"ring": "#31748f",
|
|
||||||
"text": "#e0def4",
|
|
||||||
"text_muted": "#908caa",
|
|
||||||
"text_placeholder": "#6e6a86",
|
|
||||||
"text_accent": "#c4a7e7",
|
|
||||||
"icon": "#e0def4",
|
|
||||||
"icon_muted": "#908caa",
|
|
||||||
"icon_accent": "#c4a7e7",
|
|
||||||
"element_foreground": "#191724",
|
|
||||||
"element_background": "#31748f",
|
|
||||||
"element_hover": "#31748fe6",
|
|
||||||
"element_active": "#2c6980",
|
|
||||||
"element_selected": "#275e71",
|
|
||||||
"element_disabled": "#31748f4d",
|
|
||||||
"secondary_foreground": "#31748f",
|
|
||||||
"secondary_background": "#21202e",
|
|
||||||
"secondary_hover": "#31748f1a",
|
|
||||||
"secondary_active": "#403d52",
|
|
||||||
"secondary_selected": "#403d52",
|
|
||||||
"secondary_disabled": "#31748f4d",
|
|
||||||
"danger_foreground": "#191724",
|
|
||||||
"danger_background": "#eb6f92",
|
|
||||||
"danger_hover": "#eb6f92e6",
|
|
||||||
"danger_active": "#d46483",
|
|
||||||
"danger_selected": "#bd5974",
|
|
||||||
"danger_disabled": "#eb6f924d",
|
|
||||||
"warning_foreground": "#191724",
|
|
||||||
"warning_background": "#f6c177",
|
|
||||||
"warning_hover": "#f6c177e6",
|
|
||||||
"warning_active": "#ddae6b",
|
|
||||||
"warning_selected": "#c49b5f",
|
|
||||||
"warning_disabled": "#f6c1774d",
|
|
||||||
"ghost_element_background": "#00000000",
|
|
||||||
"ghost_element_background_alt": "#21202e",
|
|
||||||
"ghost_element_hover": "#e0def41a",
|
|
||||||
"ghost_element_active": "#403d52",
|
|
||||||
"ghost_element_selected": "#403d52",
|
|
||||||
"ghost_element_disabled": "#e0def40d",
|
|
||||||
"tab_inactive_background": "#21202e",
|
|
||||||
"tab_hover_background": "#403d52",
|
|
||||||
"tab_active_background": "#524f67",
|
|
||||||
"scrollbar_thumb_background": "#e0def433",
|
|
||||||
"scrollbar_thumb_hover_background": "#e0def44d",
|
|
||||||
"scrollbar_thumb_border": "#00000000",
|
|
||||||
"scrollbar_track_background": "#00000000",
|
|
||||||
"scrollbar_track_border": "#403d52",
|
|
||||||
"drop_target_background": "#31748f1a",
|
|
||||||
"cursor": "#9ccfd8",
|
|
||||||
"selection": "#9ccfd840"
|
|
||||||
},
|
|
||||||
"dark": {
|
|
||||||
"background": "#191724",
|
|
||||||
"surface_background": "#1f1d2e",
|
|
||||||
"elevated_surface_background": "#26233a",
|
|
||||||
"panel_background": "#1f1d2e",
|
|
||||||
"overlay": "#e0def41a",
|
|
||||||
"title_bar": "#00000000",
|
|
||||||
"title_bar_inactive": "#191724",
|
|
||||||
"window_border": "#524f67",
|
|
||||||
"border": "#524f67",
|
|
||||||
"border_variant": "#403d52",
|
|
||||||
"border_focused": "#31748f",
|
|
||||||
"border_selected": "#31748f",
|
|
||||||
"border_transparent": "#00000000",
|
|
||||||
"border_disabled": "#21202e",
|
|
||||||
"ring": "#31748f",
|
|
||||||
"text": "#e0def4",
|
|
||||||
"text_muted": "#908caa",
|
|
||||||
"text_placeholder": "#6e6a86",
|
|
||||||
"text_accent": "#c4a7e7",
|
|
||||||
"icon": "#e0def4",
|
|
||||||
"icon_muted": "#908caa",
|
|
||||||
"icon_accent": "#c4a7e7",
|
|
||||||
"element_foreground": "#191724",
|
|
||||||
"element_background": "#31748f",
|
|
||||||
"element_hover": "#31748fe6",
|
|
||||||
"element_active": "#2c6980",
|
|
||||||
"element_selected": "#275e71",
|
|
||||||
"element_disabled": "#31748f4d",
|
|
||||||
"secondary_foreground": "#31748f",
|
|
||||||
"secondary_background": "#21202e",
|
|
||||||
"secondary_hover": "#31748f1a",
|
|
||||||
"secondary_active": "#403d52",
|
|
||||||
"secondary_selected": "#403d52",
|
|
||||||
"secondary_disabled": "#31748f4d",
|
|
||||||
"danger_foreground": "#191724",
|
|
||||||
"danger_background": "#eb6f92",
|
|
||||||
"danger_hover": "#eb6f92e6",
|
|
||||||
"danger_active": "#d46483",
|
|
||||||
"danger_selected": "#bd5974",
|
|
||||||
"danger_disabled": "#eb6f924d",
|
|
||||||
"warning_foreground": "#191724",
|
|
||||||
"warning_background": "#f6c177",
|
|
||||||
"warning_hover": "#f6c177e6",
|
|
||||||
"warning_active": "#ddae6b",
|
|
||||||
"warning_selected": "#c49b5f",
|
|
||||||
"warning_disabled": "#f6c1774d",
|
|
||||||
"ghost_element_background": "#00000000",
|
|
||||||
"ghost_element_background_alt": "#21202e",
|
|
||||||
"ghost_element_hover": "#e0def41a",
|
|
||||||
"ghost_element_active": "#403d52",
|
|
||||||
"ghost_element_selected": "#403d52",
|
|
||||||
"ghost_element_disabled": "#e0def40d",
|
|
||||||
"tab_inactive_background": "#21202e",
|
|
||||||
"tab_hover_background": "#403d52",
|
|
||||||
"tab_active_background": "#524f67",
|
|
||||||
"scrollbar_thumb_background": "#e0def433",
|
|
||||||
"scrollbar_thumb_hover_background": "#e0def44d",
|
|
||||||
"scrollbar_thumb_border": "#00000000",
|
|
||||||
"scrollbar_track_background": "#00000000",
|
|
||||||
"scrollbar_track_border": "#403d52",
|
|
||||||
"drop_target_background": "#31748f1a",
|
|
||||||
"cursor": "#9ccfd8",
|
|
||||||
"selection": "#9ccfd840"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error, anyhow};
|
||||||
use gpui::http_client::{AsyncBody, HttpClient};
|
use gpui::http_client::{AsyncBody, HttpClient};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
App, AppContext, AsyncApp, BackgroundExecutor, Context, Entity, Global, Subscription, Task,
|
App, AppContext, AsyncApp, BackgroundExecutor, Context, Entity, Global, Subscription, Task,
|
||||||
@@ -11,7 +11,7 @@ use gpui::{
|
|||||||
};
|
};
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use smol::fs::File;
|
use smol::fs::File;
|
||||||
use smol::io::AsyncReadExt;
|
use smol::io::AsyncReadExt;
|
||||||
use smol::process::Command;
|
use smol::process::Command;
|
||||||
@@ -20,11 +20,11 @@ const GITHUB_API_URL: &str = "https://api.github.com";
|
|||||||
const COOP_UPDATE_EXPLANATION: &str = "COOP_UPDATE_EXPLANATION";
|
const COOP_UPDATE_EXPLANATION: &str = "COOP_UPDATE_EXPLANATION";
|
||||||
|
|
||||||
fn get_github_repo_owner() -> String {
|
fn get_github_repo_owner() -> String {
|
||||||
std::env::var("COOP_GITHUB_REPO_OWNER").unwrap_or_else(|_| "your-username".to_string())
|
std::env::var("COOP_GITHUB_REPO_OWNER").unwrap_or_else(|_| "reyakov".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_github_repo_name() -> String {
|
fn get_github_repo_name() -> String {
|
||||||
std::env::var("COOP_GITHUB_REPO_NAME").unwrap_or_else(|_| "your-repo".to_string())
|
std::env::var("COOP_GITHUB_REPO_NAME").unwrap_or_else(|_| "coop".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_flatpak_installation() -> bool {
|
fn is_flatpak_installation() -> bool {
|
||||||
|
|||||||
@@ -1,20 +1,23 @@
|
|||||||
use std::cmp::Reverse;
|
use std::cmp::Reverse;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error, anyhow};
|
||||||
use common::EventUtils;
|
use common::EventExt;
|
||||||
use fuzzy_matcher::skim::SkimMatcherV2;
|
use device::{DeviceEvent, DeviceRegistry};
|
||||||
use fuzzy_matcher::FuzzyMatcher;
|
use fuzzy_matcher::FuzzyMatcher;
|
||||||
|
use fuzzy_matcher::skim::SkimMatcherV2;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
App, AppContext, Context, Entity, EventEmitter, Global, Subscription, Task, WeakEntity, Window,
|
App, AppContext, Context, Entity, EventEmitter, Global, SharedString, Subscription, Task,
|
||||||
|
WeakEntity, Window,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use state::{NostrRegistry, RelayState, DEVICE_GIFTWRAP, TIMEOUT, USER_GIFTWRAP};
|
use smol::lock::RwLock;
|
||||||
|
use state::{CoopSigner, DEVICE_GIFTWRAP, NostrRegistry, StateEvent, TIMEOUT, USER_GIFTWRAP};
|
||||||
|
|
||||||
mod message;
|
mod message;
|
||||||
mod room;
|
mod room;
|
||||||
@@ -39,6 +42,8 @@ pub enum ChatEvent {
|
|||||||
CloseRoom(u64),
|
CloseRoom(u64),
|
||||||
/// An event to notify UI about a new chat request
|
/// An event to notify UI about a new chat request
|
||||||
Ping,
|
Ping,
|
||||||
|
/// An error occurred
|
||||||
|
Error(SharedString),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Channel signal.
|
/// Channel signal.
|
||||||
@@ -48,25 +53,62 @@ enum Signal {
|
|||||||
Message(NewMessage),
|
Message(NewMessage),
|
||||||
/// Eose received from relay pool
|
/// Eose received from relay pool
|
||||||
Eose,
|
Eose,
|
||||||
|
/// An error occurred
|
||||||
|
Error(FailedMessage),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Signal {
|
||||||
|
pub fn message(gift_wrap: EventId, rumor: UnsignedEvent) -> Self {
|
||||||
|
Self::Message(NewMessage::new(gift_wrap, rumor))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn eose() -> Self {
|
||||||
|
Self::Eose
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn error<T>(event: &Event, reason: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<SharedString>,
|
||||||
|
{
|
||||||
|
Self::Error(FailedMessage::new(event, reason))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Dekey = bool;
|
||||||
|
type GiftWrapId = EventId;
|
||||||
|
|
||||||
/// Chat Registry
|
/// Chat Registry
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ChatRegistry {
|
pub struct ChatRegistry {
|
||||||
/// Relay state for messaging relay list
|
/// Whether the chat registry is currently initializing.
|
||||||
messaging_relay_list: Entity<RelayState>,
|
pub initializing: bool,
|
||||||
|
|
||||||
/// Collection of all chat rooms
|
/// Chat rooms
|
||||||
rooms: Vec<Entity<Room>>,
|
rooms: Vec<Entity<Room>>,
|
||||||
|
|
||||||
|
/// Events that failed to unwrap for any reason
|
||||||
|
trashes: Entity<BTreeSet<FailedMessage>>,
|
||||||
|
|
||||||
|
/// Tracking events seen on which relays in the current session
|
||||||
|
seens: Arc<RwLock<HashMap<EventId, HashSet<RelayUrl>>>>,
|
||||||
|
|
||||||
|
/// Mapping of unwrapped event ids to their gift wrap event ids
|
||||||
|
event_map: Arc<RwLock<HashMap<EventId, (GiftWrapId, Dekey)>>>,
|
||||||
|
|
||||||
/// Tracking the status of unwrapping gift wrap events.
|
/// Tracking the status of unwrapping gift wrap events.
|
||||||
tracking_flag: Arc<AtomicBool>,
|
tracking_flag: Arc<AtomicBool>,
|
||||||
|
|
||||||
|
/// Channel for sending signals to the UI.
|
||||||
|
signal_tx: flume::Sender<Signal>,
|
||||||
|
|
||||||
|
/// Channel for receiving signals from the UI.
|
||||||
|
signal_rx: flume::Receiver<Signal>,
|
||||||
|
|
||||||
/// Async tasks
|
/// Async tasks
|
||||||
tasks: SmallVec<[Task<Result<(), Error>>; 2]>,
|
tasks: SmallVec<[Task<Result<(), Error>>; 2]>,
|
||||||
|
|
||||||
/// Subscriptions
|
/// Subscriptions
|
||||||
_subscriptions: SmallVec<[Subscription; 1]>,
|
_subscriptions: SmallVec<[Subscription; 2]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter<ChatEvent> for ChatRegistry {}
|
impl EventEmitter<ChatEvent> for ChatRegistry {}
|
||||||
@@ -84,50 +126,69 @@ impl ChatRegistry {
|
|||||||
|
|
||||||
/// Create a new chat registry instance
|
/// Create a new chat registry instance
|
||||||
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let messaging_relay_list = cx.new(|_| RelayState::default());
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let device = DeviceRegistry::global(cx);
|
||||||
|
|
||||||
|
let (tx, rx) = flume::unbounded::<Signal>();
|
||||||
let mut subscriptions = smallvec![];
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
// Observe the nip65 state and load chat rooms on every state change
|
// Subscribe to the signer event
|
||||||
cx.observe(&nostr, |this, state, cx| {
|
cx.subscribe_in(&nostr, window, |this, state, event, window, cx| {
|
||||||
match state.read(cx).relay_list_state() {
|
if event == &StateEvent::SignerSet {
|
||||||
RelayState::Idle => {
|
this.reset(cx);
|
||||||
this.reset(cx);
|
this.get_contact_list(cx);
|
||||||
}
|
this.get_rooms(cx);
|
||||||
RelayState::Configured => {
|
|
||||||
this.ensure_messaging_relays(cx);
|
let signer = state.read(cx).signer();
|
||||||
}
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
_ => {}
|
let user_signer = signer.get().await;
|
||||||
}
|
this.update(cx, |this, cx| {
|
||||||
|
this.get_messages(user_signer, cx);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
// Observe the nip17 state and load chat rooms on every state change
|
// Subscribe to the device event
|
||||||
cx.observe(&messaging_relay_list, |this, state, cx| {
|
cx.subscribe_in(&device, window, |_this, _s, event, window, cx| {
|
||||||
match state.read(cx) {
|
if event == &DeviceEvent::Set {
|
||||||
RelayState::Configured => {
|
let nostr = NostrRegistry::global(cx);
|
||||||
this.get_messages(cx);
|
let signer = nostr.read(cx).signer();
|
||||||
}
|
|
||||||
_ => {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
this.get_rooms(cx);
|
if let Some(device_signer) = signer.get_encryption_signer().await {
|
||||||
}
|
this.update(cx, |this, cx| {
|
||||||
}
|
this.get_messages(device_signer, cx);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Run at the end of current cycle
|
// Run at the end of the current cycle
|
||||||
cx.defer_in(window, |this, _window, cx| {
|
cx.defer_in(window, |this, _window, cx| {
|
||||||
|
this.get_rooms(cx);
|
||||||
this.handle_notifications(cx);
|
this.handle_notifications(cx);
|
||||||
this.tracking(cx);
|
this.tracking(cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
messaging_relay_list,
|
initializing: true,
|
||||||
rooms: vec![],
|
rooms: vec![],
|
||||||
|
trashes: cx.new(|_| BTreeSet::default()),
|
||||||
|
seens: Arc::new(RwLock::new(HashMap::default())),
|
||||||
|
event_map: Arc::new(RwLock::new(HashMap::default())),
|
||||||
tracking_flag: Arc::new(AtomicBool::new(false)),
|
tracking_flag: Arc::new(AtomicBool::new(false)),
|
||||||
|
signal_rx: rx,
|
||||||
|
signal_tx: tx,
|
||||||
tasks: smallvec![],
|
tasks: smallvec![],
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
}
|
}
|
||||||
@@ -139,60 +200,85 @@ impl ChatRegistry {
|
|||||||
let client = nostr.read(cx).client();
|
let client = nostr.read(cx).client();
|
||||||
let signer = nostr.read(cx).signer();
|
let signer = nostr.read(cx).signer();
|
||||||
let status = self.tracking_flag.clone();
|
let status = self.tracking_flag.clone();
|
||||||
|
let seens = self.seens.clone();
|
||||||
|
let event_map = self.event_map.clone();
|
||||||
|
let trashes = self.trashes.downgrade();
|
||||||
|
|
||||||
let initialized_at = Timestamp::now();
|
let initialized_at = Timestamp::now();
|
||||||
let sub_id1 = SubscriptionId::new(DEVICE_GIFTWRAP);
|
let sub_id1 = SubscriptionId::new(DEVICE_GIFTWRAP);
|
||||||
let sub_id2 = SubscriptionId::new(USER_GIFTWRAP);
|
let sub_id2 = SubscriptionId::new(USER_GIFTWRAP);
|
||||||
|
|
||||||
// Channel for communication between nostr and gpui
|
// Channel for communication between nostr and gpui
|
||||||
let (tx, rx) = flume::bounded::<Signal>(1024);
|
let tx = self.signal_tx.clone();
|
||||||
|
let rx = self.signal_rx.clone();
|
||||||
|
|
||||||
self.tasks.push(cx.background_spawn(async move {
|
self.tasks.push(cx.background_spawn(async move {
|
||||||
let device_signer = signer.get_encryption_signer().await;
|
|
||||||
let mut notifications = client.notifications();
|
let mut notifications = client.notifications();
|
||||||
let mut processed_events = HashSet::new();
|
let mut processed_events = HashSet::new();
|
||||||
|
|
||||||
while let Some(notification) = notifications.next().await {
|
while let Some(notification) = notifications.next().await {
|
||||||
let ClientNotification::Message { message, .. } = notification else {
|
let ClientNotification::Message { message, relay_url } = notification else {
|
||||||
// Skip non-message notifications
|
// Skip non-message notifications
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
match message {
|
match *message {
|
||||||
RelayMessage::Event { event, .. } => {
|
RelayMessage::Event {
|
||||||
|
event,
|
||||||
|
subscription_id,
|
||||||
|
} => {
|
||||||
|
// Keep track of which relays have seen this event
|
||||||
|
{
|
||||||
|
let mut seens = seens.write().await;
|
||||||
|
seens.entry(event.id).or_default().insert(relay_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-duplicate events by their ID
|
||||||
if !processed_events.insert(event.id) {
|
if !processed_events.insert(event.id) {
|
||||||
// Skip if the event has already been processed
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip non-gift wrap events
|
||||||
if event.kind != Kind::GiftWrap {
|
if event.kind != Kind::GiftWrap {
|
||||||
// Skip non-gift wrap events
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
log::info!("Received gift wrap event: {:?}", event);
|
|
||||||
|
|
||||||
// Extract the rumor from the gift wrap event
|
// Extract the rumor from the gift wrap event
|
||||||
match Self::extract_rumor(&client, &device_signer, event.as_ref()).await {
|
match extract_rumor(&client, &signer, event.as_ref()).await {
|
||||||
Ok(rumor) => match rumor.created_at >= initialized_at {
|
Ok(rumor) => {
|
||||||
true => {
|
// Map the rumor id to the gift wrap event id for later lookup
|
||||||
let new_message = NewMessage::new(event.id, rumor);
|
{
|
||||||
let signal = Signal::Message(new_message);
|
let mut event_map = event_map.write().await;
|
||||||
|
let dekey = subscription_id.as_ref() == &sub_id1;
|
||||||
|
event_map.insert(rumor.id.unwrap(), (event.id, dekey));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the rumor has a recipient
|
||||||
|
if rumor.tags.is_empty() {
|
||||||
|
let signal =
|
||||||
|
Signal::error(event.as_ref(), "Recipient is missing");
|
||||||
tx.send_async(signal).await?;
|
tx.send_async(signal).await?;
|
||||||
}
|
}
|
||||||
false => {
|
|
||||||
|
// Check if the rumor was created after the chat was initialized (for detecting new messages)
|
||||||
|
if rumor.created_at >= initialized_at {
|
||||||
|
let signal = Signal::message(event.id, rumor);
|
||||||
|
tx.send_async(signal).await?;
|
||||||
|
} else {
|
||||||
|
// Mark the chat still processing new messages
|
||||||
status.store(true, Ordering::Release);
|
status.store(true, Ordering::Release);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("Failed to unwrap the gift wrap event: {e}");
|
let reason = format!("Failed to extract rumor: {e}");
|
||||||
|
let signal = Signal::error(event.as_ref(), reason);
|
||||||
|
tx.send_async(signal).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RelayMessage::EndOfStoredEvents(id) => {
|
RelayMessage::EndOfStoredEvents(id) => {
|
||||||
if id.as_ref() == &sub_id1 || id.as_ref() == &sub_id2 {
|
if id.as_ref() == &sub_id1 || id.as_ref() == &sub_id2 {
|
||||||
tx.send_async(Signal::Eose).await?;
|
tx.send_async(Signal::eose()).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -215,6 +301,12 @@ impl ChatRegistry {
|
|||||||
this.get_rooms(cx);
|
this.get_rooms(cx);
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
Signal::Error(trash) => {
|
||||||
|
trashes.update(cx, |this, cx| {
|
||||||
|
this.insert(trash);
|
||||||
|
cx.notify();
|
||||||
|
})?;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,48 +317,87 @@ impl ChatRegistry {
|
|||||||
/// Tracking the status of unwrapping gift wrap events.
|
/// Tracking the status of unwrapping gift wrap events.
|
||||||
fn tracking(&mut self, cx: &mut Context<Self>) {
|
fn tracking(&mut self, cx: &mut Context<Self>) {
|
||||||
let status = self.tracking_flag.clone();
|
let status = self.tracking_flag.clone();
|
||||||
|
let tx = self.signal_tx.clone();
|
||||||
|
|
||||||
self.tasks.push(cx.background_spawn(async move {
|
self.tasks.push(cx.background_spawn(async move {
|
||||||
let loop_duration = Duration::from_secs(10);
|
let loop_duration = Duration::from_secs(15);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if status.load(Ordering::Acquire) {
|
if status.load(Ordering::Acquire) {
|
||||||
_ = status.compare_exchange(true, false, Ordering::Release, Ordering::Relaxed);
|
_ = status.compare_exchange(true, false, Ordering::Release, Ordering::Relaxed);
|
||||||
|
_ = tx.send_async(Signal::Eose).await;
|
||||||
|
} else {
|
||||||
|
_ = tx.send_async(Signal::Eose).await;
|
||||||
}
|
}
|
||||||
smol::Timer::after(loop_duration).await;
|
smol::Timer::after(loop_duration).await;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_messaging_relays(&mut self, cx: &mut Context<Self>) {
|
/// Get contact list from relays
|
||||||
let state = self.messaging_relay_list.downgrade();
|
fn get_contact_list(&mut self, cx: &mut Context<Self>) {
|
||||||
let task = self.verify_relays(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let client = nostr.read(cx).client();
|
||||||
|
let signer = nostr.read(cx).signer();
|
||||||
|
|
||||||
self.tasks.push(cx.spawn(async move |_this, cx| {
|
let Some(public_key) = signer.public_key() else {
|
||||||
let result = task.await?;
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
// Update state
|
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
||||||
state.update(cx, |this, cx| {
|
let id = SubscriptionId::new("contact-list");
|
||||||
*this = result;
|
let opts = SubscribeAutoCloseOptions::default()
|
||||||
cx.notify();
|
.exit_policy(ReqExitPolicy::ExitOnEOSE)
|
||||||
})?;
|
.timeout(Some(Duration::from_secs(TIMEOUT)));
|
||||||
|
|
||||||
|
// Construct filter for inbox relays
|
||||||
|
let filter = Filter::new()
|
||||||
|
.kind(Kind::ContactList)
|
||||||
|
.author(public_key)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
// Subscribe
|
||||||
|
client.subscribe(filter).close_on(opts).with_id(id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
|
||||||
|
self.tasks.push(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get all messages for the provided signer
|
||||||
|
fn get_messages<T>(&mut self, signer: T, cx: &mut Context<Self>)
|
||||||
|
where
|
||||||
|
T: NostrSigner + 'static,
|
||||||
|
{
|
||||||
|
let task = self.subscribe_gift_wrap_events(signer, cx);
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn(async move |this, cx| {
|
||||||
|
match task.await {
|
||||||
|
Ok(_) => {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.set_initializing(false, cx);
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
this.update(cx, |_this, cx| {
|
||||||
|
cx.emit(ChatEvent::Error(SharedString::from(e.to_string())));
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify messaging relay list for current user
|
// Get messaging relay list for current user
|
||||||
fn verify_relays(&mut self, cx: &mut Context<Self>) -> Task<Result<RelayState, Error>> {
|
fn get_messaging_relays(&self, cx: &App) -> Task<Result<Vec<RelayUrl>, Error>> {
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
let client = nostr.read(cx).client();
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
let signer = nostr.read(cx).signer();
|
let signer = nostr.read(cx).signer();
|
||||||
let public_key = signer.public_key().unwrap();
|
|
||||||
|
|
||||||
let write_relays = nostr.read(cx).write_relays(&public_key, cx);
|
|
||||||
|
|
||||||
cx.background_spawn(async move {
|
cx.background_spawn(async move {
|
||||||
let urls = write_relays.await;
|
let public_key = signer.get_public_key().await?;
|
||||||
|
let id = SubscriptionId::new("inbox-relay");
|
||||||
|
|
||||||
// Construct filter for inbox relays
|
// Construct filter for inbox relays
|
||||||
let filter = Filter::new()
|
let filter = Filter::new()
|
||||||
@@ -274,63 +405,49 @@ impl ChatRegistry {
|
|||||||
.author(public_key)
|
.author(public_key)
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
// Construct target for subscription
|
|
||||||
let target: HashMap<&RelayUrl, Filter> =
|
|
||||||
urls.iter().map(|relay| (relay, filter.clone())).collect();
|
|
||||||
|
|
||||||
// Stream events from user's write relays
|
// Stream events from user's write relays
|
||||||
let mut stream = client
|
let mut stream = client
|
||||||
.stream_events(target)
|
.stream_events(filter)
|
||||||
|
.with_id(id)
|
||||||
.timeout(Duration::from_secs(TIMEOUT))
|
.timeout(Duration::from_secs(TIMEOUT))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
while let Some((_url, res)) = stream.next().await {
|
while let Some((_url, res)) = stream.next().await {
|
||||||
match res {
|
if let Ok(event) = res {
|
||||||
Ok(event) => {
|
let urls: Vec<RelayUrl> = nip17::extract_owned_relay_list(event).collect();
|
||||||
log::info!("Received relay list event: {event:?}");
|
return Ok(urls);
|
||||||
return Ok(RelayState::Configured);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
log::error!("Failed to receive relay list event: {e}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RelayState::NotConfigured)
|
Err(anyhow!("Messaging Relays not found"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all messages for current user
|
/// Continuously get gift wrap events for the signer
|
||||||
fn get_messages(&mut self, cx: &mut Context<Self>) {
|
fn subscribe_gift_wrap_events<T>(&self, signer: T, cx: &App) -> Task<Result<(), Error>>
|
||||||
let task = self.subscribe_to_giftwrap_events(cx);
|
where
|
||||||
|
T: NostrSigner + 'static,
|
||||||
self.tasks.push(cx.spawn(async move |_this, _cx| {
|
{
|
||||||
task.await?;
|
|
||||||
|
|
||||||
// Update state
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Continuously get gift wrap events for the current user in their messaging relays
|
|
||||||
fn subscribe_to_giftwrap_events(&mut self, cx: &mut Context<Self>) -> Task<Result<(), Error>> {
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
let client = nostr.read(cx).client();
|
let client = nostr.read(cx).client();
|
||||||
|
let urls = self.get_messaging_relays(cx);
|
||||||
let signer = nostr.read(cx).signer();
|
|
||||||
let public_key = signer.public_key().unwrap();
|
|
||||||
|
|
||||||
let messaging_relays = nostr.read(cx).messaging_relays(&public_key, cx);
|
|
||||||
|
|
||||||
cx.background_spawn(async move {
|
cx.background_spawn(async move {
|
||||||
let urls = messaging_relays.await;
|
let urls = urls.await?;
|
||||||
|
let public_key = signer.get_public_key().await?;
|
||||||
let filter = Filter::new().kind(Kind::GiftWrap).pubkey(public_key);
|
let filter = Filter::new().kind(Kind::GiftWrap).pubkey(public_key);
|
||||||
let id = SubscriptionId::new(USER_GIFTWRAP);
|
let id = SubscriptionId::new(format!("{}-msg", public_key.to_hex()));
|
||||||
|
|
||||||
|
// Ensure relay connections
|
||||||
|
for url in urls.iter() {
|
||||||
|
client.add_relay(url).and_connect().await?;
|
||||||
|
}
|
||||||
|
|
||||||
// Construct target for subscription
|
// Construct target for subscription
|
||||||
let target: HashMap<&RelayUrl, Filter> =
|
let target: HashMap<RelayUrl, Filter> = urls
|
||||||
urls.iter().map(|relay| (relay, filter.clone())).collect();
|
.into_iter()
|
||||||
|
.map(|relay| (relay, filter.clone()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
let output = client.subscribe(target).with_id(id).await?;
|
let output = client.subscribe(target).with_id(id).await?;
|
||||||
|
|
||||||
@@ -343,9 +460,35 @@ impl ChatRegistry {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the relay state
|
/// Refresh the chat registry, fetching messages and contact list from relays.
|
||||||
pub fn relay_state(&self, cx: &App) -> RelayState {
|
pub fn refresh(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
self.messaging_relay_list.read(cx).clone()
|
self.reset(cx);
|
||||||
|
self.get_contact_list(cx);
|
||||||
|
self.get_rooms(cx);
|
||||||
|
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let signer = nostr.read(cx).signer();
|
||||||
|
|
||||||
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
|
let user_signer = signer.get().await;
|
||||||
|
let device_signer = signer.get_encryption_signer().await;
|
||||||
|
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.get_messages(user_signer, cx);
|
||||||
|
|
||||||
|
if let Some(device_signer) = device_signer {
|
||||||
|
this.get_messages(device_signer, cx);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the initializing status of the chat registry
|
||||||
|
fn set_initializing(&mut self, initializing: bool, cx: &mut Context<Self>) {
|
||||||
|
self.initializing = initializing;
|
||||||
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the loading status of the chat registry
|
/// Get the loading status of the chat registry
|
||||||
@@ -378,6 +521,51 @@ impl ChatRegistry {
|
|||||||
.count()
|
.count()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Count the number of messages seen by a given relay.
|
||||||
|
pub fn count_messages(&self, relay_url: &RelayUrl) -> usize {
|
||||||
|
self.seens
|
||||||
|
.read_blocking()
|
||||||
|
.values()
|
||||||
|
.filter(|seen| seen.contains(relay_url))
|
||||||
|
.count()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Count the number of trash messages.
|
||||||
|
pub fn count_trash_messages(&self, cx: &App) -> usize {
|
||||||
|
self.trashes.read(cx).len()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the trash messages entity.
|
||||||
|
pub fn trashes(&self) -> Entity<BTreeSet<FailedMessage>> {
|
||||||
|
self.trashes.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the relays that have seen a given rumor id.
|
||||||
|
pub fn rumor_seen_on(&self, id: &EventId) -> Option<HashSet<RelayUrl>> {
|
||||||
|
self.event_map
|
||||||
|
.read_blocking()
|
||||||
|
.get(id)
|
||||||
|
.map(|(id, _dekey)| self.seen_on(id))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the relays that have seen a given gift wrap id.
|
||||||
|
pub fn seen_on(&self, id: &EventId) -> HashSet<RelayUrl> {
|
||||||
|
self.seens
|
||||||
|
.read_blocking()
|
||||||
|
.get(id)
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if a given rumor was encrypted by the dekey.
|
||||||
|
pub fn encrypted_by_dekey(&self, id: &EventId) -> bool {
|
||||||
|
self.event_map
|
||||||
|
.read_blocking()
|
||||||
|
.get(id)
|
||||||
|
.map(|(_, dekey)| *dekey)
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
/// Add a new room to the start of list.
|
/// Add a new room to the start of list.
|
||||||
pub fn add_room<I>(&mut self, room: I, cx: &mut Context<Self>)
|
pub fn add_room<I>(&mut self, room: I, cx: &mut Context<Self>)
|
||||||
where
|
where
|
||||||
@@ -455,7 +643,12 @@ impl ChatRegistry {
|
|||||||
|
|
||||||
/// Reset the registry.
|
/// Reset the registry.
|
||||||
pub fn reset(&mut self, cx: &mut Context<Self>) {
|
pub fn reset(&mut self, cx: &mut Context<Self>) {
|
||||||
|
self.initializing = true;
|
||||||
self.rooms.clear();
|
self.rooms.clear();
|
||||||
|
self.trashes.update(cx, |this, cx| {
|
||||||
|
this.clear();
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,16 +684,21 @@ impl ChatRegistry {
|
|||||||
pub fn get_rooms(&mut self, cx: &mut Context<Self>) {
|
pub fn get_rooms(&mut self, cx: &mut Context<Self>) {
|
||||||
let task = self.get_rooms_from_database(cx);
|
let task = self.get_rooms_from_database(cx);
|
||||||
|
|
||||||
cx.spawn(async move |this, cx| {
|
self.tasks.push(cx.spawn(async move |this, cx| {
|
||||||
let rooms = task.await.ok()?;
|
match task.await {
|
||||||
|
Ok(rooms) => {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.extend_rooms(rooms, cx);
|
||||||
|
this.sort(cx);
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to load rooms: {}", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.update(cx, move |this, cx| {
|
Ok(())
|
||||||
this.extend_rooms(rooms, cx);
|
}));
|
||||||
this.sort(cx);
|
|
||||||
})
|
|
||||||
.ok()
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a task to load rooms from the database
|
/// Create a task to load rooms from the database
|
||||||
@@ -513,7 +711,11 @@ impl ChatRegistry {
|
|||||||
let public_key = signer.get_public_key().await?;
|
let public_key = signer.get_public_key().await?;
|
||||||
|
|
||||||
// Get contacts
|
// Get contacts
|
||||||
let contacts = client.database().contacts_public_keys(public_key).await?;
|
let contacts = client
|
||||||
|
.database()
|
||||||
|
.contacts_public_keys(public_key)
|
||||||
|
.await
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
// Construct authored filter
|
// Construct authored filter
|
||||||
let authored_filter = Filter::new()
|
let authored_filter = Filter::new()
|
||||||
@@ -540,10 +742,10 @@ impl ChatRegistry {
|
|||||||
|
|
||||||
// Process each event and group by room hash
|
// Process each event and group by room hash
|
||||||
for raw in events.into_iter() {
|
for raw in events.into_iter() {
|
||||||
if let Ok(rumor) = UnsignedEvent::from_json(&raw.content) {
|
if let Ok(rumor) = UnsignedEvent::from_json(&raw.content)
|
||||||
if rumor.tags.public_keys().peekable().peek().is_some() {
|
&& rumor.tags.public_keys().peekable().peek().is_some()
|
||||||
grouped.entry(rumor.uniq_id()).or_default().push(rumor);
|
{
|
||||||
}
|
grouped.entry(rumor.uniq_id()).or_default().push(rumor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,11 +785,21 @@ impl ChatRegistry {
|
|||||||
/// If the room doesn't exist, it will be created.
|
/// If the room doesn't exist, it will be created.
|
||||||
/// Updates room ordering based on the most recent messages.
|
/// Updates room ordering based on the most recent messages.
|
||||||
pub fn new_message(&mut self, message: NewMessage, cx: &mut Context<Self>) {
|
pub fn new_message(&mut self, message: NewMessage, cx: &mut Context<Self>) {
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let signer = nostr.read(cx).signer();
|
||||||
|
|
||||||
match self.rooms.iter().find(|e| e.read(cx).id == message.room) {
|
match self.rooms.iter().find(|e| e.read(cx).id == message.room) {
|
||||||
Some(room) => {
|
Some(room) => {
|
||||||
room.update(cx, |this, cx| {
|
room.update(cx, |this, cx| {
|
||||||
|
if this.kind == RoomKind::Request
|
||||||
|
&& let Some(public_key) = signer.public_key()
|
||||||
|
&& message.rumor.pubkey == public_key
|
||||||
|
{
|
||||||
|
this.set_ongoing(cx);
|
||||||
|
}
|
||||||
this.push_message(message, cx);
|
this.push_message(message, cx);
|
||||||
});
|
});
|
||||||
|
self.sort(cx);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// Push the new room to the front of the list
|
// Push the new room to the front of the list
|
||||||
@@ -597,158 +809,155 @@ impl ChatRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Trigger a refresh of the opened chat rooms by their IDs
|
/// Trigger a refresh of the opened chat rooms by their IDs
|
||||||
pub fn refresh_rooms(&mut self, ids: Option<Vec<u64>>, cx: &mut Context<Self>) {
|
pub fn refresh_rooms(&mut self, ids: &[u64], cx: &mut Context<Self>) {
|
||||||
if let Some(ids) = ids {
|
for room in self.rooms.iter() {
|
||||||
for room in self.rooms.iter() {
|
if ids.contains(&room.read(cx).id) {
|
||||||
if ids.contains(&room.read(cx).id) {
|
room.update(cx, |this, cx| {
|
||||||
room.update(cx, |this, cx| {
|
this.emit_refresh(cx);
|
||||||
this.emit_refresh(cx);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Unwraps a gift-wrapped event and processes its contents.
|
/// Unwraps a gift-wrapped event and processes its contents.
|
||||||
async fn extract_rumor(
|
async fn extract_rumor(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
device_signer: &Option<Arc<dyn NostrSigner>>,
|
signer: &Arc<CoopSigner>,
|
||||||
gift_wrap: &Event,
|
gift_wrap: &Event,
|
||||||
) -> Result<UnsignedEvent, Error> {
|
) -> Result<UnsignedEvent, Error> {
|
||||||
// Try to get cached rumor first
|
// Try to get cached rumor first
|
||||||
if let Ok(event) = Self::get_rumor(client, gift_wrap.id).await {
|
if let Ok(rumor) = get_rumor(client, gift_wrap.id).await {
|
||||||
return Ok(event);
|
return Ok(rumor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to unwrap with the available signer
|
||||||
|
let unwrapped = try_unwrap(signer, gift_wrap).await?;
|
||||||
|
let mut rumor = unwrapped.rumor;
|
||||||
|
|
||||||
|
// Generate event id for the rumor if it doesn't have one
|
||||||
|
rumor.ensure_id();
|
||||||
|
|
||||||
|
// Cache the rumor
|
||||||
|
if let Err(e) = set_rumor(client, gift_wrap.id, &rumor).await {
|
||||||
|
log::error!("Failed to cache rumor: {e:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(rumor)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper method to try unwrapping with different signers
|
||||||
|
async fn try_unwrap(signer: &Arc<CoopSigner>, gift_wrap: &Event) -> Result<UnwrappedGift, Error> {
|
||||||
|
// Try with the device signer first
|
||||||
|
if let Some(signer) = signer.get_encryption_signer().await {
|
||||||
|
log::info!("trying with encryption key");
|
||||||
|
if let Ok(unwrapped) = try_unwrap_with(gift_wrap, &signer).await {
|
||||||
|
return Ok(unwrapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to unwrap with the available signer
|
|
||||||
let unwrapped = Self::try_unwrap(client, device_signer, gift_wrap).await?;
|
|
||||||
let mut rumor_unsigned = unwrapped.rumor;
|
|
||||||
|
|
||||||
// Generate event id for the rumor if it doesn't have one
|
|
||||||
rumor_unsigned.ensure_id();
|
|
||||||
|
|
||||||
// Cache the rumor
|
|
||||||
Self::set_rumor(client, gift_wrap.id, &rumor_unsigned).await?;
|
|
||||||
|
|
||||||
Ok(rumor_unsigned)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper method to try unwrapping with different signers
|
// Fallback to the user's signer
|
||||||
async fn try_unwrap(
|
let user_signer = signer.get().await;
|
||||||
client: &Client,
|
let unwrapped = try_unwrap_with(gift_wrap, &user_signer).await?;
|
||||||
device_signer: &Option<Arc<dyn NostrSigner>>,
|
|
||||||
gift_wrap: &Event,
|
|
||||||
) -> Result<UnwrappedGift, Error> {
|
|
||||||
// Try with the device signer first
|
|
||||||
if let Some(signer) = device_signer {
|
|
||||||
if let Ok(unwrapped) = Self::try_unwrap_with(gift_wrap, signer).await {
|
|
||||||
return Ok(unwrapped);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Try with the user's signer
|
Ok(unwrapped)
|
||||||
let user_signer = client.signer().context("Signer not found")?;
|
}
|
||||||
let unwrapped = UnwrappedGift::from_gift_wrap(user_signer, gift_wrap).await?;
|
|
||||||
|
|
||||||
Ok(unwrapped)
|
/// Attempts to unwrap a gift wrap event with a given signer.
|
||||||
}
|
async fn try_unwrap_with<T>(gift_wrap: &Event, signer: &T) -> Result<UnwrappedGift, Error>
|
||||||
|
where
|
||||||
|
T: NostrSigner + 'static,
|
||||||
|
{
|
||||||
|
// Get the sealed event
|
||||||
|
let seal = signer
|
||||||
|
.nip44_decrypt(&gift_wrap.pubkey, &gift_wrap.content)
|
||||||
|
.await?;
|
||||||
|
|
||||||
/// Attempts to unwrap a gift wrap event with a given signer.
|
// Verify the sealed event
|
||||||
async fn try_unwrap_with(
|
let seal: Event = Event::from_json(seal)?;
|
||||||
gift_wrap: &Event,
|
seal.verify_with_ctx(&SECP256K1)?;
|
||||||
signer: &Arc<dyn NostrSigner>,
|
|
||||||
) -> Result<UnwrappedGift, Error> {
|
|
||||||
// Get the sealed event
|
|
||||||
let seal = signer
|
|
||||||
.nip44_decrypt(&gift_wrap.pubkey, &gift_wrap.content)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// Verify the sealed event
|
// Get the rumor event
|
||||||
let seal: Event = Event::from_json(seal)?;
|
let rumor = signer.nip44_decrypt(&seal.pubkey, &seal.content).await?;
|
||||||
seal.verify_with_ctx(&SECP256K1)?;
|
let rumor = UnsignedEvent::from_json(rumor)?;
|
||||||
|
|
||||||
// Get the rumor event
|
Ok(UnwrappedGift {
|
||||||
let rumor = signer.nip44_decrypt(&seal.pubkey, &seal.content).await?;
|
sender: seal.pubkey,
|
||||||
let rumor = UnsignedEvent::from_json(rumor)?;
|
rumor,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
Ok(UnwrappedGift {
|
/// Stores an unwrapped event in local database with reference to original
|
||||||
sender: seal.pubkey,
|
async fn set_rumor(client: &Client, id: EventId, rumor: &UnsignedEvent) -> Result<(), Error> {
|
||||||
rumor,
|
let rumor_id = rumor.id.context("Rumor is missing an event id")?;
|
||||||
})
|
let author = rumor.pubkey;
|
||||||
}
|
let conversation = conversation_id(rumor);
|
||||||
|
|
||||||
/// Stores an unwrapped event in local database with reference to original
|
let mut tags = rumor.tags.clone().to_vec();
|
||||||
async fn set_rumor(client: &Client, id: EventId, rumor: &UnsignedEvent) -> Result<(), Error> {
|
|
||||||
let rumor_id = rumor.id.context("Rumor is missing an event id")?;
|
|
||||||
let author = rumor.pubkey;
|
|
||||||
let conversation = Self::conversation_id(rumor);
|
|
||||||
|
|
||||||
let mut tags = rumor.tags.clone().to_vec();
|
// Add a unique identifier
|
||||||
|
tags.push(Tag::identifier(id));
|
||||||
|
|
||||||
// Add a unique identifier
|
// Add a reference to the rumor's author
|
||||||
tags.push(Tag::identifier(id));
|
tags.push(Tag::custom(
|
||||||
|
TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::A)),
|
||||||
|
[author],
|
||||||
|
));
|
||||||
|
|
||||||
// Add a reference to the rumor's author
|
// Add a conversation id
|
||||||
|
tags.push(Tag::custom(
|
||||||
|
TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::C)),
|
||||||
|
[conversation.to_string()],
|
||||||
|
));
|
||||||
|
|
||||||
|
// Add a reference to the rumor's id
|
||||||
|
tags.push(Tag::event(rumor_id));
|
||||||
|
|
||||||
|
// Add references to the rumor's participants
|
||||||
|
for receiver in rumor.tags.public_keys().copied() {
|
||||||
tags.push(Tag::custom(
|
tags.push(Tag::custom(
|
||||||
TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::A)),
|
TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::P)),
|
||||||
[author],
|
[receiver],
|
||||||
));
|
));
|
||||||
|
|
||||||
// Add a conversation id
|
|
||||||
tags.push(Tag::custom(
|
|
||||||
TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::C)),
|
|
||||||
[conversation.to_string()],
|
|
||||||
));
|
|
||||||
|
|
||||||
// Add a reference to the rumor's id
|
|
||||||
tags.push(Tag::event(rumor_id));
|
|
||||||
|
|
||||||
// Add references to the rumor's participants
|
|
||||||
for receiver in rumor.tags.public_keys().copied() {
|
|
||||||
tags.push(Tag::custom(
|
|
||||||
TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::P)),
|
|
||||||
[receiver],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert rumor to json
|
|
||||||
let content = rumor.as_json();
|
|
||||||
|
|
||||||
// Construct the event
|
|
||||||
let event = EventBuilder::new(Kind::ApplicationSpecificData, content)
|
|
||||||
.tags(tags)
|
|
||||||
.sign(&Keys::generate())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// Save the event to the database
|
|
||||||
client.database().save_event(&event).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves a previously unwrapped event from local database
|
// Convert rumor to json
|
||||||
async fn get_rumor(client: &Client, gift_wrap: EventId) -> Result<UnsignedEvent, Error> {
|
let content = rumor.as_json();
|
||||||
let filter = Filter::new()
|
|
||||||
.kind(Kind::ApplicationSpecificData)
|
|
||||||
.identifier(gift_wrap)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if let Some(event) = client.database().query(filter).await?.first_owned() {
|
// Construct the event
|
||||||
UnsignedEvent::from_json(event.content).map_err(|e| anyhow!(e))
|
let event = EventBuilder::new(Kind::ApplicationSpecificData, content)
|
||||||
} else {
|
.tags(tags)
|
||||||
Err(anyhow!("Event is not cached yet."))
|
.sign(&Keys::generate())
|
||||||
}
|
.await?;
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the conversation ID for a given rumor (message).
|
// Save the event to the database
|
||||||
fn conversation_id(rumor: &UnsignedEvent) -> u64 {
|
client.database().save_event(&event).await?;
|
||||||
let mut hasher = DefaultHasher::new();
|
|
||||||
let mut pubkeys: Vec<PublicKey> = rumor.tags.public_keys().copied().collect();
|
|
||||||
pubkeys.push(rumor.pubkey);
|
|
||||||
pubkeys.sort();
|
|
||||||
pubkeys.dedup();
|
|
||||||
pubkeys.hash(&mut hasher);
|
|
||||||
|
|
||||||
hasher.finish()
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieves a previously unwrapped event from local database
|
||||||
|
async fn get_rumor(client: &Client, gift_wrap: EventId) -> Result<UnsignedEvent, Error> {
|
||||||
|
let filter = Filter::new()
|
||||||
|
.kind(Kind::ApplicationSpecificData)
|
||||||
|
.identifier(gift_wrap)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if let Some(event) = client.database().query(filter).await?.first_owned() {
|
||||||
|
UnsignedEvent::from_json(event.content).map_err(|e| anyhow!(e))
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("Event is not cached yet."))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the conversation ID for a given rumor (message).
|
||||||
|
fn conversation_id(rumor: &UnsignedEvent) -> u64 {
|
||||||
|
let mut hasher = DefaultHasher::new();
|
||||||
|
let mut pubkeys: Vec<PublicKey> = rumor.tags.public_keys().copied().collect();
|
||||||
|
pubkeys.push(rumor.pubkey);
|
||||||
|
pubkeys.sort();
|
||||||
|
pubkeys.dedup();
|
||||||
|
pubkeys.hash(&mut hasher);
|
||||||
|
|
||||||
|
hasher.finish()
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
use std::ops::Range;
|
||||||
|
|
||||||
use common::EventUtils;
|
use common::{EventExt, NostrParser};
|
||||||
|
use gpui::SharedString;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
/// New message.
|
/// New message.
|
||||||
@@ -23,6 +25,25 @@ impl NewMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Trash message.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct FailedMessage {
|
||||||
|
pub raw_event: SharedString,
|
||||||
|
pub reason: SharedString,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FailedMessage {
|
||||||
|
pub fn new<T>(event: &Event, reason: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<SharedString>,
|
||||||
|
{
|
||||||
|
Self {
|
||||||
|
raw_event: SharedString::from(event.as_json()),
|
||||||
|
reason: reason.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Message.
|
/// Message.
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
@@ -91,6 +112,18 @@ impl PartialOrd for Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Mention {
|
||||||
|
pub public_key: PublicKey,
|
||||||
|
pub range: Range<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Mention {
|
||||||
|
pub fn new(public_key: PublicKey, range: Range<usize>) -> Self {
|
||||||
|
Self { public_key, range }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Rendered message.
|
/// Rendered message.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RenderedMessage {
|
pub struct RenderedMessage {
|
||||||
@@ -102,7 +135,7 @@ pub struct RenderedMessage {
|
|||||||
/// Message created time as unix timestamp
|
/// Message created time as unix timestamp
|
||||||
pub created_at: Timestamp,
|
pub created_at: Timestamp,
|
||||||
/// List of mentioned public keys in the message
|
/// List of mentioned public keys in the message
|
||||||
pub mentions: Vec<PublicKey>,
|
pub mentions: Vec<Mention>,
|
||||||
/// List of event of the message this message is a reply to
|
/// List of event of the message this message is a reply to
|
||||||
pub replies_to: Vec<EventId>,
|
pub replies_to: Vec<EventId>,
|
||||||
}
|
}
|
||||||
@@ -184,20 +217,17 @@ impl Hash for RenderedMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extracts all mentions (public keys) from a content string.
|
/// Extracts all mentions (public keys) from a content string.
|
||||||
fn extract_mentions(content: &str) -> Vec<PublicKey> {
|
fn extract_mentions(content: &str) -> Vec<Mention> {
|
||||||
let parser = NostrParser::new();
|
let parser = NostrParser::new();
|
||||||
let tokens = parser.parse(content);
|
let tokens = parser.parse(content);
|
||||||
|
|
||||||
tokens
|
tokens
|
||||||
.filter_map(|token| match token {
|
.filter_map(|token| match token.value {
|
||||||
Token::Nostr(nip21) => match nip21 {
|
Nip21::Pubkey(public_key) => Some(Mention::new(public_key, token.range)),
|
||||||
Nip21::Pubkey(pubkey) => Some(pubkey),
|
Nip21::Profile(profile) => Some(Mention::new(profile.public_key, token.range)),
|
||||||
Nip21::Profile(profile) => Some(profile.public_key),
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extracts all reply (ids) from the event tags.
|
/// Extracts all reply (ids) from the event tags.
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ use std::cmp::Ordering;
|
|||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{Context as AnyhowContext, Error};
|
use anyhow::{Error, anyhow};
|
||||||
use common::EventUtils;
|
use common::EventExt;
|
||||||
use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task};
|
use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
@@ -11,7 +11,10 @@ use person::{Person, PersonRegistry};
|
|||||||
use settings::{RoomConfig, SignerKind};
|
use settings::{RoomConfig, SignerKind};
|
||||||
use state::{NostrRegistry, TIMEOUT};
|
use state::{NostrRegistry, TIMEOUT};
|
||||||
|
|
||||||
use crate::{ChatRegistry, NewMessage};
|
use crate::NewMessage;
|
||||||
|
|
||||||
|
const NO_DEKEY: &str = "User hasn't set up a decoupled encryption key yet.";
|
||||||
|
const USER_NO_DEKEY: &str = "You haven't set up a decoupled encryption key or it's not available.";
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SendReport {
|
pub struct SendReport {
|
||||||
@@ -54,16 +57,44 @@ impl SendReport {
|
|||||||
|
|
||||||
/// Returns true if the send is pending.
|
/// Returns true if the send is pending.
|
||||||
pub fn pending(&self) -> bool {
|
pub fn pending(&self) -> bool {
|
||||||
self.output.is_none() && self.error.is_none()
|
self.error.is_none()
|
||||||
|
&& self
|
||||||
|
.output
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|o| o.success.is_empty() && o.failed.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the send was successful.
|
/// Returns true if the send was successful.
|
||||||
pub fn success(&self) -> bool {
|
pub fn success(&self) -> bool {
|
||||||
if let Some(output) = self.output.as_ref() {
|
self.error.is_none() && self.output.as_ref().is_some_and(|o| !o.success.is_empty())
|
||||||
!output.failed.is_empty()
|
}
|
||||||
} else {
|
|
||||||
false
|
/// Returns true if the send failed.
|
||||||
}
|
pub fn failed(&self) -> bool {
|
||||||
|
self.error.is_some() && self.output.as_ref().is_some_and(|o| !o.failed.is_empty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum SendStatus {
|
||||||
|
Ok {
|
||||||
|
id: EventId,
|
||||||
|
relay: RelayUrl,
|
||||||
|
},
|
||||||
|
Failed {
|
||||||
|
id: EventId,
|
||||||
|
relay: RelayUrl,
|
||||||
|
message: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SendStatus {
|
||||||
|
pub fn ok(id: EventId, relay: RelayUrl) -> Self {
|
||||||
|
Self::Ok { id, relay }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn failed(id: EventId, relay: RelayUrl, message: String) -> Self {
|
||||||
|
Self::Failed { id, relay, message }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +180,7 @@ impl From<&UnsignedEvent> for Room {
|
|||||||
subject,
|
subject,
|
||||||
members,
|
members,
|
||||||
kind: RoomKind::default(),
|
kind: RoomKind::default(),
|
||||||
config: RoomConfig::default(),
|
config: RoomConfig::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,10 +232,8 @@ impl Room {
|
|||||||
|
|
||||||
/// Sets this room is ongoing conversation
|
/// Sets this room is ongoing conversation
|
||||||
pub fn set_ongoing(&mut self, cx: &mut Context<Self>) {
|
pub fn set_ongoing(&mut self, cx: &mut Context<Self>) {
|
||||||
if self.kind != RoomKind::Ongoing {
|
self.kind = RoomKind::Ongoing;
|
||||||
self.kind = RoomKind::Ongoing;
|
cx.notify();
|
||||||
cx.notify();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the creation timestamp of the room
|
/// Updates the creation timestamp of the room
|
||||||
@@ -222,6 +251,23 @@ impl Room {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the signer kind config for the room
|
||||||
|
pub fn set_signer_kind(&mut self, kind: &SignerKind, cx: &mut Context<Self>) {
|
||||||
|
self.config.set_signer_kind(kind);
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Updates the backup config for the room
|
||||||
|
pub fn set_backup(&mut self, cx: &mut Context<Self>) {
|
||||||
|
self.config.toggle_backup();
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the config of the room
|
||||||
|
pub fn config(&self) -> &RoomConfig {
|
||||||
|
&self.config
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the members of the room
|
/// Returns the members of the room
|
||||||
pub fn members(&self) -> Vec<PublicKey> {
|
pub fn members(&self) -> Vec<PublicKey> {
|
||||||
self.members.clone()
|
self.members.clone()
|
||||||
@@ -296,10 +342,6 @@ impl Room {
|
|||||||
|
|
||||||
if new_message {
|
if new_message {
|
||||||
self.set_created_at(created_at, cx);
|
self.set_created_at(created_at, cx);
|
||||||
// Sort chats after emitting a new message
|
|
||||||
ChatRegistry::global(cx).update(cx, |this, cx| {
|
|
||||||
this.sort(cx);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,43 +351,31 @@ impl Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get gossip relays for each member
|
/// Get gossip relays for each member
|
||||||
pub fn early_connect(&self, cx: &App) -> Task<Result<(), Error>> {
|
pub fn connect(&self, cx: &App) -> Task<Result<(), Error>> {
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
let client = nostr.read(cx).client();
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
let members = self.members();
|
let members = self.members();
|
||||||
let subscription_id = SubscriptionId::new(format!("room-{}", self.id));
|
|
||||||
|
|
||||||
cx.background_spawn(async move {
|
cx.background_spawn(async move {
|
||||||
let signer = client.signer().context("Signer not found")?;
|
let opts = SubscribeAutoCloseOptions::default()
|
||||||
let public_key = signer.get_public_key().await?;
|
.exit_policy(ReqExitPolicy::ExitOnEOSE)
|
||||||
|
.timeout(Some(Duration::from_secs(TIMEOUT)));
|
||||||
|
|
||||||
for member in members.into_iter() {
|
for public_key in members.into_iter() {
|
||||||
if member == public_key {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Construct a filter for messaging relays
|
|
||||||
let inbox = Filter::new()
|
let inbox = Filter::new()
|
||||||
|
.author(public_key)
|
||||||
.kind(Kind::InboxRelays)
|
.kind(Kind::InboxRelays)
|
||||||
.author(member)
|
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
// Construct a filter for announcement
|
|
||||||
let announcement = Filter::new()
|
let announcement = Filter::new()
|
||||||
|
.author(public_key)
|
||||||
.kind(Kind::Custom(10044))
|
.kind(Kind::Custom(10044))
|
||||||
.author(member)
|
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
// Subscribe to get member's gossip relays
|
// Subscribe to the target
|
||||||
client
|
client
|
||||||
.subscribe(vec![inbox, announcement])
|
.subscribe(vec![inbox, announcement])
|
||||||
.with_id(subscription_id.clone())
|
.close_on(opts)
|
||||||
.close_on(
|
|
||||||
SubscribeAutoCloseOptions::default()
|
|
||||||
.timeout(Some(Duration::from_secs(TIMEOUT)))
|
|
||||||
.exit_policy(ReqExitPolicy::ExitOnEOSE),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +423,7 @@ impl Room {
|
|||||||
// Get current user's public key
|
// Get current user's public key
|
||||||
let sender = nostr.read(cx).signer().public_key()?;
|
let sender = nostr.read(cx).signer().public_key()?;
|
||||||
|
|
||||||
// Get all members
|
// Get all members, excluding the sender
|
||||||
let members: Vec<Person> = self
|
let members: Vec<Person> = self
|
||||||
.members
|
.members
|
||||||
.iter()
|
.iter()
|
||||||
@@ -418,11 +448,6 @@ impl Room {
|
|||||||
|
|
||||||
// Add all receiver tags
|
// Add all receiver tags
|
||||||
for member in members.into_iter() {
|
for member in members.into_iter() {
|
||||||
// Skip current user
|
|
||||||
if member.public_key() == sender {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
tags.push(Tag::from_standardized_without_cell(
|
tags.push(Tag::from_standardized_without_cell(
|
||||||
TagStandard::PublicKey {
|
TagStandard::PublicKey {
|
||||||
public_key: member.public_key(),
|
public_key: member.public_key(),
|
||||||
@@ -445,116 +470,114 @@ impl Room {
|
|||||||
|
|
||||||
/// Send rumor event to all members's messaging relays
|
/// Send rumor event to all members's messaging relays
|
||||||
pub fn send(&self, rumor: UnsignedEvent, cx: &App) -> Option<Task<Vec<SendReport>>> {
|
pub fn send(&self, rumor: UnsignedEvent, cx: &App) -> Option<Task<Vec<SendReport>>> {
|
||||||
|
let config = self.config.clone();
|
||||||
let persons = PersonRegistry::global(cx);
|
let persons = PersonRegistry::global(cx);
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
let client = nostr.read(cx).client();
|
let client = nostr.read(cx).client();
|
||||||
let signer = nostr.read(cx).signer();
|
let signer = nostr.read(cx).signer();
|
||||||
|
|
||||||
// Get room's config
|
|
||||||
let config = self.config.clone();
|
|
||||||
|
|
||||||
// Get current user's public key
|
// Get current user's public key
|
||||||
let sender = nostr.read(cx).signer().public_key()?;
|
let public_key = nostr.read(cx).signer().public_key()?;
|
||||||
|
let sender = persons.read(cx).get(&public_key, cx);
|
||||||
|
|
||||||
// Get all members (excluding sender)
|
// Get all members (excluding sender)
|
||||||
let members: Vec<Person> = self
|
let members: Vec<Person> = self
|
||||||
.members
|
.members
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|public_key| public_key != &&sender)
|
.filter(|public_key| public_key != &&sender.public_key())
|
||||||
.map(|member| persons.read(cx).get(member, cx))
|
.map(|member| persons.read(cx).get(member, cx))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Some(cx.background_spawn(async move {
|
Some(cx.background_spawn(async move {
|
||||||
let signer_kind = config.signer_kind();
|
let signer_kind = config.signer_kind();
|
||||||
|
let backup = config.backup();
|
||||||
|
|
||||||
let user_signer = signer.get().await;
|
let user_signer = signer.get().await;
|
||||||
let encryption_signer = signer.get_encryption_signer().await;
|
let encryption_signer = signer.get_encryption_signer().await;
|
||||||
|
|
||||||
|
let mut sents = 0;
|
||||||
let mut reports = Vec::new();
|
let mut reports = Vec::new();
|
||||||
|
|
||||||
|
// Process each member
|
||||||
for member in members {
|
for member in members {
|
||||||
let relays = member.messaging_relays();
|
|
||||||
let announcement = member.announcement();
|
let announcement = member.announcement();
|
||||||
|
let public_key = member.public_key();
|
||||||
|
|
||||||
// Skip if member has no messaging relays
|
// Handle encryption signer requirements
|
||||||
if relays.is_empty() {
|
if signer_kind.encryption() {
|
||||||
reports.push(SendReport::new(member.public_key()).error("No messaging relays"));
|
// Receiver didn't set up a decoupled encryption key
|
||||||
continue;
|
if announcement.is_none() {
|
||||||
|
reports.push(SendReport::new(public_key).error(NO_DEKEY));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sender didn't set up a decoupled encryption key
|
||||||
|
if encryption_signer.is_none() {
|
||||||
|
reports.push(SendReport::new(sender.public_key()).error(USER_NO_DEKEY));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure relay connections
|
// Determine the signer to use
|
||||||
for url in relays.iter() {
|
let signer = match signer_kind {
|
||||||
client
|
|
||||||
.add_relay(url)
|
|
||||||
.and_connect()
|
|
||||||
.capabilities(RelayCapabilities::GOSSIP)
|
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
// When forced to use encryption signer, skip if receiver has no announcement
|
|
||||||
if signer_kind.encryption() && announcement.is_none() {
|
|
||||||
reports
|
|
||||||
.push(SendReport::new(member.public_key()).error("Encryption not found"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine receiver and signer based on signer kind
|
|
||||||
let (receiver, signer_to_use) = match signer_kind {
|
|
||||||
SignerKind::Auto => {
|
SignerKind::Auto => {
|
||||||
if let Some(announcement) = announcement {
|
if announcement.is_some()
|
||||||
if let Some(enc_signer) = encryption_signer.as_ref() {
|
&& let Some(encryption_signer) = encryption_signer.clone()
|
||||||
(announcement.public_key(), enc_signer.clone())
|
{
|
||||||
} else {
|
// Safe to unwrap due to earlier checks
|
||||||
(member.public_key(), user_signer.clone())
|
encryption_signer
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
(member.public_key(), user_signer.clone())
|
user_signer.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SignerKind::Encryption => {
|
SignerKind::Encryption => {
|
||||||
let Some(encryption_signer) = encryption_signer.as_ref() else {
|
// Safe to unwrap due to earlier checks
|
||||||
reports.push(
|
encryption_signer.as_ref().unwrap().clone()
|
||||||
SendReport::new(member.public_key()).error("Encryption not found"),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let Some(announcement) = announcement else {
|
|
||||||
reports.push(
|
|
||||||
SendReport::new(member.public_key())
|
|
||||||
.error("Announcement not found"),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
(announcement.public_key(), encryption_signer.clone())
|
|
||||||
}
|
}
|
||||||
SignerKind::User => (member.public_key(), user_signer.clone()),
|
SignerKind::User => user_signer.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create and send gift-wrapped event
|
// Send the gift wrap event and collect the report
|
||||||
match EventBuilder::gift_wrap(&signer_to_use, &receiver, rumor.clone(), []).await {
|
match send_gift_wrap(&client, &signer, &member, &rumor, signer_kind).await {
|
||||||
Ok(event) => {
|
Ok(report) => {
|
||||||
match client
|
reports.push(report);
|
||||||
.send_event(&event)
|
sents += 1;
|
||||||
.to(relays)
|
}
|
||||||
.ack_policy(AckPolicy::none())
|
Err(error) => {
|
||||||
.await
|
let report = SendReport::new(public_key).error(error.to_string());
|
||||||
|
reports.push(report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send backup to current user if needed
|
||||||
|
if backup && sents >= 1 {
|
||||||
|
let public_key = sender.public_key();
|
||||||
|
|
||||||
|
// Determine the signer to use
|
||||||
|
let signer = match signer_kind {
|
||||||
|
SignerKind::Auto => {
|
||||||
|
if sender.announcement().is_some()
|
||||||
|
&& let Some(encryption_signer) = encryption_signer.clone()
|
||||||
{
|
{
|
||||||
Ok(output) => {
|
// Safe to unwrap due to earlier checks
|
||||||
reports.push(
|
encryption_signer
|
||||||
SendReport::new(member.public_key())
|
} else {
|
||||||
.gift_wrap_id(event.id)
|
user_signer.clone()
|
||||||
.output(output),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
reports.push(
|
|
||||||
SendReport::new(member.public_key()).error(e.to_string()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
SignerKind::Encryption => {
|
||||||
reports.push(SendReport::new(member.public_key()).error(e.to_string()));
|
// Safe to unwrap due to earlier checks
|
||||||
|
encryption_signer.as_ref().unwrap().clone()
|
||||||
|
}
|
||||||
|
SignerKind::User => user_signer.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
match send_gift_wrap(&client, &signer, &sender, &rumor, signer_kind).await {
|
||||||
|
Ok(report) => reports.push(report),
|
||||||
|
Err(error) => {
|
||||||
|
let report = SendReport::new(public_key).error(error.to_string());
|
||||||
|
reports.push(report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -562,222 +585,56 @@ impl Room {
|
|||||||
reports
|
reports
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*
|
|
||||||
* /// Create a new unsigned message event
|
// Helper function to send a gift-wrapped event
|
||||||
pub fn create_message(
|
async fn send_gift_wrap<T>(
|
||||||
&self,
|
client: &Client,
|
||||||
content: &str,
|
signer: &T,
|
||||||
replies: Vec<EventId>,
|
receiver: &Person,
|
||||||
cx: &App,
|
rumor: &UnsignedEvent,
|
||||||
) -> Task<Result<UnsignedEvent, Error>> {
|
config: &SignerKind,
|
||||||
let nostr = NostrRegistry::global(cx);
|
) -> Result<SendReport, Error>
|
||||||
let client = nostr.read(cx).client();
|
where
|
||||||
|
T: NostrSigner + 'static,
|
||||||
let subject = self.subject.clone();
|
{
|
||||||
let content = content.to_string();
|
let mut extra_tags = vec![];
|
||||||
|
|
||||||
let mut member_and_relay_hints = HashMap::new();
|
// Determine the receiver public key based on the config
|
||||||
|
let receiver = match config {
|
||||||
// Populate the hashmap with member and relay hint tasks
|
SignerKind::Auto => {
|
||||||
for member in self.members.iter() {
|
if let Some(announcement) = receiver.announcement().as_ref() {
|
||||||
let hint = nostr.read(cx).relay_hint(member, cx);
|
extra_tags.push(Tag::public_key(receiver.public_key()));
|
||||||
member_and_relay_hints.insert(member.to_owned(), hint);
|
announcement.public_key()
|
||||||
}
|
} else {
|
||||||
|
receiver.public_key()
|
||||||
cx.background_spawn(async move {
|
}
|
||||||
let signer = client.signer().context("Signer not found")?;
|
}
|
||||||
let public_key = signer.get_public_key().await?;
|
SignerKind::Encryption => {
|
||||||
|
if let Some(announcement) = receiver.announcement().as_ref() {
|
||||||
// List of event tags for each receiver
|
extra_tags.push(Tag::public_key(receiver.public_key()));
|
||||||
let mut tags = vec![];
|
announcement.public_key()
|
||||||
|
} else {
|
||||||
for (member, task) in member_and_relay_hints.into_iter() {
|
return Err(anyhow!("User has no encryption announcement"));
|
||||||
// Skip current user
|
}
|
||||||
if member == public_key {
|
}
|
||||||
continue;
|
SignerKind::User => receiver.public_key(),
|
||||||
}
|
};
|
||||||
|
|
||||||
// Get relay hint if available
|
// Construct the gift wrap event
|
||||||
let relay_url = task.await;
|
let event = EventBuilder::gift_wrap(signer, &receiver, rumor.clone(), extra_tags).await?;
|
||||||
|
|
||||||
// Construct a public key tag with relay hint
|
// Send the gift wrap event and collect the report
|
||||||
let tag = TagStandard::PublicKey {
|
let report = client
|
||||||
public_key: member,
|
.send_event(&event)
|
||||||
relay_url,
|
.to_nip17()
|
||||||
alias: None,
|
.ack_policy(AckPolicy::none())
|
||||||
uppercase: false,
|
.await
|
||||||
};
|
.map(|output| {
|
||||||
|
SendReport::new(receiver)
|
||||||
tags.push(Tag::from_standardized_without_cell(tag));
|
.gift_wrap_id(event.id)
|
||||||
}
|
.output(output)
|
||||||
|
})?;
|
||||||
// Add subject tag if present
|
|
||||||
if let Some(value) = subject {
|
Ok(report)
|
||||||
tags.push(Tag::from_standardized_without_cell(TagStandard::Subject(
|
|
||||||
value.to_string(),
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add all reply tags
|
|
||||||
for id in replies {
|
|
||||||
tags.push(Tag::event(id))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct a direct message event
|
|
||||||
//
|
|
||||||
// WARNING: never sign and send this event to relays
|
|
||||||
let mut event = EventBuilder::new(Kind::PrivateDirectMessage, content)
|
|
||||||
.tags(tags)
|
|
||||||
.build(public_key);
|
|
||||||
|
|
||||||
// Ensure the event ID has been generated
|
|
||||||
event.ensure_id();
|
|
||||||
|
|
||||||
Ok(event)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a task to send a message to all room members
|
|
||||||
pub fn send_message(
|
|
||||||
&self,
|
|
||||||
rumor: &UnsignedEvent,
|
|
||||||
cx: &App,
|
|
||||||
) -> Task<Result<Vec<SendReport>, Error>> {
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let client = nostr.read(cx).client();
|
|
||||||
|
|
||||||
let mut members = self.members();
|
|
||||||
let rumor = rumor.to_owned();
|
|
||||||
|
|
||||||
cx.background_spawn(async move {
|
|
||||||
let signer = client.signer().context("Signer not found")?;
|
|
||||||
let current_user = signer.get_public_key().await?;
|
|
||||||
|
|
||||||
// Remove the current user's public key from the list of receivers
|
|
||||||
// the current user will be handled separately
|
|
||||||
members.retain(|this| this != ¤t_user);
|
|
||||||
|
|
||||||
// Collect the send reports
|
|
||||||
let mut reports: Vec<SendReport> = vec![];
|
|
||||||
|
|
||||||
for receiver in members.into_iter() {
|
|
||||||
// Construct the gift wrap event
|
|
||||||
let event =
|
|
||||||
EventBuilder::gift_wrap(signer, &receiver, rumor.clone(), vec![]).await?;
|
|
||||||
|
|
||||||
// Send the gift wrap event to the messaging relays
|
|
||||||
match client.send_event(&event).to_nip17().await {
|
|
||||||
Ok(output) => {
|
|
||||||
let id = output.id().to_owned();
|
|
||||||
let auth = output.failed.iter().any(|(_, s)| s.starts_with("auth-"));
|
|
||||||
let report = SendReport::new(receiver).status(output);
|
|
||||||
let tracker = tracker().read().await;
|
|
||||||
|
|
||||||
if auth {
|
|
||||||
// Wait for authenticated and resent event successfully
|
|
||||||
for attempt in 0..=SEND_RETRY {
|
|
||||||
// Check if event was successfully resent
|
|
||||||
if tracker.is_sent_by_coop(&id) {
|
|
||||||
let output = Output::new(id);
|
|
||||||
let report = SendReport::new(receiver).status(output);
|
|
||||||
reports.push(report);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if retry limit exceeded
|
|
||||||
if attempt == SEND_RETRY {
|
|
||||||
reports.push(report);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
smol::Timer::after(Duration::from_millis(1200)).await;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reports.push(report);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
reports.push(SendReport::new(receiver).error(e.to_string()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct the gift-wrapped event
|
|
||||||
let event =
|
|
||||||
EventBuilder::gift_wrap(signer, ¤t_user, rumor.clone(), vec![]).await?;
|
|
||||||
|
|
||||||
// Only send a backup message to current user if sent successfully to others
|
|
||||||
if reports.iter().all(|r| r.is_sent_success()) {
|
|
||||||
// Send the event to the messaging relays
|
|
||||||
match client.send_event(&event).to_nip17().await {
|
|
||||||
Ok(output) => {
|
|
||||||
reports.push(SendReport::new(current_user).status(output));
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
reports.push(SendReport::new(current_user).error(e.to_string()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reports.push(SendReport::new(current_user).on_hold(event));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(reports)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a task to resend a failed message
|
|
||||||
pub fn resend_message(
|
|
||||||
&self,
|
|
||||||
reports: Vec<SendReport>,
|
|
||||||
cx: &App,
|
|
||||||
) -> Task<Result<Vec<SendReport>, Error>> {
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let client = nostr.read(cx).client();
|
|
||||||
|
|
||||||
cx.background_spawn(async move {
|
|
||||||
let mut resend_reports = vec![];
|
|
||||||
|
|
||||||
for report in reports.into_iter() {
|
|
||||||
let receiver = report.receiver;
|
|
||||||
|
|
||||||
// Process failed events
|
|
||||||
if let Some(output) = report.status {
|
|
||||||
let id = output.id();
|
|
||||||
let urls: Vec<&RelayUrl> = output.failed.keys().collect();
|
|
||||||
|
|
||||||
if let Some(event) = client.database().event_by_id(id).await? {
|
|
||||||
for url in urls.into_iter() {
|
|
||||||
let relay = client.relay(url).await?.context("Relay not found")?;
|
|
||||||
let id = relay.send_event(&event).await?;
|
|
||||||
|
|
||||||
let resent: Output<EventId> = Output {
|
|
||||||
val: id,
|
|
||||||
success: HashSet::from([url.to_owned()]),
|
|
||||||
failed: HashMap::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
resend_reports.push(SendReport::new(receiver).status(resent));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process the on hold event if it exists
|
|
||||||
if let Some(event) = report.on_hold {
|
|
||||||
// Send the event to the messaging relays
|
|
||||||
match client.send_event(&event).await {
|
|
||||||
Ok(output) => {
|
|
||||||
resend_reports.push(SendReport::new(receiver).status(output));
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
resend_reports.push(SendReport::new(receiver).error(e.to_string()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(resend_reports)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,3 +28,5 @@ serde_json.workspace = true
|
|||||||
|
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
|
linkify = "0.10.0"
|
||||||
|
pulldown-cmark = "0.13.1"
|
||||||
|
|||||||
@@ -1,24 +1,17 @@
|
|||||||
use gpui::Action;
|
use gpui::Action;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use settings::SignerKind;
|
||||||
|
|
||||||
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[action(namespace = chat, no_json)]
|
#[action(namespace = chat, no_json)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
Insert(&'static str),
|
Insert(&'static str),
|
||||||
ChangeSubject(&'static str),
|
ChangeSubject(String),
|
||||||
|
ChangeSigner(SignerKind),
|
||||||
|
ToggleBackup,
|
||||||
|
Copy(PublicKey),
|
||||||
|
Relays(PublicKey),
|
||||||
|
Njump(PublicKey),
|
||||||
|
Trace(EventId),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
|
||||||
#[action(namespace = chat, no_json)]
|
|
||||||
pub struct SeenOn(pub EventId);
|
|
||||||
|
|
||||||
/// Define a open public key action
|
|
||||||
#[derive(Action, Clone, PartialEq, Eq, Deserialize, Debug)]
|
|
||||||
#[action(namespace = pubkey, no_json)]
|
|
||||||
pub struct OpenPublicKey(pub PublicKey);
|
|
||||||
|
|
||||||
/// Define a copy inline public key action
|
|
||||||
#[derive(Action, Clone, PartialEq, Eq, Deserialize, Debug)]
|
|
||||||
#[action(namespace = pubkey, no_json)]
|
|
||||||
pub struct CopyPublicKey(pub PublicKey);
|
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
use gpui::{
|
|
||||||
div, App, AppContext, Context, Entity, IntoElement, ParentElement, Render, SharedString,
|
|
||||||
Styled, Window,
|
|
||||||
};
|
|
||||||
use theme::ActiveTheme;
|
|
||||||
use ui::input::{InputState, TextInput};
|
|
||||||
use ui::{v_flex, Sizable};
|
|
||||||
|
|
||||||
pub fn init(subject: Option<String>, window: &mut Window, cx: &mut App) -> Entity<Subject> {
|
|
||||||
cx.new(|cx| Subject::new(subject, window, cx))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Subject {
|
|
||||||
input: Entity<InputState>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Subject {
|
|
||||||
pub fn new(subject: Option<String>, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
|
||||||
let input = cx.new(|cx| InputState::new(window, cx).placeholder("Plan for holiday"));
|
|
||||||
|
|
||||||
if let Some(value) = subject {
|
|
||||||
input.update(cx, |this, cx| {
|
|
||||||
this.set_value(value, window, cx);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Self { input }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_subject(&self, cx: &App) -> SharedString {
|
|
||||||
self.input.read(cx).value()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Render for Subject {
|
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
||||||
v_flex()
|
|
||||||
.gap_2()
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_1()
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.text_sm()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from("Subject:")),
|
|
||||||
)
|
|
||||||
.child(TextInput::new(&self.input).small()),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.text_xs()
|
|
||||||
.italic()
|
|
||||||
.text_color(cx.theme().text_placeholder)
|
|
||||||
.child(SharedString::from(
|
|
||||||
"Subject will be updated when you send a new message.",
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +1,29 @@
|
|||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use chat::Mention;
|
||||||
|
use common::RangeExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, ElementId, HighlightStyle, InteractiveText, IntoElement, SharedString,
|
AnyElement, App, ElementId, Entity, FontStyle, FontWeight, HighlightStyle, InteractiveText,
|
||||||
StyledText, UnderlineStyle, Window,
|
IntoElement, SharedString, StrikethroughStyle, StyledText, UnderlineStyle, Window,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use person::PersonRegistry;
|
use person::PersonRegistry;
|
||||||
use regex::Regex;
|
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
|
|
||||||
use crate::actions::OpenPublicKey;
|
#[allow(clippy::enum_variant_names)]
|
||||||
|
#[allow(dead_code)]
|
||||||
static URL_REGEX: Lazy<Regex> = Lazy::new(|| {
|
|
||||||
Regex::new(r"(?i)(?:^|\s)(?:https?://)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}(?::\d+)?(?:/[^\s]*)?(?:\s|$)").unwrap()
|
|
||||||
});
|
|
||||||
|
|
||||||
static NOSTR_URI_REGEX: Lazy<Regex> =
|
|
||||||
Lazy::new(|| Regex::new(r"nostr:(npub|note|nprofile|nevent|naddr)[a-zA-Z0-9]+").unwrap());
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum Highlight {
|
pub enum Highlight {
|
||||||
Link,
|
Code,
|
||||||
Nostr,
|
InlineCode(bool),
|
||||||
|
Highlight(HighlightStyle),
|
||||||
|
Mention,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<HighlightStyle> for Highlight {
|
||||||
|
fn from(style: HighlightStyle) -> Self {
|
||||||
|
Self::Highlight(style)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -35,7 +35,12 @@ pub struct RenderedText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RenderedText {
|
impl RenderedText {
|
||||||
pub fn new(content: &str, cx: &App) -> Self {
|
pub fn new(
|
||||||
|
content: &str,
|
||||||
|
mentions: &[Mention],
|
||||||
|
persons: &Entity<PersonRegistry>,
|
||||||
|
cx: &App,
|
||||||
|
) -> Self {
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
let mut highlights = Vec::new();
|
let mut highlights = Vec::new();
|
||||||
let mut link_ranges = Vec::new();
|
let mut link_ranges = Vec::new();
|
||||||
@@ -43,10 +48,12 @@ impl RenderedText {
|
|||||||
|
|
||||||
render_plain_text_mut(
|
render_plain_text_mut(
|
||||||
content,
|
content,
|
||||||
|
mentions,
|
||||||
&mut text,
|
&mut text,
|
||||||
&mut highlights,
|
&mut highlights,
|
||||||
&mut link_ranges,
|
&mut link_ranges,
|
||||||
&mut link_urls,
|
&mut link_urls,
|
||||||
|
persons,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -61,7 +68,7 @@ impl RenderedText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn element(&self, id: ElementId, window: &Window, cx: &App) -> AnyElement {
|
pub fn element(&self, id: ElementId, window: &Window, cx: &App) -> AnyElement {
|
||||||
let link_color = cx.theme().text_accent;
|
let code_background = cx.theme().elevated_surface_background;
|
||||||
|
|
||||||
InteractiveText::new(
|
InteractiveText::new(
|
||||||
id,
|
id,
|
||||||
@@ -71,15 +78,35 @@ impl RenderedText {
|
|||||||
(
|
(
|
||||||
range.clone(),
|
range.clone(),
|
||||||
match highlight {
|
match highlight {
|
||||||
Highlight::Link => HighlightStyle {
|
Highlight::Code => HighlightStyle {
|
||||||
color: Some(link_color),
|
background_color: Some(code_background),
|
||||||
underline: Some(UnderlineStyle::default()),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Highlight::Nostr => HighlightStyle {
|
Highlight::InlineCode(link) => {
|
||||||
color: Some(link_color),
|
if *link {
|
||||||
|
HighlightStyle {
|
||||||
|
background_color: Some(code_background),
|
||||||
|
underline: Some(UnderlineStyle {
|
||||||
|
thickness: 1.0.into(),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
HighlightStyle {
|
||||||
|
background_color: Some(code_background),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Highlight::Mention => HighlightStyle {
|
||||||
|
underline: Some(UnderlineStyle {
|
||||||
|
thickness: 1.0.into(),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
Highlight::Highlight(highlight) => *highlight,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
@@ -87,22 +114,10 @@ impl RenderedText {
|
|||||||
)
|
)
|
||||||
.on_click(self.link_ranges.clone(), {
|
.on_click(self.link_ranges.clone(), {
|
||||||
let link_urls = self.link_urls.clone();
|
let link_urls = self.link_urls.clone();
|
||||||
move |ix, window, cx| {
|
move |ix, _, cx| {
|
||||||
let token = link_urls[ix].as_str();
|
let url = &link_urls[ix];
|
||||||
|
if url.starts_with("http") {
|
||||||
if let Some(clean_url) = token.strip_prefix("nostr:") {
|
cx.open_url(url);
|
||||||
if let Ok(public_key) = PublicKey::parse(clean_url) {
|
|
||||||
window.dispatch_action(Box::new(OpenPublicKey(public_key)), cx);
|
|
||||||
}
|
|
||||||
} else if is_url(token) {
|
|
||||||
let url = if token.starts_with("http") {
|
|
||||||
token.to_string()
|
|
||||||
} else {
|
|
||||||
format!("https://{token}")
|
|
||||||
};
|
|
||||||
cx.open_url(&url);
|
|
||||||
} else {
|
|
||||||
log::warn!("Unrecognized token {token}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -110,214 +125,273 @@ impl RenderedText {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn render_plain_text_mut(
|
fn render_plain_text_mut(
|
||||||
content: &str,
|
block: &str,
|
||||||
|
mut mentions: &[Mention],
|
||||||
text: &mut String,
|
text: &mut String,
|
||||||
highlights: &mut Vec<(Range<usize>, Highlight)>,
|
highlights: &mut Vec<(Range<usize>, Highlight)>,
|
||||||
link_ranges: &mut Vec<Range<usize>>,
|
link_ranges: &mut Vec<Range<usize>>,
|
||||||
link_urls: &mut Vec<String>,
|
link_urls: &mut Vec<String>,
|
||||||
|
persons: &Entity<PersonRegistry>,
|
||||||
cx: &App,
|
cx: &App,
|
||||||
) {
|
) {
|
||||||
// Copy the content directly
|
use pulldown_cmark::{Event, Options, Parser, Tag, TagEnd};
|
||||||
text.push_str(content);
|
|
||||||
|
|
||||||
// Collect all URLs
|
let mut bold_depth = 0;
|
||||||
let mut url_matches: Vec<(Range<usize>, String)> = Vec::new();
|
let mut italic_depth = 0;
|
||||||
|
let mut strikethrough_depth = 0;
|
||||||
|
let mut link_url = None;
|
||||||
|
let mut list_stack = Vec::new();
|
||||||
|
|
||||||
for link in URL_REGEX.find_iter(content) {
|
let mut options = Options::all();
|
||||||
let range = link.start()..link.end();
|
options.remove(pulldown_cmark::Options::ENABLE_DEFINITION_LIST);
|
||||||
let url = link.as_str().to_string();
|
|
||||||
|
|
||||||
url_matches.push((range, url));
|
for (event, source_range) in Parser::new_ext(block, options).into_offset_iter() {
|
||||||
}
|
let prev_len = text.len();
|
||||||
|
|
||||||
// Collect all nostr entities with nostr: prefix
|
match event {
|
||||||
let mut nostr_matches: Vec<(Range<usize>, String)> = Vec::new();
|
Event::Text(t) => {
|
||||||
|
// Process text with mention replacements
|
||||||
|
let t_str = t.as_ref();
|
||||||
|
let mut last_processed = 0;
|
||||||
|
|
||||||
for nostr_match in NOSTR_URI_REGEX.find_iter(content) {
|
while let Some(mention) = mentions.first() {
|
||||||
let range = nostr_match.start()..nostr_match.end();
|
if !source_range.contains_inclusive(&mention.range) {
|
||||||
let nostr_uri = nostr_match.as_str().to_string();
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if this nostr URI overlaps with any already processed URL
|
// Calculate positions within the current text
|
||||||
if !url_matches
|
let mention_start_in_text = mention.range.start - source_range.start;
|
||||||
.iter()
|
let mention_end_in_text = mention.range.end - source_range.start;
|
||||||
.any(|(url_range, _)| url_range.start < range.end && range.start < url_range.end)
|
|
||||||
{
|
|
||||||
nostr_matches.push((range, nostr_uri));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Combine all matches for processing from end to start
|
// Add text before this mention
|
||||||
let mut all_matches = Vec::new();
|
if mention_start_in_text > last_processed {
|
||||||
all_matches.extend(url_matches);
|
let before_mention = &t_str[last_processed..mention_start_in_text];
|
||||||
all_matches.extend(nostr_matches);
|
process_text_segment(
|
||||||
|
before_mention,
|
||||||
|
prev_len + last_processed,
|
||||||
|
bold_depth,
|
||||||
|
italic_depth,
|
||||||
|
strikethrough_depth,
|
||||||
|
link_url.clone(),
|
||||||
|
text,
|
||||||
|
highlights,
|
||||||
|
link_ranges,
|
||||||
|
link_urls,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Sort by position (end to start) to avoid changing positions when replacing text
|
// Process the mention replacement
|
||||||
all_matches.sort_by(|(range_a, _), (range_b, _)| range_b.start.cmp(&range_a.start));
|
let profile = persons.read(cx).get(&mention.public_key, cx);
|
||||||
|
let replacement_text = format!("@{}", profile.name());
|
||||||
|
|
||||||
// Process all matches
|
let replacement_start = text.len();
|
||||||
for (range, entity) in all_matches {
|
text.push_str(&replacement_text);
|
||||||
// Handle URL token
|
let replacement_end = text.len();
|
||||||
if is_url(&entity) {
|
|
||||||
highlights.push((range.clone(), Highlight::Link));
|
|
||||||
link_ranges.push(range);
|
|
||||||
link_urls.push(entity);
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(nip21) = Nip21::parse(&entity) {
|
highlights.push((replacement_start..replacement_end, Highlight::Mention));
|
||||||
match nip21 {
|
|
||||||
Nip21::Pubkey(public_key) => {
|
last_processed = mention_end_in_text;
|
||||||
render_pubkey(
|
mentions = &mentions[1..];
|
||||||
public_key,
|
|
||||||
text,
|
|
||||||
&range,
|
|
||||||
highlights,
|
|
||||||
link_ranges,
|
|
||||||
link_urls,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Nip21::Profile(nip19_profile) => {
|
|
||||||
render_pubkey(
|
// Add any remaining text after the last mention
|
||||||
nip19_profile.public_key,
|
if last_processed < t_str.len() {
|
||||||
|
let remaining_text = &t_str[last_processed..];
|
||||||
|
process_text_segment(
|
||||||
|
remaining_text,
|
||||||
|
prev_len + last_processed,
|
||||||
|
bold_depth,
|
||||||
|
italic_depth,
|
||||||
|
strikethrough_depth,
|
||||||
|
link_url.clone(),
|
||||||
text,
|
text,
|
||||||
&range,
|
|
||||||
highlights,
|
|
||||||
link_ranges,
|
|
||||||
link_urls,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Nip21::EventId(event_id) => {
|
|
||||||
render_bech32(
|
|
||||||
event_id.to_bech32().unwrap(),
|
|
||||||
text,
|
|
||||||
&range,
|
|
||||||
highlights,
|
|
||||||
link_ranges,
|
|
||||||
link_urls,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Nip21::Event(nip19_event) => {
|
|
||||||
render_bech32(
|
|
||||||
nip19_event.to_bech32().unwrap(),
|
|
||||||
text,
|
|
||||||
&range,
|
|
||||||
highlights,
|
|
||||||
link_ranges,
|
|
||||||
link_urls,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Nip21::Coordinate(nip19_coordinate) => {
|
|
||||||
render_bech32(
|
|
||||||
nip19_coordinate.to_bech32().unwrap(),
|
|
||||||
text,
|
|
||||||
&range,
|
|
||||||
highlights,
|
highlights,
|
||||||
link_ranges,
|
link_ranges,
|
||||||
link_urls,
|
link_urls,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Event::Code(t) => {
|
||||||
|
text.push_str(t.as_ref());
|
||||||
|
let is_link = link_url.is_some();
|
||||||
|
|
||||||
|
if let Some(link_url) = link_url.clone() {
|
||||||
|
link_ranges.push(prev_len..text.len());
|
||||||
|
link_urls.push(link_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
highlights.push((prev_len..text.len(), Highlight::InlineCode(is_link)))
|
||||||
|
}
|
||||||
|
Event::Start(tag) => match tag {
|
||||||
|
Tag::Paragraph => new_paragraph(text, &mut list_stack),
|
||||||
|
Tag::Heading { .. } => {
|
||||||
|
new_paragraph(text, &mut list_stack);
|
||||||
|
bold_depth += 1;
|
||||||
|
}
|
||||||
|
Tag::CodeBlock(_kind) => {
|
||||||
|
new_paragraph(text, &mut list_stack);
|
||||||
|
}
|
||||||
|
Tag::Emphasis => italic_depth += 1,
|
||||||
|
Tag::Strong => bold_depth += 1,
|
||||||
|
Tag::Strikethrough => strikethrough_depth += 1,
|
||||||
|
Tag::Link { dest_url, .. } => link_url = Some(dest_url.to_string()),
|
||||||
|
Tag::List(number) => {
|
||||||
|
list_stack.push((number, false));
|
||||||
|
}
|
||||||
|
Tag::Item => {
|
||||||
|
let len = list_stack.len();
|
||||||
|
if let Some((list_number, has_content)) = list_stack.last_mut() {
|
||||||
|
*has_content = false;
|
||||||
|
if !text.is_empty() && !text.ends_with('\n') {
|
||||||
|
text.push('\n');
|
||||||
|
}
|
||||||
|
for _ in 0..len - 1 {
|
||||||
|
text.push_str(" ");
|
||||||
|
}
|
||||||
|
if let Some(number) = list_number {
|
||||||
|
text.push_str(&format!("{}. ", number));
|
||||||
|
*number += 1;
|
||||||
|
*has_content = false;
|
||||||
|
} else {
|
||||||
|
text.push_str("- ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
Event::End(tag) => match tag {
|
||||||
|
TagEnd::Heading(_) => bold_depth -= 1,
|
||||||
|
TagEnd::Emphasis => italic_depth -= 1,
|
||||||
|
TagEnd::Strong => bold_depth -= 1,
|
||||||
|
TagEnd::Strikethrough => strikethrough_depth -= 1,
|
||||||
|
TagEnd::Link => link_url = None,
|
||||||
|
TagEnd::List(_) => drop(list_stack.pop()),
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
|
Event::HardBreak => text.push('\n'),
|
||||||
|
Event::SoftBreak => text.push('\n'),
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if a string is a URL
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn is_url(s: &str) -> bool {
|
fn process_text_segment(
|
||||||
URL_REGEX.is_match(s)
|
segment: &str,
|
||||||
}
|
segment_start: usize,
|
||||||
|
bold_depth: i32,
|
||||||
|
italic_depth: i32,
|
||||||
|
strikethrough_depth: i32,
|
||||||
|
link_url: Option<String>,
|
||||||
|
text: &mut String,
|
||||||
|
highlights: &mut Vec<(Range<usize>, Highlight)>,
|
||||||
|
link_ranges: &mut Vec<Range<usize>>,
|
||||||
|
link_urls: &mut Vec<String>,
|
||||||
|
) {
|
||||||
|
// Build the style for this segment
|
||||||
|
let mut style = HighlightStyle::default();
|
||||||
|
if bold_depth > 0 {
|
||||||
|
style.font_weight = Some(FontWeight::BOLD);
|
||||||
|
}
|
||||||
|
if italic_depth > 0 {
|
||||||
|
style.font_style = Some(FontStyle::Italic);
|
||||||
|
}
|
||||||
|
if strikethrough_depth > 0 {
|
||||||
|
style.strikethrough = Some(StrikethroughStyle {
|
||||||
|
thickness: 1.0.into(),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// Format a bech32 entity with ellipsis and last 4 characters
|
// Add the text
|
||||||
fn format_shortened_entity(entity: &str) -> String {
|
text.push_str(segment);
|
||||||
let prefix_end = entity.find('1').unwrap_or(0);
|
let text_end = text.len();
|
||||||
|
|
||||||
if prefix_end > 0 && entity.len() > prefix_end + 5 {
|
if let Some(link_url) = link_url {
|
||||||
let prefix = &entity[0..=prefix_end]; // Include the '1'
|
// Handle as a markdown link
|
||||||
let suffix = &entity[entity.len() - 4..]; // Last 4 chars
|
link_ranges.push(segment_start..text_end);
|
||||||
|
link_urls.push(link_url);
|
||||||
|
style.underline = Some(UnderlineStyle {
|
||||||
|
thickness: 1.0.into(),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
|
||||||
format!("{prefix}...{suffix}")
|
// Add highlight for the entire linked segment
|
||||||
|
if style != HighlightStyle::default() {
|
||||||
|
highlights.push((segment_start..text_end, Highlight::Highlight(style)));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
entity.to_string()
|
// Handle link detection within the segment
|
||||||
}
|
let mut finder = linkify::LinkFinder::new();
|
||||||
}
|
finder.kinds(&[linkify::LinkKind::Url]);
|
||||||
|
let mut last_link_pos = 0;
|
||||||
|
|
||||||
fn render_pubkey(
|
for link in finder.links(segment) {
|
||||||
public_key: PublicKey,
|
let start = link.start();
|
||||||
text: &mut String,
|
let end = link.end();
|
||||||
range: &Range<usize>,
|
|
||||||
highlights: &mut Vec<(Range<usize>, Highlight)>,
|
|
||||||
link_ranges: &mut Vec<Range<usize>>,
|
|
||||||
link_urls: &mut Vec<String>,
|
|
||||||
cx: &App,
|
|
||||||
) {
|
|
||||||
let persons = PersonRegistry::global(cx);
|
|
||||||
let profile = persons.read(cx).get(&public_key, cx);
|
|
||||||
let display_name = format!("@{}", profile.name());
|
|
||||||
|
|
||||||
text.replace_range(range.clone(), &display_name);
|
// Add non-link text before this link
|
||||||
|
if start > last_link_pos {
|
||||||
|
let non_link_start = segment_start + last_link_pos;
|
||||||
|
let non_link_end = segment_start + start;
|
||||||
|
|
||||||
let new_length = display_name.len();
|
if style != HighlightStyle::default() {
|
||||||
let length_diff = new_length as isize - (range.end - range.start) as isize;
|
highlights.push((non_link_start..non_link_end, Highlight::Highlight(style)));
|
||||||
let new_range = range.start..(range.start + new_length);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
highlights.push((new_range.clone(), Highlight::Nostr));
|
// Add the link
|
||||||
link_ranges.push(new_range);
|
let range = (segment_start + start)..(segment_start + end);
|
||||||
link_urls.push(format!("nostr:{}", profile.public_key().to_hex()));
|
link_ranges.push(range.clone());
|
||||||
|
link_urls.push(link.as_str().to_string());
|
||||||
|
|
||||||
if length_diff != 0 {
|
// Apply link styling (underline + existing style)
|
||||||
adjust_ranges(highlights, link_ranges, range.end, length_diff);
|
let mut link_style = style;
|
||||||
}
|
link_style.underline = Some(UnderlineStyle {
|
||||||
}
|
thickness: 1.0.into(),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
|
||||||
fn render_bech32(
|
highlights.push((range, Highlight::Highlight(link_style)));
|
||||||
bech32: String,
|
|
||||||
text: &mut String,
|
|
||||||
range: &Range<usize>,
|
|
||||||
highlights: &mut Vec<(Range<usize>, Highlight)>,
|
|
||||||
link_ranges: &mut Vec<Range<usize>>,
|
|
||||||
link_urls: &mut Vec<String>,
|
|
||||||
) {
|
|
||||||
let njump_url = format!("https://njump.me/{bech32}");
|
|
||||||
let shortened_entity = format_shortened_entity(&bech32);
|
|
||||||
let display_text = format!("https://njump.me/{shortened_entity}");
|
|
||||||
|
|
||||||
text.replace_range(range.clone(), &display_text);
|
last_link_pos = end;
|
||||||
|
|
||||||
let new_length = display_text.len();
|
|
||||||
let length_diff = new_length as isize - (range.end - range.start) as isize;
|
|
||||||
let new_range = range.start..(range.start + new_length);
|
|
||||||
|
|
||||||
highlights.push((new_range.clone(), Highlight::Link));
|
|
||||||
link_ranges.push(new_range);
|
|
||||||
link_urls.push(njump_url);
|
|
||||||
|
|
||||||
if length_diff != 0 {
|
|
||||||
adjust_ranges(highlights, link_ranges, range.end, length_diff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to adjust ranges when text length changes
|
|
||||||
fn adjust_ranges(
|
|
||||||
highlights: &mut [(Range<usize>, Highlight)],
|
|
||||||
link_ranges: &mut [Range<usize>],
|
|
||||||
position: usize,
|
|
||||||
length_diff: isize,
|
|
||||||
) {
|
|
||||||
// Adjust highlight ranges
|
|
||||||
for (range, _) in highlights.iter_mut() {
|
|
||||||
if range.start > position {
|
|
||||||
range.start = (range.start as isize + length_diff) as usize;
|
|
||||||
range.end = (range.end as isize + length_diff) as usize;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Adjust link ranges
|
// Add any remaining text after the last link
|
||||||
for range in link_ranges.iter_mut() {
|
if last_link_pos < segment.len() {
|
||||||
if range.start > position {
|
let remaining_start = segment_start + last_link_pos;
|
||||||
range.start = (range.start as isize + length_diff) as usize;
|
let remaining_end = segment_start + segment.len();
|
||||||
range.end = (range.end as isize + length_diff) as usize;
|
|
||||||
|
if style != HighlightStyle::default() {
|
||||||
|
highlights.push((remaining_start..remaining_end, Highlight::Highlight(style)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_paragraph(text: &mut String, list_stack: &mut [(Option<u64>, bool)]) {
|
||||||
|
let mut is_subsequent_paragraph_of_list = false;
|
||||||
|
if let Some((_, has_content)) = list_stack.last_mut() {
|
||||||
|
if *has_content {
|
||||||
|
is_subsequent_paragraph_of_list = true;
|
||||||
|
} else {
|
||||||
|
*has_content = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !text.is_empty() {
|
||||||
|
if !text.ends_with('\n') {
|
||||||
|
text.push('\n');
|
||||||
|
}
|
||||||
|
text.push('\n');
|
||||||
|
}
|
||||||
|
for _ in 0..list_stack.len().saturating_sub(1) {
|
||||||
|
text.push_str(" ");
|
||||||
|
}
|
||||||
|
if is_subsequent_paragraph_of_list {
|
||||||
|
text.push_str(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,3 +19,4 @@ log.workspace = true
|
|||||||
|
|
||||||
dirs = "5.0"
|
dirs = "5.0"
|
||||||
qrcode = "0.14.1"
|
qrcode = "0.14.1"
|
||||||
|
bech32 = "0.11.1"
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
|
||||||
use chrono::{Local, TimeZone};
|
use chrono::{Local, TimeZone};
|
||||||
use gpui::{Image, ImageFormat, SharedString};
|
use gpui::{Image, ImageFormat, SharedString};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use qrcode::render::svg;
|
|
||||||
use qrcode::QrCode;
|
use qrcode::QrCode;
|
||||||
|
use qrcode::render::svg;
|
||||||
|
|
||||||
const NOW: &str = "now";
|
const NOW: &str = "now";
|
||||||
const SECONDS_IN_MINUTE: i64 = 60;
|
const SECONDS_IN_MINUTE: i64 = 60;
|
||||||
@@ -13,44 +12,12 @@ const MINUTES_IN_HOUR: i64 = 60;
|
|||||||
const HOURS_IN_DAY: i64 = 24;
|
const HOURS_IN_DAY: i64 = 24;
|
||||||
const DAYS_IN_MONTH: i64 = 30;
|
const DAYS_IN_MONTH: i64 = 30;
|
||||||
|
|
||||||
pub trait RenderedProfile {
|
pub trait TimestampExt {
|
||||||
fn avatar(&self) -> SharedString;
|
|
||||||
fn display_name(&self) -> SharedString;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RenderedProfile for Profile {
|
|
||||||
fn avatar(&self) -> SharedString {
|
|
||||||
self.metadata()
|
|
||||||
.picture
|
|
||||||
.as_ref()
|
|
||||||
.filter(|picture| !picture.is_empty())
|
|
||||||
.map(|picture| picture.into())
|
|
||||||
.unwrap_or_else(|| "brand/avatar.png".into())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn display_name(&self) -> SharedString {
|
|
||||||
if let Some(display_name) = self.metadata().display_name.as_ref() {
|
|
||||||
if !display_name.is_empty() {
|
|
||||||
return SharedString::from(display_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(name) = self.metadata().name.as_ref() {
|
|
||||||
if !name.is_empty() {
|
|
||||||
return SharedString::from(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedString::from(shorten_pubkey(self.public_key(), 4))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait RenderedTimestamp {
|
|
||||||
fn to_human_time(&self) -> SharedString;
|
fn to_human_time(&self) -> SharedString;
|
||||||
fn to_ago(&self) -> SharedString;
|
fn to_ago(&self) -> SharedString;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderedTimestamp for Timestamp {
|
impl TimestampExt for Timestamp {
|
||||||
fn to_human_time(&self) -> SharedString {
|
fn to_human_time(&self) -> SharedString {
|
||||||
let input_time = match Local.timestamp_opt(self.as_secs() as i64, 0) {
|
let input_time = match Local.timestamp_opt(self.as_secs() as i64, 0) {
|
||||||
chrono::LocalResult::Single(time) => time,
|
chrono::LocalResult::Single(time) => time,
|
||||||
@@ -93,23 +60,11 @@ impl RenderedTimestamp for Timestamp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TextUtils {
|
pub trait StringExt {
|
||||||
fn to_public_key(&self) -> Result<PublicKey, Error>;
|
|
||||||
fn to_qr(&self) -> Option<Arc<Image>>;
|
fn to_qr(&self) -> Option<Arc<Image>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsRef<str>> TextUtils for T {
|
impl<T: AsRef<str>> StringExt for T {
|
||||||
fn to_public_key(&self) -> Result<PublicKey, Error> {
|
|
||||||
let s = self.as_ref();
|
|
||||||
if s.starts_with("nprofile1") {
|
|
||||||
Ok(Nip19Profile::from_bech32(s)?.public_key)
|
|
||||||
} else if s.starts_with("npub1") {
|
|
||||||
Ok(PublicKey::parse(s)?)
|
|
||||||
} else {
|
|
||||||
Err(anyhow!("Invalid public key"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_qr(&self) -> Option<Arc<Image>> {
|
fn to_qr(&self) -> Option<Arc<Image>> {
|
||||||
let s = self.as_ref();
|
let s = self.as_ref();
|
||||||
let code = QrCode::new(s).unwrap();
|
let code = QrCode::new(s).unwrap();
|
||||||
@@ -126,13 +81,3 @@ impl<T: AsRef<str>> TextUtils for T {
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shorten_pubkey(public_key: PublicKey, len: usize) -> String {
|
|
||||||
let Ok(pubkey) = public_key.to_bech32();
|
|
||||||
|
|
||||||
format!(
|
|
||||||
"{}:{}",
|
|
||||||
&pubkey[0..(len + 1)],
|
|
||||||
&pubkey[pubkey.len() - len..]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ use std::hash::{DefaultHasher, Hash, Hasher};
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
pub trait EventUtils {
|
pub trait EventExt {
|
||||||
fn uniq_id(&self) -> u64;
|
fn uniq_id(&self) -> u64;
|
||||||
fn extract_public_keys(&self) -> Vec<PublicKey>;
|
fn extract_public_keys(&self) -> Vec<PublicKey>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventUtils for Event {
|
impl EventExt for Event {
|
||||||
fn uniq_id(&self) -> u64 {
|
fn uniq_id(&self) -> u64 {
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
let mut pubkeys: Vec<PublicKey> = self.extract_public_keys();
|
let mut pubkeys: Vec<PublicKey> = self.extract_public_keys();
|
||||||
@@ -25,7 +25,7 @@ impl EventUtils for Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventUtils for UnsignedEvent {
|
impl EventExt for UnsignedEvent {
|
||||||
fn uniq_id(&self) -> u64 {
|
fn uniq_id(&self) -> u64 {
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
let mut pubkeys: Vec<PublicKey> = vec![];
|
let mut pubkeys: Vec<PublicKey> = vec![];
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
pub use debounced_delay::*;
|
pub use debounced_delay::*;
|
||||||
pub use display::*;
|
pub use display::*;
|
||||||
pub use event::*;
|
pub use event::*;
|
||||||
|
pub use parser::*;
|
||||||
pub use paths::*;
|
pub use paths::*;
|
||||||
|
pub use range::*;
|
||||||
|
|
||||||
mod debounced_delay;
|
mod debounced_delay;
|
||||||
mod display;
|
mod display;
|
||||||
mod event;
|
mod event;
|
||||||
|
mod parser;
|
||||||
mod paths;
|
mod paths;
|
||||||
|
mod range;
|
||||||
|
|||||||
210
crates/common/src/parser.rs
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
use std::ops::Range;
|
||||||
|
|
||||||
|
use nostr::prelude::*;
|
||||||
|
|
||||||
|
const BECH32_SEPARATOR: u8 = b'1';
|
||||||
|
const SCHEME_WITH_COLON: &str = "nostr:";
|
||||||
|
|
||||||
|
/// Nostr parsed token with its range in the original text
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct Token {
|
||||||
|
/// The parsed NIP-21 URI
|
||||||
|
///
|
||||||
|
/// <https://github.com/nostr-protocol/nips/blob/master/21.md>
|
||||||
|
pub value: Nip21,
|
||||||
|
/// The range of this token in the original text
|
||||||
|
pub range: Range<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
struct Match {
|
||||||
|
start: usize,
|
||||||
|
end: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Nostr parser
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
pub struct NostrParser;
|
||||||
|
|
||||||
|
impl Default for NostrParser {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NostrParser {
|
||||||
|
/// Create new parser
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse text
|
||||||
|
pub fn parse<'a>(&self, text: &'a str) -> NostrParserIter<'a> {
|
||||||
|
NostrParserIter::new(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FindMatches<'a> {
|
||||||
|
bytes: &'a [u8],
|
||||||
|
pos: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> FindMatches<'a> {
|
||||||
|
fn new(text: &'a str) -> Self {
|
||||||
|
Self {
|
||||||
|
bytes: text.as_bytes(),
|
||||||
|
pos: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_parse_nostr_uri(&mut self) -> Option<Match> {
|
||||||
|
let start = self.pos;
|
||||||
|
let bytes = self.bytes;
|
||||||
|
let len = bytes.len();
|
||||||
|
|
||||||
|
// Check if we have "nostr:" prefix
|
||||||
|
if len - start < SCHEME_WITH_COLON.len() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for "nostr:" prefix (case-insensitive)
|
||||||
|
let scheme_prefix = &bytes[start..start + SCHEME_WITH_COLON.len()];
|
||||||
|
if !scheme_prefix.eq_ignore_ascii_case(SCHEME_WITH_COLON.as_bytes()) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip the scheme
|
||||||
|
let pos = start + SCHEME_WITH_COLON.len();
|
||||||
|
|
||||||
|
// Parse bech32 entity
|
||||||
|
let mut has_separator = false;
|
||||||
|
let mut end = pos;
|
||||||
|
|
||||||
|
while end < len {
|
||||||
|
let byte = bytes[end];
|
||||||
|
|
||||||
|
// Check for bech32 separator
|
||||||
|
if byte == BECH32_SEPARATOR && !has_separator {
|
||||||
|
has_separator = true;
|
||||||
|
end += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if character is valid for bech32
|
||||||
|
if !byte.is_ascii_alphanumeric() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
end += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Must have at least one character after separator
|
||||||
|
if !has_separator || end <= pos + 1 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update position
|
||||||
|
self.pos = end;
|
||||||
|
|
||||||
|
Some(Match { start, end })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for FindMatches<'_> {
|
||||||
|
type Item = Match;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
while self.pos < self.bytes.len() {
|
||||||
|
// Try to parse nostr URI
|
||||||
|
if let Some(mat) = self.try_parse_nostr_uri() {
|
||||||
|
return Some(mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip one character if no match found
|
||||||
|
self.pos += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum HandleMatch {
|
||||||
|
Token(Token),
|
||||||
|
Recursion,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NostrParserIter<'a> {
|
||||||
|
/// The original text
|
||||||
|
text: &'a str,
|
||||||
|
/// Matches found
|
||||||
|
matches: FindMatches<'a>,
|
||||||
|
/// A pending match
|
||||||
|
pending_match: Option<Match>,
|
||||||
|
/// Last match end index
|
||||||
|
last_match_end: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> NostrParserIter<'a> {
|
||||||
|
fn new(text: &'a str) -> Self {
|
||||||
|
Self {
|
||||||
|
text,
|
||||||
|
matches: FindMatches::new(text),
|
||||||
|
pending_match: None,
|
||||||
|
last_match_end: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_match(&mut self, mat: Match) -> HandleMatch {
|
||||||
|
// Update last match end
|
||||||
|
self.last_match_end = mat.end;
|
||||||
|
|
||||||
|
// Extract the matched string
|
||||||
|
let data: &str = &self.text[mat.start..mat.end];
|
||||||
|
|
||||||
|
// Parse NIP-21 URI
|
||||||
|
match Nip21::parse(data) {
|
||||||
|
Ok(uri) => HandleMatch::Token(Token {
|
||||||
|
value: uri,
|
||||||
|
range: mat.start..mat.end,
|
||||||
|
}),
|
||||||
|
// If the nostr URI parsing is invalid, skip it
|
||||||
|
Err(_) => HandleMatch::Recursion,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Iterator for NostrParserIter<'a> {
|
||||||
|
type Item = Token;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
// Handle a pending match
|
||||||
|
if let Some(pending_match) = self.pending_match.take() {
|
||||||
|
return match self.handle_match(pending_match) {
|
||||||
|
HandleMatch::Token(token) => Some(token),
|
||||||
|
HandleMatch::Recursion => self.next(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.matches.next() {
|
||||||
|
Some(mat) => {
|
||||||
|
// Skip any text before this match
|
||||||
|
if mat.start > self.last_match_end {
|
||||||
|
// Update pending match
|
||||||
|
// This will be handled at next iteration, in `handle_match` method.
|
||||||
|
self.pending_match = Some(mat);
|
||||||
|
|
||||||
|
// Skip the text before the match
|
||||||
|
self.last_match_end = mat.start;
|
||||||
|
return self.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle match
|
||||||
|
match self.handle_match(mat) {
|
||||||
|
HandleMatch::Token(token) => Some(token),
|
||||||
|
HandleMatch::Recursion => self.next(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,13 @@ pub fn home_dir() -> &'static PathBuf {
|
|||||||
HOME_DIR.get_or_init(|| dirs::home_dir().expect("failed to determine home directory"))
|
HOME_DIR.get_or_init(|| dirs::home_dir().expect("failed to determine home directory"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the path to the user's download directory.
|
||||||
|
pub fn download_dir() -> &'static PathBuf {
|
||||||
|
static DOWNLOAD_DIR: OnceLock<PathBuf> = OnceLock::new();
|
||||||
|
DOWNLOAD_DIR
|
||||||
|
.get_or_init(|| dirs::download_dir().expect("failed to determine download directory"))
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the path to the configuration directory used by Coop.
|
/// Returns the path to the configuration directory used by Coop.
|
||||||
pub fn config_dir() -> &'static PathBuf {
|
pub fn config_dir() -> &'static PathBuf {
|
||||||
static CONFIG_DIR: OnceLock<PathBuf> = OnceLock::new();
|
static CONFIG_DIR: OnceLock<PathBuf> = OnceLock::new();
|
||||||
@@ -56,9 +63,3 @@ pub fn support_dir() -> &'static PathBuf {
|
|||||||
config_dir().clone()
|
config_dir().clone()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the path to the `nostr` file.
|
|
||||||
pub fn nostr_file() -> &'static PathBuf {
|
|
||||||
static NOSTR_FILE: OnceLock<PathBuf> = OnceLock::new();
|
|
||||||
NOSTR_FILE.get_or_init(|| support_dir().join("nostr-db"))
|
|
||||||
}
|
|
||||||
|
|||||||
45
crates/common/src/range.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
use std::cmp::{self};
|
||||||
|
use std::ops::{Range, RangeInclusive};
|
||||||
|
|
||||||
|
pub trait RangeExt<T> {
|
||||||
|
fn sorted(&self) -> Self;
|
||||||
|
fn to_inclusive(&self) -> RangeInclusive<T>;
|
||||||
|
fn overlaps(&self, other: &Range<T>) -> bool;
|
||||||
|
fn contains_inclusive(&self, other: &Range<T>) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Ord + Clone> RangeExt<T> for Range<T> {
|
||||||
|
fn sorted(&self) -> Self {
|
||||||
|
cmp::min(&self.start, &self.end).clone()..cmp::max(&self.start, &self.end).clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_inclusive(&self) -> RangeInclusive<T> {
|
||||||
|
self.start.clone()..=self.end.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn overlaps(&self, other: &Range<T>) -> bool {
|
||||||
|
self.start < other.end && other.start < self.end
|
||||||
|
}
|
||||||
|
|
||||||
|
fn contains_inclusive(&self, other: &Range<T>) -> bool {
|
||||||
|
self.start <= other.start && other.end <= self.end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Ord + Clone> RangeExt<T> for RangeInclusive<T> {
|
||||||
|
fn sorted(&self) -> Self {
|
||||||
|
cmp::min(self.start(), self.end()).clone()..=cmp::max(self.start(), self.end()).clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_inclusive(&self) -> RangeInclusive<T> {
|
||||||
|
self.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn overlaps(&self, other: &Range<T>) -> bool {
|
||||||
|
self.start() < &other.end && &other.start <= self.end()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn contains_inclusive(&self, other: &Range<T>) -> bool {
|
||||||
|
self.start() <= &other.start && &other.end <= self.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ product-name = "Coop"
|
|||||||
description = "Chat Freely, Stay Private on Nostr"
|
description = "Chat Freely, Stay Private on Nostr"
|
||||||
identifier = "su.reya.coop"
|
identifier = "su.reya.coop"
|
||||||
category = "SocialNetworking"
|
category = "SocialNetworking"
|
||||||
version = "0.3.0"
|
version = "1.0.0-beta3"
|
||||||
out-dir = "../../dist"
|
out-dir = "../../dist"
|
||||||
before-packaging-command = "cargo build --release"
|
before-packaging-command = "cargo build --release"
|
||||||
resources = ["Cargo.toml", "src"]
|
resources = ["Cargo.toml", "src"]
|
||||||
@@ -34,7 +34,6 @@ theme = { path = "../theme" }
|
|||||||
common = { path = "../common" }
|
common = { path = "../common" }
|
||||||
state = { path = "../state" }
|
state = { path = "../state" }
|
||||||
device = { path = "../device" }
|
device = { path = "../device" }
|
||||||
key_store = { path = "../key_store" }
|
|
||||||
chat = { path = "../chat" }
|
chat = { path = "../chat" }
|
||||||
chat_ui = { path = "../chat_ui" }
|
chat_ui = { path = "../chat_ui" }
|
||||||
settings = { path = "../settings" }
|
settings = { path = "../settings" }
|
||||||
@@ -63,6 +62,10 @@ smol.workspace = true
|
|||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
oneshot.workspace = true
|
oneshot.workspace = true
|
||||||
webbrowser.workspace = true
|
webbrowser.workspace = true
|
||||||
|
tracing-subscriber.workspace = true
|
||||||
|
|
||||||
indexset = "0.12.3"
|
indexset = "0.12.3"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
|
# Temporary workaround https://github.com/zed-industries/zed/issues/47168
|
||||||
|
core-text = "=21.0.0"
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
use gpui::{actions, App};
|
|
||||||
use key_store::{KeyItem, KeyStore};
|
|
||||||
use nostr_connect::prelude::*;
|
|
||||||
use state::NostrRegistry;
|
|
||||||
|
|
||||||
// Sidebar actions
|
|
||||||
actions!(sidebar, [Reload, RelayStatus]);
|
|
||||||
|
|
||||||
// User actions
|
|
||||||
actions!(
|
|
||||||
coop,
|
|
||||||
[
|
|
||||||
KeyringPopup,
|
|
||||||
DarkMode,
|
|
||||||
ViewProfile,
|
|
||||||
ViewRelays,
|
|
||||||
Themes,
|
|
||||||
Settings,
|
|
||||||
Logout,
|
|
||||||
Quit
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct CoopAuthUrlHandler;
|
|
||||||
|
|
||||||
impl AuthUrlHandler for CoopAuthUrlHandler {
|
|
||||||
#[allow(mismatched_lifetime_syntaxes)]
|
|
||||||
fn on_auth_url(&self, auth_url: Url) -> BoxedFuture<Result<()>> {
|
|
||||||
Box::pin(async move {
|
|
||||||
log::info!("Received Auth URL: {auth_url}");
|
|
||||||
webbrowser::open(auth_url.as_str())?;
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load_embedded_fonts(cx: &App) {
|
|
||||||
let asset_source = cx.asset_source();
|
|
||||||
let font_paths = asset_source.list("fonts").unwrap();
|
|
||||||
let embedded_fonts = Mutex::new(Vec::new());
|
|
||||||
let executor = cx.background_executor();
|
|
||||||
|
|
||||||
cx.foreground_executor().block_on(executor.scoped(|scope| {
|
|
||||||
for font_path in &font_paths {
|
|
||||||
if !font_path.ends_with(".ttf") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
scope.spawn(async {
|
|
||||||
let font_bytes = asset_source.load(font_path).unwrap().unwrap();
|
|
||||||
embedded_fonts.lock().unwrap().push(font_bytes);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
cx.text_system()
|
|
||||||
.add_fonts(embedded_fonts.into_inner().unwrap())
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset(cx: &mut App) {
|
|
||||||
let backend = KeyStore::global(cx).read(cx).backend();
|
|
||||||
let client = NostrRegistry::global(cx).read(cx).client();
|
|
||||||
|
|
||||||
cx.spawn(async move |cx| {
|
|
||||||
// Remove the signer
|
|
||||||
client.unset_signer().await;
|
|
||||||
|
|
||||||
// Delete user's credentials
|
|
||||||
backend
|
|
||||||
.delete_credentials(&KeyItem::User.to_string(), cx)
|
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
// Remove bunker's credentials if available
|
|
||||||
backend
|
|
||||||
.delete_credentials(&KeyItem::Bunker.to_string(), cx)
|
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
cx.update(|cx| {
|
|
||||||
cx.restart();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn quit(_: &Quit, cx: &mut App) {
|
|
||||||
log::info!("Gracefully quitting the application . . .");
|
|
||||||
cx.quit();
|
|
||||||
}
|
|
||||||
257
crates/coop/src/dialogs/accounts.rs
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
use anyhow::Error;
|
||||||
|
use gpui::prelude::FluentBuilder;
|
||||||
|
use gpui::{
|
||||||
|
App, AppContext, Context, Entity, InteractiveElement, IntoElement, ParentElement, Render,
|
||||||
|
SharedString, StatefulInteractiveElement, Styled, Subscription, Task, Window, div, px,
|
||||||
|
};
|
||||||
|
use nostr_sdk::prelude::*;
|
||||||
|
use person::PersonRegistry;
|
||||||
|
use state::{NostrRegistry, StateEvent};
|
||||||
|
use theme::ActiveTheme;
|
||||||
|
use ui::avatar::Avatar;
|
||||||
|
use ui::button::{Button, ButtonVariants};
|
||||||
|
use ui::indicator::Indicator;
|
||||||
|
use ui::{Disableable, Icon, IconName, Sizable, WindowExtension, h_flex, v_flex};
|
||||||
|
|
||||||
|
use crate::dialogs::connect::ConnectSigner;
|
||||||
|
use crate::dialogs::import::ImportKey;
|
||||||
|
|
||||||
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<AccountSelector> {
|
||||||
|
cx.new(|cx| AccountSelector::new(window, cx))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Account selector
|
||||||
|
pub struct AccountSelector {
|
||||||
|
/// Public key currently being chosen for login
|
||||||
|
logging_in: Entity<Option<PublicKey>>,
|
||||||
|
|
||||||
|
/// The error message displayed when an error occurs.
|
||||||
|
error: Entity<Option<SharedString>>,
|
||||||
|
|
||||||
|
/// Async tasks
|
||||||
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
|
|
||||||
|
/// Subscription to the signer events
|
||||||
|
_subscription: Option<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AccountSelector {
|
||||||
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let logging_in = cx.new(|_| None);
|
||||||
|
let error = cx.new(|_| None);
|
||||||
|
|
||||||
|
// Subscribe to the signer events
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let subscription = cx.subscribe_in(&nostr, window, |this, _state, event, window, cx| {
|
||||||
|
match event {
|
||||||
|
StateEvent::SignerSet => {
|
||||||
|
window.close_all_modals(cx);
|
||||||
|
window.refresh();
|
||||||
|
}
|
||||||
|
StateEvent::Error(e) => {
|
||||||
|
this.set_error(e.to_string(), cx);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
logging_in,
|
||||||
|
error,
|
||||||
|
tasks: vec![],
|
||||||
|
_subscription: Some(subscription),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn logging_in(&self, public_key: &PublicKey, cx: &App) -> bool {
|
||||||
|
self.logging_in.read(cx) == &Some(*public_key)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_logging_in(&mut self, public_key: PublicKey, cx: &mut Context<Self>) {
|
||||||
|
self.logging_in.update(cx, |this, cx| {
|
||||||
|
*this = Some(public_key);
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_error<T>(&mut self, error: T, cx: &mut Context<Self>)
|
||||||
|
where
|
||||||
|
T: Into<SharedString>,
|
||||||
|
{
|
||||||
|
self.error.update(cx, |this, cx| {
|
||||||
|
*this = Some(error.into());
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.logging_in.update(cx, |this, cx| {
|
||||||
|
*this = None;
|
||||||
|
cx.notify();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn login(&mut self, public_key: PublicKey, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let task = nostr.read(cx).get_secret(public_key, cx);
|
||||||
|
|
||||||
|
// Mark the public key as being logged in
|
||||||
|
self.set_logging_in(public_key, cx);
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
match task.await {
|
||||||
|
Ok(signer) => {
|
||||||
|
nostr.update(cx, |this, cx| {
|
||||||
|
this.set_signer(signer, cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.set_error(e.to_string(), cx);
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove(&mut self, public_key: PublicKey, cx: &mut Context<Self>) {
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
|
||||||
|
nostr.update(cx, |this, cx| {
|
||||||
|
this.remove_secret(&public_key, cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_import(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let import = cx.new(|cx| ImportKey::new(window, cx));
|
||||||
|
|
||||||
|
window.open_modal(cx, move |this, _window, _cx| {
|
||||||
|
this.width(px(460.))
|
||||||
|
.title("Import a Secret Key or Bunker Connection")
|
||||||
|
.show_close(true)
|
||||||
|
.pb_2()
|
||||||
|
.child(import.clone())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_connect(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let connect = cx.new(|cx| ConnectSigner::new(window, cx));
|
||||||
|
|
||||||
|
window.open_modal(cx, move |this, _window, _cx| {
|
||||||
|
this.width(px(460.))
|
||||||
|
.title("Scan QR Code to Connect")
|
||||||
|
.show_close(true)
|
||||||
|
.pb_2()
|
||||||
|
.child(connect.clone())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for AccountSelector {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let persons = PersonRegistry::global(cx);
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let npubs = nostr.read(cx).npubs();
|
||||||
|
let loading = self.logging_in.read(cx).is_some();
|
||||||
|
|
||||||
|
v_flex()
|
||||||
|
.size_full()
|
||||||
|
.gap_2()
|
||||||
|
.when_some(self.error.read(cx).as_ref(), |this, error| {
|
||||||
|
this.child(
|
||||||
|
div()
|
||||||
|
.italic()
|
||||||
|
.text_xs()
|
||||||
|
.text_center()
|
||||||
|
.text_color(cx.theme().text_danger)
|
||||||
|
.child(error.clone()),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.children({
|
||||||
|
let mut items = vec![];
|
||||||
|
|
||||||
|
for (ix, public_key) in npubs.read(cx).iter().enumerate() {
|
||||||
|
let profile = persons.read(cx).get(public_key, cx);
|
||||||
|
let logging_in = self.logging_in(public_key, cx);
|
||||||
|
|
||||||
|
items.push(
|
||||||
|
h_flex()
|
||||||
|
.id(ix)
|
||||||
|
.group("")
|
||||||
|
.px_2()
|
||||||
|
.h_10()
|
||||||
|
.justify_between()
|
||||||
|
.w_full()
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
|
.bg(cx.theme().ghost_element_background)
|
||||||
|
.hover(|this| this.bg(cx.theme().ghost_element_hover))
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_2()
|
||||||
|
.child(Avatar::new(profile.avatar()).small())
|
||||||
|
.child(div().text_sm().child(profile.name())),
|
||||||
|
)
|
||||||
|
.when(logging_in, |this| this.child(Indicator::new().small()))
|
||||||
|
.when(!logging_in, |this| {
|
||||||
|
this.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.invisible()
|
||||||
|
.group_hover("", |this| this.visible())
|
||||||
|
.child(
|
||||||
|
Button::new(format!("del-{ix}"))
|
||||||
|
.icon(IconName::Close)
|
||||||
|
.ghost()
|
||||||
|
.small()
|
||||||
|
.disabled(logging_in)
|
||||||
|
.on_click(cx.listener({
|
||||||
|
let public_key = *public_key;
|
||||||
|
move |this, _ev, _window, cx| {
|
||||||
|
cx.stop_propagation();
|
||||||
|
this.remove(public_key, cx);
|
||||||
|
}
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when(!logging_in, |this| {
|
||||||
|
let public_key = *public_key;
|
||||||
|
this.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||||
|
this.login(public_key, window, cx);
|
||||||
|
}))
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
items
|
||||||
|
})
|
||||||
|
.child(div().w_full().h_px().bg(cx.theme().border_variant))
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.justify_end()
|
||||||
|
.w_full()
|
||||||
|
.child(
|
||||||
|
Button::new("input")
|
||||||
|
.icon(Icon::new(IconName::Usb))
|
||||||
|
.label("Import")
|
||||||
|
.ghost()
|
||||||
|
.small()
|
||||||
|
.disabled(loading)
|
||||||
|
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||||
|
this.open_import(window, cx);
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("qr")
|
||||||
|
.icon(Icon::new(IconName::Scan))
|
||||||
|
.label("Scan QR to connect")
|
||||||
|
.ghost()
|
||||||
|
.small()
|
||||||
|
.disabled(loading)
|
||||||
|
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||||
|
this.open_connect(window, cx);
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
115
crates/coop/src/dialogs/connect.rs
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use common::StringExt;
|
||||||
|
use gpui::prelude::FluentBuilder;
|
||||||
|
use gpui::{
|
||||||
|
AppContext, Context, Entity, Image, IntoElement, ParentElement, Render, SharedString, Styled,
|
||||||
|
Subscription, Window, div, img, px,
|
||||||
|
};
|
||||||
|
use nostr_connect::prelude::*;
|
||||||
|
use state::{
|
||||||
|
CLIENT_NAME, CoopAuthUrlHandler, NOSTR_CONNECT_RELAY, NOSTR_CONNECT_TIMEOUT, NostrRegistry,
|
||||||
|
StateEvent,
|
||||||
|
};
|
||||||
|
use theme::ActiveTheme;
|
||||||
|
use ui::v_flex;
|
||||||
|
|
||||||
|
pub struct ConnectSigner {
|
||||||
|
/// QR Code
|
||||||
|
qr_code: Option<Arc<Image>>,
|
||||||
|
|
||||||
|
/// Error message
|
||||||
|
error: Entity<Option<SharedString>>,
|
||||||
|
|
||||||
|
/// Subscription to the signer event
|
||||||
|
_subscription: Option<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ConnectSigner {
|
||||||
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let error = cx.new(|_| None);
|
||||||
|
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let app_keys = nostr.read(cx).keys();
|
||||||
|
|
||||||
|
let timeout = Duration::from_secs(NOSTR_CONNECT_TIMEOUT);
|
||||||
|
let relay = RelayUrl::parse(NOSTR_CONNECT_RELAY).unwrap();
|
||||||
|
|
||||||
|
// Generate the nostr connect uri
|
||||||
|
let uri = NostrConnectUri::client(app_keys.public_key(), vec![relay], CLIENT_NAME);
|
||||||
|
|
||||||
|
// Generate the nostr connect
|
||||||
|
let mut signer = NostrConnect::new(uri.clone(), app_keys.clone(), timeout, None).unwrap();
|
||||||
|
|
||||||
|
// Handle the auth request
|
||||||
|
signer.auth_url_handler(CoopAuthUrlHandler);
|
||||||
|
|
||||||
|
// Generate a QR code for quick connection
|
||||||
|
let qr_code = uri.to_string().to_qr();
|
||||||
|
|
||||||
|
// Set signer in the background
|
||||||
|
nostr.update(cx, |this, cx| {
|
||||||
|
this.add_nip46_signer(&signer, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Subscribe to the signer event
|
||||||
|
let subscription = cx.subscribe_in(&nostr, window, |this, _state, event, _window, cx| {
|
||||||
|
if let StateEvent::Error(e) = event {
|
||||||
|
this.set_error(e, cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
qr_code,
|
||||||
|
error,
|
||||||
|
_subscription: Some(subscription),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_error<S>(&mut self, message: S, cx: &mut Context<Self>)
|
||||||
|
where
|
||||||
|
S: Into<SharedString>,
|
||||||
|
{
|
||||||
|
self.error.update(cx, |this, cx| {
|
||||||
|
*this = Some(message.into());
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ConnectSigner {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
const MSG: &str = "Scan with any Nostr Connect-compatible app to connect";
|
||||||
|
|
||||||
|
v_flex()
|
||||||
|
.size_full()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.p_4()
|
||||||
|
.when_some(self.qr_code.as_ref(), |this, qr| {
|
||||||
|
this.child(
|
||||||
|
img(qr.clone())
|
||||||
|
.size(px(256.))
|
||||||
|
.rounded(cx.theme().radius_lg)
|
||||||
|
.border_1()
|
||||||
|
.border_color(cx.theme().border),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when_some(self.error.read(cx).as_ref(), |this, error| {
|
||||||
|
this.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_center()
|
||||||
|
.text_color(cx.theme().text_danger)
|
||||||
|
.child(error.clone()),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from(MSG)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
300
crates/coop/src/dialogs/import.rs
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use anyhow::{Error, anyhow};
|
||||||
|
use gpui::prelude::FluentBuilder;
|
||||||
|
use gpui::{
|
||||||
|
AppContext, Context, Entity, IntoElement, ParentElement, Render, SharedString, Styled,
|
||||||
|
Subscription, Task, Window, div,
|
||||||
|
};
|
||||||
|
use nostr_connect::prelude::*;
|
||||||
|
use smallvec::{SmallVec, smallvec};
|
||||||
|
use state::{CoopAuthUrlHandler, NostrRegistry, StateEvent};
|
||||||
|
use theme::ActiveTheme;
|
||||||
|
use ui::button::{Button, ButtonVariants};
|
||||||
|
use ui::input::{InputEvent, InputState, TextInput};
|
||||||
|
use ui::{Disableable, v_flex};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ImportKey {
|
||||||
|
/// Secret key input
|
||||||
|
key_input: Entity<InputState>,
|
||||||
|
|
||||||
|
/// Password input (if required)
|
||||||
|
pass_input: Entity<InputState>,
|
||||||
|
|
||||||
|
/// Error message
|
||||||
|
error: Entity<Option<SharedString>>,
|
||||||
|
|
||||||
|
/// Countdown timer for nostr connect
|
||||||
|
countdown: Entity<Option<u64>>,
|
||||||
|
|
||||||
|
/// Whether the user is currently loading
|
||||||
|
loading: bool,
|
||||||
|
|
||||||
|
/// Async tasks
|
||||||
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
|
|
||||||
|
/// Event subscriptions
|
||||||
|
_subscriptions: SmallVec<[Subscription; 2]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImportKey {
|
||||||
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let key_input = cx.new(|cx| InputState::new(window, cx).masked(true));
|
||||||
|
let pass_input = cx.new(|cx| InputState::new(window, cx).masked(true));
|
||||||
|
let error = cx.new(|_| None);
|
||||||
|
let countdown = cx.new(|_| None);
|
||||||
|
|
||||||
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
|
subscriptions.push(
|
||||||
|
// Subscribe to key input events and process login when the user presses enter
|
||||||
|
cx.subscribe_in(&key_input, window, |this, _input, event, window, cx| {
|
||||||
|
if let InputEvent::PressEnter { .. } = event {
|
||||||
|
this.login(window, cx);
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
subscriptions.push(
|
||||||
|
// Subscribe to the nostr signer event
|
||||||
|
cx.subscribe_in(&nostr, window, |this, _state, event, _window, cx| {
|
||||||
|
if let StateEvent::Error(e) = event {
|
||||||
|
this.set_error(e, cx);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
key_input,
|
||||||
|
pass_input,
|
||||||
|
error,
|
||||||
|
countdown,
|
||||||
|
loading: false,
|
||||||
|
tasks: vec![],
|
||||||
|
_subscriptions: subscriptions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn login(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self.loading {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
// Prevent duplicate login requests
|
||||||
|
self.set_loading(true, cx);
|
||||||
|
|
||||||
|
let value = self.key_input.read(cx).value();
|
||||||
|
let password = self.pass_input.read(cx).value();
|
||||||
|
|
||||||
|
if value.starts_with("bunker://") {
|
||||||
|
self.bunker(&value, window, cx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if value.starts_with("ncryptsec1") {
|
||||||
|
self.ncryptsec(value, password, window, cx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(secret) = SecretKey::parse(&value) {
|
||||||
|
let keys = Keys::new(secret);
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
|
||||||
|
// Update the signer
|
||||||
|
nostr.update(cx, |this, cx| {
|
||||||
|
this.add_key_signer(&keys, cx);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
self.set_error("Invalid key", cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bunker(&mut self, content: &str, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let Ok(uri) = NostrConnectUri::parse(content) else {
|
||||||
|
self.set_error("Bunker is not valid", cx);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let app_keys = nostr.read(cx).keys();
|
||||||
|
let timeout = Duration::from_secs(30);
|
||||||
|
|
||||||
|
// Construct the nostr connect signer
|
||||||
|
let mut signer = NostrConnect::new(uri, app_keys.clone(), timeout, None).unwrap();
|
||||||
|
|
||||||
|
// Handle auth url with the default browser
|
||||||
|
signer.auth_url_handler(CoopAuthUrlHandler);
|
||||||
|
|
||||||
|
// Set signer in the background
|
||||||
|
nostr.update(cx, |this, cx| {
|
||||||
|
this.add_nip46_signer(&signer, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start countdown
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
for i in (0..=30).rev() {
|
||||||
|
if i == 0 {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.set_countdown(None, cx);
|
||||||
|
})?;
|
||||||
|
} else {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.set_countdown(Some(i), cx);
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
cx.background_executor().timer(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ncryptsec<S>(&mut self, content: S, pwd: S, window: &mut Window, cx: &mut Context<Self>)
|
||||||
|
where
|
||||||
|
S: Into<String>,
|
||||||
|
{
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let content: String = content.into();
|
||||||
|
let password: String = pwd.into();
|
||||||
|
|
||||||
|
if password.is_empty() {
|
||||||
|
self.set_error("Password is required", cx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let Ok(enc) = EncryptedSecretKey::from_bech32(&content) else {
|
||||||
|
self.set_error("Secret Key is invalid", cx);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Decrypt in the background to ensure it doesn't block the UI
|
||||||
|
let task = cx.background_spawn(async move {
|
||||||
|
if let Ok(content) = enc.decrypt(&password) {
|
||||||
|
Ok(Keys::new(content))
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("Invalid password"))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
match task.await {
|
||||||
|
Ok(keys) => {
|
||||||
|
nostr.update(cx, |this, cx| {
|
||||||
|
this.add_key_signer(&keys, cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.set_error(e.to_string(), cx);
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_error<S>(&mut self, message: S, cx: &mut Context<Self>)
|
||||||
|
where
|
||||||
|
S: Into<SharedString>,
|
||||||
|
{
|
||||||
|
// Reset the log in state
|
||||||
|
self.set_loading(false, cx);
|
||||||
|
|
||||||
|
// Reset the countdown
|
||||||
|
self.set_countdown(None, cx);
|
||||||
|
|
||||||
|
// Update error message
|
||||||
|
self.error.update(cx, |this, cx| {
|
||||||
|
*this = Some(message.into());
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear the error message after 3 secs
|
||||||
|
self.tasks.push(cx.spawn(async move |this, cx| {
|
||||||
|
cx.background_executor().timer(Duration::from_secs(3)).await;
|
||||||
|
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.error.update(cx, |this, cx| {
|
||||||
|
*this = None;
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_loading(&mut self, status: bool, cx: &mut Context<Self>) {
|
||||||
|
self.loading = status;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_countdown(&mut self, i: Option<u64>, cx: &mut Context<Self>) {
|
||||||
|
self.countdown.update(cx, |this, cx| {
|
||||||
|
*this = i;
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ImportKey {
|
||||||
|
fn render(&mut self, _window: &mut gpui::Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
v_flex()
|
||||||
|
.size_full()
|
||||||
|
.gap_2()
|
||||||
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child("nsec or bunker://")
|
||||||
|
.child(TextInput::new(&self.key_input)),
|
||||||
|
)
|
||||||
|
.when(
|
||||||
|
self.key_input.read(cx).value().starts_with("ncryptsec1"),
|
||||||
|
|this| {
|
||||||
|
this.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child("Password:")
|
||||||
|
.child(TextInput::new(&self.pass_input)),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("login")
|
||||||
|
.label("Continue")
|
||||||
|
.primary()
|
||||||
|
.loading(self.loading)
|
||||||
|
.disabled(self.loading)
|
||||||
|
.on_click(cx.listener(move |this, _, window, cx| {
|
||||||
|
this.login(window, cx);
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.when_some(self.countdown.read(cx).as_ref(), |this, i| {
|
||||||
|
this.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_center()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from(format!(
|
||||||
|
"Approve connection request from your signer in {} seconds",
|
||||||
|
i
|
||||||
|
))),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when_some(self.error.read(cx).as_ref(), |this, error| {
|
||||||
|
this.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_center()
|
||||||
|
.text_color(cx.theme().text_danger)
|
||||||
|
.child(error.clone()),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,6 @@
|
|||||||
|
pub mod accounts;
|
||||||
|
pub mod connect;
|
||||||
|
pub mod import;
|
||||||
|
pub mod restore;
|
||||||
pub mod screening;
|
pub mod screening;
|
||||||
|
pub mod settings;
|
||||||
|
|||||||
130
crates/coop/src/dialogs/restore.rs
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use anyhow::Error;
|
||||||
|
use device::DeviceRegistry;
|
||||||
|
use gpui::prelude::FluentBuilder;
|
||||||
|
use gpui::{
|
||||||
|
AppContext, Context, Entity, IntoElement, ParentElement, Render, SharedString, Styled,
|
||||||
|
Subscription, Task, Window, div,
|
||||||
|
};
|
||||||
|
use nostr_connect::prelude::*;
|
||||||
|
use theme::ActiveTheme;
|
||||||
|
use ui::button::{Button, ButtonVariants};
|
||||||
|
use ui::input::{InputEvent, InputState, TextInput};
|
||||||
|
use ui::{WindowExtension, v_flex};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct RestoreEncryption {
|
||||||
|
/// Secret key input
|
||||||
|
key_input: Entity<InputState>,
|
||||||
|
|
||||||
|
/// Error message
|
||||||
|
error: Entity<Option<SharedString>>,
|
||||||
|
|
||||||
|
/// Async tasks
|
||||||
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
|
|
||||||
|
/// Event subscription
|
||||||
|
_subscription: Option<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RestoreEncryption {
|
||||||
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let key_input = cx.new(|cx| InputState::new(window, cx).masked(true));
|
||||||
|
let error = cx.new(|_| None);
|
||||||
|
|
||||||
|
let subscription =
|
||||||
|
cx.subscribe_in(&key_input, window, |this, _input, event, window, cx| {
|
||||||
|
if let InputEvent::PressEnter { .. } = event {
|
||||||
|
this.restore(window, cx);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
key_input,
|
||||||
|
error,
|
||||||
|
tasks: vec![],
|
||||||
|
_subscription: Some(subscription),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn restore(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let device = DeviceRegistry::global(cx);
|
||||||
|
let content = self.key_input.read(cx).value();
|
||||||
|
|
||||||
|
if !content.is_empty() {
|
||||||
|
self.set_error("Secret Key cannot be empty.", cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
let Ok(secret) = SecretKey::parse(&content) else {
|
||||||
|
self.set_error("Secret Key is invalid.", cx);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
device.update(cx, |this, cx| {
|
||||||
|
this.set_announcement(Keys::new(secret), cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Close the current modal
|
||||||
|
window.close_modal(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_error<S>(&mut self, message: S, cx: &mut Context<Self>)
|
||||||
|
where
|
||||||
|
S: Into<SharedString>,
|
||||||
|
{
|
||||||
|
// Update error message
|
||||||
|
self.error.update(cx, |this, cx| {
|
||||||
|
*this = Some(message.into());
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear the error message after 3 secs
|
||||||
|
self.tasks.push(cx.spawn(async move |this, cx| {
|
||||||
|
cx.background_executor().timer(Duration::from_secs(3)).await;
|
||||||
|
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.error.update(cx, |this, cx| {
|
||||||
|
*this = None;
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for RestoreEncryption {
|
||||||
|
fn render(&mut self, _window: &mut gpui::Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
v_flex()
|
||||||
|
.size_full()
|
||||||
|
.gap_2()
|
||||||
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child("Secret Key")
|
||||||
|
.child(TextInput::new(&self.key_input)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("restore")
|
||||||
|
.label("Restore")
|
||||||
|
.primary()
|
||||||
|
.on_click(cx.listener(move |this, _, window, cx| {
|
||||||
|
this.restore(window, cx);
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.when_some(self.error.read(cx).as_ref(), |this, error| {
|
||||||
|
this.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_center()
|
||||||
|
.text_color(cx.theme().text_danger)
|
||||||
|
.child(error.clone()),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,21 +2,21 @@ use std::collections::HashMap;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error};
|
||||||
use common::{shorten_pubkey, RenderedTimestamp};
|
use common::TimestampExt;
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, px, relative, rems, uniform_list, App, AppContext, Context, Div, Entity,
|
App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, ParentElement, Render,
|
||||||
InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Task, Window,
|
SharedString, Styled, Subscription, Task, Window, div, px, relative, uniform_list,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use person::{Person, PersonRegistry};
|
use person::{Person, PersonRegistry, shorten_pubkey};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use state::{NostrAddress, NostrRegistry, BOOTSTRAP_RELAYS, TIMEOUT};
|
use state::{BOOTSTRAP_RELAYS, NostrAddress, NostrRegistry, TIMEOUT};
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::indicator::Indicator;
|
use ui::indicator::Indicator;
|
||||||
use ui::{h_flex, v_flex, Icon, IconName, Sizable, StyledExt, WindowExtension};
|
use ui::{Icon, IconName, Sizable, StyledExt, WindowExtension, h_flex, v_flex};
|
||||||
|
|
||||||
pub fn init(public_key: PublicKey, window: &mut Window, cx: &mut App) -> Entity<Screening> {
|
pub fn init(public_key: PublicKey, window: &mut Window, cx: &mut App) -> Entity<Screening> {
|
||||||
cx.new(|cx| Screening::new(public_key, window, cx))
|
cx.new(|cx| Screening::new(public_key, window, cx))
|
||||||
@@ -41,10 +41,20 @@ pub struct Screening {
|
|||||||
|
|
||||||
/// Async tasks
|
/// Async tasks
|
||||||
tasks: SmallVec<[Task<()>; 3]>,
|
tasks: SmallVec<[Task<()>; 3]>,
|
||||||
|
|
||||||
|
/// Subscriptions
|
||||||
|
_subscriptions: SmallVec<[Subscription; 1]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Screening {
|
impl Screening {
|
||||||
pub fn new(public_key: PublicKey, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
pub fn new(public_key: PublicKey, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
|
subscriptions.push(cx.on_release_in(window, move |this, window, cx| {
|
||||||
|
this.tasks.clear();
|
||||||
|
window.close_all_modals(cx);
|
||||||
|
}));
|
||||||
|
|
||||||
cx.defer_in(window, move |this, _window, cx| {
|
cx.defer_in(window, move |this, _window, cx| {
|
||||||
this.check_contact(cx);
|
this.check_contact(cx);
|
||||||
this.check_wot(cx);
|
this.check_wot(cx);
|
||||||
@@ -59,6 +69,7 @@ impl Screening {
|
|||||||
last_active: None,
|
last_active: None,
|
||||||
mutual_contacts: vec![],
|
mutual_contacts: vec![],
|
||||||
tasks: smallvec![],
|
tasks: smallvec![],
|
||||||
|
_subscriptions: subscriptions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,10 +148,10 @@ impl Screening {
|
|||||||
let mut activity: Option<Timestamp> = None;
|
let mut activity: Option<Timestamp> = None;
|
||||||
|
|
||||||
// Construct target for subscription
|
// Construct target for subscription
|
||||||
let target = BOOTSTRAP_RELAYS
|
let target: HashMap<&str, Vec<Filter>> = BOOTSTRAP_RELAYS
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|relay| (relay, vec![filter.clone()]))
|
.map(|relay| (relay, vec![filter.clone()]))
|
||||||
.collect::<HashMap<_, _>>();
|
.collect();
|
||||||
|
|
||||||
if let Ok(mut stream) = client
|
if let Ok(mut stream) = client
|
||||||
.stream_events(target)
|
.stream_events(target)
|
||||||
@@ -243,7 +254,7 @@ impl Screening {
|
|||||||
let total = contacts.len();
|
let total = contacts.len();
|
||||||
|
|
||||||
this.title(SharedString::from("Mutual contacts")).child(
|
this.title(SharedString::from("Mutual contacts")).child(
|
||||||
v_flex().gap_1().pb_4().child(
|
v_flex().gap_1().pb_2().child(
|
||||||
uniform_list("contacts", total, move |range, _window, cx| {
|
uniform_list("contacts", total, move |range, _window, cx| {
|
||||||
let persons = PersonRegistry::global(cx);
|
let persons = PersonRegistry::global(cx);
|
||||||
let mut items = Vec::with_capacity(total);
|
let mut items = Vec::with_capacity(total);
|
||||||
@@ -263,7 +274,7 @@ impl Screening {
|
|||||||
.rounded(cx.theme().radius)
|
.rounded(cx.theme().radius)
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.hover(|this| this.bg(cx.theme().elevated_surface_background))
|
.hover(|this| this.bg(cx.theme().elevated_surface_background))
|
||||||
.child(Avatar::new(profile.avatar()).size(rems(1.75)))
|
.child(Avatar::new(profile.avatar()).small())
|
||||||
.child(profile.name()),
|
.child(profile.name()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -279,11 +290,21 @@ impl Screening {
|
|||||||
|
|
||||||
impl Render for Screening {
|
impl Render for Screening {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
const CONTACT: &str = "This person is one of your contacts.";
|
||||||
|
const NOT_CONTACT: &str = "This person is not one of your contacts.";
|
||||||
|
const NO_ACTIVITY: &str = "This person hasn't had any activity.";
|
||||||
|
const RELAY_INFO: &str = "Only checked on public relays; may be inaccurate.";
|
||||||
|
const NO_MUTUAL: &str = "You don't have any mutual contacts.";
|
||||||
|
const NIP05_MATCH: &str = "The address matches the user's public key.";
|
||||||
|
const NIP05_NOT_MATCH: &str = "The address does not match the user's public key.";
|
||||||
|
const NO_NIP05: &str = "This person has not set up their friendly address";
|
||||||
|
|
||||||
let profile = self.profile(cx);
|
let profile = self.profile(cx);
|
||||||
let shorten_pubkey = shorten_pubkey(self.public_key, 8);
|
let shorten_pubkey = shorten_pubkey(self.public_key, 8);
|
||||||
|
|
||||||
let total_mutuals = self.mutual_contacts.len();
|
|
||||||
let last_active = self.last_active.map(|_| true);
|
let last_active = self.last_active.map(|_| true);
|
||||||
|
let mutuals = self.mutual_contacts.len();
|
||||||
|
let mutuals_str = format!("You have {} mutual contacts with this person.", mutuals);
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_4()
|
.gap_4()
|
||||||
@@ -293,7 +314,7 @@ impl Render for Screening {
|
|||||||
.items_center()
|
.items_center()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.text_center()
|
.text_center()
|
||||||
.child(Avatar::new(profile.avatar()).size(rems(4.)))
|
.child(Avatar::new(profile.avatar()).large())
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.font_semibold()
|
.font_semibold()
|
||||||
@@ -335,8 +356,9 @@ impl Render for Screening {
|
|||||||
.child(
|
.child(
|
||||||
Button::new("report")
|
Button::new("report")
|
||||||
.tooltip("Report as a scam or impostor")
|
.tooltip("Report as a scam or impostor")
|
||||||
.icon(IconName::Boom)
|
.icon(IconName::Warning)
|
||||||
.danger()
|
.small()
|
||||||
|
.warning()
|
||||||
.rounded()
|
.rounded()
|
||||||
.on_click(cx.listener(move |this, _e, window, cx| {
|
.on_click(cx.listener(move |this, _e, window, cx| {
|
||||||
this.report(window, cx);
|
this.report(window, cx);
|
||||||
@@ -363,9 +385,9 @@ impl Render for Screening {
|
|||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.child({
|
.child({
|
||||||
if self.followed {
|
if self.followed {
|
||||||
SharedString::from("This person is one of your contacts.")
|
SharedString::from(CONTACT)
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("This person is not one of your contacts.")
|
SharedString::from(NOT_CONTACT)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -390,7 +412,7 @@ impl Render for Screening {
|
|||||||
.xsmall()
|
.xsmall()
|
||||||
.ghost()
|
.ghost()
|
||||||
.rounded()
|
.rounded()
|
||||||
.tooltip("This may be inaccurate if the user only publishes to their private relays."),
|
.tooltip(RELAY_INFO),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
@@ -399,13 +421,13 @@ impl Render for Screening {
|
|||||||
.line_clamp(1)
|
.line_clamp(1)
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.map(|this| {
|
.map(|this| {
|
||||||
if let Some(date) = self.last_active {
|
if let Some(t) = self.last_active {
|
||||||
this.child(SharedString::from(format!(
|
this.child(SharedString::from(format!(
|
||||||
"Last active: {}.",
|
"Last active: {}.",
|
||||||
date.to_human_time()
|
t.to_human_time()
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
this.child(SharedString::from("This person hasn't had any activity."))
|
this.child(SharedString::from(NO_ACTIVITY))
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -423,7 +445,9 @@ impl Render for Screening {
|
|||||||
if let Some(addr) = self.address(cx) {
|
if let Some(addr) = self.address(cx) {
|
||||||
SharedString::from(format!("{} validation", addr))
|
SharedString::from(format!("{} validation", addr))
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("Friendly Address (NIP-05) validation")
|
SharedString::from(
|
||||||
|
"Friendly Address (NIP-05) validation",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
@@ -433,12 +457,12 @@ impl Render for Screening {
|
|||||||
.child({
|
.child({
|
||||||
if self.address(cx).is_some() {
|
if self.address(cx).is_some() {
|
||||||
if self.verified {
|
if self.verified {
|
||||||
SharedString::from("The address matches the user's public key.")
|
SharedString::from(NIP05_MATCH)
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("The address does not match the user's public key.")
|
SharedString::from(NIP05_NOT_MATCH)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("This person has not set up their friendly address")
|
SharedString::from(NO_NIP05)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -448,7 +472,7 @@ impl Render for Screening {
|
|||||||
h_flex()
|
h_flex()
|
||||||
.items_start()
|
.items_start()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.child(status_badge(Some(total_mutuals > 0), cx))
|
.child(status_badge(Some(mutuals > 0), cx))
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
@@ -474,13 +498,10 @@ impl Render for Screening {
|
|||||||
.line_clamp(1)
|
.line_clamp(1)
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.child({
|
.child({
|
||||||
if total_mutuals > 0 {
|
if mutuals > 0 {
|
||||||
SharedString::from(format!(
|
SharedString::from(mutuals_str)
|
||||||
"You have {} mutual contacts with this person.",
|
|
||||||
total_mutuals
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
SharedString::from("You don't have any mutual contacts with this person.")
|
SharedString::from(NO_MUTUAL)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
242
crates/coop/src/dialogs/settings.rs
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
use gpui::http_client::Url;
|
||||||
|
use gpui::{
|
||||||
|
App, AppContext, Context, Entity, IntoElement, ParentElement, Render, SharedString, Styled,
|
||||||
|
Window, div, px,
|
||||||
|
};
|
||||||
|
use settings::{AppSettings, AuthMode};
|
||||||
|
use theme::{ActiveTheme, Theme, ThemeMode};
|
||||||
|
use ui::button::{Button, ButtonVariants};
|
||||||
|
use ui::group_box::{GroupBox, GroupBoxVariants};
|
||||||
|
use ui::input::{InputState, TextInput};
|
||||||
|
use ui::menu::{DropdownMenu, PopupMenuItem};
|
||||||
|
use ui::notification::Notification;
|
||||||
|
use ui::switch::Switch;
|
||||||
|
use ui::{IconName, Sizable, WindowExtension, h_flex, v_flex};
|
||||||
|
|
||||||
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<Preferences> {
|
||||||
|
cx.new(|cx| Preferences::new(window, cx))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Preferences {
|
||||||
|
file_input: Entity<InputState>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Preferences {
|
||||||
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let server = AppSettings::get_file_server(cx);
|
||||||
|
let file_input = cx.new(|cx| {
|
||||||
|
InputState::new(window, cx)
|
||||||
|
.default_value(server.to_string())
|
||||||
|
.placeholder("https://myblossom.com")
|
||||||
|
});
|
||||||
|
|
||||||
|
Self { file_input }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the file server (blossom) URL
|
||||||
|
fn update_file_server(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let value = self.file_input.read(cx).value();
|
||||||
|
|
||||||
|
match Url::parse(&value) {
|
||||||
|
Ok(url) => {
|
||||||
|
AppSettings::update_file_server(url, cx);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
window.push_notification(Notification::error(e.to_string()).autohide(false), cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the theme mode (light or dark)
|
||||||
|
fn set_theme_mode(mode: ThemeMode, window: &mut Window, cx: &mut App) {
|
||||||
|
AppSettings::update_theme_mode(mode, cx);
|
||||||
|
Theme::change(mode, Some(window), cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for Preferences {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
const SCREENING: &str =
|
||||||
|
"When opening a request, a popup will appear to help you identify the sender.";
|
||||||
|
const AVATAR: &str =
|
||||||
|
"Hide all avatar pictures to improve performance and protect your privacy.";
|
||||||
|
const MODE: &str =
|
||||||
|
"Choose whether to use the selected light or dark theme, or to follow the OS.";
|
||||||
|
const AUTH: &str = "Choose the authentication behavior for relays.";
|
||||||
|
const RESET: &str = "Reset the theme to the default one.";
|
||||||
|
|
||||||
|
let screening = AppSettings::get_screening(cx);
|
||||||
|
let hide_avatar = AppSettings::get_hide_avatar(cx);
|
||||||
|
let auth_mode = AppSettings::get_auth_mode(cx);
|
||||||
|
let theme_mode = AppSettings::get_theme_mode(cx);
|
||||||
|
|
||||||
|
v_flex()
|
||||||
|
.gap_4()
|
||||||
|
.child(
|
||||||
|
GroupBox::new()
|
||||||
|
.id("general")
|
||||||
|
.title("General")
|
||||||
|
.fill()
|
||||||
|
.child(
|
||||||
|
Switch::new("screening")
|
||||||
|
.label("Screening")
|
||||||
|
.description(SCREENING)
|
||||||
|
.checked(screening)
|
||||||
|
.on_click(move |_, _window, cx| {
|
||||||
|
AppSettings::update_screening(!screening, cx);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Switch::new("avatar")
|
||||||
|
.label("Hide user avatar")
|
||||||
|
.description(AVATAR)
|
||||||
|
.checked(hide_avatar)
|
||||||
|
.on_click(move |_, _window, cx| {
|
||||||
|
AppSettings::update_hide_avatar(!hide_avatar, cx);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_3()
|
||||||
|
.justify_between()
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.child(SharedString::from("Relay authentication")),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from(AUTH)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("auth")
|
||||||
|
.label(auth_mode.to_string())
|
||||||
|
.ghost_alt()
|
||||||
|
.small()
|
||||||
|
.dropdown_menu(|this, _window, _cx| {
|
||||||
|
this.min_w(px(256.))
|
||||||
|
.item(
|
||||||
|
PopupMenuItem::new("Auto authentication").on_click(
|
||||||
|
|_ev, _window, cx| {
|
||||||
|
AppSettings::update_auth_mode(
|
||||||
|
AuthMode::Auto,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.item(PopupMenuItem::new("Ask every time").on_click(
|
||||||
|
|_ev, _window, cx| {
|
||||||
|
AppSettings::update_auth_mode(
|
||||||
|
AuthMode::Manual,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
))
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
GroupBox::new()
|
||||||
|
.id("appearance")
|
||||||
|
.title("Appearance")
|
||||||
|
.fill()
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_3()
|
||||||
|
.justify_between()
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.child(div().text_sm().child(SharedString::from("Mode")))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from(MODE)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("theme-mode")
|
||||||
|
.label(theme_mode.name())
|
||||||
|
.ghost_alt()
|
||||||
|
.small()
|
||||||
|
.dropdown_menu(|this, _window, _cx| {
|
||||||
|
this.item(PopupMenuItem::new("Light").on_click(
|
||||||
|
|_, window, cx| {
|
||||||
|
Self::set_theme_mode(ThemeMode::Light, window, cx);
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.item(
|
||||||
|
PopupMenuItem::new("Dark").on_click(|_, window, cx| {
|
||||||
|
Self::set_theme_mode(ThemeMode::Dark, window, cx);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_3()
|
||||||
|
.justify_between()
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.child(div().text_sm().child(SharedString::from("Reset theme")))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from(RESET)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("reset")
|
||||||
|
.label("Reset")
|
||||||
|
.ghost_alt()
|
||||||
|
.small()
|
||||||
|
.on_click(move |_ev, window, cx| {
|
||||||
|
AppSettings::global(cx).update(cx, |this, cx| {
|
||||||
|
this.reset_theme(window, cx);
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
GroupBox::new()
|
||||||
|
.id("media")
|
||||||
|
.title("Media Upload Service")
|
||||||
|
.fill()
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_0p5()
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.child(TextInput::new(&self.file_input).text_xs().small())
|
||||||
|
.child(
|
||||||
|
Button::new("update-file-server")
|
||||||
|
.icon(IconName::Check)
|
||||||
|
.ghost()
|
||||||
|
.size_8()
|
||||||
|
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||||
|
this.update_file_server(window, cx)
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_size(px(10.))
|
||||||
|
.italic()
|
||||||
|
.text_color(cx.theme().text_placeholder)
|
||||||
|
.child(SharedString::from("Only support blossom service")),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,9 @@ use std::sync::{Arc, Mutex};
|
|||||||
|
|
||||||
use assets::Assets;
|
use assets::Assets;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, point, px, size, App, AppContext, Bounds, KeyBinding, Menu, MenuItem, SharedString,
|
App, AppContext, Bounds, KeyBinding, Menu, MenuItem, SharedString, TitlebarOptions,
|
||||||
TitlebarOptions, WindowBackgroundAppearance, WindowBounds, WindowDecorations, WindowKind,
|
WindowBackgroundAppearance, WindowBounds, WindowDecorations, WindowKind, WindowOptions,
|
||||||
WindowOptions,
|
actions, point, px, size,
|
||||||
};
|
};
|
||||||
use gpui_platform::application;
|
use gpui_platform::application;
|
||||||
use state::{APP_ID, CLIENT_NAME};
|
use state::{APP_ID, CLIENT_NAME};
|
||||||
@@ -44,6 +44,7 @@ fn main() {
|
|||||||
cx.set_menus(vec![Menu {
|
cx.set_menus(vec![Menu {
|
||||||
name: "Coop".into(),
|
name: "Coop".into(),
|
||||||
items: vec![MenuItem::action("Quit", Quit)],
|
items: vec![MenuItem::action("Quit", Quit)],
|
||||||
|
disabled: false,
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
// Set up the window bounds
|
// Set up the window bounds
|
||||||
@@ -79,29 +80,26 @@ fn main() {
|
|||||||
// Initialize theme registry
|
// Initialize theme registry
|
||||||
theme::init(cx);
|
theme::init(cx);
|
||||||
|
|
||||||
// Initialize backend for keys storage
|
// Initialize settings
|
||||||
key_store::init(cx);
|
settings::init(window, cx);
|
||||||
|
|
||||||
// Initialize the nostr client
|
// Initialize the nostr client
|
||||||
state::init(window, cx);
|
state::init(window, cx);
|
||||||
|
|
||||||
|
// Initialize person registry
|
||||||
|
person::init(window, cx);
|
||||||
|
|
||||||
|
// Initialize relay auth registry
|
||||||
|
relay_auth::init(window, cx);
|
||||||
|
|
||||||
// Initialize device signer
|
// Initialize device signer
|
||||||
//
|
//
|
||||||
// NIP-4e: https://github.com/nostr-protocol/nips/blob/per-device-keys/4e.md
|
// NIP-4e: https://github.com/nostr-protocol/nips/blob/per-device-keys/4e.md
|
||||||
device::init(window, cx);
|
device::init(window, cx);
|
||||||
|
|
||||||
// Initialize settings
|
|
||||||
settings::init(cx);
|
|
||||||
|
|
||||||
// Initialize relay auth registry
|
|
||||||
relay_auth::init(window, cx);
|
|
||||||
|
|
||||||
// Initialize app registry
|
// Initialize app registry
|
||||||
chat::init(window, cx);
|
chat::init(window, cx);
|
||||||
|
|
||||||
// Initialize person registry
|
|
||||||
person::init(cx);
|
|
||||||
|
|
||||||
// Initialize auto update
|
// Initialize auto update
|
||||||
auto_update::init(window, cx);
|
auto_update::init(window, cx);
|
||||||
|
|
||||||
|
|||||||
202
crates/coop/src/panels/backup.rs
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use anyhow::Error;
|
||||||
|
use gpui::{
|
||||||
|
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
|
||||||
|
Focusable, IntoElement, ParentElement, Render, SharedString, Styled, Task, Window, div,
|
||||||
|
};
|
||||||
|
use nostr_sdk::prelude::*;
|
||||||
|
use state::KEYRING;
|
||||||
|
use theme::ActiveTheme;
|
||||||
|
use ui::button::{Button, ButtonVariants};
|
||||||
|
use ui::dock::{Panel, PanelEvent};
|
||||||
|
use ui::input::{InputState, TextInput};
|
||||||
|
use ui::{IconName, Sizable, StyledExt, divider, v_flex};
|
||||||
|
|
||||||
|
const MSG: &str = "Store your account keys in a safe location. \
|
||||||
|
You can restore your account or move to another client anytime you want.";
|
||||||
|
|
||||||
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<BackupPanel> {
|
||||||
|
cx.new(|cx| BackupPanel::new(window, cx))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct BackupPanel {
|
||||||
|
name: SharedString,
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
|
||||||
|
/// Public key input
|
||||||
|
npub_input: Entity<InputState>,
|
||||||
|
|
||||||
|
/// Secret key input
|
||||||
|
nsec_input: Entity<InputState>,
|
||||||
|
|
||||||
|
/// Copied status
|
||||||
|
copied: bool,
|
||||||
|
|
||||||
|
/// Background tasks
|
||||||
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BackupPanel {
|
||||||
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let npub_input = cx.new(|cx| InputState::new(window, cx).disabled(true));
|
||||||
|
let nsec_input = cx.new(|cx| InputState::new(window, cx).disabled(true).masked(true));
|
||||||
|
|
||||||
|
// Run at the end of current cycle
|
||||||
|
cx.defer_in(window, |this, window, cx| {
|
||||||
|
this.load(window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
name: "Backup".into(),
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
|
npub_input,
|
||||||
|
nsec_input,
|
||||||
|
copied: false,
|
||||||
|
tasks: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let keyring = cx.read_credentials(KEYRING);
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
if let Some((_, secret)) = keyring.await? {
|
||||||
|
let secret = SecretKey::from_slice(&secret)?;
|
||||||
|
let keys = Keys::new(secret);
|
||||||
|
|
||||||
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
this.npub_input.update(cx, |this, cx| {
|
||||||
|
this.set_value(keys.public_key().to_bech32().unwrap(), window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.nsec_input.update(cx, |this, cx| {
|
||||||
|
this.set_value(keys.secret_key().to_bech32().unwrap(), window, cx);
|
||||||
|
});
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn copy_secret(&mut self, cx: &mut Context<Self>) {
|
||||||
|
let value = self.nsec_input.read(cx).value();
|
||||||
|
let item = ClipboardItem::new_string(value.to_string());
|
||||||
|
cx.write_to_clipboard(item);
|
||||||
|
|
||||||
|
// Set the copied status to true
|
||||||
|
self.set_copied(true, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_copied(&mut self, status: bool, cx: &mut Context<Self>) {
|
||||||
|
self.copied = status;
|
||||||
|
cx.notify();
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn(async move |this, cx| {
|
||||||
|
cx.background_executor().timer(Duration::from_secs(2)).await;
|
||||||
|
|
||||||
|
// Clear the error message after a delay
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.set_copied(false, cx);
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Panel for BackupPanel {
|
||||||
|
fn panel_id(&self) -> SharedString {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title(&self, _cx: &App) -> AnyElement {
|
||||||
|
self.name.clone().into_any_element()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<PanelEvent> for BackupPanel {}
|
||||||
|
|
||||||
|
impl Focusable for BackupPanel {
|
||||||
|
fn focus_handle(&self, _: &App) -> gpui::FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for BackupPanel {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
v_flex()
|
||||||
|
.p_3()
|
||||||
|
.gap_3()
|
||||||
|
.w_full()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from(MSG)),
|
||||||
|
)
|
||||||
|
.child(divider(cx))
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_2()
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1p5()
|
||||||
|
.w_full()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.font_semibold()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("Public Key:")),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
TextInput::new(&self.npub_input)
|
||||||
|
.small()
|
||||||
|
.bordered(false)
|
||||||
|
.disabled(true),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1p5()
|
||||||
|
.w_full()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.font_semibold()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("Secret Key:")),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
TextInput::new(&self.nsec_input)
|
||||||
|
.small()
|
||||||
|
.bordered(false)
|
||||||
|
.disabled(true),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("copy")
|
||||||
|
.icon(IconName::Copy)
|
||||||
|
.label({
|
||||||
|
if self.copied {
|
||||||
|
"Copied"
|
||||||
|
} else {
|
||||||
|
"Copy secret key"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.primary()
|
||||||
|
.small()
|
||||||
|
.font_semibold()
|
||||||
|
.on_click(cx.listener(move |this, _ev, _window, cx| {
|
||||||
|
this.copy_secret(cx);
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use common::TextUtils;
|
|
||||||
use gpui::prelude::FluentBuilder;
|
|
||||||
use gpui::{
|
|
||||||
div, img, px, relative, AnyElement, App, AppContext, Context, Entity, EventEmitter,
|
|
||||||
FocusHandle, Focusable, Image, IntoElement, ParentElement, Render, SharedString, Styled, Task,
|
|
||||||
Window,
|
|
||||||
};
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
|
||||||
use state::NostrRegistry;
|
|
||||||
use theme::ActiveTheme;
|
|
||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
|
||||||
use ui::dock_area::ClosePanel;
|
|
||||||
use ui::notification::Notification;
|
|
||||||
use ui::{v_flex, StyledExt, WindowExtension};
|
|
||||||
|
|
||||||
pub fn init(window: &mut Window, cx: &mut App) -> Entity<ConnectPanel> {
|
|
||||||
cx.new(|cx| ConnectPanel::new(window, cx))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ConnectPanel {
|
|
||||||
name: SharedString,
|
|
||||||
focus_handle: FocusHandle,
|
|
||||||
|
|
||||||
/// QR Code
|
|
||||||
qr_code: Option<Arc<Image>>,
|
|
||||||
|
|
||||||
/// Background tasks
|
|
||||||
_tasks: SmallVec<[Task<()>; 1]>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ConnectPanel {
|
|
||||||
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let weak_state = nostr.downgrade();
|
|
||||||
let (signer, uri) = nostr.read(cx).client_connect(None);
|
|
||||||
|
|
||||||
// Generate a QR code for quick connection
|
|
||||||
let qr_code = uri.to_string().to_qr();
|
|
||||||
|
|
||||||
let mut tasks = smallvec![];
|
|
||||||
|
|
||||||
tasks.push(
|
|
||||||
// Wait for nostr connect
|
|
||||||
cx.spawn_in(window, async move |_this, cx| {
|
|
||||||
let result = signer.bunker_uri().await;
|
|
||||||
|
|
||||||
weak_state
|
|
||||||
.update_in(cx, |this, window, cx| {
|
|
||||||
match result {
|
|
||||||
Ok(uri) => {
|
|
||||||
this.persist_bunker(uri, cx);
|
|
||||||
this.set_signer(signer, true, cx);
|
|
||||||
// Close the current panel after setting the signer
|
|
||||||
window.dispatch_action(Box::new(ClosePanel), cx);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
window.push_notification(Notification::error(e.to_string()), cx);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
name: "Nostr Connect".into(),
|
|
||||||
focus_handle: cx.focus_handle(),
|
|
||||||
qr_code,
|
|
||||||
_tasks: tasks,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Panel for ConnectPanel {
|
|
||||||
fn panel_id(&self) -> SharedString {
|
|
||||||
self.name.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn title(&self, _cx: &App) -> AnyElement {
|
|
||||||
self.name.clone().into_any_element()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventEmitter<PanelEvent> for ConnectPanel {}
|
|
||||||
|
|
||||||
impl Focusable for ConnectPanel {
|
|
||||||
fn focus_handle(&self, _: &App) -> gpui::FocusHandle {
|
|
||||||
self.focus_handle.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Render for ConnectPanel {
|
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
||||||
v_flex()
|
|
||||||
.size_full()
|
|
||||||
.items_center()
|
|
||||||
.justify_center()
|
|
||||||
.p_2()
|
|
||||||
.gap_10()
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.justify_center()
|
|
||||||
.items_center()
|
|
||||||
.text_center()
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.font_semibold()
|
|
||||||
.line_height(relative(1.25))
|
|
||||||
.child(SharedString::from("Continue with Nostr Connect")),
|
|
||||||
)
|
|
||||||
.child(div().text_sm().text_color(cx.theme().text_muted).child(
|
|
||||||
SharedString::from("Use Nostr Connect apps to scan the code"),
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
.when_some(self.qr_code.as_ref(), |this, qr| {
|
|
||||||
this.child(
|
|
||||||
img(qr.clone())
|
|
||||||
.size(px(256.))
|
|
||||||
.rounded(cx.theme().radius_lg)
|
|
||||||
.border_1()
|
|
||||||
.border_color(cx.theme().border),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
358
crates/coop/src/panels/contact_list.rs
Normal file
@@ -0,0 +1,358 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use anyhow::{Context as AnyhowContext, Error};
|
||||||
|
use gpui::prelude::FluentBuilder;
|
||||||
|
use gpui::{
|
||||||
|
AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable,
|
||||||
|
InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Subscription,
|
||||||
|
Task, TextAlign, Window, div, rems,
|
||||||
|
};
|
||||||
|
use nostr_sdk::prelude::*;
|
||||||
|
use person::PersonRegistry;
|
||||||
|
use smallvec::{SmallVec, smallvec};
|
||||||
|
use state::NostrRegistry;
|
||||||
|
use theme::ActiveTheme;
|
||||||
|
use ui::avatar::Avatar;
|
||||||
|
use ui::button::{Button, ButtonVariants};
|
||||||
|
use ui::dock::{Panel, PanelEvent};
|
||||||
|
use ui::input::{InputEvent, InputState, TextInput};
|
||||||
|
use ui::{Disableable, IconName, Sizable, StyledExt, WindowExtension, h_flex, v_flex};
|
||||||
|
|
||||||
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<ContactListPanel> {
|
||||||
|
cx.new(|cx| ContactListPanel::new(window, cx))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ContactListPanel {
|
||||||
|
name: SharedString,
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
|
||||||
|
/// Npub input
|
||||||
|
input: Entity<InputState>,
|
||||||
|
|
||||||
|
/// Whether the panel is updating
|
||||||
|
updating: bool,
|
||||||
|
|
||||||
|
/// Error message
|
||||||
|
error: Option<SharedString>,
|
||||||
|
|
||||||
|
/// All contacts
|
||||||
|
contacts: HashSet<PublicKey>,
|
||||||
|
|
||||||
|
/// Event subscriptions
|
||||||
|
_subscriptions: SmallVec<[Subscription; 1]>,
|
||||||
|
|
||||||
|
/// Background tasks
|
||||||
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ContactListPanel {
|
||||||
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let input = cx.new(|cx| InputState::new(window, cx).placeholder("npub1..."));
|
||||||
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
|
subscriptions.push(
|
||||||
|
// Subscribe to user's input events
|
||||||
|
cx.subscribe_in(&input, window, move |this, _input, event, window, cx| {
|
||||||
|
if let InputEvent::PressEnter { .. } = event {
|
||||||
|
this.add(window, cx);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Run at the end of current cycle
|
||||||
|
cx.defer_in(window, |this, window, cx| {
|
||||||
|
this.load(window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
name: "Contact List".into(),
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
|
input,
|
||||||
|
updating: false,
|
||||||
|
contacts: HashSet::new(),
|
||||||
|
error: None,
|
||||||
|
_subscriptions: subscriptions,
|
||||||
|
tasks: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
|
let task: Task<Result<HashSet<PublicKey>, Error>> = cx.background_spawn(async move {
|
||||||
|
let signer = client.signer().context("Signer not found")?;
|
||||||
|
let public_key = signer.get_public_key().await?;
|
||||||
|
let contact_list = client.database().contacts_public_keys(public_key).await?;
|
||||||
|
|
||||||
|
Ok(contact_list)
|
||||||
|
});
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
let public_keys = task.await?;
|
||||||
|
|
||||||
|
// Update state
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.contacts.extend(public_keys);
|
||||||
|
cx.notify();
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let value = self.input.read(cx).value().to_string();
|
||||||
|
|
||||||
|
if let Ok(public_key) = PublicKey::parse(&value) {
|
||||||
|
if self.contacts.insert(public_key) {
|
||||||
|
self.input.update(cx, |this, cx| {
|
||||||
|
this.set_value("", window, cx);
|
||||||
|
});
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.set_error("Public Key is invalid", window, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove(&mut self, public_key: &PublicKey, cx: &mut Context<Self>) {
|
||||||
|
self.contacts.remove(public_key);
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_error<E>(&mut self, error: E, window: &mut Window, cx: &mut Context<Self>)
|
||||||
|
where
|
||||||
|
E: Into<SharedString>,
|
||||||
|
{
|
||||||
|
self.error = Some(error.into());
|
||||||
|
cx.notify();
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
cx.background_executor().timer(Duration::from_secs(2)).await;
|
||||||
|
|
||||||
|
// Clear the error message after a delay
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.error = None;
|
||||||
|
cx.notify();
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_updating(&mut self, updating: bool, cx: &mut Context<Self>) {
|
||||||
|
self.updating = updating;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if self.contacts.is_empty() {
|
||||||
|
self.set_error("You need to add at least 1 contact", window, cx);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
|
// Get contacts
|
||||||
|
let contacts: Vec<Contact> = self
|
||||||
|
.contacts
|
||||||
|
.iter()
|
||||||
|
.map(|public_key| Contact::new(*public_key))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Set updating state
|
||||||
|
self.set_updating(true, cx);
|
||||||
|
|
||||||
|
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
||||||
|
// Construct contact list event builder
|
||||||
|
let builder = EventBuilder::contact_list(contacts);
|
||||||
|
let event = client.sign_event_builder(builder).await?;
|
||||||
|
|
||||||
|
// Set contact list
|
||||||
|
client.send_event(&event).to_nip65().await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
match task.await {
|
||||||
|
Ok(_) => {
|
||||||
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
this.set_updating(false, cx);
|
||||||
|
this.load(window, cx);
|
||||||
|
|
||||||
|
window.push_notification("Update successful", cx);
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
this.set_updating(false, cx);
|
||||||
|
this.set_error(e.to_string(), window, cx);
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_list_items(&mut self, cx: &mut Context<Self>) -> Vec<impl IntoElement> {
|
||||||
|
let persons = PersonRegistry::global(cx);
|
||||||
|
let mut items = Vec::new();
|
||||||
|
|
||||||
|
for (ix, public_key) in self.contacts.iter().enumerate() {
|
||||||
|
let profile = persons.read(cx).get(public_key, cx);
|
||||||
|
|
||||||
|
items.push(
|
||||||
|
h_flex()
|
||||||
|
.id(ix)
|
||||||
|
.group("")
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.h_8()
|
||||||
|
.px_2()
|
||||||
|
.justify_between()
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
|
.bg(cx.theme().secondary_background)
|
||||||
|
.text_color(cx.theme().secondary_foreground)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_2()
|
||||||
|
.text_sm()
|
||||||
|
.child(Avatar::new(profile.avatar()).small())
|
||||||
|
.child(profile.name()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("remove_{ix}")
|
||||||
|
.icon(IconName::Close)
|
||||||
|
.xsmall()
|
||||||
|
.ghost()
|
||||||
|
.invisible()
|
||||||
|
.group_hover("", |this| this.visible())
|
||||||
|
.on_click({
|
||||||
|
let public_key = public_key.to_owned();
|
||||||
|
cx.listener(move |this, _ev, _window, cx| {
|
||||||
|
this.remove(&public_key, cx);
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
items
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_empty(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
h_flex()
|
||||||
|
.h_20()
|
||||||
|
.justify_center()
|
||||||
|
.border_2()
|
||||||
|
.border_dashed()
|
||||||
|
.border_color(cx.theme().border)
|
||||||
|
.rounded(cx.theme().radius_lg)
|
||||||
|
.text_sm()
|
||||||
|
.text_align(TextAlign::Center)
|
||||||
|
.child(SharedString::from("Please add some relays."))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Panel for ContactListPanel {
|
||||||
|
fn panel_id(&self) -> SharedString {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title(&self, _cx: &App) -> AnyElement {
|
||||||
|
self.name.clone().into_any_element()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<PanelEvent> for ContactListPanel {}
|
||||||
|
|
||||||
|
impl Focusable for ContactListPanel {
|
||||||
|
fn focus_handle(&self, _: &App) -> gpui::FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ContactListPanel {
|
||||||
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
v_flex().p_3().gap_3().w_full().child(
|
||||||
|
v_flex()
|
||||||
|
.gap_2()
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.font_semibold()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("New contact:")),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1()
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.w_full()
|
||||||
|
.child(
|
||||||
|
TextInput::new(&self.input)
|
||||||
|
.small()
|
||||||
|
.bordered(false)
|
||||||
|
.cleanable(),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("add")
|
||||||
|
.icon(IconName::Plus)
|
||||||
|
.tooltip("Add contact")
|
||||||
|
.ghost()
|
||||||
|
.size(rems(2.))
|
||||||
|
.on_click(cx.listener(move |this, _, window, cx| {
|
||||||
|
this.add(window, cx);
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.when_some(self.error.as_ref(), |this, error| {
|
||||||
|
this.child(
|
||||||
|
div()
|
||||||
|
.italic()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().text_danger)
|
||||||
|
.child(error.clone()),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.map(|this| {
|
||||||
|
if self.contacts.is_empty() {
|
||||||
|
this.child(self.render_empty(window, cx))
|
||||||
|
} else {
|
||||||
|
this.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1()
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.children(self.render_list_items(cx)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.child(
|
||||||
|
Button::new("submit")
|
||||||
|
.icon(IconName::CheckCircle)
|
||||||
|
.label("Update")
|
||||||
|
.primary()
|
||||||
|
.small()
|
||||||
|
.font_semibold()
|
||||||
|
.loading(self.updating)
|
||||||
|
.disabled(self.updating)
|
||||||
|
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||||
|
this.update(window, cx);
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
use chat::ChatRegistry;
|
|
||||||
use gpui::prelude::FluentBuilder;
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, relative, svg, AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle,
|
AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable,
|
||||||
Focusable, IntoElement, ParentElement, Render, SharedString, Styled, Window,
|
IntoElement, ParentElement, Render, SharedString, Styled, Window, div, svg,
|
||||||
};
|
};
|
||||||
use state::{NostrRegistry, RelayState};
|
use state::NostrRegistry;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::dock_area::dock::DockPlacement;
|
use ui::dock::{DockPlacement, Panel, PanelEvent};
|
||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
use ui::{Icon, IconName, Sizable, StyledExt, h_flex, v_flex};
|
||||||
use ui::{h_flex, v_flex, Icon, IconName, Sizable, StyledExt};
|
|
||||||
|
|
||||||
use crate::panels::{connect, import, messaging_relays, profile, relay_list};
|
use crate::panels::profile;
|
||||||
use crate::workspace::Workspace;
|
use crate::workspace::Workspace;
|
||||||
|
|
||||||
pub fn init(window: &mut Window, cx: &mut App) -> Entity<GreeterPanel> {
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<GreeterPanel> {
|
||||||
@@ -40,7 +37,7 @@ impl GreeterPanel {
|
|||||||
cx.update(|window, cx| {
|
cx.update(|window, cx| {
|
||||||
Workspace::add_panel(
|
Workspace::add_panel(
|
||||||
profile::init(public_key, window, cx),
|
profile::init(public_key, window, cx),
|
||||||
DockPlacement::Center,
|
DockPlacement::Right,
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
@@ -82,17 +79,6 @@ impl Render for GreeterPanel {
|
|||||||
const TITLE: &str = "Welcome to Coop!";
|
const TITLE: &str = "Welcome to Coop!";
|
||||||
const DESCRIPTION: &str = "Chat Freely, Stay Private on Nostr.";
|
const DESCRIPTION: &str = "Chat Freely, Stay Private on Nostr.";
|
||||||
|
|
||||||
let chat = ChatRegistry::global(cx);
|
|
||||||
let nip17_state = chat.read(cx).relay_state(cx);
|
|
||||||
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let nip65_state = nostr.read(cx).relay_list_state();
|
|
||||||
let signer = nostr.read(cx).signer();
|
|
||||||
let owned = signer.owned();
|
|
||||||
|
|
||||||
let required_actions =
|
|
||||||
nip65_state == RelayState::NotConfigured || nip17_state == RelayState::NotConfigured;
|
|
||||||
|
|
||||||
h_flex()
|
h_flex()
|
||||||
.size_full()
|
.size_full()
|
||||||
.items_center()
|
.items_center()
|
||||||
@@ -121,139 +107,26 @@ impl Render for GreeterPanel {
|
|||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.font_semibold()
|
.font_semibold()
|
||||||
.line_height(relative(1.25))
|
.text_color(cx.theme().text)
|
||||||
.child(SharedString::from(TITLE)),
|
.child(SharedString::from(TITLE)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_sm()
|
.text_xs()
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.line_height(relative(1.25))
|
|
||||||
.child(SharedString::from(DESCRIPTION)),
|
.child(SharedString::from(DESCRIPTION)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.when(required_actions, |this| {
|
|
||||||
this.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_2()
|
|
||||||
.w_full()
|
|
||||||
.child(
|
|
||||||
h_flex()
|
|
||||||
.gap_1()
|
|
||||||
.w_full()
|
|
||||||
.text_sm()
|
|
||||||
.font_semibold()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from("Required Actions"))
|
|
||||||
.child(div().flex_1().h_px().bg(cx.theme().border)),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_2()
|
|
||||||
.w_full()
|
|
||||||
.when(nip65_state.not_configured(), |this| {
|
|
||||||
this.child(
|
|
||||||
Button::new("relaylist")
|
|
||||||
.icon(Icon::new(IconName::Relay))
|
|
||||||
.label("Set up relay list")
|
|
||||||
.ghost()
|
|
||||||
.small()
|
|
||||||
.justify_start()
|
|
||||||
.on_click(move |_ev, window, cx| {
|
|
||||||
Workspace::add_panel(
|
|
||||||
relay_list::init(window, cx),
|
|
||||||
DockPlacement::Center,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.when(nip17_state.not_configured(), |this| {
|
|
||||||
this.child(
|
|
||||||
Button::new("import")
|
|
||||||
.icon(Icon::new(IconName::Relay))
|
|
||||||
.label("Set up messaging relays")
|
|
||||||
.ghost()
|
|
||||||
.small()
|
|
||||||
.justify_start()
|
|
||||||
.on_click(move |_ev, window, cx| {
|
|
||||||
Workspace::add_panel(
|
|
||||||
messaging_relays::init(window, cx),
|
|
||||||
DockPlacement::Center,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.when(!owned, |this| {
|
|
||||||
this.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_2()
|
|
||||||
.w_full()
|
|
||||||
.child(
|
|
||||||
h_flex()
|
|
||||||
.gap_1()
|
|
||||||
.w_full()
|
|
||||||
.text_sm()
|
|
||||||
.font_semibold()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from("Use your own identity"))
|
|
||||||
.child(div().flex_1().h_px().bg(cx.theme().border)),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_2()
|
|
||||||
.w_full()
|
|
||||||
.child(
|
|
||||||
Button::new("connect")
|
|
||||||
.icon(Icon::new(IconName::Door))
|
|
||||||
.label("Connect account via Nostr Connect")
|
|
||||||
.ghost()
|
|
||||||
.small()
|
|
||||||
.justify_start()
|
|
||||||
.on_click(move |_ev, window, cx| {
|
|
||||||
Workspace::add_panel(
|
|
||||||
connect::init(window, cx),
|
|
||||||
DockPlacement::Center,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Button::new("import")
|
|
||||||
.icon(Icon::new(IconName::Usb))
|
|
||||||
.label("Import a secret key or bunker")
|
|
||||||
.ghost()
|
|
||||||
.small()
|
|
||||||
.justify_start()
|
|
||||||
.on_click(move |_ev, window, cx| {
|
|
||||||
Workspace::add_panel(
|
|
||||||
import::init(window, cx),
|
|
||||||
DockPlacement::Center,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.w_full()
|
.w_full()
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_2()
|
||||||
.w_full()
|
.w_full()
|
||||||
.text_sm()
|
.text_xs()
|
||||||
.font_semibold()
|
.font_semibold()
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.child(SharedString::from("Get Started"))
|
.child(SharedString::from("Get Started"))
|
||||||
@@ -263,14 +136,6 @@ impl Render for GreeterPanel {
|
|||||||
v_flex()
|
v_flex()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.w_full()
|
.w_full()
|
||||||
.child(
|
|
||||||
Button::new("backup")
|
|
||||||
.icon(Icon::new(IconName::Shield))
|
|
||||||
.label("Backup account")
|
|
||||||
.ghost()
|
|
||||||
.small()
|
|
||||||
.justify_start(),
|
|
||||||
)
|
|
||||||
.child(
|
.child(
|
||||||
Button::new("profile")
|
Button::new("profile")
|
||||||
.icon(Icon::new(IconName::Profile))
|
.icon(Icon::new(IconName::Profile))
|
||||||
|
|||||||
@@ -1,371 +0,0 @@
|
|||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use anyhow::anyhow;
|
|
||||||
use gpui::prelude::FluentBuilder;
|
|
||||||
use gpui::{
|
|
||||||
div, relative, AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle,
|
|
||||||
Focusable, IntoElement, ParentElement, Render, SharedString, Styled, Subscription, Window,
|
|
||||||
};
|
|
||||||
use nostr_connect::prelude::*;
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
|
||||||
use state::{CoopAuthUrlHandler, NostrRegistry};
|
|
||||||
use theme::ActiveTheme;
|
|
||||||
use ui::button::{Button, ButtonVariants};
|
|
||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
|
||||||
use ui::dock_area::ClosePanel;
|
|
||||||
use ui::input::{InputEvent, InputState, TextInput};
|
|
||||||
use ui::notification::Notification;
|
|
||||||
use ui::{v_flex, Disableable, StyledExt, WindowExtension};
|
|
||||||
|
|
||||||
pub fn init(window: &mut Window, cx: &mut App) -> Entity<ImportPanel> {
|
|
||||||
cx.new(|cx| ImportPanel::new(window, cx))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ImportPanel {
|
|
||||||
name: SharedString,
|
|
||||||
focus_handle: FocusHandle,
|
|
||||||
|
|
||||||
/// Secret key input
|
|
||||||
key_input: Entity<InputState>,
|
|
||||||
|
|
||||||
/// Password input (if required)
|
|
||||||
pass_input: Entity<InputState>,
|
|
||||||
|
|
||||||
/// Error message
|
|
||||||
error: Entity<Option<SharedString>>,
|
|
||||||
|
|
||||||
/// Countdown timer for nostr connect
|
|
||||||
countdown: Entity<Option<u64>>,
|
|
||||||
|
|
||||||
/// Whether the user is currently logging in
|
|
||||||
logging_in: bool,
|
|
||||||
|
|
||||||
/// Event subscriptions
|
|
||||||
_subscriptions: SmallVec<[Subscription; 1]>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ImportPanel {
|
|
||||||
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
|
||||||
let key_input = cx.new(|cx| InputState::new(window, cx).masked(true));
|
|
||||||
let pass_input = cx.new(|cx| InputState::new(window, cx).masked(true));
|
|
||||||
|
|
||||||
let error = cx.new(|_| None);
|
|
||||||
let countdown = cx.new(|_| None);
|
|
||||||
|
|
||||||
let mut subscriptions = smallvec![];
|
|
||||||
|
|
||||||
subscriptions.push(
|
|
||||||
// Subscribe to key input events and process login when the user presses enter
|
|
||||||
cx.subscribe_in(&key_input, window, |this, _input, event, window, cx| {
|
|
||||||
if let InputEvent::PressEnter { .. } = event {
|
|
||||||
this.login(window, cx);
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
key_input,
|
|
||||||
pass_input,
|
|
||||||
error,
|
|
||||||
countdown,
|
|
||||||
name: "Import".into(),
|
|
||||||
focus_handle: cx.focus_handle(),
|
|
||||||
logging_in: false,
|
|
||||||
_subscriptions: subscriptions,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn login(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
|
||||||
if self.logging_in {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
// Prevent duplicate login requests
|
|
||||||
self.set_logging_in(true, cx);
|
|
||||||
|
|
||||||
let value = self.key_input.read(cx).value();
|
|
||||||
let password = self.pass_input.read(cx).value();
|
|
||||||
|
|
||||||
if value.starts_with("bunker://") {
|
|
||||||
self.login_with_bunker(&value, window, cx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if value.starts_with("ncryptsec1") {
|
|
||||||
self.login_with_password(&value, &password, window, cx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(secret) = SecretKey::parse(&value) {
|
|
||||||
let keys = Keys::new(secret);
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
// Update the signer
|
|
||||||
nostr.update(cx, |this, cx| {
|
|
||||||
this.set_signer(keys, true, cx);
|
|
||||||
});
|
|
||||||
// Close the current panel after setting the signer
|
|
||||||
window.dispatch_action(Box::new(ClosePanel), cx);
|
|
||||||
} else {
|
|
||||||
self.set_error("Invalid", cx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn login_with_bunker(&mut self, content: &str, window: &mut Window, cx: &mut Context<Self>) {
|
|
||||||
let Ok(uri) = NostrConnectUri::parse(content) else {
|
|
||||||
self.set_error("Bunker is not valid", cx);
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let weak_state = nostr.downgrade();
|
|
||||||
|
|
||||||
let app_keys = nostr.read(cx).app_keys();
|
|
||||||
let timeout = Duration::from_secs(30);
|
|
||||||
let mut signer = NostrConnect::new(uri, app_keys.clone(), timeout, None).unwrap();
|
|
||||||
|
|
||||||
// Handle auth url with the default browser
|
|
||||||
signer.auth_url_handler(CoopAuthUrlHandler);
|
|
||||||
|
|
||||||
// Start countdown
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
|
||||||
for i in (0..=30).rev() {
|
|
||||||
if i == 0 {
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
this.set_countdown(None, cx);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
} else {
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
this.set_countdown(Some(i), cx);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
cx.background_executor().timer(Duration::from_secs(1)).await;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
|
|
||||||
// Handle connection
|
|
||||||
cx.spawn_in(window, async move |_this, cx| {
|
|
||||||
let result = signer.bunker_uri().await;
|
|
||||||
|
|
||||||
weak_state
|
|
||||||
.update_in(cx, |this, window, cx| {
|
|
||||||
match result {
|
|
||||||
Ok(uri) => {
|
|
||||||
this.persist_bunker(uri, cx);
|
|
||||||
this.set_signer(signer, true, cx);
|
|
||||||
// Close the current panel after setting the signer
|
|
||||||
window.dispatch_action(Box::new(ClosePanel), cx);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
window.push_notification(Notification::error(e.to_string()), cx);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn login_with_password(
|
|
||||||
&mut self,
|
|
||||||
content: &str,
|
|
||||||
pwd: &str,
|
|
||||||
window: &mut Window,
|
|
||||||
cx: &mut Context<Self>,
|
|
||||||
) {
|
|
||||||
if pwd.is_empty() {
|
|
||||||
self.set_error("Password is required", cx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let Ok(enc) = EncryptedSecretKey::from_bech32(content) else {
|
|
||||||
self.set_error("Secret Key is invalid", cx);
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let password = pwd.to_owned();
|
|
||||||
|
|
||||||
// Decrypt in the background to ensure it doesn't block the UI
|
|
||||||
let task = cx.background_spawn(async move {
|
|
||||||
if let Ok(content) = enc.decrypt(&password) {
|
|
||||||
Ok(Keys::new(content))
|
|
||||||
} else {
|
|
||||||
Err(anyhow!("Invalid password"))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
|
||||||
let result = task.await;
|
|
||||||
|
|
||||||
this.update_in(cx, |this, window, cx| {
|
|
||||||
match result {
|
|
||||||
Ok(keys) => {
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
// Update the signer
|
|
||||||
nostr.update(cx, |this, cx| {
|
|
||||||
this.set_signer(keys, true, cx);
|
|
||||||
});
|
|
||||||
// Close the current panel after setting the signer
|
|
||||||
window.dispatch_action(Box::new(ClosePanel), cx);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
this.set_error(e.to_string(), cx);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_error<S>(&mut self, message: S, cx: &mut Context<Self>)
|
|
||||||
where
|
|
||||||
S: Into<SharedString>,
|
|
||||||
{
|
|
||||||
// Reset the log in state
|
|
||||||
self.set_logging_in(false, cx);
|
|
||||||
|
|
||||||
// Reset the countdown
|
|
||||||
self.set_countdown(None, cx);
|
|
||||||
|
|
||||||
// Update error message
|
|
||||||
self.error.update(cx, |this, cx| {
|
|
||||||
*this = Some(message.into());
|
|
||||||
cx.notify();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clear the error message after 3 secs
|
|
||||||
cx.spawn(async move |this, cx| {
|
|
||||||
cx.background_executor().timer(Duration::from_secs(3)).await;
|
|
||||||
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
this.error.update(cx, |this, cx| {
|
|
||||||
*this = None;
|
|
||||||
cx.notify();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_logging_in(&mut self, status: bool, cx: &mut Context<Self>) {
|
|
||||||
self.logging_in = status;
|
|
||||||
cx.notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_countdown(&mut self, i: Option<u64>, cx: &mut Context<Self>) {
|
|
||||||
self.countdown.update(cx, |this, cx| {
|
|
||||||
*this = i;
|
|
||||||
cx.notify();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Panel for ImportPanel {
|
|
||||||
fn panel_id(&self) -> SharedString {
|
|
||||||
self.name.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn title(&self, _cx: &App) -> AnyElement {
|
|
||||||
self.name.clone().into_any_element()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventEmitter<PanelEvent> for ImportPanel {}
|
|
||||||
|
|
||||||
impl Focusable for ImportPanel {
|
|
||||||
fn focus_handle(&self, _: &App) -> gpui::FocusHandle {
|
|
||||||
self.focus_handle.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Render for ImportPanel {
|
|
||||||
fn render(&mut self, _window: &mut gpui::Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
||||||
const SECRET_WARN: &str = "* Coop doesn't store your secret key. \
|
|
||||||
It will be cleared when you close the app. \
|
|
||||||
To persist your identity, please connect via Nostr Connect.";
|
|
||||||
|
|
||||||
v_flex()
|
|
||||||
.size_full()
|
|
||||||
.items_center()
|
|
||||||
.justify_center()
|
|
||||||
.p_2()
|
|
||||||
.gap_10()
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.text_center()
|
|
||||||
.font_semibold()
|
|
||||||
.line_height(relative(1.25))
|
|
||||||
.child(SharedString::from("Import a Secret Key or Bunker")),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.w_112()
|
|
||||||
.gap_2()
|
|
||||||
.text_sm()
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_1()
|
|
||||||
.text_sm()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child("nsec or bunker://")
|
|
||||||
.child(TextInput::new(&self.key_input)),
|
|
||||||
)
|
|
||||||
.when(
|
|
||||||
self.key_input.read(cx).value().starts_with("ncryptsec1"),
|
|
||||||
|this| {
|
|
||||||
this.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_1()
|
|
||||||
.text_sm()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child("Password:")
|
|
||||||
.child(TextInput::new(&self.pass_input)),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Button::new("login")
|
|
||||||
.label("Continue")
|
|
||||||
.primary()
|
|
||||||
.loading(self.logging_in)
|
|
||||||
.disabled(self.logging_in)
|
|
||||||
.on_click(cx.listener(move |this, _, window, cx| {
|
|
||||||
this.login(window, cx);
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
.when_some(self.countdown.read(cx).as_ref(), |this, i| {
|
|
||||||
this.child(
|
|
||||||
div()
|
|
||||||
.text_xs()
|
|
||||||
.text_center()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from(format!(
|
|
||||||
"Approve connection request from your signer in {} seconds",
|
|
||||||
i
|
|
||||||
))),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.when_some(self.error.read(cx).as_ref(), |this, error| {
|
|
||||||
this.child(
|
|
||||||
div()
|
|
||||||
.text_xs()
|
|
||||||
.text_center()
|
|
||||||
.text_color(cx.theme().danger_foreground)
|
|
||||||
.child(error.clone()),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.mt_2()
|
|
||||||
.italic()
|
|
||||||
.text_xs()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from(SECRET_WARN)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +1,24 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error, anyhow};
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, relative, uniform_list, AnyElement, App, AppContext, Context, Entity, EventEmitter,
|
AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable,
|
||||||
FocusHandle, Focusable, InteractiveElement, IntoElement, ParentElement, Render, SharedString,
|
InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Subscription,
|
||||||
Styled, Subscription, Task, TextAlign, UniformList, Window,
|
Task, TextAlign, Window, div, rems,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use state::NostrRegistry;
|
use state::NostrRegistry;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
use ui::dock::{Panel, PanelEvent};
|
||||||
use ui::input::{InputEvent, InputState, TextInput};
|
use ui::input::{InputEvent, InputState, TextInput};
|
||||||
use ui::{divider, h_flex, v_flex, IconName, Sizable, StyledExt};
|
use ui::{Disableable, IconName, Sizable, StyledExt, WindowExtension, divider, h_flex, v_flex};
|
||||||
|
|
||||||
|
const MSG: &str = "Messaging Relays are relays that hosted all your messages. \
|
||||||
|
Other users will find your relays and send messages to it.";
|
||||||
|
|
||||||
pub fn init(window: &mut Window, cx: &mut App) -> Entity<MessagingRelayPanel> {
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<MessagingRelayPanel> {
|
||||||
cx.new(|cx| MessagingRelayPanel::new(window, cx))
|
cx.new(|cx| MessagingRelayPanel::new(window, cx))
|
||||||
@@ -29,44 +32,26 @@ pub struct MessagingRelayPanel {
|
|||||||
/// Relay URL input
|
/// Relay URL input
|
||||||
input: Entity<InputState>,
|
input: Entity<InputState>,
|
||||||
|
|
||||||
|
/// Whether the panel is updating
|
||||||
|
updating: bool,
|
||||||
|
|
||||||
/// Error message
|
/// Error message
|
||||||
error: Option<SharedString>,
|
error: Option<SharedString>,
|
||||||
|
|
||||||
// All relays
|
/// All relays
|
||||||
relays: HashSet<RelayUrl>,
|
relays: HashSet<RelayUrl>,
|
||||||
|
|
||||||
// Event subscriptions
|
/// Event subscriptions
|
||||||
_subscriptions: SmallVec<[Subscription; 1]>,
|
_subscriptions: SmallVec<[Subscription; 1]>,
|
||||||
|
|
||||||
// Background tasks
|
/// Background tasks
|
||||||
_tasks: SmallVec<[Task<()>; 1]>,
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessagingRelayPanel {
|
impl MessagingRelayPanel {
|
||||||
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let input = cx.new(|cx| InputState::new(window, cx).placeholder("wss://example.com"));
|
let input = cx.new(|cx| InputState::new(window, cx).placeholder("wss://example.com"));
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let client = nostr.read(cx).client();
|
|
||||||
|
|
||||||
let mut subscriptions = smallvec![];
|
let mut subscriptions = smallvec![];
|
||||||
let mut tasks = smallvec![];
|
|
||||||
|
|
||||||
tasks.push(
|
|
||||||
// Load user's relays in the local database
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
|
||||||
let result = cx
|
|
||||||
.background_spawn(async move { Self::load(&client).await })
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if let Ok(relays) = result {
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
this.relays.extend(relays);
|
|
||||||
cx.notify();
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
// Subscribe to user's input events
|
// Subscribe to user's input events
|
||||||
@@ -77,31 +62,54 @@ impl MessagingRelayPanel {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Run at the end of current cycle
|
||||||
|
cx.defer_in(window, |this, window, cx| {
|
||||||
|
this.load(window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
name: "Update Messaging Relays".into(),
|
name: "Update Messaging Relays".into(),
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
input,
|
input,
|
||||||
|
updating: false,
|
||||||
relays: HashSet::new(),
|
relays: HashSet::new(),
|
||||||
error: None,
|
error: None,
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
_tasks: tasks,
|
tasks: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn load(client: &Client) -> Result<Vec<RelayUrl>, Error> {
|
fn load(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let signer = client.signer().context("Signer not found")?;
|
let nostr = NostrRegistry::global(cx);
|
||||||
let public_key = signer.get_public_key().await?;
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
let filter = Filter::new()
|
let task: Task<Result<Vec<RelayUrl>, Error>> = cx.background_spawn(async move {
|
||||||
.kind(Kind::InboxRelays)
|
let signer = client.signer().context("Signer not found")?;
|
||||||
.author(public_key)
|
let public_key = signer.get_public_key().await?;
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
if let Some(event) = client.database().query(filter).await?.first_owned() {
|
let filter = Filter::new()
|
||||||
Ok(nip17::extract_owned_relay_list(event).collect())
|
.kind(Kind::InboxRelays)
|
||||||
} else {
|
.author(public_key)
|
||||||
Err(anyhow!("Not found."))
|
.limit(1);
|
||||||
}
|
|
||||||
|
if let Some(event) = client.database().query(filter).await?.first_owned() {
|
||||||
|
Ok(nip17::extract_owned_relay_list(event).collect())
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("Not found."))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
let relays = task.await?;
|
||||||
|
|
||||||
|
// Update state
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.relays.extend(relays);
|
||||||
|
cx.notify();
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn add(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
@@ -113,7 +121,7 @@ impl MessagingRelayPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(url) = RelayUrl::parse(&value) {
|
if let Ok(url) = RelayUrl::parse(&value) {
|
||||||
if !self.relays.insert(url) {
|
if self.relays.insert(url) {
|
||||||
self.input.update(cx, |this, cx| {
|
self.input.update(cx, |this, cx| {
|
||||||
this.set_value("", window, cx);
|
this.set_value("", window, cx);
|
||||||
});
|
});
|
||||||
@@ -136,16 +144,22 @@ impl MessagingRelayPanel {
|
|||||||
self.error = Some(error.into());
|
self.error = Some(error.into());
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
cx.background_executor().timer(Duration::from_secs(2)).await;
|
cx.background_executor().timer(Duration::from_secs(2)).await;
|
||||||
|
|
||||||
// Clear the error message after a delay
|
// Clear the error message after a delay
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.error = None;
|
this.error = None;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})?;
|
||||||
.ok();
|
|
||||||
})
|
Ok(())
|
||||||
.detach();
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_updating(&mut self, updating: bool, cx: &mut Context<Self>) {
|
||||||
|
self.updating = updating;
|
||||||
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_relays(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
pub fn set_relays(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
@@ -157,12 +171,16 @@ impl MessagingRelayPanel {
|
|||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
let client = nostr.read(cx).client();
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
|
// Construct event tags
|
||||||
let tags: Vec<Tag> = self
|
let tags: Vec<Tag> = self
|
||||||
.relays
|
.relays
|
||||||
.iter()
|
.iter()
|
||||||
.map(|relay| Tag::relay(relay.clone()))
|
.map(|relay| Tag::relay(relay.clone()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
// Set updating state
|
||||||
|
self.set_updating(true, cx);
|
||||||
|
|
||||||
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
||||||
// Construct nip17 event builder
|
// Construct nip17 event builder
|
||||||
let builder = EventBuilder::new(Kind::InboxRelays, "").tags(tags);
|
let builder = EventBuilder::new(Kind::InboxRelays, "").tags(tags);
|
||||||
@@ -174,81 +192,67 @@ impl MessagingRelayPanel {
|
|||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
match task.await {
|
match task.await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// TODO
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
this.set_updating(false, cx);
|
||||||
|
this.load(window, cx);
|
||||||
|
|
||||||
|
window.push_notification("Update successful", cx);
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
this.update_in(cx, |this, window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
this.set_updating(false, cx);
|
||||||
this.set_error(e.to_string(), window, cx);
|
this.set_error(e.to_string(), window, cx);
|
||||||
})
|
})?;
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
|
||||||
.detach();
|
Ok(())
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_list(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> UniformList {
|
fn render_list_items(&mut self, cx: &mut Context<Self>) -> Vec<impl IntoElement> {
|
||||||
let relays = self.relays.clone();
|
let mut items = Vec::new();
|
||||||
let total = relays.len();
|
|
||||||
|
|
||||||
uniform_list(
|
for url in self.relays.iter() {
|
||||||
"relays",
|
items.push(
|
||||||
total,
|
h_flex()
|
||||||
cx.processor(move |_v, range, _window, cx| {
|
.id(SharedString::from(url.to_string()))
|
||||||
let mut items = Vec::new();
|
.group("")
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.h_8()
|
||||||
|
.px_2()
|
||||||
|
.justify_between()
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
|
.bg(cx.theme().secondary_background)
|
||||||
|
.text_color(cx.theme().secondary_foreground)
|
||||||
|
.child(div().text_sm().child(SharedString::from(url.to_string())))
|
||||||
|
.child(
|
||||||
|
Button::new("remove_{ix}")
|
||||||
|
.icon(IconName::Close)
|
||||||
|
.xsmall()
|
||||||
|
.ghost()
|
||||||
|
.invisible()
|
||||||
|
.group_hover("", |this| this.visible())
|
||||||
|
.on_click({
|
||||||
|
let url = url.to_owned();
|
||||||
|
cx.listener(move |this, _ev, _window, cx| {
|
||||||
|
this.remove(&url, cx);
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
for ix in range {
|
items
|
||||||
let Some(url) = relays.iter().nth(ix) else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
items.push(
|
|
||||||
div()
|
|
||||||
.id(SharedString::from(url.to_string()))
|
|
||||||
.group("")
|
|
||||||
.w_full()
|
|
||||||
.h_9()
|
|
||||||
.py_0p5()
|
|
||||||
.child(
|
|
||||||
h_flex()
|
|
||||||
.px_2()
|
|
||||||
.flex()
|
|
||||||
.justify_between()
|
|
||||||
.rounded(cx.theme().radius)
|
|
||||||
.bg(cx.theme().elevated_surface_background)
|
|
||||||
.child(
|
|
||||||
div().text_sm().child(SharedString::from(url.to_string())),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Button::new("remove_{ix}")
|
|
||||||
.icon(IconName::Close)
|
|
||||||
.xsmall()
|
|
||||||
.ghost()
|
|
||||||
.invisible()
|
|
||||||
.group_hover("", |this| this.visible())
|
|
||||||
.on_click({
|
|
||||||
let url = url.to_owned();
|
|
||||||
cx.listener(move |this, _ev, _window, cx| {
|
|
||||||
this.remove(&url, cx);
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
items
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.h_full()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_empty(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render_empty(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
h_flex()
|
h_flex()
|
||||||
.mt_2()
|
|
||||||
.h_20()
|
.h_20()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.border_2()
|
.border_2()
|
||||||
@@ -282,36 +286,48 @@ impl Focusable for MessagingRelayPanel {
|
|||||||
impl Render for MessagingRelayPanel {
|
impl Render for MessagingRelayPanel {
|
||||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
v_flex()
|
v_flex()
|
||||||
.size_full()
|
.p_3()
|
||||||
.items_center()
|
.gap_3()
|
||||||
.justify_center()
|
.w_full()
|
||||||
.p_2()
|
|
||||||
.gap_10()
|
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_center()
|
.text_xs()
|
||||||
.font_semibold()
|
.text_color(cx.theme().text_muted)
|
||||||
.line_height(relative(1.25))
|
.child(SharedString::from(MSG)),
|
||||||
.child(SharedString::from("Update Messaging Relays")),
|
|
||||||
)
|
)
|
||||||
|
.child(divider(cx))
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.w_112()
|
|
||||||
.gap_2()
|
.gap_2()
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.font_semibold()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("Relays:")),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_1p5()
|
.gap_1()
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.w_full()
|
.w_full()
|
||||||
.child(TextInput::new(&self.input).small())
|
.child(
|
||||||
|
TextInput::new(&self.input)
|
||||||
|
.small()
|
||||||
|
.bordered(false)
|
||||||
|
.cleanable(),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
Button::new("add")
|
Button::new("add")
|
||||||
.icon(IconName::Plus)
|
.icon(IconName::Plus)
|
||||||
.label("Add")
|
.tooltip("Add relay")
|
||||||
.ghost()
|
.ghost()
|
||||||
|
.size(rems(2.))
|
||||||
.on_click(cx.listener(move |this, _, window, cx| {
|
.on_click(cx.listener(move |this, _, window, cx| {
|
||||||
this.add(window, cx);
|
this.add(window, cx);
|
||||||
})),
|
})),
|
||||||
@@ -322,23 +338,33 @@ impl Render for MessagingRelayPanel {
|
|||||||
div()
|
div()
|
||||||
.italic()
|
.italic()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.text_color(cx.theme().danger_foreground)
|
.text_color(cx.theme().text_danger)
|
||||||
.child(error.clone()),
|
.child(error.clone()),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.map(|this| {
|
.map(|this| {
|
||||||
if !self.relays.is_empty() {
|
if self.relays.is_empty() {
|
||||||
this.child(self.render_list(window, cx))
|
|
||||||
} else {
|
|
||||||
this.child(self.render_empty(window, cx))
|
this.child(self.render_empty(window, cx))
|
||||||
|
} else {
|
||||||
|
this.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1()
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.children(self.render_list_items(cx)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.child(divider(cx))
|
|
||||||
.child(
|
.child(
|
||||||
Button::new("submit")
|
Button::new("submit")
|
||||||
|
.icon(IconName::CheckCircle)
|
||||||
.label("Update")
|
.label("Update")
|
||||||
.primary()
|
.primary()
|
||||||
|
.small()
|
||||||
|
.font_semibold()
|
||||||
|
.loading(self.updating)
|
||||||
|
.disabled(self.updating)
|
||||||
.on_click(cx.listener(move |this, _ev, window, cx| {
|
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||||
this.set_relays(window, cx);
|
this.set_relays(window, cx);
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod connect;
|
pub mod backup;
|
||||||
|
pub mod contact_list;
|
||||||
pub mod greeter;
|
pub mod greeter;
|
||||||
pub mod import;
|
|
||||||
pub mod messaging_relays;
|
pub mod messaging_relays;
|
||||||
pub mod profile;
|
pub mod profile;
|
||||||
pub mod relay_list;
|
pub mod relay_list;
|
||||||
|
pub mod trash;
|
||||||
|
|||||||
@@ -1,26 +1,23 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::{Context as AnyhowContext, Error};
|
||||||
use common::shorten_pubkey;
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, rems, AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter,
|
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
|
||||||
FocusHandle, Focusable, IntoElement, ParentElement, PathPromptOptions, Render, SharedString,
|
Focusable, IntoElement, ParentElement, PathPromptOptions, Render, SharedString, Styled, Task,
|
||||||
Styled, Task, Window,
|
Window, div,
|
||||||
};
|
};
|
||||||
use gpui_tokio::Tokio;
|
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use person::{Person, PersonRegistry};
|
use person::{Person, PersonRegistry, shorten_pubkey};
|
||||||
use settings::AppSettings;
|
use settings::AppSettings;
|
||||||
use smol::fs;
|
use state::{NostrRegistry, upload};
|
||||||
use state::{nostr_upload, NostrRegistry};
|
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
use ui::dock::{Panel, PanelEvent};
|
||||||
use ui::input::{InputState, TextInput};
|
use ui::input::{InputState, TextInput};
|
||||||
use ui::notification::Notification;
|
use ui::notification::Notification;
|
||||||
use ui::{divider, h_flex, v_flex, Disableable, IconName, Sizable, StyledExt, WindowExtension};
|
use ui::{Disableable, IconName, Sizable, StyledExt, WindowExtension, h_flex, v_flex};
|
||||||
|
|
||||||
pub fn init(public_key: PublicKey, window: &mut Window, cx: &mut App) -> Entity<ProfilePanel> {
|
pub fn init(public_key: PublicKey, window: &mut Window, cx: &mut App) -> Entity<ProfilePanel> {
|
||||||
cx.new(|cx| ProfilePanel::new(public_key, window, cx))
|
cx.new(|cx| ProfilePanel::new(public_key, window, cx))
|
||||||
@@ -51,6 +48,12 @@ pub struct ProfilePanel {
|
|||||||
|
|
||||||
/// Copied states
|
/// Copied states
|
||||||
copied: bool,
|
copied: bool,
|
||||||
|
|
||||||
|
/// Updating state
|
||||||
|
updating: bool,
|
||||||
|
|
||||||
|
/// Tasks
|
||||||
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProfilePanel {
|
impl ProfilePanel {
|
||||||
@@ -58,6 +61,7 @@ impl ProfilePanel {
|
|||||||
let name_input = cx.new(|cx| InputState::new(window, cx).placeholder("Alice"));
|
let name_input = cx.new(|cx| InputState::new(window, cx).placeholder("Alice"));
|
||||||
let website_input = cx.new(|cx| InputState::new(window, cx).placeholder("alice.me"));
|
let website_input = cx.new(|cx| InputState::new(window, cx).placeholder("alice.me"));
|
||||||
let avatar_input = cx.new(|cx| InputState::new(window, cx).placeholder("alice.me/a.jpg"));
|
let avatar_input = cx.new(|cx| InputState::new(window, cx).placeholder("alice.me/a.jpg"));
|
||||||
|
|
||||||
// Use multi-line input for bio
|
// Use multi-line input for bio
|
||||||
let bio_input = cx.new(|cx| {
|
let bio_input = cx.new(|cx| {
|
||||||
InputState::new(window, cx)
|
InputState::new(window, cx)
|
||||||
@@ -68,10 +72,7 @@ impl ProfilePanel {
|
|||||||
|
|
||||||
// Get user's profile and update inputs
|
// Get user's profile and update inputs
|
||||||
cx.defer_in(window, move |this, window, cx| {
|
cx.defer_in(window, move |this, window, cx| {
|
||||||
let persons = PersonRegistry::global(cx);
|
this.set_profile(window, cx);
|
||||||
let profile = persons.read(cx).get(&public_key, cx);
|
|
||||||
// Set all input's values with current profile
|
|
||||||
this.set_profile(profile, window, cx);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@@ -84,11 +85,15 @@ impl ProfilePanel {
|
|||||||
website_input,
|
website_input,
|
||||||
uploading: false,
|
uploading: false,
|
||||||
copied: false,
|
copied: false,
|
||||||
|
updating: false,
|
||||||
|
tasks: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_profile(&mut self, person: Person, window: &mut Window, cx: &mut Context<Self>) {
|
fn set_profile(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let metadata = person.metadata();
|
let persons = PersonRegistry::global(cx);
|
||||||
|
let profile = persons.read(cx).get(&self.public_key, cx);
|
||||||
|
let metadata = profile.metadata();
|
||||||
|
|
||||||
self.avatar_input.update(cx, |this, cx| {
|
self.avatar_input.update(cx, |this, cx| {
|
||||||
if let Some(avatar) = metadata.picture.as_ref() {
|
if let Some(avatar) = metadata.picture.as_ref() {
|
||||||
@@ -143,66 +148,59 @@ impl ProfilePanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uploading(&mut self, status: bool, cx: &mut Context<Self>) {
|
fn set_uploading(&mut self, status: bool, cx: &mut Context<Self>) {
|
||||||
self.uploading = status;
|
self.uploading = status;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upload(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn upload(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
self.uploading(true, cx);
|
// Get the user's configured blossom server
|
||||||
|
let server = AppSettings::get_file_server(cx);
|
||||||
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
// Ask user for file upload
|
||||||
let client = nostr.read(cx).client();
|
let path = cx.prompt_for_paths(PathPromptOptions {
|
||||||
|
|
||||||
// Get the user's configured NIP96 server
|
|
||||||
let nip96_server = AppSettings::get_file_server(cx);
|
|
||||||
|
|
||||||
// Open native file dialog
|
|
||||||
let paths = cx.prompt_for_paths(PathPromptOptions {
|
|
||||||
files: true,
|
files: true,
|
||||||
directories: false,
|
directories: false,
|
||||||
multiple: false,
|
multiple: false,
|
||||||
prompt: None,
|
prompt: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
let task = Tokio::spawn(cx, async move {
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
match paths.await {
|
this.update(cx, |this, cx| {
|
||||||
Ok(Ok(Some(mut paths))) => {
|
this.set_uploading(true, cx);
|
||||||
if let Some(path) = paths.pop() {
|
})?;
|
||||||
let file = fs::read(path).await?;
|
|
||||||
let url = nostr_upload(&client, &nip96_server, file).await?;
|
|
||||||
|
|
||||||
Ok(url)
|
let mut paths = path.await??.context("Not found")?;
|
||||||
} else {
|
let path = paths.pop().context("No path")?;
|
||||||
Err(anyhow!("Path not found"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => Err(anyhow!("Error")),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
// Upload via blossom client
|
||||||
let result = task.await;
|
match upload(server, path, cx).await {
|
||||||
|
Ok(url) => {
|
||||||
this.update_in(cx, |this, window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
match result {
|
|
||||||
Ok(Ok(url)) => {
|
|
||||||
this.avatar_input.update(cx, |this, cx| {
|
this.avatar_input.update(cx, |this, cx| {
|
||||||
this.set_value(url.to_string(), window, cx);
|
this.set_value(url.to_string(), window, cx);
|
||||||
});
|
});
|
||||||
}
|
this.set_uploading(false, cx);
|
||||||
Ok(Err(e)) => {
|
})?;
|
||||||
window.push_notification(e.to_string(), cx);
|
}
|
||||||
}
|
Err(e) => {
|
||||||
Err(e) => {
|
this.update_in(cx, |this, window, cx| {
|
||||||
log::warn!("Failed to upload avatar: {e}");
|
this.set_uploading(false, cx);
|
||||||
}
|
window.push_notification(
|
||||||
};
|
Notification::error(e.to_string()).autohide(false),
|
||||||
this.uploading(false, cx);
|
cx,
|
||||||
})
|
);
|
||||||
.expect("Entity has been released");
|
})?;
|
||||||
})
|
}
|
||||||
.detach();
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_updating(&mut self, updating: bool, cx: &mut Context<Self>) {
|
||||||
|
self.updating = updating;
|
||||||
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the metadata for the current user
|
/// Set the metadata for the current user
|
||||||
@@ -253,26 +251,37 @@ impl ProfilePanel {
|
|||||||
// Set the metadata
|
// Set the metadata
|
||||||
let task = self.publish(&new_metadata, cx);
|
let task = self.publish(&new_metadata, cx);
|
||||||
|
|
||||||
cx.spawn_in(window, async move |_this, cx| {
|
// Set the updating state
|
||||||
|
self.set_updating(true, cx);
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
match task.await {
|
match task.await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
cx.update(|window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
// Update the registry
|
||||||
persons.update(cx, |this, cx| {
|
persons.update(cx, |this, cx| {
|
||||||
this.insert(Person::new(public_key, new_metadata), cx);
|
this.insert(Person::new(public_key, new_metadata), cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Update current panel
|
||||||
|
this.set_updating(false, cx);
|
||||||
|
this.set_profile(window, cx);
|
||||||
|
|
||||||
window.push_notification("Profile updated successfully", cx);
|
window.push_notification("Profile updated successfully", cx);
|
||||||
})
|
})?;
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
cx.update(|window, cx| {
|
cx.update(|window, cx| {
|
||||||
window.push_notification(Notification::error(e.to_string()), cx);
|
window.push_notification(
|
||||||
})
|
Notification::error(e.to_string()).autohide(false),
|
||||||
.ok();
|
cx,
|
||||||
|
);
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
|
||||||
.detach();
|
Ok(())
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,123 +305,126 @@ impl Focusable for ProfilePanel {
|
|||||||
|
|
||||||
impl Render for ProfilePanel {
|
impl Render for ProfilePanel {
|
||||||
fn render(&mut self, _window: &mut gpui::Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut gpui::Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let shorten_pkey = SharedString::from(shorten_pubkey(self.public_key, 8));
|
let avatar_input = self.avatar_input.read(cx).value();
|
||||||
|
|
||||||
// Get the avatar
|
// Get the avatar
|
||||||
let avatar_input = self.avatar_input.read(cx).value();
|
|
||||||
let avatar = if avatar_input.is_empty() {
|
let avatar = if avatar_input.is_empty() {
|
||||||
"brand/avatar.png"
|
"brand/avatar.png"
|
||||||
} else {
|
} else {
|
||||||
avatar_input.as_str()
|
avatar_input.as_str()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get the public key as short string
|
||||||
|
let shorten_pkey = SharedString::from(shorten_pubkey(self.public_key, 8));
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.size_full()
|
.p_3()
|
||||||
.items_center()
|
.gap_3()
|
||||||
.justify_center()
|
.w_full()
|
||||||
.p_2()
|
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_2()
|
.h_40()
|
||||||
.w_112()
|
.w_full()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.gap_4()
|
||||||
|
.child(Avatar::new(avatar).large())
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
Button::new("upload")
|
||||||
.h_40()
|
.icon(IconName::PlusCircle)
|
||||||
.w_full()
|
.label("Add an avatar")
|
||||||
.items_center()
|
.xsmall()
|
||||||
.justify_center()
|
.ghost()
|
||||||
.gap_4()
|
.rounded()
|
||||||
.child(Avatar::new(avatar).size(rems(4.25)))
|
|
||||||
.child(
|
|
||||||
Button::new("upload")
|
|
||||||
.icon(IconName::PlusCircle)
|
|
||||||
.label("Add an avatar")
|
|
||||||
.xsmall()
|
|
||||||
.ghost()
|
|
||||||
.rounded()
|
|
||||||
.disabled(self.uploading)
|
|
||||||
.loading(self.uploading)
|
|
||||||
.on_click(cx.listener(move |this, _, window, cx| {
|
|
||||||
this.upload(window, cx);
|
|
||||||
})),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_1()
|
|
||||||
.text_sm()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from("What should people call you?"))
|
|
||||||
.child(TextInput::new(&self.name_input).small()),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_1()
|
|
||||||
.text_sm()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from("A short introduction about you:"))
|
|
||||||
.child(TextInput::new(&self.bio_input).small()),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_1()
|
|
||||||
.text_sm()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from("Website:"))
|
|
||||||
.child(TextInput::new(&self.website_input).small()),
|
|
||||||
)
|
|
||||||
.child(divider(cx))
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.gap_1()
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.font_semibold()
|
|
||||||
.text_xs()
|
|
||||||
.text_color(cx.theme().text_placeholder)
|
|
||||||
.child(SharedString::from("Public Key:")),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
h_flex()
|
|
||||||
.h_8()
|
|
||||||
.w_full()
|
|
||||||
.justify_center()
|
|
||||||
.gap_2()
|
|
||||||
.bg(cx.theme().surface_background)
|
|
||||||
.rounded(cx.theme().radius)
|
|
||||||
.text_sm()
|
|
||||||
.child(shorten_pkey)
|
|
||||||
.child(
|
|
||||||
Button::new("copy")
|
|
||||||
.icon({
|
|
||||||
if self.copied {
|
|
||||||
IconName::CheckCircle
|
|
||||||
} else {
|
|
||||||
IconName::Copy
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.xsmall()
|
|
||||||
.ghost()
|
|
||||||
.on_click(cx.listener(move |this, _ev, window, cx| {
|
|
||||||
this.copy(
|
|
||||||
this.public_key.to_bech32().unwrap(),
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
})),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.child(divider(cx))
|
|
||||||
.child(
|
|
||||||
Button::new("submit")
|
|
||||||
.label("Update")
|
|
||||||
.primary()
|
|
||||||
.disabled(self.uploading)
|
.disabled(self.uploading)
|
||||||
.on_click(cx.listener(move |this, _ev, window, cx| {
|
.loading(self.uploading)
|
||||||
this.update(window, cx);
|
.on_click(cx.listener(move |this, _, window, cx| {
|
||||||
|
this.upload(window, cx);
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1p5()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("What should people call you?")),
|
||||||
|
)
|
||||||
|
.child(TextInput::new(&self.name_input).bordered(false).small()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1p5()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("A short introduction about you:")),
|
||||||
|
)
|
||||||
|
.child(TextInput::new(&self.bio_input).bordered(false).small()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1p5()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("Website:")),
|
||||||
|
)
|
||||||
|
.child(TextInput::new(&self.website_input).bordered(false).small()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1p5()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("Public Key:")),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.h_8()
|
||||||
|
.w_full()
|
||||||
|
.justify_center()
|
||||||
|
.gap_3()
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
|
.bg(cx.theme().secondary_background)
|
||||||
|
.text_sm()
|
||||||
|
.text_color(cx.theme().secondary_foreground)
|
||||||
|
.child(shorten_pkey)
|
||||||
|
.child(
|
||||||
|
Button::new("copy")
|
||||||
|
.icon({
|
||||||
|
if self.copied {
|
||||||
|
IconName::CheckCircle
|
||||||
|
} else {
|
||||||
|
IconName::Copy
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.xsmall()
|
||||||
|
.secondary()
|
||||||
|
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||||
|
this.copy(this.public_key.to_bech32().unwrap(), window, cx);
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("submit")
|
||||||
|
.icon(IconName::CheckCircle)
|
||||||
|
.label("Update")
|
||||||
|
.primary()
|
||||||
|
.small()
|
||||||
|
.font_semibold()
|
||||||
|
.loading(self.updating)
|
||||||
|
.disabled(self.updating)
|
||||||
|
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||||
|
this.update(window, cx);
|
||||||
|
})),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,39 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error, anyhow};
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, relative, uniform_list, AnyElement, App, AppContext, Context, Entity, EventEmitter,
|
Action, AnyElement, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable,
|
||||||
FocusHandle, Focusable, InteractiveElement, IntoElement, ParentElement, Render, SharedString,
|
InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Subscription,
|
||||||
Styled, Subscription, Task, TextAlign, UniformList, Window,
|
Task, TextAlign, Window, div, px, rems,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use serde::Deserialize;
|
||||||
use state::{NostrRegistry, BOOTSTRAP_RELAYS};
|
use smallvec::{SmallVec, smallvec};
|
||||||
|
use state::NostrRegistry;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
use ui::dock::{Panel, PanelEvent};
|
||||||
use ui::input::{InputEvent, InputState, TextInput};
|
use ui::input::{InputEvent, InputState, TextInput};
|
||||||
use ui::{divider, h_flex, v_flex, IconName, Sizable, StyledExt};
|
use ui::menu::DropdownMenu;
|
||||||
|
use ui::{Disableable, IconName, Sizable, StyledExt, WindowExtension, divider, h_flex, v_flex};
|
||||||
|
|
||||||
|
const MSG: &str = "Relay List (or Gossip Relays) are a set of relays \
|
||||||
|
where you will publish all your events. Others also publish events \
|
||||||
|
related to you here.";
|
||||||
|
|
||||||
pub fn init(window: &mut Window, cx: &mut App) -> Entity<RelayListPanel> {
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<RelayListPanel> {
|
||||||
cx.new(|cx| RelayListPanel::new(window, cx))
|
cx.new(|cx| RelayListPanel::new(window, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
||||||
|
#[action(namespace = relay, no_json)]
|
||||||
|
enum SetMetadata {
|
||||||
|
Read,
|
||||||
|
Write,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RelayListPanel {
|
pub struct RelayListPanel {
|
||||||
name: SharedString,
|
name: SharedString,
|
||||||
@@ -29,6 +42,9 @@ pub struct RelayListPanel {
|
|||||||
/// Relay URL input
|
/// Relay URL input
|
||||||
input: Entity<InputState>,
|
input: Entity<InputState>,
|
||||||
|
|
||||||
|
/// Whether the panel is updating
|
||||||
|
updating: bool,
|
||||||
|
|
||||||
/// Relay metadata input
|
/// Relay metadata input
|
||||||
metadata: Entity<Option<RelayMetadata>>,
|
metadata: Entity<Option<RelayMetadata>>,
|
||||||
|
|
||||||
@@ -42,7 +58,7 @@ pub struct RelayListPanel {
|
|||||||
_subscriptions: SmallVec<[Subscription; 1]>,
|
_subscriptions: SmallVec<[Subscription; 1]>,
|
||||||
|
|
||||||
// Background tasks
|
// Background tasks
|
||||||
_tasks: SmallVec<[Task<()>; 1]>,
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RelayListPanel {
|
impl RelayListPanel {
|
||||||
@@ -50,28 +66,7 @@ impl RelayListPanel {
|
|||||||
let input = cx.new(|cx| InputState::new(window, cx).placeholder("wss://example.com"));
|
let input = cx.new(|cx| InputState::new(window, cx).placeholder("wss://example.com"));
|
||||||
let metadata = cx.new(|_| None);
|
let metadata = cx.new(|_| None);
|
||||||
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
|
||||||
let client = nostr.read(cx).client();
|
|
||||||
|
|
||||||
let mut subscriptions = smallvec![];
|
let mut subscriptions = smallvec![];
|
||||||
let mut tasks = smallvec![];
|
|
||||||
|
|
||||||
tasks.push(
|
|
||||||
// Load user's relays in the local database
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
|
||||||
let result = cx
|
|
||||||
.background_spawn(async move { Self::load(&client).await })
|
|
||||||
.await;
|
|
||||||
|
|
||||||
if let Ok(relays) = result {
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
this.relays.extend(relays);
|
|
||||||
cx.notify();
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
// Subscribe to user's input events
|
// Subscribe to user's input events
|
||||||
@@ -82,32 +77,57 @@ impl RelayListPanel {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Run at the end of current cycle
|
||||||
|
cx.defer_in(window, |this, window, cx| {
|
||||||
|
this.load(window, cx);
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
name: "Update Relay List".into(),
|
name: "Update Relay List".into(),
|
||||||
focus_handle: cx.focus_handle(),
|
focus_handle: cx.focus_handle(),
|
||||||
input,
|
input,
|
||||||
|
updating: false,
|
||||||
metadata,
|
metadata,
|
||||||
relays: HashSet::new(),
|
relays: HashSet::new(),
|
||||||
error: None,
|
error: None,
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
_tasks: tasks,
|
tasks: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn load(client: &Client) -> Result<Vec<(RelayUrl, Option<RelayMetadata>)>, Error> {
|
#[allow(clippy::type_complexity)]
|
||||||
let signer = client.signer().context("Signer not found")?;
|
fn load(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let public_key = signer.get_public_key().await?;
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
let filter = Filter::new()
|
let task: Task<Result<Vec<(RelayUrl, Option<RelayMetadata>)>, Error>> = cx
|
||||||
.kind(Kind::RelayList)
|
.background_spawn(async move {
|
||||||
.author(public_key)
|
let signer = client.signer().context("Signer not found")?;
|
||||||
.limit(1);
|
let public_key = signer.get_public_key().await?;
|
||||||
|
|
||||||
if let Some(event) = client.database().query(filter).await?.first_owned() {
|
let filter = Filter::new()
|
||||||
Ok(nip65::extract_owned_relay_list(event).collect())
|
.kind(Kind::RelayList)
|
||||||
} else {
|
.author(public_key)
|
||||||
Err(anyhow!("Not found."))
|
.limit(1);
|
||||||
}
|
|
||||||
|
if let Some(event) = client.database().query(filter).await?.first_owned() {
|
||||||
|
Ok(nip65::extract_owned_relay_list(event).collect())
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("Not found."))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
|
let relays = task.await?;
|
||||||
|
|
||||||
|
// Update state
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.relays.extend(relays);
|
||||||
|
cx.notify();
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn add(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
@@ -120,7 +140,7 @@ impl RelayListPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(url) = RelayUrl::parse(&value) {
|
if let Ok(url) = RelayUrl::parse(&value) {
|
||||||
if !self.relays.insert((url, metadata.to_owned())) {
|
if self.relays.insert((url, metadata.to_owned())) {
|
||||||
self.input.update(cx, |this, cx| {
|
self.input.update(cx, |this, cx| {
|
||||||
this.set_value("", window, cx);
|
this.set_value("", window, cx);
|
||||||
});
|
});
|
||||||
@@ -143,19 +163,42 @@ impl RelayListPanel {
|
|||||||
self.error = Some(error.into());
|
self.error = Some(error.into());
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
cx.background_executor().timer(Duration::from_secs(2)).await;
|
cx.background_executor().timer(Duration::from_secs(2)).await;
|
||||||
|
|
||||||
// Clear the error message after a delay
|
// Clear the error message after a delay
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.error = None;
|
this.error = None;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})?;
|
||||||
.ok();
|
|
||||||
})
|
Ok(())
|
||||||
.detach();
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_relays(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn set_updating(&mut self, updating: bool, cx: &mut Context<Self>) {
|
||||||
|
self.updating = updating;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_metadata(&mut self, ev: &SetMetadata, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
match ev {
|
||||||
|
SetMetadata::Read => {
|
||||||
|
self.metadata.update(cx, |this, cx| {
|
||||||
|
*this = Some(RelayMetadata::Read);
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
SetMetadata::Write => {
|
||||||
|
self.metadata.update(cx, |this, cx| {
|
||||||
|
*this = Some(RelayMetadata::Write);
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_relays(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if self.relays.is_empty() {
|
if self.relays.is_empty() {
|
||||||
self.set_error("You need to add at least 1 relay", window, cx);
|
self.set_error("You need to add at least 1 relay", window, cx);
|
||||||
return;
|
return;
|
||||||
@@ -163,109 +206,104 @@ impl RelayListPanel {
|
|||||||
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
let client = nostr.read(cx).client();
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
|
// Get all relays
|
||||||
let relays = self.relays.clone();
|
let relays = self.relays.clone();
|
||||||
|
|
||||||
|
// Set updating state
|
||||||
|
self.set_updating(true, cx);
|
||||||
|
|
||||||
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
||||||
let builder = EventBuilder::relay_list(relays);
|
let builder = EventBuilder::relay_list(relays);
|
||||||
let event = client.sign_event_builder(builder).await?;
|
let event = client.sign_event_builder(builder).await?;
|
||||||
|
|
||||||
// Set relay list for current user
|
// Set relay list for current user
|
||||||
client.send_event(&event).to(BOOTSTRAP_RELAYS).await?;
|
client.send_event(&event).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
match task.await {
|
match task.await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// TODO
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
this.set_updating(false, cx);
|
||||||
|
this.load(window, cx);
|
||||||
|
|
||||||
|
window.push_notification("Update successful", cx);
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
this.update_in(cx, |this, window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
|
this.set_updating(false, cx);
|
||||||
this.set_error(e.to_string(), window, cx);
|
this.set_error(e.to_string(), window, cx);
|
||||||
})
|
})?;
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
|
||||||
.detach();
|
Ok(())
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_list(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> UniformList {
|
fn render_list_items(&mut self, cx: &mut Context<Self>) -> Vec<impl IntoElement> {
|
||||||
let relays = self.relays.clone();
|
let mut items = Vec::new();
|
||||||
let total = relays.len();
|
|
||||||
|
|
||||||
uniform_list(
|
for (url, metadata) in self.relays.iter() {
|
||||||
"relays",
|
items.push(
|
||||||
total,
|
h_flex()
|
||||||
cx.processor(move |_v, range, _window, cx| {
|
.id(SharedString::from(url.to_string()))
|
||||||
let mut items = Vec::new();
|
.group("")
|
||||||
|
.flex_1()
|
||||||
for ix in range {
|
.w_full()
|
||||||
let Some((url, metadata)) = relays.iter().nth(ix) else {
|
.h_8()
|
||||||
continue;
|
.px_2()
|
||||||
};
|
.justify_between()
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
items.push(
|
.bg(cx.theme().secondary_background)
|
||||||
div()
|
.text_color(cx.theme().secondary_foreground)
|
||||||
.id(SharedString::from(url.to_string()))
|
.child(
|
||||||
.group("")
|
h_flex()
|
||||||
.w_full()
|
.gap_1()
|
||||||
.h_9()
|
.text_sm()
|
||||||
.py_0p5()
|
.child(SharedString::from(url.to_string()))
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
div()
|
||||||
.px_2()
|
.p_0p5()
|
||||||
.flex()
|
.rounded_xs()
|
||||||
.justify_between()
|
.font_semibold()
|
||||||
.rounded(cx.theme().radius)
|
.text_size(px(8.))
|
||||||
.bg(cx.theme().elevated_surface_background)
|
.text_color(cx.theme().secondary_foreground)
|
||||||
.child(
|
.map(|this| {
|
||||||
div().text_sm().child(SharedString::from(url.to_string())),
|
if let Some(metadata) = metadata {
|
||||||
)
|
this.child(SharedString::from(metadata.to_string()))
|
||||||
.child(
|
} else {
|
||||||
h_flex()
|
this.child("Read and Write")
|
||||||
.gap_1()
|
}
|
||||||
.text_xs()
|
}),
|
||||||
.map(|this| {
|
|
||||||
if let Some(metadata) = metadata {
|
|
||||||
this.child(SharedString::from(
|
|
||||||
metadata.to_string(),
|
|
||||||
))
|
|
||||||
} else {
|
|
||||||
this.child(SharedString::from("Read+Write"))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.child(
|
|
||||||
Button::new("remove_{ix}")
|
|
||||||
.icon(IconName::Close)
|
|
||||||
.xsmall()
|
|
||||||
.ghost()
|
|
||||||
.invisible()
|
|
||||||
.group_hover("", |this| this.visible())
|
|
||||||
.on_click({
|
|
||||||
let url = url.to_owned();
|
|
||||||
cx.listener(
|
|
||||||
move |this, _ev, _window, cx| {
|
|
||||||
this.remove(&url, cx);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
.child(
|
||||||
|
Button::new("remove_{ix}")
|
||||||
|
.icon(IconName::Close)
|
||||||
|
.xsmall()
|
||||||
|
.ghost()
|
||||||
|
.invisible()
|
||||||
|
.group_hover("", |this| this.visible())
|
||||||
|
.on_click({
|
||||||
|
let url = url.to_owned();
|
||||||
|
cx.listener(move |this, _ev, _window, cx| {
|
||||||
|
this.remove(&url, cx);
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
items
|
items
|
||||||
}),
|
|
||||||
)
|
|
||||||
.h_full()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_empty(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render_empty(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
h_flex()
|
h_flex()
|
||||||
.mt_2()
|
|
||||||
.h_20()
|
.h_20()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.border_2()
|
.border_2()
|
||||||
@@ -299,36 +337,67 @@ impl Focusable for RelayListPanel {
|
|||||||
impl Render for RelayListPanel {
|
impl Render for RelayListPanel {
|
||||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
v_flex()
|
v_flex()
|
||||||
.size_full()
|
.on_action(cx.listener(Self::set_metadata))
|
||||||
.items_center()
|
.p_3()
|
||||||
.justify_center()
|
.gap_3()
|
||||||
.p_2()
|
.w_full()
|
||||||
.gap_10()
|
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_center()
|
.text_xs()
|
||||||
.font_semibold()
|
.text_color(cx.theme().text_muted)
|
||||||
.line_height(relative(1.25))
|
.child(SharedString::from(MSG)),
|
||||||
.child(SharedString::from("Update Relay List")),
|
|
||||||
)
|
)
|
||||||
|
.child(divider(cx))
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.w_112()
|
|
||||||
.gap_2()
|
.gap_2()
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.font_semibold()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("Relays:")),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_1p5()
|
.gap_1()
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.w_full()
|
.w_full()
|
||||||
.child(TextInput::new(&self.input).small())
|
.child(
|
||||||
|
TextInput::new(&self.input)
|
||||||
|
.small()
|
||||||
|
.bordered(false)
|
||||||
|
.cleanable(),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("metadata")
|
||||||
|
.map(|this| {
|
||||||
|
if let Some(metadata) = self.metadata.read(cx) {
|
||||||
|
this.label(metadata.to_string())
|
||||||
|
} else {
|
||||||
|
this.label("R & W")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.tooltip("Relay metadata")
|
||||||
|
.ghost()
|
||||||
|
.h(rems(2.))
|
||||||
|
.text_xs()
|
||||||
|
.dropdown_menu(|this, _window, _cx| {
|
||||||
|
this.menu("Read", Box::new(SetMetadata::Read))
|
||||||
|
.menu("Write", Box::new(SetMetadata::Write))
|
||||||
|
}),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
Button::new("add")
|
Button::new("add")
|
||||||
.icon(IconName::Plus)
|
.icon(IconName::Plus)
|
||||||
.label("Add")
|
.tooltip("Add relay")
|
||||||
.ghost()
|
.ghost()
|
||||||
|
.size(rems(2.))
|
||||||
.on_click(cx.listener(move |this, _, window, cx| {
|
.on_click(cx.listener(move |this, _, window, cx| {
|
||||||
this.add(window, cx);
|
this.add(window, cx);
|
||||||
})),
|
})),
|
||||||
@@ -339,23 +408,33 @@ impl Render for RelayListPanel {
|
|||||||
div()
|
div()
|
||||||
.italic()
|
.italic()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.text_color(cx.theme().danger_foreground)
|
.text_color(cx.theme().text_danger)
|
||||||
.child(error.clone()),
|
.child(error.clone()),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.map(|this| {
|
.map(|this| {
|
||||||
if !self.relays.is_empty() {
|
if self.relays.is_empty() {
|
||||||
this.child(self.render_list(window, cx))
|
|
||||||
} else {
|
|
||||||
this.child(self.render_empty(window, cx))
|
this.child(self.render_empty(window, cx))
|
||||||
|
} else {
|
||||||
|
this.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1()
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.children(self.render_list_items(cx)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.child(divider(cx))
|
|
||||||
.child(
|
.child(
|
||||||
Button::new("submit")
|
Button::new("submit")
|
||||||
|
.icon(IconName::CheckCircle)
|
||||||
.label("Update")
|
.label("Update")
|
||||||
.primary()
|
.primary()
|
||||||
|
.small()
|
||||||
|
.font_semibold()
|
||||||
|
.loading(self.updating)
|
||||||
|
.disabled(self.updating)
|
||||||
.on_click(cx.listener(move |this, _ev, window, cx| {
|
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||||
this.set_relays(window, cx);
|
this.set_relays(window, cx);
|
||||||
})),
|
})),
|
||||||
|
|||||||
152
crates/coop/src/panels/trash.rs
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
use chat::ChatRegistry;
|
||||||
|
use gpui::{
|
||||||
|
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
|
||||||
|
Focusable, InteractiveElement, IntoElement, ListAlignment, ListState, ParentElement, Render,
|
||||||
|
SharedString, Styled, Window, div, list, px, relative,
|
||||||
|
};
|
||||||
|
use theme::ActiveTheme;
|
||||||
|
use ui::button::{Button, ButtonVariants};
|
||||||
|
use ui::dock::{Panel, PanelEvent};
|
||||||
|
use ui::scroll::Scrollbar;
|
||||||
|
use ui::{Icon, IconName, Sizable, h_flex, v_flex};
|
||||||
|
|
||||||
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<TrashPanel> {
|
||||||
|
cx.new(|cx| TrashPanel::new(window, cx))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TrashPanel {
|
||||||
|
name: SharedString,
|
||||||
|
focus_handle: FocusHandle,
|
||||||
|
|
||||||
|
/// List state for messages
|
||||||
|
list_state: ListState,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TrashPanel {
|
||||||
|
fn new(_window: &mut Window, cx: &mut App) -> Self {
|
||||||
|
let chat = ChatRegistry::global(cx);
|
||||||
|
let count = chat.read(cx).count_trash_messages(cx);
|
||||||
|
let list_state = ListState::new(count, ListAlignment::Bottom, px(1024.));
|
||||||
|
|
||||||
|
Self {
|
||||||
|
name: "Trash".into(),
|
||||||
|
focus_handle: cx.focus_handle(),
|
||||||
|
list_state,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn copy(&self, ix: usize, cx: &App) {
|
||||||
|
let chat = ChatRegistry::global(cx);
|
||||||
|
let trashes = chat.read(cx).trashes();
|
||||||
|
|
||||||
|
if let Some(message) = trashes.read(cx).iter().nth(ix) {
|
||||||
|
let item = ClipboardItem::new_string(message.raw_event.to_string());
|
||||||
|
cx.write_to_clipboard(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_list_item(
|
||||||
|
&mut self,
|
||||||
|
ix: usize,
|
||||||
|
_window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> AnyElement {
|
||||||
|
let chat = ChatRegistry::global(cx);
|
||||||
|
let trashes = chat.read(cx).trashes();
|
||||||
|
|
||||||
|
if let Some(message) = trashes.read(cx).iter().nth(ix) {
|
||||||
|
v_flex()
|
||||||
|
.id(ix)
|
||||||
|
.p_2()
|
||||||
|
.w_full()
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.p_2()
|
||||||
|
.w_full()
|
||||||
|
.gap_1()
|
||||||
|
.rounded(cx.theme().radius_lg)
|
||||||
|
.bg(cx.theme().surface_background)
|
||||||
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_color(cx.theme().text_danger)
|
||||||
|
.child(message.reason.clone()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.h_10()
|
||||||
|
.w_full()
|
||||||
|
.px_2()
|
||||||
|
.justify_between()
|
||||||
|
.bg(cx.theme().elevated_surface_background)
|
||||||
|
.border_1()
|
||||||
|
.border_color(cx.theme().border)
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.truncate()
|
||||||
|
.text_ellipsis()
|
||||||
|
.text_xs()
|
||||||
|
.line_height(relative(1.))
|
||||||
|
.child(message.raw_event.clone()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new(format!("copy-{ix}"))
|
||||||
|
.icon(IconName::Copy)
|
||||||
|
.ghost()
|
||||||
|
.small()
|
||||||
|
.on_click(cx.listener(move |this, _ev, _window, cx| {
|
||||||
|
this.copy(ix, cx);
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.into_any_element()
|
||||||
|
} else {
|
||||||
|
div().id(ix).into_any_element()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Panel for TrashPanel {
|
||||||
|
fn panel_id(&self) -> SharedString {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title(&self, _cx: &App) -> AnyElement {
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.text_sm()
|
||||||
|
.child(Icon::new(IconName::Warning).small())
|
||||||
|
.child("Errors")
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<PanelEvent> for TrashPanel {}
|
||||||
|
|
||||||
|
impl Focusable for TrashPanel {
|
||||||
|
fn focus_handle(&self, _: &App) -> gpui::FocusHandle {
|
||||||
|
self.focus_handle.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for TrashPanel {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
v_flex().size_full().relative().child(
|
||||||
|
v_flex()
|
||||||
|
.flex_1()
|
||||||
|
.relative()
|
||||||
|
.child(
|
||||||
|
list(
|
||||||
|
self.list_state.clone(),
|
||||||
|
cx.processor(move |this, ix, window, cx| {
|
||||||
|
this.render_list_item(ix, window, cx)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.size_full(),
|
||||||
|
)
|
||||||
|
.child(Scrollbar::vertical(&self.list_state)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,16 +3,16 @@ use std::rc::Rc;
|
|||||||
use chat::RoomKind;
|
use chat::RoomKind;
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, rems, App, ClickEvent, InteractiveElement, IntoElement, ParentElement as _, RenderOnce,
|
App, ClickEvent, InteractiveElement, IntoElement, ParentElement as _, RenderOnce, SharedString,
|
||||||
SharedString, StatefulInteractiveElement, Styled, Window,
|
StatefulInteractiveElement, Styled, Window, div,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use settings::AppSettings;
|
use settings::AppSettings;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::dock_area::ClosePanel;
|
use ui::dock::ClosePanel;
|
||||||
use ui::modal::ModalButtonProps;
|
use ui::modal::ModalButtonProps;
|
||||||
use ui::{h_flex, Icon, IconName, Selectable, Sizable, StyledExt, WindowExtension};
|
use ui::{Icon, IconName, Selectable, Sizable, StyledExt, WindowExtension, h_flex};
|
||||||
|
|
||||||
use crate::dialogs::screening;
|
use crate::dialogs::screening;
|
||||||
|
|
||||||
@@ -106,14 +106,7 @@ impl RenderOnce for RoomEntry {
|
|||||||
.rounded(cx.theme().radius)
|
.rounded(cx.theme().radius)
|
||||||
.when(!hide_avatar, |this| {
|
.when(!hide_avatar, |this| {
|
||||||
this.when_some(self.avatar, |this, avatar| {
|
this.when_some(self.avatar, |this, avatar| {
|
||||||
this.child(
|
this.child(Avatar::new(avatar).small().flex_shrink_0())
|
||||||
div()
|
|
||||||
.flex_shrink_0()
|
|
||||||
.size_6()
|
|
||||||
.rounded_full()
|
|
||||||
.overflow_hidden()
|
|
||||||
.child(Avatar::new(avatar).size(rems(1.5))),
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
@@ -155,26 +148,27 @@ impl RenderOnce for RoomEntry {
|
|||||||
this.on_click(move |event, window, cx| {
|
this.on_click(move |event, window, cx| {
|
||||||
handler(event, window, cx);
|
handler(event, window, cx);
|
||||||
|
|
||||||
if let Some(public_key) = public_key {
|
if let Some(public_key) = public_key
|
||||||
if self.kind != Some(RoomKind::Ongoing) && screening {
|
&& self.kind != Some(RoomKind::Ongoing)
|
||||||
let screening = screening::init(public_key, window, cx);
|
&& screening
|
||||||
|
{
|
||||||
|
let screening = screening::init(public_key, window, cx);
|
||||||
|
|
||||||
window.open_modal(cx, move |this, _window, _cx| {
|
window.open_modal(cx, move |this, _window, _cx| {
|
||||||
this.confirm()
|
this.confirm()
|
||||||
.child(screening.clone())
|
.child(screening.clone())
|
||||||
.button_props(
|
.button_props(
|
||||||
ModalButtonProps::default()
|
ModalButtonProps::default()
|
||||||
.cancel_text("Ignore")
|
.cancel_text("Ignore")
|
||||||
.ok_text("Response"),
|
.ok_text("Response"),
|
||||||
)
|
)
|
||||||
.on_cancel(move |_event, window, cx| {
|
.on_cancel(move |_event, window, cx| {
|
||||||
window.dispatch_action(Box::new(ClosePanel), cx);
|
window.dispatch_action(Box::new(ClosePanel), cx);
|
||||||
// Prevent closing the modal on click
|
// Prevent closing the modal on click
|
||||||
// modal will be automatically closed after closing panel
|
// modal will be automatically closed after closing panel
|
||||||
false
|
false
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,29 +4,26 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use anyhow::{Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error};
|
||||||
use chat::{ChatEvent, ChatRegistry, Room, RoomKind};
|
use chat::{ChatEvent, ChatRegistry, Room, RoomKind};
|
||||||
use common::{DebouncedDelay, RenderedTimestamp};
|
use common::{DebouncedDelay, TimestampExt};
|
||||||
use entry::RoomEntry;
|
use entry::RoomEntry;
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, uniform_list, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable,
|
App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement,
|
||||||
IntoElement, ParentElement, Render, RetainAllImageCache, SharedString, Styled, Subscription,
|
ParentElement, Render, RetainAllImageCache, SharedString, Styled, Subscription, Task,
|
||||||
Task, UniformListScrollHandle, Window,
|
UniformListScrollHandle, Window, div, uniform_list,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use person::PersonRegistry;
|
use person::PersonRegistry;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use state::{NostrRegistry, FIND_DELAY};
|
use state::{FIND_DELAY, NostrRegistry};
|
||||||
use theme::{ActiveTheme, TITLEBAR_HEIGHT};
|
use theme::{ActiveTheme, SIDEBAR_WIDTH, TABBAR_HEIGHT};
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::divider::Divider;
|
use ui::dock::{Panel, PanelEvent};
|
||||||
use ui::dock_area::panel::{Panel, PanelEvent};
|
|
||||||
use ui::indicator::Indicator;
|
use ui::indicator::Indicator;
|
||||||
use ui::input::{InputEvent, InputState, TextInput};
|
use ui::input::{InputEvent, InputState, TextInput};
|
||||||
use ui::notification::Notification;
|
use ui::notification::Notification;
|
||||||
use ui::scroll::Scrollbar;
|
use ui::scroll::Scrollbar;
|
||||||
use ui::{
|
use ui::{Icon, IconName, Selectable, Sizable, StyledExt, WindowExtension, h_flex, v_flex};
|
||||||
h_flex, v_flex, Disableable, Icon, IconName, Selectable, Sizable, StyledExt, WindowExtension,
|
|
||||||
};
|
|
||||||
|
|
||||||
mod entry;
|
mod entry;
|
||||||
|
|
||||||
@@ -122,12 +119,10 @@ impl Sidebar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
InputEvent::Focus => {
|
InputEvent::Focus => {
|
||||||
this.set_input_focus(window, cx);
|
this.set_input_focus(true, window, cx);
|
||||||
this.get_contact_list(window, cx);
|
this.get_contact_list(window, cx);
|
||||||
}
|
}
|
||||||
InputEvent::Blur => {
|
_ => {}
|
||||||
this.set_input_focus(window, cx);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -185,7 +180,10 @@ impl Sidebar {
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
cx.update(|window, cx| {
|
cx.update(|window, cx| {
|
||||||
window.push_notification(Notification::error(e.to_string()), cx);
|
window.push_notification(
|
||||||
|
Notification::error(e.to_string()).autohide(false),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -246,6 +244,7 @@ impl Sidebar {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the results of the search
|
||||||
fn set_results(&mut self, results: Vec<PublicKey>, cx: &mut Context<Self>) {
|
fn set_results(&mut self, results: Vec<PublicKey>, cx: &mut Context<Self>) {
|
||||||
self.find_results.update(cx, |this, cx| {
|
self.find_results.update(cx, |this, cx| {
|
||||||
*this = Some(results);
|
*this = Some(results);
|
||||||
@@ -253,6 +252,7 @@ impl Sidebar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the finding status
|
||||||
fn set_finding(&mut self, status: bool, _window: &mut Window, cx: &mut Context<Self>) {
|
fn set_finding(&mut self, status: bool, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
// Disable the input to prevent duplicate requests
|
// Disable the input to prevent duplicate requests
|
||||||
self.find_input.update(cx, |this, cx| {
|
self.find_input.update(cx, |this, cx| {
|
||||||
@@ -264,13 +264,14 @@ impl Sidebar {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_input_focus(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
/// Set the focus status of the input element.
|
||||||
self.find_focused = !self.find_focused;
|
fn set_input_focus(&mut self, status: bool, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.find_focused = status;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
|
||||||
// Reset the find panel
|
// Focus to the input element
|
||||||
if !self.find_focused {
|
if !status {
|
||||||
self.reset(window, cx);
|
window.focus_prev(cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +357,8 @@ impl Sidebar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the active filter for the sidebar.
|
/// Set the active filter for the sidebar.
|
||||||
fn set_filter(&mut self, kind: RoomKind, cx: &mut Context<Self>) {
|
fn set_filter(&mut self, kind: RoomKind, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.set_input_focus(false, window, cx);
|
||||||
self.filter.update(cx, |this, cx| {
|
self.filter.update(cx, |this, cx| {
|
||||||
*this = kind;
|
*this = kind;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
@@ -364,7 +366,11 @@ impl Sidebar {
|
|||||||
self.new_requests = false;
|
self.new_requests = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_list_items(&self, range: Range<usize>, cx: &Context<Self>) -> Vec<impl IntoElement> {
|
fn render_list_items(
|
||||||
|
&self,
|
||||||
|
range: Range<usize>,
|
||||||
|
cx: &Context<Self>,
|
||||||
|
) -> Vec<impl IntoElement + use<>> {
|
||||||
let chat = ChatRegistry::global(cx);
|
let chat = ChatRegistry::global(cx);
|
||||||
let rooms = chat.read(cx).rooms(self.filter.read(cx), cx);
|
let rooms = chat.read(cx).rooms(self.filter.read(cx), cx);
|
||||||
|
|
||||||
@@ -396,7 +402,11 @@ impl Sidebar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Render the contact list
|
/// Render the contact list
|
||||||
fn render_results(&self, range: Range<usize>, cx: &Context<Self>) -> Vec<impl IntoElement> {
|
fn render_results(
|
||||||
|
&self,
|
||||||
|
range: Range<usize>,
|
||||||
|
cx: &Context<Self>,
|
||||||
|
) -> Vec<impl IntoElement + use<>> {
|
||||||
let persons = PersonRegistry::global(cx);
|
let persons = PersonRegistry::global(cx);
|
||||||
|
|
||||||
// Get the contact list
|
// Get the contact list
|
||||||
@@ -429,7 +439,11 @@ impl Sidebar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Render the contact list
|
/// Render the contact list
|
||||||
fn render_contacts(&self, range: Range<usize>, cx: &Context<Self>) -> Vec<impl IntoElement> {
|
fn render_contacts(
|
||||||
|
&self,
|
||||||
|
range: Range<usize>,
|
||||||
|
cx: &Context<Self>,
|
||||||
|
) -> Vec<impl IntoElement + use<>> {
|
||||||
let persons = PersonRegistry::global(cx);
|
let persons = PersonRegistry::global(cx);
|
||||||
|
|
||||||
// Get the contact list
|
// Get the contact list
|
||||||
@@ -495,12 +509,13 @@ impl Render for Sidebar {
|
|||||||
v_flex()
|
v_flex()
|
||||||
.image_cache(self.image_cache.clone())
|
.image_cache(self.image_cache.clone())
|
||||||
.size_full()
|
.size_full()
|
||||||
.relative()
|
.gap_2()
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.h(TITLEBAR_HEIGHT)
|
.h(TABBAR_HEIGHT)
|
||||||
.border_b_1()
|
.border_b_1()
|
||||||
.border_color(cx.theme().border)
|
.border_color(cx.theme().border)
|
||||||
|
.bg(cx.theme().tab_background)
|
||||||
.child(
|
.child(
|
||||||
TextInput::new(&self.find_input)
|
TextInput::new(&self.find_input)
|
||||||
.appearance(false)
|
.appearance(false)
|
||||||
@@ -520,22 +535,17 @@ impl Render for Sidebar {
|
|||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.h(TITLEBAR_HEIGHT)
|
.px_2()
|
||||||
|
.gap_2()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.border_b_1()
|
|
||||||
.border_color(cx.theme().border)
|
|
||||||
.when(show_find_panel, |this| {
|
.when(show_find_panel, |this| {
|
||||||
this.child(
|
this.child(
|
||||||
Button::new("search-results")
|
Button::new("search-results")
|
||||||
.icon(IconName::Search)
|
.icon(IconName::Search)
|
||||||
.label("Search")
|
|
||||||
.tooltip("All search results")
|
.tooltip("All search results")
|
||||||
.small()
|
.small()
|
||||||
.underline()
|
.ghost_alt()
|
||||||
.ghost()
|
|
||||||
.font_semibold()
|
.font_semibold()
|
||||||
.rounded_none()
|
|
||||||
.h_full()
|
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.selected(true),
|
.selected(true),
|
||||||
)
|
)
|
||||||
@@ -552,21 +562,16 @@ impl Render for Sidebar {
|
|||||||
.when(!show_find_panel, |this| this.label("Inbox"))
|
.when(!show_find_panel, |this| this.label("Inbox"))
|
||||||
.tooltip("All ongoing conversations")
|
.tooltip("All ongoing conversations")
|
||||||
.small()
|
.small()
|
||||||
.underline()
|
.ghost_alt()
|
||||||
.ghost()
|
|
||||||
.font_semibold()
|
.font_semibold()
|
||||||
.rounded_none()
|
|
||||||
.h_full()
|
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.disabled(show_find_panel)
|
|
||||||
.selected(
|
.selected(
|
||||||
!show_find_panel && self.current_filter(&RoomKind::Ongoing, cx),
|
!show_find_panel && self.current_filter(&RoomKind::Ongoing, cx),
|
||||||
)
|
)
|
||||||
.on_click(cx.listener(|this, _ev, _window, cx| {
|
.on_click(cx.listener(|this, _ev, window, cx| {
|
||||||
this.set_filter(RoomKind::Ongoing, cx);
|
this.set_filter(RoomKind::Ongoing, window, cx);
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
.child(Divider::vertical())
|
|
||||||
.child(
|
.child(
|
||||||
Button::new("requests")
|
Button::new("requests")
|
||||||
.map(|this| {
|
.map(|this| {
|
||||||
@@ -579,27 +584,23 @@ impl Render for Sidebar {
|
|||||||
.when(!show_find_panel, |this| this.label("Requests"))
|
.when(!show_find_panel, |this| this.label("Requests"))
|
||||||
.tooltip("Incoming new conversations")
|
.tooltip("Incoming new conversations")
|
||||||
.small()
|
.small()
|
||||||
.ghost()
|
.ghost_alt()
|
||||||
.underline()
|
|
||||||
.font_semibold()
|
.font_semibold()
|
||||||
.rounded_none()
|
|
||||||
.h_full()
|
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.disabled(show_find_panel)
|
|
||||||
.selected(
|
.selected(
|
||||||
!show_find_panel && !self.current_filter(&RoomKind::Ongoing, cx),
|
!show_find_panel && !self.current_filter(&RoomKind::Ongoing, cx),
|
||||||
)
|
)
|
||||||
.when(self.new_requests, |this| {
|
.when(self.new_requests, |this| {
|
||||||
this.child(div().size_1().rounded_full().bg(cx.theme().cursor))
|
this.child(div().size_1().rounded_full().bg(cx.theme().cursor))
|
||||||
})
|
})
|
||||||
.on_click(cx.listener(|this, _ev, _window, cx| {
|
.on_click(cx.listener(|this, _ev, window, cx| {
|
||||||
this.set_filter(RoomKind::default(), cx);
|
this.set_filter(RoomKind::default(), window, cx);
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.when(!show_find_panel && !loading && total_rooms == 0, |this| {
|
.when(!show_find_panel && !loading && total_rooms == 0, |this| {
|
||||||
this.child(
|
this.child(
|
||||||
div().mt_2().px_2().child(
|
div().w(SIDEBAR_WIDTH).px_2().child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.p_3()
|
.p_3()
|
||||||
.h_24()
|
.h_24()
|
||||||
@@ -627,12 +628,9 @@ impl Render for Sidebar {
|
|||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.h_full()
|
.size_full()
|
||||||
.px_1p5()
|
|
||||||
.mt_2()
|
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.overflow_y_hidden()
|
|
||||||
.when(show_find_panel, |this| {
|
.when(show_find_panel, |this| {
|
||||||
this.gap_3()
|
this.gap_3()
|
||||||
.when_some(self.find_results.read(cx).as_ref(), |this, results| {
|
.when_some(self.find_results.read(cx).as_ref(), |this, results| {
|
||||||
@@ -655,7 +653,7 @@ impl Render for Sidebar {
|
|||||||
uniform_list(
|
uniform_list(
|
||||||
"rooms",
|
"rooms",
|
||||||
results.len(),
|
results.len(),
|
||||||
cx.processor(|this, range, _window, cx| {
|
cx.processor(move |this, range, _window, cx| {
|
||||||
this.render_results(range, cx)
|
this.render_results(range, cx)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -675,14 +673,14 @@ impl Render for Sidebar {
|
|||||||
.text_xs()
|
.text_xs()
|
||||||
.font_semibold()
|
.font_semibold()
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.child(Icon::new(IconName::ChevronDown))
|
.child(Icon::new(IconName::ChevronDown).small())
|
||||||
.child(SharedString::from("Suggestions")),
|
.child(SharedString::from("Suggestions")),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
uniform_list(
|
uniform_list(
|
||||||
"contacts",
|
"contacts",
|
||||||
contacts.len(),
|
contacts.len(),
|
||||||
cx.processor(move |this, range, _window, cx| {
|
cx.processor(|this, range, _window, cx| {
|
||||||
this.render_contacts(range, cx)
|
this.render_contacts(range, cx)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -703,7 +701,8 @@ impl Render for Sidebar {
|
|||||||
)
|
)
|
||||||
.track_scroll(&self.scroll_handle)
|
.track_scroll(&self.scroll_handle)
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.h_full(),
|
.h_full()
|
||||||
|
.px_2(),
|
||||||
)
|
)
|
||||||
.child(Scrollbar::vertical(&self.scroll_handle))
|
.child(Scrollbar::vertical(&self.scroll_handle))
|
||||||
}),
|
}),
|
||||||
@@ -747,7 +746,7 @@ impl Render for Sidebar {
|
|||||||
.bg(cx.theme().background.opacity(0.85))
|
.bg(cx.theme().background.opacity(0.85))
|
||||||
.border_color(cx.theme().border_disabled)
|
.border_color(cx.theme().border_disabled)
|
||||||
.border_1()
|
.border_1()
|
||||||
.when(cx.theme().shadow, |this| this.shadow_sm())
|
.when(cx.theme().shadow, |this| this.shadow_xs())
|
||||||
.rounded_full()
|
.rounded_full()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.font_semibold()
|
.font_semibold()
|
||||||
|
|||||||
@@ -1,31 +1,68 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use ::settings::AppSettings;
|
||||||
use chat::{ChatEvent, ChatRegistry};
|
use chat::{ChatEvent, ChatRegistry};
|
||||||
|
use common::download_dir;
|
||||||
|
use device::{DeviceEvent, DeviceRegistry};
|
||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, rems, App, AppContext, Axis, Context, Entity, InteractiveElement, IntoElement,
|
Action, App, AppContext, Axis, Context, Entity, InteractiveElement, IntoElement, ParentElement,
|
||||||
ParentElement, Render, SharedString, Styled, Subscription, Window,
|
Render, SharedString, StatefulInteractiveElement, Styled, Subscription, Window, div, px,
|
||||||
|
relative,
|
||||||
};
|
};
|
||||||
use person::PersonRegistry;
|
use nostr_sdk::prelude::*;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use person::{PersonRegistry, shorten_pubkey};
|
||||||
use state::{NostrRegistry, RelayState};
|
use serde::Deserialize;
|
||||||
use theme::{ActiveTheme, SIDEBAR_WIDTH, TITLEBAR_HEIGHT};
|
use smallvec::{SmallVec, smallvec};
|
||||||
|
use state::{NostrRegistry, StateEvent};
|
||||||
|
use theme::{ActiveTheme, SIDEBAR_WIDTH, Theme, ThemeRegistry};
|
||||||
use title_bar::TitleBar;
|
use title_bar::TitleBar;
|
||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::dock_area::dock::DockPlacement;
|
use ui::dock::{ClosePanel, DockArea, DockItem, DockPlacement, PanelView};
|
||||||
use ui::dock_area::panel::{PanelStyle, PanelView};
|
use ui::menu::{DropdownMenu, PopupMenuItem};
|
||||||
use ui::dock_area::{ClosePanel, DockArea, DockItem};
|
use ui::notification::{Notification, NotificationKind};
|
||||||
use ui::menu::DropdownMenu;
|
use ui::{Icon, IconName, Root, Sizable, WindowExtension, h_flex, v_flex};
|
||||||
use ui::{h_flex, v_flex, Root, Sizable, WindowExtension};
|
|
||||||
|
|
||||||
use crate::panels::greeter;
|
use crate::dialogs::restore::RestoreEncryption;
|
||||||
|
use crate::dialogs::{accounts, settings};
|
||||||
|
use crate::panels::{backup, contact_list, greeter, messaging_relays, profile, relay_list, trash};
|
||||||
use crate::sidebar;
|
use crate::sidebar;
|
||||||
|
|
||||||
|
const PREPARE_MSG: &str = "Coop is preparing a new identity for you. This may take a moment...";
|
||||||
|
const ENC_MSG: &str = "Encryption Key is a special key that used to encrypt and decrypt your messages. \
|
||||||
|
Your identity is completely decoupled from all encryption processes to protect your privacy.";
|
||||||
|
const ENC_WARN: &str = "By resetting your encryption key, you will lose access to \
|
||||||
|
all your encrypted messages before. This action cannot be undone.";
|
||||||
|
|
||||||
pub fn init(window: &mut Window, cx: &mut App) -> Entity<Workspace> {
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<Workspace> {
|
||||||
cx.new(|cx| Workspace::new(window, cx))
|
cx.new(|cx| Workspace::new(window, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DeviceNotifcation;
|
||||||
|
struct SignerNotifcation;
|
||||||
|
struct RelayNotifcation;
|
||||||
|
|
||||||
|
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
||||||
|
#[action(namespace = workspace, no_json)]
|
||||||
|
enum Command {
|
||||||
|
ToggleTheme,
|
||||||
|
ToggleAccount,
|
||||||
|
|
||||||
|
RefreshMessagingRelays,
|
||||||
|
BackupEncryption,
|
||||||
|
ImportEncryption,
|
||||||
|
RefreshEncryption,
|
||||||
|
ResetEncryption,
|
||||||
|
|
||||||
|
ShowRelayList,
|
||||||
|
ShowMessaging,
|
||||||
|
ShowProfile,
|
||||||
|
ShowSettings,
|
||||||
|
ShowBackup,
|
||||||
|
ShowContactList,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Workspace {
|
pub struct Workspace {
|
||||||
/// App's Title Bar
|
/// App's Title Bar
|
||||||
titlebar: Entity<TitleBar>,
|
titlebar: Entity<TitleBar>,
|
||||||
@@ -34,17 +71,111 @@ pub struct Workspace {
|
|||||||
dock: Entity<DockArea>,
|
dock: Entity<DockArea>,
|
||||||
|
|
||||||
/// Event subscriptions
|
/// Event subscriptions
|
||||||
_subscriptions: SmallVec<[Subscription; 3]>,
|
_subscriptions: SmallVec<[Subscription; 5]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Workspace {
|
impl Workspace {
|
||||||
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let chat = ChatRegistry::global(cx);
|
let chat = ChatRegistry::global(cx);
|
||||||
|
let device = DeviceRegistry::global(cx);
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
|
||||||
let titlebar = cx.new(|_| TitleBar::new());
|
let titlebar = cx.new(|_| TitleBar::new());
|
||||||
let dock = cx.new(|cx| DockArea::new(window, cx).panel_style(PanelStyle::TabBar));
|
let dock = cx.new(|cx| DockArea::new(window, cx));
|
||||||
|
|
||||||
let mut subscriptions = smallvec![];
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
|
subscriptions.push(
|
||||||
|
// Observe system appearance and update theme
|
||||||
|
cx.observe_window_appearance(window, |_this, window, cx| {
|
||||||
|
Theme::sync_system_appearance(Some(window), cx);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
subscriptions.push(
|
||||||
|
// Subscribe to the signer events
|
||||||
|
cx.subscribe_in(&nostr, window, move |this, _state, event, window, cx| {
|
||||||
|
match event {
|
||||||
|
StateEvent::Creating => {
|
||||||
|
let note = Notification::new()
|
||||||
|
.id::<SignerNotifcation>()
|
||||||
|
.title("Preparing a new identity")
|
||||||
|
.message(PREPARE_MSG)
|
||||||
|
.autohide(false)
|
||||||
|
.with_kind(NotificationKind::Info);
|
||||||
|
|
||||||
|
window.push_notification(note, cx);
|
||||||
|
}
|
||||||
|
StateEvent::Connecting => {
|
||||||
|
let note = Notification::new()
|
||||||
|
.id::<RelayNotifcation>()
|
||||||
|
.message("Connecting to the bootstrap relays...")
|
||||||
|
.with_kind(NotificationKind::Info);
|
||||||
|
|
||||||
|
window.push_notification(note, cx);
|
||||||
|
}
|
||||||
|
StateEvent::Connected => {
|
||||||
|
let note = Notification::new()
|
||||||
|
.id::<RelayNotifcation>()
|
||||||
|
.message("Connected to the bootstrap relays")
|
||||||
|
.with_kind(NotificationKind::Success);
|
||||||
|
|
||||||
|
window.push_notification(note, cx);
|
||||||
|
}
|
||||||
|
StateEvent::SignerSet => {
|
||||||
|
this.set_center_layout(window, cx);
|
||||||
|
// Clear the signer notification
|
||||||
|
window.clear_notification::<SignerNotifcation>(cx);
|
||||||
|
}
|
||||||
|
StateEvent::Show => {
|
||||||
|
this.account_selector(window, cx);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
subscriptions.push(
|
||||||
|
// Observe all events emitted by the device registry
|
||||||
|
cx.subscribe_in(&device, window, |_this, _device, event, window, cx| {
|
||||||
|
match event {
|
||||||
|
DeviceEvent::Requesting => {
|
||||||
|
const MSG: &str =
|
||||||
|
"Coop has sent a request for an encryption key. Please open the other client then approve the request.";
|
||||||
|
|
||||||
|
let note = Notification::new()
|
||||||
|
.id::<DeviceNotifcation>()
|
||||||
|
.autohide(false)
|
||||||
|
.title("Wait for approval")
|
||||||
|
.message(MSG)
|
||||||
|
.with_kind(NotificationKind::Info);
|
||||||
|
|
||||||
|
window.push_notification(note, cx);
|
||||||
|
}
|
||||||
|
DeviceEvent::Creating => {
|
||||||
|
let note = Notification::new()
|
||||||
|
.id::<DeviceNotifcation>()
|
||||||
|
.autohide(false)
|
||||||
|
.message("Creating encryption key")
|
||||||
|
.with_kind(NotificationKind::Info);
|
||||||
|
|
||||||
|
window.push_notification(note, cx);
|
||||||
|
}
|
||||||
|
DeviceEvent::Set => {
|
||||||
|
let note = Notification::new()
|
||||||
|
.id::<DeviceNotifcation>()
|
||||||
|
.message("Encryption Key has been set")
|
||||||
|
.with_kind(NotificationKind::Success);
|
||||||
|
|
||||||
|
window.push_notification(note, cx);
|
||||||
|
}
|
||||||
|
DeviceEvent::Error(error) => {
|
||||||
|
window.push_notification(Notification::error(error).autohide(false), cx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
// Observe all events emitted by the chat registry
|
// Observe all events emitted by the chat registry
|
||||||
cx.subscribe_in(&chat, window, move |this, chat, ev, window, cx| {
|
cx.subscribe_in(&chat, window, move |this, chat, ev, window, cx| {
|
||||||
@@ -73,6 +204,9 @@ impl Workspace {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
ChatEvent::Error(error) => {
|
||||||
|
window.push_notification(Notification::error(error).autohide(false), cx);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
@@ -84,12 +218,12 @@ impl Workspace {
|
|||||||
let ids = this.panel_ids(cx);
|
let ids = this.panel_ids(cx);
|
||||||
|
|
||||||
chat.update(cx, |this, cx| {
|
chat.update(cx, |this, cx| {
|
||||||
this.refresh_rooms(ids, cx);
|
this.refresh_rooms(&ids, cx);
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set the default layout for app's dock
|
// Set the layout at the end of cycle
|
||||||
cx.defer_in(window, |this, window, cx| {
|
cx.defer_in(window, |this, window, cx| {
|
||||||
this.set_layout(window, cx);
|
this.set_layout(window, cx);
|
||||||
});
|
});
|
||||||
@@ -106,151 +240,591 @@ impl Workspace {
|
|||||||
where
|
where
|
||||||
P: PanelView,
|
P: PanelView,
|
||||||
{
|
{
|
||||||
if let Some(root) = window.root::<Root>().flatten() {
|
if let Some(root) = window.root::<Root>().flatten()
|
||||||
if let Ok(workspace) = root.read(cx).view().clone().downcast::<Self>() {
|
&& let Ok(workspace) = root.read(cx).view().clone().downcast::<Self>()
|
||||||
workspace.update(cx, |this, cx| {
|
{
|
||||||
this.dock.update(cx, |this, cx| {
|
workspace.update(cx, |this, cx| {
|
||||||
this.add_panel(Arc::new(panel), placement, window, cx);
|
this.dock.update(cx, |this, cx| {
|
||||||
});
|
this.add_panel(Arc::new(panel), placement, window, cx);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all panel ids
|
/// Get all panel ids
|
||||||
fn panel_ids(&self, cx: &App) -> Option<Vec<u64>> {
|
fn panel_ids(&self, cx: &App) -> Vec<u64> {
|
||||||
let ids: Vec<u64> = self
|
self.dock
|
||||||
.dock
|
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.items
|
.items
|
||||||
.panel_ids(cx)
|
.panel_ids(cx)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|panel| panel.parse::<u64>().ok())
|
.filter_map(|panel| panel.parse::<u64>().ok())
|
||||||
.collect();
|
.collect()
|
||||||
|
|
||||||
Some(ids)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the dock layout
|
/// Set the dock layout
|
||||||
fn set_layout(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
fn set_layout(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let weak_dock = self.dock.downgrade();
|
|
||||||
|
|
||||||
// Sidebar
|
|
||||||
let left = DockItem::panel(Arc::new(sidebar::init(window, cx)));
|
let left = DockItem::panel(Arc::new(sidebar::init(window, cx)));
|
||||||
|
|
||||||
// Main workspace
|
// Update the dock layout with sidebar on the left
|
||||||
let center = DockItem::split_with_sizes(
|
|
||||||
Axis::Vertical,
|
|
||||||
vec![DockItem::tabs(
|
|
||||||
vec![Arc::new(greeter::init(window, cx))],
|
|
||||||
None,
|
|
||||||
&weak_dock,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
)],
|
|
||||||
vec![None],
|
|
||||||
&weak_dock,
|
|
||||||
window,
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update the dock layout
|
|
||||||
self.dock.update(cx, |this, cx| {
|
self.dock.update(cx, |this, cx| {
|
||||||
this.set_left_dock(left, Some(SIDEBAR_WIDTH), true, window, cx);
|
this.set_left_dock(left, Some(SIDEBAR_WIDTH), true, window, cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the center dock layout
|
||||||
|
fn set_center_layout(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let dock = self.dock.downgrade();
|
||||||
|
let greeter = Arc::new(greeter::init(window, cx));
|
||||||
|
let tabs = DockItem::tabs(vec![greeter], None, &dock, window, cx);
|
||||||
|
let center = DockItem::split(Axis::Vertical, vec![tabs], &dock, window, cx);
|
||||||
|
|
||||||
|
// Update the layout with center dock
|
||||||
|
self.dock.update(cx, |this, cx| {
|
||||||
this.set_center(center, window, cx);
|
this.set_center(center, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn titlebar_left(&mut self, _window: &mut Window, cx: &Context<Self>) -> impl IntoElement {
|
/// Handle command events
|
||||||
let chat = ChatRegistry::global(cx);
|
fn on_command(&mut self, command: &Command, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
match command {
|
||||||
|
Command::ShowSettings => {
|
||||||
|
let view = settings::init(window, cx);
|
||||||
|
|
||||||
|
window.open_modal(cx, move |this, _window, _cx| {
|
||||||
|
this.width(px(520.))
|
||||||
|
.show_close(true)
|
||||||
|
.pb_2()
|
||||||
|
.title("Preferences")
|
||||||
|
.child(view.clone())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Command::ShowProfile => {
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let signer = nostr.read(cx).signer();
|
||||||
|
|
||||||
|
if let Some(public_key) = signer.public_key() {
|
||||||
|
self.dock.update(cx, |this, cx| {
|
||||||
|
this.add_panel(
|
||||||
|
Arc::new(profile::init(public_key, window, cx)),
|
||||||
|
DockPlacement::Right,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Command::ShowContactList => {
|
||||||
|
self.dock.update(cx, |this, cx| {
|
||||||
|
this.add_panel(
|
||||||
|
Arc::new(contact_list::init(window, cx)),
|
||||||
|
DockPlacement::Right,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Command::ShowBackup => {
|
||||||
|
self.dock.update(cx, |this, cx| {
|
||||||
|
this.add_panel(
|
||||||
|
Arc::new(backup::init(window, cx)),
|
||||||
|
DockPlacement::Right,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Command::ShowMessaging => {
|
||||||
|
self.dock.update(cx, |this, cx| {
|
||||||
|
this.add_panel(
|
||||||
|
Arc::new(messaging_relays::init(window, cx)),
|
||||||
|
DockPlacement::Right,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Command::RefreshMessagingRelays => {
|
||||||
|
let chat = ChatRegistry::global(cx);
|
||||||
|
// Trigger a refresh of the chat registry
|
||||||
|
chat.update(cx, |this, cx| {
|
||||||
|
this.refresh(window, cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Command::ShowRelayList => {
|
||||||
|
self.dock.update(cx, |this, cx| {
|
||||||
|
this.add_panel(
|
||||||
|
Arc::new(relay_list::init(window, cx)),
|
||||||
|
DockPlacement::Right,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Command::RefreshEncryption => {
|
||||||
|
let device = DeviceRegistry::global(cx);
|
||||||
|
device.update(cx, |this, cx| {
|
||||||
|
this.get_announcement(cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Command::ResetEncryption => {
|
||||||
|
self.confirm_reset_encryption(window, cx);
|
||||||
|
}
|
||||||
|
Command::ToggleTheme => {
|
||||||
|
self.theme_selector(window, cx);
|
||||||
|
}
|
||||||
|
Command::ToggleAccount => {
|
||||||
|
self.account_selector(window, cx);
|
||||||
|
}
|
||||||
|
Command::BackupEncryption => {
|
||||||
|
let device = DeviceRegistry::global(cx).downgrade();
|
||||||
|
let save_dialog = cx.prompt_for_new_path(download_dir(), Some("encryption.txt"));
|
||||||
|
|
||||||
|
cx.spawn_in(window, async move |_this, cx| {
|
||||||
|
// Get the output path from the save dialog
|
||||||
|
let output_path = match save_dialog.await {
|
||||||
|
Ok(Ok(Some(path))) => path,
|
||||||
|
Ok(Ok(None)) | Err(_) => return Ok(()),
|
||||||
|
Ok(Err(error)) => {
|
||||||
|
cx.update(|window, cx| {
|
||||||
|
let message = format!("Failed to pick save location: {error:#}");
|
||||||
|
let note = Notification::error(message).autohide(false);
|
||||||
|
window.push_notification(note, cx);
|
||||||
|
})?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the backup task
|
||||||
|
let backup =
|
||||||
|
device.read_with(cx, |this, cx| this.backup(output_path.clone(), cx))?;
|
||||||
|
|
||||||
|
// Run the backup task
|
||||||
|
backup.await?;
|
||||||
|
|
||||||
|
// Open the backup file with the system's default application
|
||||||
|
cx.update(|_window, cx| {
|
||||||
|
cx.open_with_system(output_path.as_path());
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok::<_, anyhow::Error>(())
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
Command::ImportEncryption => {
|
||||||
|
self.import_encryption(window, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn confirm_reset_encryption(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let device = DeviceRegistry::global(cx);
|
||||||
|
let ent = device.downgrade();
|
||||||
|
|
||||||
|
window.open_modal(cx, move |this, _window, cx| {
|
||||||
|
let ent = ent.clone();
|
||||||
|
|
||||||
|
this.confirm()
|
||||||
|
.show_close(true)
|
||||||
|
.title("Reset Encryption Key")
|
||||||
|
.child(
|
||||||
|
v_flex()
|
||||||
|
.gap_1()
|
||||||
|
.text_sm()
|
||||||
|
.child(SharedString::from(ENC_MSG))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.italic()
|
||||||
|
.text_color(cx.theme().text_danger)
|
||||||
|
.child(SharedString::from(ENC_WARN)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.on_ok(move |_ev, _window, cx| {
|
||||||
|
ent.update(cx, |this, cx| {
|
||||||
|
this.set_announcement(Keys::generate(), cx);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
// true to close modal
|
||||||
|
true
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn import_encryption(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let restore = cx.new(|cx| RestoreEncryption::new(window, cx));
|
||||||
|
|
||||||
|
window.open_modal(cx, move |this, _window, _cx| {
|
||||||
|
this.width(px(520.))
|
||||||
|
.title("Restore Encryption")
|
||||||
|
.child(restore.clone())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn account_selector(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let accounts = accounts::init(window, cx);
|
||||||
|
|
||||||
|
window.open_modal(cx, move |this, _window, _cx| {
|
||||||
|
this.width(px(520.))
|
||||||
|
.title("Continue with")
|
||||||
|
.show_close(false)
|
||||||
|
.keyboard(false)
|
||||||
|
.overlay_closable(false)
|
||||||
|
.child(accounts.clone())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn theme_selector(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
window.open_modal(cx, move |this, _window, cx| {
|
||||||
|
let registry = ThemeRegistry::global(cx);
|
||||||
|
let themes = registry.read(cx).themes();
|
||||||
|
|
||||||
|
this.width(px(520.))
|
||||||
|
.show_close(true)
|
||||||
|
.title("Select theme")
|
||||||
|
.child(v_flex().gap_2().w_full().children({
|
||||||
|
let mut items = vec![];
|
||||||
|
|
||||||
|
for (ix, (path, theme)) in themes.iter().enumerate() {
|
||||||
|
items.push(
|
||||||
|
h_flex()
|
||||||
|
.id(ix)
|
||||||
|
.group("")
|
||||||
|
.px_2()
|
||||||
|
.h_8()
|
||||||
|
.w_full()
|
||||||
|
.justify_between()
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
|
.bg(cx.theme().ghost_element_background)
|
||||||
|
.hover(|this| this.bg(cx.theme().ghost_element_hover))
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_1p5()
|
||||||
|
.flex_1()
|
||||||
|
.text_sm()
|
||||||
|
.child(theme.name.clone())
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.italic()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(theme.author.clone()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.invisible()
|
||||||
|
.group_hover("", |this| this.visible())
|
||||||
|
.child(
|
||||||
|
Button::new(format!("url-{ix}"))
|
||||||
|
.icon(IconName::Link)
|
||||||
|
.ghost()
|
||||||
|
.small()
|
||||||
|
.on_click({
|
||||||
|
let theme = theme.clone();
|
||||||
|
move |_ev, _window, cx| {
|
||||||
|
cx.open_url(&theme.url);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new(format!("set-{ix}"))
|
||||||
|
.icon(IconName::Check)
|
||||||
|
.primary()
|
||||||
|
.small()
|
||||||
|
.on_click({
|
||||||
|
let path = path.clone();
|
||||||
|
move |_ev, window, cx| {
|
||||||
|
let settings = AppSettings::global(cx);
|
||||||
|
let path = path.clone();
|
||||||
|
|
||||||
|
settings.update(cx, |this, cx| {
|
||||||
|
this.set_theme(path, window, cx);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
items
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn titlebar_left(&mut self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
let signer = nostr.read(cx).signer();
|
let signer = nostr.read(cx).signer();
|
||||||
let current_user = signer.public_key();
|
let current_user = signer.public_key();
|
||||||
|
|
||||||
h_flex()
|
h_flex()
|
||||||
.h(TITLEBAR_HEIGHT)
|
|
||||||
.flex_shrink_0()
|
.flex_shrink_0()
|
||||||
.justify_between()
|
|
||||||
.gap_2()
|
.gap_2()
|
||||||
|
.when_none(¤t_user, |this| {
|
||||||
|
this.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(SharedString::from("Choose an account to continue...")),
|
||||||
|
)
|
||||||
|
})
|
||||||
.when_some(current_user.as_ref(), |this, public_key| {
|
.when_some(current_user.as_ref(), |this, public_key| {
|
||||||
let persons = PersonRegistry::global(cx);
|
let persons = PersonRegistry::global(cx);
|
||||||
let profile = persons.read(cx).get(public_key, cx);
|
let profile = persons.read(cx).get(public_key, cx);
|
||||||
|
let avatar = profile.avatar();
|
||||||
|
let name = profile.name();
|
||||||
|
|
||||||
this.child(
|
this.child(
|
||||||
Button::new("current-user")
|
Button::new("current-user")
|
||||||
.child(Avatar::new(profile.avatar()).size(rems(1.25)))
|
.child(Avatar::new(avatar.clone()).xsmall())
|
||||||
.small()
|
.small()
|
||||||
.caret()
|
.caret()
|
||||||
.compact()
|
.compact()
|
||||||
.transparent()
|
.transparent()
|
||||||
.dropdown_menu(move |this, _window, _cx| {
|
.dropdown_menu(move |this, _window, _cx| {
|
||||||
this.label(profile.name())
|
let avatar = avatar.clone();
|
||||||
|
let name = name.clone();
|
||||||
|
|
||||||
|
this.min_w(px(256.))
|
||||||
|
.item(PopupMenuItem::element(move |_window, cx| {
|
||||||
|
h_flex()
|
||||||
|
.gap_1p5()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(Avatar::new(avatar.clone()).xsmall())
|
||||||
|
.child(name.clone())
|
||||||
|
}))
|
||||||
.separator()
|
.separator()
|
||||||
.menu("Profile", Box::new(ClosePanel))
|
.menu_with_icon(
|
||||||
.menu("Backup", Box::new(ClosePanel))
|
"Profile",
|
||||||
.menu("Themes", Box::new(ClosePanel))
|
IconName::Profile,
|
||||||
.menu("Settings", Box::new(ClosePanel))
|
Box::new(Command::ShowProfile),
|
||||||
|
)
|
||||||
|
.menu_with_icon(
|
||||||
|
"Contact List",
|
||||||
|
IconName::Book,
|
||||||
|
Box::new(Command::ShowContactList),
|
||||||
|
)
|
||||||
|
.menu_with_icon(
|
||||||
|
"Backup",
|
||||||
|
IconName::UserKey,
|
||||||
|
Box::new(Command::ShowBackup),
|
||||||
|
)
|
||||||
|
.menu_with_icon(
|
||||||
|
"Themes",
|
||||||
|
IconName::Sun,
|
||||||
|
Box::new(Command::ToggleTheme),
|
||||||
|
)
|
||||||
|
.separator()
|
||||||
|
.menu_with_icon(
|
||||||
|
"Accounts",
|
||||||
|
IconName::Group,
|
||||||
|
Box::new(Command::ToggleAccount),
|
||||||
|
)
|
||||||
|
.menu_with_icon(
|
||||||
|
"Settings",
|
||||||
|
IconName::Settings,
|
||||||
|
Box::new(Command::ShowSettings),
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.when(nostr.read(cx).creating(), |this| {
|
|
||||||
this.child(div().text_xs().text_color(cx.theme().text_muted).child(
|
|
||||||
SharedString::from("Coop is creating a new identity for you..."),
|
|
||||||
))
|
|
||||||
})
|
|
||||||
.when(!nostr.read(cx).connected(), |this| {
|
|
||||||
this.child(
|
|
||||||
div()
|
|
||||||
.text_xs()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from("Connecting...")),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.map(|this| match nostr.read(cx).relay_list_state() {
|
|
||||||
RelayState::Checking => this.child(
|
|
||||||
div()
|
|
||||||
.text_xs()
|
|
||||||
.text_color(cx.theme().text_muted)
|
|
||||||
.child(SharedString::from("Fetching user's relay list...")),
|
|
||||||
),
|
|
||||||
RelayState::NotConfigured => this.child(
|
|
||||||
h_flex()
|
|
||||||
.h_6()
|
|
||||||
.w_full()
|
|
||||||
.px_1()
|
|
||||||
.text_xs()
|
|
||||||
.text_color(cx.theme().warning_foreground)
|
|
||||||
.bg(cx.theme().warning_background)
|
|
||||||
.rounded_sm()
|
|
||||||
.child(SharedString::from("User hasn't configured a relay list")),
|
|
||||||
),
|
|
||||||
_ => this,
|
|
||||||
})
|
|
||||||
.map(|this| match chat.read(cx).relay_state(cx) {
|
|
||||||
RelayState::Checking => {
|
|
||||||
this.child(div().text_xs().text_color(cx.theme().text_muted).child(
|
|
||||||
SharedString::from("Fetching user's messaging relay list..."),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
RelayState::NotConfigured => this.child(
|
|
||||||
h_flex()
|
|
||||||
.h_6()
|
|
||||||
.w_full()
|
|
||||||
.px_1()
|
|
||||||
.text_xs()
|
|
||||||
.text_color(cx.theme().warning_foreground)
|
|
||||||
.bg(cx.theme().warning_background)
|
|
||||||
.rounded_sm()
|
|
||||||
.child(SharedString::from(
|
|
||||||
"User hasn't configured a messaging relay list",
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
_ => this,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn titlebar_right(&mut self, _window: &mut Window, _cx: &Context<Self>) -> impl IntoElement {
|
fn titlebar_right(&mut self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
h_flex().h(TITLEBAR_HEIGHT).flex_shrink_0()
|
let chat = ChatRegistry::global(cx);
|
||||||
|
let initializing = chat.read(cx).initializing;
|
||||||
|
let trash_messages = chat.read(cx).count_trash_messages(cx);
|
||||||
|
|
||||||
|
let device = DeviceRegistry::global(cx);
|
||||||
|
let device_initializing = device.read(cx).initializing;
|
||||||
|
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let signer = nostr.read(cx).signer();
|
||||||
|
|
||||||
|
let Some(public_key) = signer.public_key() else {
|
||||||
|
return div();
|
||||||
|
};
|
||||||
|
|
||||||
|
let persons = PersonRegistry::global(cx);
|
||||||
|
let profile = persons.read(cx).get(&public_key, cx);
|
||||||
|
let announcement = profile.announcement();
|
||||||
|
|
||||||
|
h_flex()
|
||||||
|
.when(!cx.theme().platform.is_mac(), |this| this.pr_2())
|
||||||
|
.gap_2()
|
||||||
|
.when(trash_messages > 0, |this| {
|
||||||
|
this.child(
|
||||||
|
h_flex()
|
||||||
|
.id("trash-messages")
|
||||||
|
.h_6()
|
||||||
|
.px_1()
|
||||||
|
.gap_1()
|
||||||
|
.rounded(cx.theme().radius)
|
||||||
|
.hover(|this| this.bg(cx.theme().ghost_element_hover))
|
||||||
|
.child(
|
||||||
|
Icon::new(IconName::Warning)
|
||||||
|
.small()
|
||||||
|
.text_color(cx.theme().text_danger),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.line_height(relative(1.))
|
||||||
|
.child(format!("{trash_messages}")),
|
||||||
|
)
|
||||||
|
.on_click(move |_ev, window, cx| {
|
||||||
|
cx.stop_propagation();
|
||||||
|
// Add the trash panel to the center workspace
|
||||||
|
Self::add_panel(
|
||||||
|
trash::init(window, cx),
|
||||||
|
DockPlacement::Center,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.child(
|
||||||
|
Button::new("key")
|
||||||
|
.icon(IconName::UserKey)
|
||||||
|
.tooltip("Decoupled encryption key")
|
||||||
|
.small()
|
||||||
|
.ghost()
|
||||||
|
.loading(device_initializing)
|
||||||
|
.when(device_initializing, |this| {
|
||||||
|
this.label("Dekey")
|
||||||
|
.xsmall()
|
||||||
|
.tooltip("Loading decoupled encryption key...")
|
||||||
|
})
|
||||||
|
.dropdown_menu(move |this, _window, _cx| {
|
||||||
|
this.min_w(px(260.))
|
||||||
|
.label("Encryption Key")
|
||||||
|
.when_some(announcement.as_ref(), |this, announcement| {
|
||||||
|
let name = announcement.client_name();
|
||||||
|
let pkey = shorten_pubkey(announcement.public_key(), 8);
|
||||||
|
|
||||||
|
this.item(PopupMenuItem::element(move |_window, cx| {
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
Icon::new(IconName::Device)
|
||||||
|
.small()
|
||||||
|
.text_color(cx.theme().icon_muted),
|
||||||
|
)
|
||||||
|
.child(name.clone())
|
||||||
|
}))
|
||||||
|
.item(PopupMenuItem::element(move |_window, cx| {
|
||||||
|
h_flex()
|
||||||
|
.gap_1()
|
||||||
|
.text_sm()
|
||||||
|
.child(
|
||||||
|
Icon::new(IconName::UserKey)
|
||||||
|
.small()
|
||||||
|
.text_color(cx.theme().icon_muted),
|
||||||
|
)
|
||||||
|
.child(SharedString::from(pkey.clone()))
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
.separator()
|
||||||
|
.menu_with_icon(
|
||||||
|
"Backup",
|
||||||
|
IconName::Shield,
|
||||||
|
Box::new(Command::BackupEncryption),
|
||||||
|
)
|
||||||
|
.menu_with_icon(
|
||||||
|
"Restore from secret key",
|
||||||
|
IconName::Usb,
|
||||||
|
Box::new(Command::ImportEncryption),
|
||||||
|
)
|
||||||
|
.separator()
|
||||||
|
.menu_with_icon(
|
||||||
|
"Reload",
|
||||||
|
IconName::Refresh,
|
||||||
|
Box::new(Command::RefreshEncryption),
|
||||||
|
)
|
||||||
|
.menu_with_icon(
|
||||||
|
"Reset",
|
||||||
|
IconName::Warning,
|
||||||
|
Box::new(Command::ResetEncryption),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("inbox")
|
||||||
|
.icon(IconName::Inbox)
|
||||||
|
.small()
|
||||||
|
.ghost()
|
||||||
|
.loading(initializing)
|
||||||
|
.when(initializing, |this| {
|
||||||
|
this.label("Inbox")
|
||||||
|
.xsmall()
|
||||||
|
.tooltip("Getting inbox messages...")
|
||||||
|
})
|
||||||
|
.dropdown_menu(move |this, _window, cx| {
|
||||||
|
let urls: Vec<(SharedString, SharedString)> = profile
|
||||||
|
.messaging_relays()
|
||||||
|
.iter()
|
||||||
|
.map(|url| {
|
||||||
|
(
|
||||||
|
SharedString::from(url.to_string()),
|
||||||
|
chat.read(cx).count_messages(url).to_string().into(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Header
|
||||||
|
let menu = this.min_w(px(260.)).label("Messaging Relays");
|
||||||
|
|
||||||
|
// Content
|
||||||
|
let menu = urls.into_iter().fold(menu, |this, (url, count)| {
|
||||||
|
this.item(PopupMenuItem::element(move |_window, cx| {
|
||||||
|
h_flex()
|
||||||
|
.px_1()
|
||||||
|
.w_full()
|
||||||
|
.text_sm()
|
||||||
|
.justify_between()
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.size_1p5()
|
||||||
|
.rounded_full()
|
||||||
|
.bg(cx.theme().icon_accent),
|
||||||
|
)
|
||||||
|
.child(url.clone()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().text_muted)
|
||||||
|
.child(count.clone()),
|
||||||
|
)
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
menu.separator()
|
||||||
|
.menu_with_icon(
|
||||||
|
"Reload",
|
||||||
|
IconName::Refresh,
|
||||||
|
Box::new(Command::RefreshMessagingRelays),
|
||||||
|
)
|
||||||
|
.menu_with_icon(
|
||||||
|
"Manage gossip relays",
|
||||||
|
IconName::Relay,
|
||||||
|
Box::new(Command::ShowRelayList),
|
||||||
|
)
|
||||||
|
.menu_with_icon(
|
||||||
|
"Manage messaging relays",
|
||||||
|
IconName::Settings,
|
||||||
|
Box::new(Command::ShowMessaging),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,8 +834,8 @@ impl Render for Workspace {
|
|||||||
let notification_layer = Root::render_notification_layer(window, cx);
|
let notification_layer = Root::render_notification_layer(window, cx);
|
||||||
|
|
||||||
// Titlebar elements
|
// Titlebar elements
|
||||||
let left = self.titlebar_left(window, cx).into_any_element();
|
let left = self.titlebar_left(cx).into_any_element();
|
||||||
let right = self.titlebar_right(window, cx).into_any_element();
|
let right = self.titlebar_right(cx).into_any_element();
|
||||||
|
|
||||||
// Update title bar children
|
// Update title bar children
|
||||||
self.titlebar.update(cx, |this, _cx| {
|
self.titlebar.update(cx, |this, _cx| {
|
||||||
@@ -270,6 +844,7 @@ impl Render for Workspace {
|
|||||||
|
|
||||||
div()
|
div()
|
||||||
.id(SharedString::from("workspace"))
|
.id(SharedString::from("workspace"))
|
||||||
|
.on_action(cx.listener(Self::on_command))
|
||||||
.relative()
|
.relative()
|
||||||
.size_full()
|
.size_full()
|
||||||
.child(
|
.child(
|
||||||
|
|||||||
36
crates/coop_mobile/Cargo.toml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
[package]
|
||||||
|
name = "coop_mobile"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
publish.workspace = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
assets = { path = "../assets" }
|
||||||
|
ui = { path = "../ui" }
|
||||||
|
theme = { path = "../theme" }
|
||||||
|
common = { path = "../common" }
|
||||||
|
state = { path = "../state" }
|
||||||
|
device = { path = "../device" }
|
||||||
|
chat = { path = "../chat" }
|
||||||
|
settings = { path = "../settings" }
|
||||||
|
person = { path = "../person" }
|
||||||
|
relay_auth = { path = "../relay_auth" }
|
||||||
|
|
||||||
|
gpui.workspace = true
|
||||||
|
gpui_platform.workspace = true
|
||||||
|
gpui_tokio.workspace = true
|
||||||
|
gpui-mobile = { git = "https://github.com/itsbalamurali/gpui-mobile" }
|
||||||
|
|
||||||
|
nostr-connect.workspace = true
|
||||||
|
nostr-sdk.workspace = true
|
||||||
|
|
||||||
|
anyhow.workspace = true
|
||||||
|
serde.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
|
itertools.workspace = true
|
||||||
|
log.workspace = true
|
||||||
|
smallvec.workspace = true
|
||||||
|
smol.workspace = true
|
||||||
|
futures.workspace = true
|
||||||
|
oneshot.workspace = true
|
||||||
|
tracing-subscriber.workspace = true
|
||||||
0
crates/coop_mobile/src/lib.rs
Normal file
42
crates/coop_web/Cargo.toml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
[package]
|
||||||
|
name = "coop_web"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
publish.workspace = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
assets = { path = "../assets" }
|
||||||
|
ui = { path = "../ui" }
|
||||||
|
theme = { path = "../theme" }
|
||||||
|
common = { path = "../common" }
|
||||||
|
state = { path = "../state" }
|
||||||
|
device = { path = "../device" }
|
||||||
|
chat = { path = "../chat" }
|
||||||
|
settings = { path = "../settings" }
|
||||||
|
person = { path = "../person" }
|
||||||
|
relay_auth = { path = "../relay_auth" }
|
||||||
|
|
||||||
|
gpui.workspace = true
|
||||||
|
gpui_platform.workspace = true
|
||||||
|
gpui_tokio.workspace = true
|
||||||
|
gpui_web = { git = "https://github.com/zed-industries/zed" }
|
||||||
|
|
||||||
|
nostr-connect.workspace = true
|
||||||
|
nostr-sdk.workspace = true
|
||||||
|
|
||||||
|
anyhow.workspace = true
|
||||||
|
serde.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
|
itertools.workspace = true
|
||||||
|
log.workspace = true
|
||||||
|
smallvec.workspace = true
|
||||||
|
smol.workspace = true
|
||||||
|
futures.workspace = true
|
||||||
|
oneshot.workspace = true
|
||||||
|
webbrowser.workspace = true
|
||||||
|
tracing-subscriber.workspace = true
|
||||||
|
|
||||||
|
console_error_panic_hook = "0.1"
|
||||||
|
tracing-wasm = "0.2"
|
||||||
|
console_log = "1.0"
|
||||||
|
wasm-bindgen = "0.2"
|
||||||
26
crates/coop_web/src/lib.rs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
use gpui::*;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn run() -> Result<(), JsValue> {
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
|
// Initialize logging to browser console
|
||||||
|
console_log::init_with_level(log::Level::Info).expect("Failed to initialize logger");
|
||||||
|
|
||||||
|
// Also initialize tracing for WASM
|
||||||
|
tracing_wasm::set_as_global_default();
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
gpui_platform::web_init();
|
||||||
|
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
|
let app = gpui_platform::application();
|
||||||
|
|
||||||
|
#[cfg(target_family = "wasm")]
|
||||||
|
let app = gpui_platform::single_threaded_web();
|
||||||
|
|
||||||
|
app.run(|_cx| {});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
77
crates/coop_web/src/www/index.html
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Coop</title>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family:
|
||||||
|
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
||||||
|
Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
|
||||||
|
sans-serif;
|
||||||
|
overflow: hidden;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
#canvas {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#loading {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
border: 4px solid rgba(0, 0, 0, 0.1);
|
||||||
|
border-left-color: #000;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
margin: 0 auto 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: #d32f2f;
|
||||||
|
padding: 20px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
<canvas id="canvas"></canvas>
|
||||||
|
<div id="loading">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<p>Loading Coop...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script type="module" src="/src/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -7,6 +7,9 @@ publish.workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
common = { path = "../common" }
|
common = { path = "../common" }
|
||||||
state = { path = "../state" }
|
state = { path = "../state" }
|
||||||
|
person = { path = "../person" }
|
||||||
|
ui = { path = "../ui" }
|
||||||
|
theme = { path = "../theme" }
|
||||||
|
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
nostr-sdk.workspace = true
|
nostr-sdk.workspace = true
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "key_store"
|
|
||||||
version.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
publish.workspace = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
common = { path = "../common" }
|
|
||||||
|
|
||||||
gpui.workspace = true
|
|
||||||
nostr-sdk.workspace = true
|
|
||||||
|
|
||||||
anyhow.workspace = true
|
|
||||||
smallvec.workspace = true
|
|
||||||
smol.workspace = true
|
|
||||||
log.workspace = true
|
|
||||||
futures.workspace = true
|
|
||||||
serde.workspace = true
|
|
||||||
serde_json.workspace = true
|
|
||||||
@@ -1,211 +0,0 @@
|
|||||||
use std::any::Any;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fmt::Display;
|
|
||||||
use std::future::Future;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::pin::Pin;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use common::config_dir;
|
|
||||||
use futures::FutureExt as _;
|
|
||||||
use gpui::AsyncApp;
|
|
||||||
use nostr_sdk::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct Credential {
|
|
||||||
public_key: PublicKey,
|
|
||||||
secret: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Credential {
|
|
||||||
pub fn new(user: String, secret: Vec<u8>) -> Self {
|
|
||||||
Self {
|
|
||||||
public_key: PublicKey::parse(&user).unwrap(),
|
|
||||||
secret: String::from_utf8(secret).unwrap(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn public_key(&self) -> PublicKey {
|
|
||||||
self.public_key
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn secret(&self) -> &str {
|
|
||||||
&self.secret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
||||||
pub enum KeyItem {
|
|
||||||
User,
|
|
||||||
Bunker,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for KeyItem {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::User => write!(f, "coop-user"),
|
|
||||||
Self::Bunker => write!(f, "coop-bunker"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<KeyItem> for String {
|
|
||||||
fn from(item: KeyItem) -> Self {
|
|
||||||
item.to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait KeyBackend: Any + Send + Sync {
|
|
||||||
fn name(&self) -> &str;
|
|
||||||
|
|
||||||
/// Reads the credentials from the provider.
|
|
||||||
#[allow(clippy::type_complexity)]
|
|
||||||
fn read_credentials<'a>(
|
|
||||||
&'a self,
|
|
||||||
url: &'a str,
|
|
||||||
cx: &'a AsyncApp,
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<Option<(String, Vec<u8>)>>> + 'a>>;
|
|
||||||
|
|
||||||
/// Writes the credentials to the provider.
|
|
||||||
fn write_credentials<'a>(
|
|
||||||
&'a self,
|
|
||||||
url: &'a str,
|
|
||||||
username: &'a str,
|
|
||||||
password: &'a [u8],
|
|
||||||
cx: &'a AsyncApp,
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a>>;
|
|
||||||
|
|
||||||
/// Deletes the credentials from the provider.
|
|
||||||
fn delete_credentials<'a>(
|
|
||||||
&'a self,
|
|
||||||
url: &'a str,
|
|
||||||
cx: &'a AsyncApp,
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A credentials provider that stores credentials in the system keychain.
|
|
||||||
pub struct KeyringProvider;
|
|
||||||
|
|
||||||
impl KeyBackend for KeyringProvider {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"keyring"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_credentials<'a>(
|
|
||||||
&'a self,
|
|
||||||
url: &'a str,
|
|
||||||
cx: &'a AsyncApp,
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<Option<(String, Vec<u8>)>>> + 'a>> {
|
|
||||||
async move { cx.update(|cx| cx.read_credentials(url)).await }.boxed_local()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn write_credentials<'a>(
|
|
||||||
&'a self,
|
|
||||||
url: &'a str,
|
|
||||||
username: &'a str,
|
|
||||||
password: &'a [u8],
|
|
||||||
cx: &'a AsyncApp,
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a>> {
|
|
||||||
async move {
|
|
||||||
cx.update(move |cx| cx.write_credentials(url, username, password))
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
.boxed_local()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete_credentials<'a>(
|
|
||||||
&'a self,
|
|
||||||
url: &'a str,
|
|
||||||
cx: &'a AsyncApp,
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a>> {
|
|
||||||
async move { cx.update(move |cx| cx.delete_credentials(url)).await }.boxed_local()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A credentials provider that stores credentials in a local file.
|
|
||||||
pub struct FileProvider {
|
|
||||||
path: PathBuf,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FileProvider {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
let path = config_dir().join(".keys");
|
|
||||||
|
|
||||||
if let Some(parent) = path.parent() {
|
|
||||||
let _ = std::fs::create_dir_all(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
Self { path }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load_credentials(&self) -> Result<HashMap<String, (String, Vec<u8>)>> {
|
|
||||||
let json = std::fs::read(&self.path)?;
|
|
||||||
let credentials: HashMap<String, (String, Vec<u8>)> = serde_json::from_slice(&json)?;
|
|
||||||
|
|
||||||
Ok(credentials)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn save_credentials(&self, credentials: &HashMap<String, (String, Vec<u8>)>) -> Result<()> {
|
|
||||||
let json = serde_json::to_string(credentials)?;
|
|
||||||
std::fs::write(&self.path, json)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for FileProvider {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl KeyBackend for FileProvider {
|
|
||||||
fn name(&self) -> &str {
|
|
||||||
"file"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_credentials<'a>(
|
|
||||||
&'a self,
|
|
||||||
url: &'a str,
|
|
||||||
_cx: &'a AsyncApp,
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<Option<(String, Vec<u8>)>>> + 'a>> {
|
|
||||||
async move {
|
|
||||||
Ok(self
|
|
||||||
.load_credentials()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.get(url)
|
|
||||||
.cloned())
|
|
||||||
}
|
|
||||||
.boxed_local()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn write_credentials<'a>(
|
|
||||||
&'a self,
|
|
||||||
url: &'a str,
|
|
||||||
username: &'a str,
|
|
||||||
password: &'a [u8],
|
|
||||||
_cx: &'a AsyncApp,
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a>> {
|
|
||||||
async move {
|
|
||||||
let mut credentials = self.load_credentials().unwrap_or_default();
|
|
||||||
credentials.insert(url.to_string(), (username.to_string(), password.to_vec()));
|
|
||||||
|
|
||||||
self.save_credentials(&credentials)
|
|
||||||
}
|
|
||||||
.boxed_local()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete_credentials<'a>(
|
|
||||||
&'a self,
|
|
||||||
url: &'a str,
|
|
||||||
_cx: &'a AsyncApp,
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a>> {
|
|
||||||
async move {
|
|
||||||
let mut credentials = self.load_credentials()?;
|
|
||||||
credentials.remove(url);
|
|
||||||
|
|
||||||
self.save_credentials(&credentials)
|
|
||||||
}
|
|
||||||
.boxed_local()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
use std::sync::{Arc, LazyLock};
|
|
||||||
|
|
||||||
pub use backend::*;
|
|
||||||
use gpui::{App, AppContext, Context, Entity, Global, Task};
|
|
||||||
use smallvec::{smallvec, SmallVec};
|
|
||||||
|
|
||||||
mod backend;
|
|
||||||
|
|
||||||
static DISABLE_KEYRING: LazyLock<bool> =
|
|
||||||
LazyLock::new(|| std::env::var("DISABLE_KEYRING").is_ok_and(|value| !value.is_empty()));
|
|
||||||
|
|
||||||
pub fn init(cx: &mut App) {
|
|
||||||
KeyStore::set_global(cx.new(KeyStore::new), cx);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct GlobalKeyStore(Entity<KeyStore>);
|
|
||||||
|
|
||||||
impl Global for GlobalKeyStore {}
|
|
||||||
|
|
||||||
pub struct KeyStore {
|
|
||||||
/// Key Store for storing credentials
|
|
||||||
pub backend: Arc<dyn KeyBackend>,
|
|
||||||
|
|
||||||
/// Whether the keystore has been initialized
|
|
||||||
pub initialized: bool,
|
|
||||||
|
|
||||||
/// Tasks for asynchronous operations
|
|
||||||
_tasks: SmallVec<[Task<()>; 1]>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl KeyStore {
|
|
||||||
/// Retrieve the global keys state
|
|
||||||
pub fn global(cx: &App) -> Entity<Self> {
|
|
||||||
cx.global::<GlobalKeyStore>().0.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the global keys instance
|
|
||||||
pub(crate) fn set_global(state: Entity<Self>, cx: &mut App) {
|
|
||||||
cx.set_global(GlobalKeyStore(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new keys instance
|
|
||||||
pub(crate) fn new(cx: &mut Context<Self>) -> Self {
|
|
||||||
// Use the file system for keystore in development or when the user specifies it
|
|
||||||
let use_file_keystore = cfg!(debug_assertions) || *DISABLE_KEYRING;
|
|
||||||
|
|
||||||
// Construct the key backend
|
|
||||||
let backend: Arc<dyn KeyBackend> = if use_file_keystore {
|
|
||||||
Arc::new(FileProvider::default())
|
|
||||||
} else {
|
|
||||||
Arc::new(KeyringProvider)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Only used for testing keyring availability on the user's system
|
|
||||||
let read_credential = cx.read_credentials("Coop");
|
|
||||||
let mut tasks = smallvec![];
|
|
||||||
|
|
||||||
tasks.push(
|
|
||||||
// Verify the keyring availability
|
|
||||||
cx.spawn(async move |this, cx| {
|
|
||||||
let result = read_credential.await;
|
|
||||||
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
if let Err(e) = result {
|
|
||||||
log::error!("Keyring error: {e}");
|
|
||||||
// For Linux:
|
|
||||||
// The user has not installed secret service on their system
|
|
||||||
// Fall back to the file provider
|
|
||||||
this.backend = Arc::new(FileProvider::default());
|
|
||||||
}
|
|
||||||
this.initialized = true;
|
|
||||||
cx.notify();
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
backend,
|
|
||||||
initialized: false,
|
|
||||||
_tasks: tasks,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the key backend.
|
|
||||||
pub fn backend(&self) -> Arc<dyn KeyBackend> {
|
|
||||||
Arc::clone(&self.backend)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the keystore is a file key backend.
|
|
||||||
pub fn is_using_file_keystore(&self) -> bool {
|
|
||||||
self.backend.name() == "file"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ publish.workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
common = { path = "../common" }
|
common = { path = "../common" }
|
||||||
state = { path = "../state" }
|
state = { path = "../state" }
|
||||||
device = { path = "../device" }
|
|
||||||
|
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
nostr-sdk.workspace = true
|
nostr-sdk.workspace = true
|
||||||
@@ -16,3 +15,4 @@ smallvec.workspace = true
|
|||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
flume.workspace = true
|
flume.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
urlencoding = "2.1.3"
|
||||||
|
|||||||
@@ -3,20 +3,19 @@ use std::collections::{HashMap, HashSet};
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::{Error, anyhow};
|
||||||
use common::EventUtils;
|
use common::EventExt;
|
||||||
use device::Announcement;
|
use gpui::{App, AppContext, Context, Entity, Global, Task, Window};
|
||||||
use gpui::{App, AppContext, Context, Entity, Global, Task};
|
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use state::{NostrRegistry, BOOTSTRAP_RELAYS, TIMEOUT};
|
use state::{Announcement, BOOTSTRAP_RELAYS, NostrRegistry, TIMEOUT};
|
||||||
|
|
||||||
mod person;
|
mod person;
|
||||||
|
|
||||||
pub use person::*;
|
pub use person::*;
|
||||||
|
|
||||||
pub fn init(cx: &mut App) {
|
pub fn init(window: &mut Window, cx: &mut App) {
|
||||||
PersonRegistry::set_global(cx.new(PersonRegistry::new), cx);
|
PersonRegistry::set_global(cx.new(|cx| PersonRegistry::new(window, cx)), cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GlobalPersonRegistry(Entity<PersonRegistry>);
|
struct GlobalPersonRegistry(Entity<PersonRegistry>);
|
||||||
@@ -37,13 +36,13 @@ pub struct PersonRegistry {
|
|||||||
persons: HashMap<PublicKey, Entity<Person>>,
|
persons: HashMap<PublicKey, Entity<Person>>,
|
||||||
|
|
||||||
/// Set of public keys that have been seen
|
/// Set of public keys that have been seen
|
||||||
seen: Rc<RefCell<HashSet<PublicKey>>>,
|
seens: Rc<RefCell<HashSet<PublicKey>>>,
|
||||||
|
|
||||||
/// Sender for requesting metadata
|
/// Sender for requesting metadata
|
||||||
sender: flume::Sender<PublicKey>,
|
sender: flume::Sender<PublicKey>,
|
||||||
|
|
||||||
/// Tasks for asynchronous operations
|
/// Tasks for asynchronous operations
|
||||||
_tasks: SmallVec<[Task<()>; 4]>,
|
tasks: SmallVec<[Task<()>; 4]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PersonRegistry {
|
impl PersonRegistry {
|
||||||
@@ -58,13 +57,13 @@ impl PersonRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new person registry instance
|
/// Create a new person registry instance
|
||||||
fn new(cx: &mut Context<Self>) -> Self {
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
let client = nostr.read(cx).client();
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
// Channel for communication between nostr and gpui
|
// Channel for communication between nostr and gpui
|
||||||
let (tx, rx) = flume::bounded::<Dispatch>(100);
|
let (tx, rx) = flume::bounded::<Dispatch>(100);
|
||||||
let (mta_tx, mta_rx) = flume::bounded::<PublicKey>(100);
|
let (mta_tx, mta_rx) = flume::unbounded::<PublicKey>();
|
||||||
|
|
||||||
let mut tasks = smallvec![];
|
let mut tasks = smallvec![];
|
||||||
|
|
||||||
@@ -112,33 +111,16 @@ impl PersonRegistry {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
tasks.push(
|
// Load all user profiles from the database
|
||||||
// Load all user profiles from the database
|
cx.defer_in(window, |this, _window, cx| {
|
||||||
cx.spawn(async move |this, cx| {
|
this.load(cx);
|
||||||
let result = cx
|
});
|
||||||
.background_executor()
|
|
||||||
.await_on_background(async move { load_persons(&client).await })
|
|
||||||
.await;
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(persons) => {
|
|
||||||
this.update(cx, |this, cx| {
|
|
||||||
this.bulk_inserts(persons, cx);
|
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
log::error!("Failed to load all persons from the database: {e}");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
persons: HashMap::new(),
|
persons: HashMap::new(),
|
||||||
seen: Rc::new(RefCell::new(HashSet::new())),
|
seens: Rc::new(RefCell::new(HashSet::new())),
|
||||||
sender: mta_tx,
|
sender: mta_tx,
|
||||||
_tasks: tasks,
|
tasks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +135,7 @@ impl PersonRegistry {
|
|||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let RelayMessage::Event { event, .. } = message {
|
if let RelayMessage::Event { event, .. } = *message {
|
||||||
// Skip if the event has already been processed
|
// Skip if the event has already been processed
|
||||||
if !processed.insert(event.id) {
|
if !processed.insert(event.id) {
|
||||||
continue;
|
continue;
|
||||||
@@ -164,25 +146,21 @@ impl PersonRegistry {
|
|||||||
let metadata = Metadata::from_json(&event.content).unwrap_or_default();
|
let metadata = Metadata::from_json(&event.content).unwrap_or_default();
|
||||||
let person = Person::new(event.pubkey, metadata);
|
let person = Person::new(event.pubkey, metadata);
|
||||||
let val = Box::new(person);
|
let val = Box::new(person);
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
tx.send_async(Dispatch::Person(val)).await.ok();
|
tx.send_async(Dispatch::Person(val)).await.ok();
|
||||||
}
|
}
|
||||||
Kind::ContactList => {
|
Kind::ContactList => {
|
||||||
let public_keys = event.extract_public_keys();
|
let public_keys = event.extract_public_keys();
|
||||||
|
|
||||||
// Get metadata for all public keys
|
// Get metadata for all public keys
|
||||||
get_metadata(client, public_keys).await.ok();
|
get_metadata(client, public_keys).await.ok();
|
||||||
}
|
}
|
||||||
Kind::InboxRelays => {
|
Kind::InboxRelays => {
|
||||||
let val = Box::new(event.into_owned());
|
let val = Box::new(event.into_owned());
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
tx.send_async(Dispatch::Relays(val)).await.ok();
|
tx.send_async(Dispatch::Relays(val)).await.ok();
|
||||||
}
|
}
|
||||||
Kind::Custom(10044) => {
|
Kind::Custom(10044) => {
|
||||||
let val = Box::new(event.into_owned());
|
let val = Box::new(event.into_owned());
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
tx.send_async(Dispatch::Announcement(val)).await.ok();
|
tx.send_async(Dispatch::Announcement(val)).await.ok();
|
||||||
}
|
}
|
||||||
@@ -199,7 +177,7 @@ impl PersonRegistry {
|
|||||||
loop {
|
loop {
|
||||||
match flume::Selector::new()
|
match flume::Selector::new()
|
||||||
.recv(rx, |result| result.ok())
|
.recv(rx, |result| result.ok())
|
||||||
.wait_timeout(Duration::from_secs(2))
|
.wait_timeout(Duration::from_secs(TIMEOUT))
|
||||||
{
|
{
|
||||||
Ok(Some(public_key)) => {
|
Ok(Some(public_key)) => {
|
||||||
batch.insert(public_key);
|
batch.insert(public_key);
|
||||||
@@ -209,40 +187,81 @@ impl PersonRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
get_metadata(client, std::mem::take(&mut batch)).await.ok();
|
if !batch.is_empty() {
|
||||||
|
get_metadata(client, std::mem::take(&mut batch)).await.ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Load all user profiles from the database
|
||||||
|
fn load(&mut self, cx: &mut Context<Self>) {
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
|
let task: Task<Result<Vec<Person>, Error>> = cx.background_spawn(async move {
|
||||||
|
let filter = Filter::new().kind(Kind::Metadata).limit(200);
|
||||||
|
let events = client.database().query(filter).await?;
|
||||||
|
let persons = events
|
||||||
|
.into_iter()
|
||||||
|
.map(|event| {
|
||||||
|
let metadata = Metadata::from_json(event.content).unwrap_or_default();
|
||||||
|
Person::new(event.pubkey, metadata)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(persons)
|
||||||
|
});
|
||||||
|
|
||||||
|
self.tasks.push(cx.spawn(async move |this, cx| {
|
||||||
|
if let Ok(persons) = task.await {
|
||||||
|
this.update(cx, |this, cx| {
|
||||||
|
this.bulk_inserts(persons, cx);
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
/// Set profile encryption keys announcement
|
/// Set profile encryption keys announcement
|
||||||
fn set_announcement(&mut self, event: &Event, cx: &mut App) {
|
fn set_announcement(&mut self, event: &Event, cx: &mut App) {
|
||||||
if let Some(person) = self.persons.get(&event.pubkey) {
|
let announcement = Announcement::from(event);
|
||||||
let announcement = Announcement::from(event);
|
|
||||||
|
|
||||||
|
if let Some(person) = self.persons.get(&event.pubkey) {
|
||||||
person.update(cx, |person, cx| {
|
person.update(cx, |person, cx| {
|
||||||
person.set_announcement(announcement);
|
person.set_announcement(announcement);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
let person =
|
||||||
|
Person::new(event.pubkey, Metadata::default()).with_announcement(announcement);
|
||||||
|
self.insert(person, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set messaging relays for a person
|
/// Set messaging relays for a person
|
||||||
fn set_messaging_relays(&mut self, event: &Event, cx: &mut App) {
|
fn set_messaging_relays(&mut self, event: &Event, cx: &mut App) {
|
||||||
if let Some(person) = self.persons.get(&event.pubkey) {
|
let urls: Vec<RelayUrl> = nip17::extract_relay_list(event).cloned().collect();
|
||||||
let urls: Vec<RelayUrl> = nip17::extract_relay_list(event).cloned().collect();
|
|
||||||
|
|
||||||
|
if let Some(person) = self.persons.get(&event.pubkey) {
|
||||||
person.update(cx, |person, cx| {
|
person.update(cx, |person, cx| {
|
||||||
person.set_messaging_relays(urls);
|
person.set_messaging_relays(urls);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
let person = Person::new(event.pubkey, Metadata::default()).with_messaging_relays(urls);
|
||||||
|
self.insert(person, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert batch of persons
|
/// Insert batch of persons
|
||||||
fn bulk_inserts(&mut self, persons: Vec<Person>, cx: &mut Context<Self>) {
|
fn bulk_inserts(&mut self, persons: Vec<Person>, cx: &mut Context<Self>) {
|
||||||
for person in persons.into_iter() {
|
for person in persons.into_iter() {
|
||||||
self.persons.insert(person.public_key(), cx.new(|_| person));
|
let public_key = person.public_key();
|
||||||
|
self.persons
|
||||||
|
.entry(public_key)
|
||||||
|
.or_insert_with(|| cx.new(|_| person));
|
||||||
}
|
}
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
@@ -254,7 +273,7 @@ impl PersonRegistry {
|
|||||||
match self.persons.get(&public_key) {
|
match self.persons.get(&public_key) {
|
||||||
Some(this) => {
|
Some(this) => {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
*this = person;
|
this.set_metadata(person.metadata());
|
||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -271,7 +290,7 @@ impl PersonRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let public_key = *public_key;
|
let public_key = *public_key;
|
||||||
let mut seen = self.seen.borrow_mut();
|
let mut seen = self.seens.borrow_mut();
|
||||||
|
|
||||||
if seen.insert(public_key) {
|
if seen.insert(public_key) {
|
||||||
let sender = self.sender.clone();
|
let sender = self.sender.clone();
|
||||||
@@ -314,28 +333,12 @@ where
|
|||||||
.limit(limit);
|
.limit(limit);
|
||||||
|
|
||||||
// Construct target for subscription
|
// Construct target for subscription
|
||||||
let target = BOOTSTRAP_RELAYS
|
let target: HashMap<&str, Vec<Filter>> = BOOTSTRAP_RELAYS
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|relay| (relay, vec![filter.clone()]))
|
.map(|relay| (relay, vec![filter.clone()]))
|
||||||
.collect::<HashMap<_, _>>();
|
.collect();
|
||||||
|
|
||||||
client.subscribe(target).close_on(opts).await?;
|
client.subscribe(target).close_on(opts).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load all user profiles from the database
|
|
||||||
async fn load_persons(client: &Client) -> Result<Vec<Person>, Error> {
|
|
||||||
let filter = Filter::new().kind(Kind::Metadata).limit(200);
|
|
||||||
let events = client.database().query(filter).await?;
|
|
||||||
|
|
||||||
let mut persons = vec![];
|
|
||||||
|
|
||||||
for event in events.into_iter() {
|
|
||||||
let metadata = Metadata::from_json(event.content).unwrap_or_default();
|
|
||||||
let person = Person::new(event.pubkey, metadata);
|
|
||||||
persons.push(person);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(persons)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
use device::Announcement;
|
|
||||||
use gpui::SharedString;
|
use gpui::SharedString;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
use state::Announcement;
|
||||||
|
|
||||||
const IMAGE_RESIZER: &str = "https://wsrv.nl";
|
const IMAGE_RESIZER: &str = "https://wsrv.nl";
|
||||||
|
|
||||||
@@ -65,6 +65,21 @@ impl Person {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build profile encryption keys announcement
|
||||||
|
pub fn with_announcement(mut self, announcement: Announcement) -> Self {
|
||||||
|
self.announcement = Some(announcement);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build profile messaging relays
|
||||||
|
pub fn with_messaging_relays<I>(mut self, relays: I) -> Self
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = RelayUrl>,
|
||||||
|
{
|
||||||
|
self.messaging_relays = relays.into_iter().collect();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Get profile public key
|
/// Get profile public key
|
||||||
pub fn public_key(&self) -> PublicKey {
|
pub fn public_key(&self) -> PublicKey {
|
||||||
self.public_key
|
self.public_key
|
||||||
@@ -80,12 +95,6 @@ impl Person {
|
|||||||
self.announcement.clone()
|
self.announcement.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set profile encryption keys announcement
|
|
||||||
pub fn set_announcement(&mut self, announcement: Announcement) {
|
|
||||||
self.announcement = Some(announcement);
|
|
||||||
log::info!("Updated announcement for: {}", self.public_key());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get profile messaging relays
|
/// Get profile messaging relays
|
||||||
pub fn messaging_relays(&self) -> &Vec<RelayUrl> {
|
pub fn messaging_relays(&self) -> &Vec<RelayUrl> {
|
||||||
&self.messaging_relays
|
&self.messaging_relays
|
||||||
@@ -96,15 +105,6 @@ impl Person {
|
|||||||
self.messaging_relays.first().cloned()
|
self.messaging_relays.first().cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set profile messaging relays
|
|
||||||
pub fn set_messaging_relays<I>(&mut self, relays: I)
|
|
||||||
where
|
|
||||||
I: IntoIterator<Item = RelayUrl>,
|
|
||||||
{
|
|
||||||
self.messaging_relays = relays.into_iter().collect();
|
|
||||||
log::info!("Updated messaging relays for: {}", self.public_key());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get profile avatar
|
/// Get profile avatar
|
||||||
pub fn avatar(&self) -> SharedString {
|
pub fn avatar(&self) -> SharedString {
|
||||||
self.metadata()
|
self.metadata()
|
||||||
@@ -112,8 +112,9 @@ impl Person {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.filter(|picture| !picture.is_empty())
|
.filter(|picture| !picture.is_empty())
|
||||||
.map(|picture| {
|
.map(|picture| {
|
||||||
|
let encoded_picture = urlencoding::encode(picture);
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{IMAGE_RESIZER}/?url={picture}&w=100&h=100&fit=cover&mask=circle&n=-1"
|
"{IMAGE_RESIZER}/?url={encoded_picture}&w=100&h=100&fit=cover&mask=circle&n=-1"
|
||||||
);
|
);
|
||||||
url.into()
|
url.into()
|
||||||
})
|
})
|
||||||
@@ -122,20 +123,38 @@ impl Person {
|
|||||||
|
|
||||||
/// Get profile name
|
/// Get profile name
|
||||||
pub fn name(&self) -> SharedString {
|
pub fn name(&self) -> SharedString {
|
||||||
if let Some(display_name) = self.metadata().display_name.as_ref() {
|
if let Some(display_name) = self.metadata().display_name.as_ref()
|
||||||
if !display_name.is_empty() {
|
&& !display_name.is_empty()
|
||||||
return SharedString::from(display_name);
|
{
|
||||||
}
|
return SharedString::from(display_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(name) = self.metadata().name.as_ref() {
|
if let Some(name) = self.metadata().name.as_ref()
|
||||||
if !name.is_empty() {
|
&& !name.is_empty()
|
||||||
return SharedString::from(name);
|
{
|
||||||
}
|
return SharedString::from(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedString::from(shorten_pubkey(self.public_key(), 4))
|
SharedString::from(shorten_pubkey(self.public_key(), 4))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set profile metadata
|
||||||
|
pub fn set_metadata(&mut self, metadata: Metadata) {
|
||||||
|
self.metadata = metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set profile encryption keys announcement
|
||||||
|
pub fn set_announcement(&mut self, announcement: Announcement) {
|
||||||
|
self.announcement = Some(announcement);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set profile messaging relays
|
||||||
|
pub fn set_messaging_relays<I>(&mut self, relays: I)
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = RelayUrl>,
|
||||||
|
{
|
||||||
|
self.messaging_relays = relays.into_iter().collect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shorten a [`PublicKey`] to a string with the first and last `len` characters
|
/// Shorten a [`PublicKey`] to a string with the first and last `len` characters
|
||||||
@@ -145,7 +164,7 @@ pub fn shorten_pubkey(public_key: PublicKey, len: usize) -> String {
|
|||||||
let Ok(pubkey) = public_key.to_bech32();
|
let Ok(pubkey) = public_key.to_bech32();
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{}:{}",
|
"{}...{}",
|
||||||
&pubkey[0..(len + 1)],
|
&pubkey[0..(len + 1)],
|
||||||
&pubkey[pubkey.len() - len..]
|
&pubkey[pubkey.len() - len..]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,19 +5,19 @@ use std::hash::Hash;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as AnyhowContext, Error};
|
use anyhow::{Context as AnyhowContext, Error, anyhow};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
App, AppContext, Context, Entity, Global, IntoElement, ParentElement, SharedString, Styled,
|
App, AppContext, Context, Entity, Global, IntoElement, ParentElement, SharedString, Styled,
|
||||||
Task, Window,
|
Task, Window, div, relative,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use settings::{AppSettings, AuthMode};
|
use settings::{AppSettings, AuthMode};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use state::NostrRegistry;
|
use state::NostrRegistry;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::Button;
|
||||||
use ui::notification::Notification;
|
use ui::notification::{Notification, NotificationKind};
|
||||||
use ui::{v_flex, Disableable, IconName, Sizable, WindowExtension};
|
use ui::{Disableable, WindowExtension, v_flex};
|
||||||
|
|
||||||
const AUTH_MESSAGE: &str =
|
const AUTH_MESSAGE: &str =
|
||||||
"Approve the authentication request to allow Coop to continue sending or receiving events.";
|
"Approve the authentication request to allow Coop to continue sending or receiving events.";
|
||||||
@@ -34,7 +34,10 @@ struct AuthRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AuthRequest {
|
impl AuthRequest {
|
||||||
pub fn new(challenge: impl Into<String>, url: RelayUrl) -> Self {
|
pub fn new<S>(challenge: S, url: RelayUrl) -> Self
|
||||||
|
where
|
||||||
|
S: Into<String>,
|
||||||
|
{
|
||||||
Self {
|
Self {
|
||||||
challenge: challenge.into(),
|
challenge: challenge.into(),
|
||||||
url,
|
url,
|
||||||
@@ -67,7 +70,7 @@ pub struct RelayAuth {
|
|||||||
pending_events: HashSet<(EventId, RelayUrl)>,
|
pending_events: HashSet<(EventId, RelayUrl)>,
|
||||||
|
|
||||||
/// Tasks for asynchronous operations
|
/// Tasks for asynchronous operations
|
||||||
tasks: SmallVec<[Task<()>; 2]>,
|
_tasks: SmallVec<[Task<()>; 2]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RelayAuth {
|
impl RelayAuth {
|
||||||
@@ -83,32 +86,21 @@ impl RelayAuth {
|
|||||||
|
|
||||||
/// Create a new relay auth instance
|
/// Create a new relay auth instance
|
||||||
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
cx.defer_in(window, |this, window, cx| {
|
|
||||||
this.handle_notifications(window, cx);
|
|
||||||
});
|
|
||||||
|
|
||||||
Self {
|
|
||||||
pending_events: HashSet::default(),
|
|
||||||
tasks: smallvec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handle nostr notifications
|
|
||||||
fn handle_notifications(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
|
||||||
let nostr = NostrRegistry::global(cx);
|
let nostr = NostrRegistry::global(cx);
|
||||||
let client = nostr.read(cx).client();
|
let client = nostr.read(cx).client();
|
||||||
|
|
||||||
|
let mut tasks = smallvec![];
|
||||||
|
|
||||||
// Channel for communication between nostr and gpui
|
// Channel for communication between nostr and gpui
|
||||||
let (tx, rx) = flume::bounded::<Signal>(256);
|
let (tx, rx) = flume::bounded::<Signal>(256);
|
||||||
|
|
||||||
self.tasks.push(cx.background_spawn(async move {
|
tasks.push(cx.background_spawn(async move {
|
||||||
log::info!("Started handling nostr notifications");
|
|
||||||
let mut notifications = client.notifications();
|
let mut notifications = client.notifications();
|
||||||
let mut challenges: HashSet<Cow<'_, str>> = HashSet::default();
|
let mut challenges: HashSet<Cow<'_, str>> = HashSet::default();
|
||||||
|
|
||||||
while let Some(notification) = notifications.next().await {
|
while let Some(notification) = notifications.next().await {
|
||||||
if let ClientNotification::Message { relay_url, message } = notification {
|
if let ClientNotification::Message { relay_url, message } = notification {
|
||||||
match message {
|
match *message {
|
||||||
RelayMessage::Auth { challenge } => {
|
RelayMessage::Auth { challenge } => {
|
||||||
if challenges.insert(challenge.clone()) {
|
if challenges.insert(challenge.clone()) {
|
||||||
let request = Arc::new(AuthRequest::new(challenge, relay_url));
|
let request = Arc::new(AuthRequest::new(challenge, relay_url));
|
||||||
@@ -134,7 +126,7 @@ impl RelayAuth {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||||
while let Ok(signal) = rx.recv_async().await {
|
while let Ok(signal) = rx.recv_async().await {
|
||||||
match signal {
|
match signal {
|
||||||
Signal::Auth(req) => {
|
Signal::Auth(req) => {
|
||||||
@@ -152,6 +144,11 @@ impl RelayAuth {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
Self {
|
||||||
|
pending_events: HashSet::default(),
|
||||||
|
_tasks: tasks,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a pending event waiting for resend after authentication
|
/// Insert a pending event waiting for resend after authentication
|
||||||
@@ -162,15 +159,12 @@ impl RelayAuth {
|
|||||||
|
|
||||||
/// Get all pending events for a specific relay,
|
/// Get all pending events for a specific relay,
|
||||||
fn get_pending_events(&self, relay: &RelayUrl, _cx: &App) -> Vec<EventId> {
|
fn get_pending_events(&self, relay: &RelayUrl, _cx: &App) -> Vec<EventId> {
|
||||||
let pending_events: Vec<EventId> = self
|
self.pending_events
|
||||||
.pending_events
|
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, pending_relay)| pending_relay == relay)
|
.filter(|(_, pending_relay)| pending_relay == relay)
|
||||||
.map(|(id, _relay)| id)
|
.map(|(id, _relay)| id)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect()
|
||||||
|
|
||||||
pending_events
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear all pending events for a specific relay,
|
/// Clear all pending events for a specific relay,
|
||||||
@@ -227,31 +221,31 @@ impl RelayAuth {
|
|||||||
|
|
||||||
while let Some(notification) = notifications.next().await {
|
while let Some(notification) = notifications.next().await {
|
||||||
match notification {
|
match notification {
|
||||||
RelayNotification::Message {
|
RelayNotification::Message { message } => {
|
||||||
message: RelayMessage::Ok { event_id, .. },
|
if let RelayMessage::Ok { event_id, .. } = *message {
|
||||||
} => {
|
if id != event_id {
|
||||||
if id != event_id {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all subscriptions
|
|
||||||
let subscriptions = relay.subscriptions().await;
|
|
||||||
|
|
||||||
// Re-subscribe to previous subscriptions
|
|
||||||
for (id, filters) in subscriptions.into_iter() {
|
|
||||||
if !filters.is_empty() {
|
|
||||||
relay.send_msg(ClientMessage::req(id, filters)).await?;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Re-send pending events
|
// Get all subscriptions
|
||||||
for id in pending_events {
|
let subscriptions = relay.subscriptions().await;
|
||||||
if let Some(event) = client.database().event_by_id(&id).await? {
|
|
||||||
relay.send_event(&event).await?;
|
// Re-subscribe to previous subscriptions
|
||||||
|
for (id, filters) in subscriptions.into_iter() {
|
||||||
|
if !filters.is_empty() {
|
||||||
|
relay.send_msg(ClientMessage::req(id, filters)).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(());
|
// Re-send pending events
|
||||||
|
for id in pending_events {
|
||||||
|
if let Some(event) = client.database().event_by_id(&id).await? {
|
||||||
|
relay.send_event(&event).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RelayNotification::AuthenticationFailed => break,
|
RelayNotification::AuthenticationFailed => break,
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -266,7 +260,7 @@ impl RelayAuth {
|
|||||||
fn response(&self, req: &Arc<AuthRequest>, window: &Window, cx: &Context<Self>) {
|
fn response(&self, req: &Arc<AuthRequest>, window: &Window, cx: &Context<Self>) {
|
||||||
let settings = AppSettings::global(cx);
|
let settings = AppSettings::global(cx);
|
||||||
let req = req.clone();
|
let req = req.clone();
|
||||||
let challenge = req.challenge().to_string();
|
let challenge = SharedString::from(req.challenge().to_string());
|
||||||
|
|
||||||
// Create a task for authentication
|
// Create a task for authentication
|
||||||
let task = self.auth(&req, cx);
|
let task = self.auth(&req, cx);
|
||||||
@@ -276,20 +270,31 @@ impl RelayAuth {
|
|||||||
let url = req.url();
|
let url = req.url();
|
||||||
|
|
||||||
this.update_in(cx, |this, window, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
window.clear_notification(challenge, cx);
|
window.clear_notification_by_id::<AuthNotification>(challenge, cx);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Clear pending events for the authenticated relay
|
// Clear pending events for the authenticated relay
|
||||||
this.clear_pending_events(url, cx);
|
this.clear_pending_events(url, cx);
|
||||||
|
|
||||||
// Save the authenticated relay to automatically authenticate future requests
|
// Save the authenticated relay to automatically authenticate future requests
|
||||||
settings.update(cx, |this, cx| {
|
settings.update(cx, |this, cx| {
|
||||||
this.add_trusted_relay(url, cx);
|
this.add_trusted_relay(url, cx);
|
||||||
});
|
});
|
||||||
window.push_notification(format!("{} has been authenticated", url), cx);
|
|
||||||
|
window.push_notification(
|
||||||
|
Notification::success(format!(
|
||||||
|
"Relay {} has been authenticated",
|
||||||
|
url.domain().unwrap_or_default()
|
||||||
|
)),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
window.push_notification(Notification::error(e.to_string()), cx);
|
window.push_notification(
|
||||||
|
Notification::error(e.to_string()).autohide(false),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -314,49 +319,50 @@ impl RelayAuth {
|
|||||||
/// Build a notification for the authentication request.
|
/// Build a notification for the authentication request.
|
||||||
fn notification(&self, req: &Arc<AuthRequest>, cx: &Context<Self>) -> Notification {
|
fn notification(&self, req: &Arc<AuthRequest>, cx: &Context<Self>) -> Notification {
|
||||||
let req = req.clone();
|
let req = req.clone();
|
||||||
|
let challenge = SharedString::from(req.challenge.clone());
|
||||||
let url = SharedString::from(req.url().to_string());
|
let url = SharedString::from(req.url().to_string());
|
||||||
let entity = cx.entity().downgrade();
|
let entity = cx.entity().downgrade();
|
||||||
let loading = Rc::new(Cell::new(false));
|
let loading = Rc::new(Cell::new(false));
|
||||||
|
|
||||||
Notification::new()
|
Notification::new()
|
||||||
.custom_id(SharedString::from(&req.challenge))
|
.type_id::<AuthNotification>(challenge)
|
||||||
.autohide(false)
|
.autohide(false)
|
||||||
.icon(IconName::Info)
|
.with_kind(NotificationKind::Info)
|
||||||
.title(SharedString::from("Authentication Required"))
|
.title("Authentication Required")
|
||||||
.content(move |_window, cx| {
|
.content(move |_this, _window, cx| {
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.text_sm()
|
.child(
|
||||||
.child(SharedString::from(AUTH_MESSAGE))
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.line_height(relative(1.25))
|
||||||
|
.child(SharedString::from(AUTH_MESSAGE)),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.py_1()
|
.py_1()
|
||||||
.px_1p5()
|
.px_1p5()
|
||||||
.rounded_sm()
|
.rounded_sm()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.bg(cx.theme().warning_background)
|
.bg(cx.theme().elevated_surface_background)
|
||||||
.text_color(cx.theme().warning_foreground)
|
.text_color(cx.theme().text)
|
||||||
.child(url.clone()),
|
.child(url.clone()),
|
||||||
)
|
)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
})
|
})
|
||||||
.action(move |_window, _cx| {
|
.action(move |_this, _window, _cx| {
|
||||||
let view = entity.clone();
|
let view = entity.clone();
|
||||||
let req = req.clone();
|
let req = req.clone();
|
||||||
|
|
||||||
Button::new("approve")
|
Button::new("approve")
|
||||||
.label("Approve")
|
.label("Approve")
|
||||||
.small()
|
|
||||||
.primary()
|
|
||||||
.loading(loading.get())
|
.loading(loading.get())
|
||||||
.disabled(loading.get())
|
.disabled(loading.get())
|
||||||
.on_click({
|
.on_click({
|
||||||
let loading = Rc::clone(&loading);
|
let loading = Rc::clone(&loading);
|
||||||
|
|
||||||
move |_ev, window, cx| {
|
move |_ev, window, cx| {
|
||||||
// Set loading state to true
|
// Set loading state to true
|
||||||
loading.set(true);
|
loading.set(true);
|
||||||
|
|
||||||
// Process to approve the request
|
// Process to approve the request
|
||||||
view.update(cx, |this, cx| {
|
view.update(cx, |this, cx| {
|
||||||
this.response(&req, window, cx);
|
this.response(&req, window, cx);
|
||||||
@@ -367,3 +373,5 @@ impl RelayAuth {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct AuthNotification;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ edition.workspace = true
|
|||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
theme = { path = "../theme" }
|
||||||
common = { path = "../common" }
|
common = { path = "../common" }
|
||||||
|
|
||||||
nostr-sdk.workspace = true
|
nostr-sdk.workspace = true
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use anyhow::{anyhow, Error};
|
use anyhow::{Error, anyhow};
|
||||||
use common::config_dir;
|
use common::config_dir;
|
||||||
use gpui::{App, AppContext, Context, Entity, Global, Subscription, Task};
|
use gpui::{App, AppContext, Context, Entity, Global, Subscription, Task, Window};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
|
use theme::{Theme, ThemeFamily, ThemeMode};
|
||||||
|
|
||||||
pub fn init(cx: &mut App) {
|
pub fn init(window: &mut Window, cx: &mut App) {
|
||||||
AppSettings::set_global(cx.new(AppSettings::new), cx)
|
AppSettings::set_global(cx.new(|cx| AppSettings::new(window, cx)), cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! setting_accessors {
|
macro_rules! setting_accessors {
|
||||||
@@ -33,6 +36,8 @@ macro_rules! setting_accessors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setting_accessors! {
|
setting_accessors! {
|
||||||
|
pub theme: Option<String>,
|
||||||
|
pub theme_mode: ThemeMode,
|
||||||
pub hide_avatar: bool,
|
pub hide_avatar: bool,
|
||||||
pub screening: bool,
|
pub screening: bool,
|
||||||
pub auth_mode: AuthMode,
|
pub auth_mode: AuthMode,
|
||||||
@@ -49,11 +54,20 @@ pub enum AuthMode {
|
|||||||
Manual,
|
Manual,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for AuthMode {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
AuthMode::Auto => write!(f, "Auto"),
|
||||||
|
AuthMode::Manual => write!(f, "Ask every time"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Signer kind
|
/// Signer kind
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum SignerKind {
|
pub enum SignerKind {
|
||||||
Auto,
|
|
||||||
#[default]
|
#[default]
|
||||||
|
Auto,
|
||||||
User,
|
User,
|
||||||
Encryption,
|
Encryption,
|
||||||
}
|
}
|
||||||
@@ -80,18 +94,43 @@ pub struct RoomConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RoomConfig {
|
impl RoomConfig {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
backup: true,
|
||||||
|
signer_kind: SignerKind::Auto,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get backup config
|
||||||
pub fn backup(&self) -> bool {
|
pub fn backup(&self) -> bool {
|
||||||
self.backup
|
self.backup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set backup config
|
||||||
|
pub fn toggle_backup(&mut self) {
|
||||||
|
self.backup = !self.backup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get signer kind config
|
||||||
pub fn signer_kind(&self) -> &SignerKind {
|
pub fn signer_kind(&self) -> &SignerKind {
|
||||||
&self.signer_kind
|
&self.signer_kind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set signer kind config
|
||||||
|
pub fn set_signer_kind(&mut self, kind: &SignerKind) {
|
||||||
|
self.signer_kind = kind.to_owned();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Settings
|
/// Settings
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
/// Theme
|
||||||
|
pub theme: Option<String>,
|
||||||
|
|
||||||
|
/// Theme mode
|
||||||
|
pub theme_mode: ThemeMode,
|
||||||
|
|
||||||
/// Hide user avatars
|
/// Hide user avatars
|
||||||
pub hide_avatar: bool,
|
pub hide_avatar: bool,
|
||||||
|
|
||||||
@@ -107,19 +146,21 @@ pub struct Settings {
|
|||||||
/// Configuration for each chat room
|
/// Configuration for each chat room
|
||||||
pub room_configs: HashMap<u64, RoomConfig>,
|
pub room_configs: HashMap<u64, RoomConfig>,
|
||||||
|
|
||||||
/// File server for NIP-96 media attachments
|
/// Server for blossom media attachments
|
||||||
pub file_server: Url,
|
pub file_server: Url,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
theme: None,
|
||||||
|
theme_mode: ThemeMode::default(),
|
||||||
hide_avatar: false,
|
hide_avatar: false,
|
||||||
screening: true,
|
screening: true,
|
||||||
auth_mode: AuthMode::default(),
|
auth_mode: AuthMode::default(),
|
||||||
trusted_relays: HashSet::default(),
|
trusted_relays: HashSet::default(),
|
||||||
room_configs: HashMap::default(),
|
room_configs: HashMap::default(),
|
||||||
file_server: Url::parse("https://nostrmedia.com").unwrap(),
|
file_server: Url::parse("https://blossom.band/").unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,7 +195,7 @@ impl AppSettings {
|
|||||||
cx.set_global(GlobalAppSettings(state));
|
cx.set_global(GlobalAppSettings(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(cx: &mut Context<Self>) -> Self {
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let mut subscriptions = smallvec![];
|
let mut subscriptions = smallvec![];
|
||||||
|
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
@@ -164,12 +205,9 @@ impl AppSettings {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
cx.defer(|cx| {
|
// Run at the end of current cycle
|
||||||
let settings = AppSettings::global(cx);
|
cx.defer_in(window, |this, window, cx| {
|
||||||
|
this.load(window, cx);
|
||||||
settings.update(cx, |this, cx| {
|
|
||||||
this.load(cx);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@@ -185,7 +223,7 @@ impl AppSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Load settings
|
/// Load settings
|
||||||
fn load(&mut self, cx: &mut Context<Self>) {
|
fn load(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let task: Task<Result<Settings, Error>> = cx.background_spawn(async move {
|
let task: Task<Result<Settings, Error>> = cx.background_spawn(async move {
|
||||||
let path = config_dir().join(".settings");
|
let path = config_dir().join(".settings");
|
||||||
|
|
||||||
@@ -196,12 +234,13 @@ impl AppSettings {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.spawn(async move |this, cx| {
|
cx.spawn_in(window, async move |this, cx| {
|
||||||
let settings = task.await.unwrap_or(Settings::default());
|
let settings = task.await.unwrap_or(Settings::default());
|
||||||
|
|
||||||
// Update settings
|
// Update settings
|
||||||
this.update(cx, |this, cx| {
|
this.update_in(cx, |this, window, cx| {
|
||||||
this.set_settings(settings, cx);
|
this.set_settings(settings, cx);
|
||||||
|
this.apply_theme(window, cx);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
})
|
})
|
||||||
@@ -225,6 +264,43 @@ impl AppSettings {
|
|||||||
task.detach();
|
task.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set theme
|
||||||
|
pub fn set_theme<T>(&mut self, theme: T, window: &mut Window, cx: &mut Context<Self>)
|
||||||
|
where
|
||||||
|
T: Into<String>,
|
||||||
|
{
|
||||||
|
// Update settings
|
||||||
|
self.values.theme = Some(theme.into());
|
||||||
|
cx.notify();
|
||||||
|
|
||||||
|
// Apply the new theme
|
||||||
|
self.apply_theme(window, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reset theme
|
||||||
|
pub fn reset_theme(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.values.theme = None;
|
||||||
|
cx.notify();
|
||||||
|
|
||||||
|
self.apply_theme(window, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Apply theme
|
||||||
|
pub fn apply_theme(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
if let Some(name) = self.values.theme.as_ref() {
|
||||||
|
let mode = self.values.theme_mode;
|
||||||
|
|
||||||
|
if let Ok(new_theme) = ThemeFamily::from_assets(name) {
|
||||||
|
Theme::apply_theme(Rc::new(new_theme), Some(window), cx);
|
||||||
|
Theme::change(mode, Some(window), cx);
|
||||||
|
} else {
|
||||||
|
log::info!("Failed to load theme: {name}");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Theme::apply_theme(Rc::new(ThemeFamily::default()), Some(window), cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if the given relay is already authenticated
|
/// Check if the given relay is already authenticated
|
||||||
pub fn trusted_relay(&self, url: &RelayUrl, _cx: &App) -> bool {
|
pub fn trusted_relay(&self, url: &RelayUrl, _cx: &App) -> bool {
|
||||||
self.values.trusted_relays.iter().any(|relay| {
|
self.values.trusted_relays.iter().any(|relay| {
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ common = { path = "../common" }
|
|||||||
nostr.workspace = true
|
nostr.workspace = true
|
||||||
nostr-sdk.workspace = true
|
nostr-sdk.workspace = true
|
||||||
nostr-lmdb.workspace = true
|
nostr-lmdb.workspace = true
|
||||||
|
nostr-gossip-memory.workspace = true
|
||||||
nostr-connect.workspace = true
|
nostr-connect.workspace = true
|
||||||
|
nostr-blossom.workspace = true
|
||||||
|
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
gpui_tokio.workspace = true
|
gpui_tokio.workspace = true
|
||||||
@@ -25,4 +27,4 @@ serde_json.workspace = true
|
|||||||
rustls = "0.23"
|
rustls = "0.23"
|
||||||
petname = "2.0.2"
|
petname = "2.0.2"
|
||||||
whoami = "1.6.1"
|
whoami = "1.6.1"
|
||||||
reqwest = { version = "0.12", features = ["multipart", "stream", "json"] }
|
mime_guess = "2.0.4"
|
||||||
|
|||||||
27
crates/state/src/blossom.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use anyhow::{anyhow, Error};
|
||||||
|
use gpui::AsyncApp;
|
||||||
|
use gpui_tokio::Tokio;
|
||||||
|
use mime_guess::from_path;
|
||||||
|
use nostr_blossom::prelude::*;
|
||||||
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
|
pub async fn upload(server: Url, path: PathBuf, cx: &AsyncApp) -> Result<Url, Error> {
|
||||||
|
let content_type = from_path(&path).first_or_octet_stream().to_string();
|
||||||
|
let data = smol::fs::read(path).await?;
|
||||||
|
let keys = Keys::generate();
|
||||||
|
|
||||||
|
// Construct the blossom client
|
||||||
|
let client = BlossomClient::new(server);
|
||||||
|
|
||||||
|
Tokio::spawn(cx, async move {
|
||||||
|
let blob = client
|
||||||
|
.upload_blob(data, Some(content_type), None, Some(&keys))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(blob.url)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.map_err(|e| anyhow!("Upload error: {e}"))?
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ use std::sync::OnceLock;
|
|||||||
pub const CLIENT_NAME: &str = "Coop";
|
pub const CLIENT_NAME: &str = "Coop";
|
||||||
|
|
||||||
/// COOP's public key
|
/// COOP's public key
|
||||||
pub const COOP_PUBKEY: &str = "npub126kl5fruqan90py77gf6pvfvygefl2mu2ukew6xdx5pc5uqscwgsnkgarv";
|
pub const COOP_PUBKEY: &str = "npub1j3rz3ndl902lya6ywxvy5c983lxs8mpukqnx4pa4lt5wrykwl5ys7wpw3x";
|
||||||
|
|
||||||
/// App ID
|
/// App ID
|
||||||
pub const APP_ID: &str = "su.reya.coop";
|
pub const APP_ID: &str = "su.reya.coop";
|
||||||
@@ -13,7 +13,7 @@ pub const APP_ID: &str = "su.reya.coop";
|
|||||||
pub const KEYRING: &str = "Coop Safe Storage";
|
pub const KEYRING: &str = "Coop Safe Storage";
|
||||||
|
|
||||||
/// Default timeout for subscription
|
/// Default timeout for subscription
|
||||||
pub const TIMEOUT: u64 = 3;
|
pub const TIMEOUT: u64 = 2;
|
||||||
|
|
||||||
/// Default delay for searching
|
/// Default delay for searching
|
||||||
pub const FIND_DELAY: u64 = 600;
|
pub const FIND_DELAY: u64 = 600;
|
||||||
@@ -21,23 +21,26 @@ pub const FIND_DELAY: u64 = 600;
|
|||||||
/// Default limit for searching
|
/// Default limit for searching
|
||||||
pub const FIND_LIMIT: usize = 20;
|
pub const FIND_LIMIT: usize = 20;
|
||||||
|
|
||||||
/// Default timeout for Nostr Connect
|
|
||||||
pub const NOSTR_CONNECT_TIMEOUT: u64 = 200;
|
|
||||||
|
|
||||||
/// Default Nostr Connect relay
|
|
||||||
pub const NOSTR_CONNECT_RELAY: &str = "wss://relay.nsec.app";
|
|
||||||
|
|
||||||
/// Default subscription id for device gift wrap events
|
/// Default subscription id for device gift wrap events
|
||||||
pub const DEVICE_GIFTWRAP: &str = "device-gift-wraps";
|
pub const DEVICE_GIFTWRAP: &str = "device-gift-wraps";
|
||||||
|
|
||||||
/// Default subscription id for user gift wrap events
|
/// Default subscription id for user gift wrap events
|
||||||
pub const USER_GIFTWRAP: &str = "user-gift-wraps";
|
pub const USER_GIFTWRAP: &str = "user-gift-wraps";
|
||||||
|
|
||||||
|
/// Default timeout for Nostr Connect
|
||||||
|
pub const NOSTR_CONNECT_TIMEOUT: u64 = 60;
|
||||||
|
|
||||||
|
/// Default Nostr Connect relay
|
||||||
|
pub const NOSTR_CONNECT_RELAY: &str = "wss://relay.nip46.com";
|
||||||
|
|
||||||
/// Default vertex relays
|
/// Default vertex relays
|
||||||
pub const WOT_RELAYS: [&str; 1] = ["wss://relay.vertexlab.io"];
|
pub const WOT_RELAYS: [&str; 1] = ["wss://relay.vertexlab.io"];
|
||||||
|
|
||||||
/// Default search relays
|
/// Default search relays
|
||||||
pub const SEARCH_RELAYS: [&str; 1] = ["wss://antiprimal.net"];
|
pub const INDEXER_RELAYS: [&str; 1] = ["wss://indexer.coracle.social"];
|
||||||
|
|
||||||
|
/// Default search relays
|
||||||
|
pub const SEARCH_RELAYS: [&str; 2] = ["wss://antiprimal.net", "wss://search.nos.today"];
|
||||||
|
|
||||||
/// Default bootstrap relays
|
/// Default bootstrap relays
|
||||||
pub const BOOTSTRAP_RELAYS: [&str; 3] = [
|
pub const BOOTSTRAP_RELAYS: [&str; 3] = [
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
use gpui::SharedString;
|
use gpui::SharedString;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
|
||||||
pub enum DeviceState {
|
|
||||||
#[default]
|
|
||||||
Initial,
|
|
||||||
Requesting,
|
|
||||||
Set,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Announcement
|
/// Announcement
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct Announcement {
|
pub struct Announcement {
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
|
|
||||||
use nostr_sdk::prelude::*;
|
|
||||||
|
|
||||||
/// Gossip
|
|
||||||
#[derive(Debug, Clone, Default)]
|
|
||||||
pub struct Gossip {
|
|
||||||
/// Gossip relays for each public key
|
|
||||||
relays: HashMap<PublicKey, HashSet<(RelayUrl, Option<RelayMetadata>)>>,
|
|
||||||
/// Messaging relays for each public key
|
|
||||||
messaging_relays: HashMap<PublicKey, HashSet<RelayUrl>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Gossip {
|
|
||||||
/// Get read relays for a given public key
|
|
||||||
pub fn read_relays(&self, public_key: &PublicKey) -> Vec<RelayUrl> {
|
|
||||||
self.relays
|
|
||||||
.get(public_key)
|
|
||||||
.map(|relays| {
|
|
||||||
relays
|
|
||||||
.iter()
|
|
||||||
.filter_map(|(url, metadata)| {
|
|
||||||
if metadata.is_none() || metadata == &Some(RelayMetadata::Read) {
|
|
||||||
Some(url.to_owned())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
})
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get write relays for a given public key
|
|
||||||
pub fn write_relays(&self, public_key: &PublicKey) -> Vec<RelayUrl> {
|
|
||||||
self.relays
|
|
||||||
.get(public_key)
|
|
||||||
.map(|relays| {
|
|
||||||
relays
|
|
||||||
.iter()
|
|
||||||
.filter_map(|(url, metadata)| {
|
|
||||||
if metadata.is_none() || metadata == &Some(RelayMetadata::Write) {
|
|
||||||
Some(url.to_owned())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
})
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Insert gossip relays for a public key
|
|
||||||
pub fn insert_relays(&mut self, event: &Event) {
|
|
||||||
self.relays.entry(event.pubkey).or_default().extend(
|
|
||||||
event
|
|
||||||
.tags
|
|
||||||
.iter()
|
|
||||||
.filter_map(|tag| {
|
|
||||||
if let Some(TagStandard::RelayMetadata {
|
|
||||||
relay_url,
|
|
||||||
metadata,
|
|
||||||
}) = tag.clone().to_standardized()
|
|
||||||
{
|
|
||||||
Some((relay_url, metadata))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.take(3),
|
|
||||||
);
|
|
||||||
|
|
||||||
log::info!("Updating gossip relays for: {}", event.pubkey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get messaging relays for a given public key
|
|
||||||
pub fn messaging_relays(&self, public_key: &PublicKey) -> Vec<RelayUrl> {
|
|
||||||
self.messaging_relays
|
|
||||||
.get(public_key)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.into_iter()
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Insert messaging relays for a public key
|
|
||||||
pub fn insert_messaging_relays(&mut self, event: &Event) {
|
|
||||||
self.messaging_relays
|
|
||||||
.entry(event.pubkey)
|
|
||||||
.or_default()
|
|
||||||
.extend(
|
|
||||||
event
|
|
||||||
.tags
|
|
||||||
.iter()
|
|
||||||
.filter_map(|tag| {
|
|
||||||
if let Some(TagStandard::Relay(url)) = tag.as_standardized() {
|
|
||||||
Some(url.to_owned())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.take(3),
|
|
||||||
);
|
|
||||||
|
|
||||||
log::info!("Updating messaging relays for: {}", event.pubkey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
use anyhow::anyhow;
|
|
||||||
use nostr::hashes::sha256::Hash as Sha256Hash;
|
|
||||||
use nostr::hashes::Hash;
|
|
||||||
use nostr::prelude::*;
|
|
||||||
use nostr_sdk::prelude::*;
|
|
||||||
use reqwest::{multipart, Client as ReqClient, Response};
|
|
||||||
|
|
||||||
pub(crate) fn make_multipart_form(
|
|
||||||
file_data: Vec<u8>,
|
|
||||||
mime_type: Option<&str>,
|
|
||||||
) -> Result<multipart::Form, anyhow::Error> {
|
|
||||||
let form_file_part = multipart::Part::bytes(file_data).file_name("filename");
|
|
||||||
|
|
||||||
// Set the part's MIME type, or leave it as is if mime_type is None
|
|
||||||
|
|
||||||
let part = match mime_type {
|
|
||||||
Some(mime) => form_file_part.mime_str(mime)?,
|
|
||||||
None => form_file_part,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(multipart::Form::new().part("file", part))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn upload<T>(
|
|
||||||
signer: &T,
|
|
||||||
desc: &ServerConfig,
|
|
||||||
file_data: Vec<u8>,
|
|
||||||
mime_type: Option<&str>,
|
|
||||||
) -> Result<Url, anyhow::Error>
|
|
||||||
where
|
|
||||||
T: NostrSigner,
|
|
||||||
{
|
|
||||||
let payload: Sha256Hash = Sha256Hash::hash(&file_data);
|
|
||||||
let data: HttpData = HttpData::new(desc.api_url.clone(), HttpMethod::POST).payload(payload);
|
|
||||||
let nip98_auth: String = data.to_authorization(signer).await?;
|
|
||||||
|
|
||||||
// Make form
|
|
||||||
let form: multipart::Form = make_multipart_form(file_data, mime_type)?;
|
|
||||||
|
|
||||||
// Make req client
|
|
||||||
let req_client = ReqClient::new();
|
|
||||||
|
|
||||||
// Send
|
|
||||||
let response: Response = req_client
|
|
||||||
.post(desc.api_url.clone())
|
|
||||||
.header("Authorization", nip98_auth)
|
|
||||||
.multipart(form)
|
|
||||||
.send()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// Parse response
|
|
||||||
let json: Value = response.json().await?;
|
|
||||||
let upload_response = nip96::UploadResponse::from_json(json.to_string())?;
|
|
||||||
|
|
||||||
if upload_response.status == UploadResponseStatus::Error {
|
|
||||||
return Err(anyhow!(upload_response.message));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(upload_response.download_url()?.to_owned())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn nostr_upload(
|
|
||||||
client: &Client,
|
|
||||||
server: &Url,
|
|
||||||
file: Vec<u8>,
|
|
||||||
) -> Result<Url, anyhow::Error> {
|
|
||||||
let req_client = ReqClient::new();
|
|
||||||
let config_url = nip96::get_server_config_url(server)?;
|
|
||||||
|
|
||||||
// Get
|
|
||||||
let res = req_client.get(config_url.to_string()).send().await?;
|
|
||||||
let json: Value = res.json().await?;
|
|
||||||
|
|
||||||
let config = nip96::ServerConfig::from_json(json.to_string())?;
|
|
||||||
let signer = client
|
|
||||||
.signer()
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or(Keys::generate().into_nostr_signer());
|
|
||||||
|
|
||||||
let url = upload(&signer, &config, file, None).await?;
|
|
||||||
|
|
||||||
Ok(url)
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
@@ -16,11 +15,6 @@ pub struct CoopSigner {
|
|||||||
|
|
||||||
/// Specific signer for encryption purposes
|
/// Specific signer for encryption purposes
|
||||||
encryption_signer: RwLock<Option<Arc<dyn NostrSigner>>>,
|
encryption_signer: RwLock<Option<Arc<dyn NostrSigner>>>,
|
||||||
|
|
||||||
/// By default, Coop generates a new signer for new users.
|
|
||||||
///
|
|
||||||
/// This flag indicates whether the signer is user-owned or Coop-generated.
|
|
||||||
owned: AtomicBool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CoopSigner {
|
impl CoopSigner {
|
||||||
@@ -32,7 +26,6 @@ impl CoopSigner {
|
|||||||
signer: RwLock::new(signer.into_nostr_signer()),
|
signer: RwLock::new(signer.into_nostr_signer()),
|
||||||
signer_pkey: RwLock::new(None),
|
signer_pkey: RwLock::new(None),
|
||||||
encryption_signer: RwLock::new(None),
|
encryption_signer: RwLock::new(None),
|
||||||
owned: AtomicBool::new(false),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,17 +40,15 @@ impl CoopSigner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get public key
|
/// Get public key
|
||||||
|
///
|
||||||
|
/// Ensure to call this method after the signer has been initialized.
|
||||||
|
/// Otherwise, it will panic.
|
||||||
pub fn public_key(&self) -> Option<PublicKey> {
|
pub fn public_key(&self) -> Option<PublicKey> {
|
||||||
self.signer_pkey.read_blocking().to_owned()
|
*self.signer_pkey.read_blocking()
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the flag indicating whether the signer is user-owned.
|
|
||||||
pub fn owned(&self) -> bool {
|
|
||||||
self.owned.load(Ordering::SeqCst)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Switch the current signer to a new signer.
|
/// Switch the current signer to a new signer.
|
||||||
pub async fn switch<T>(&self, new: T, owned: bool)
|
pub async fn switch<T>(&self, new: T)
|
||||||
where
|
where
|
||||||
T: IntoNostrSigner,
|
T: IntoNostrSigner,
|
||||||
{
|
{
|
||||||
@@ -75,9 +66,6 @@ impl CoopSigner {
|
|||||||
|
|
||||||
// Reset the encryption signer
|
// Reset the encryption signer
|
||||||
*encryption_signer = None;
|
*encryption_signer = None;
|
||||||
|
|
||||||
// Update the owned flag
|
|
||||||
self.owned.store(owned, Ordering::SeqCst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the encryption signer.
|
/// Set the encryption signer.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use gpui::{hsla, Hsla, Rgba};
|
use gpui::{Hsla, Rgba, hsla};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -30,6 +30,8 @@ pub struct ThemeColors {
|
|||||||
pub text_muted: Hsla,
|
pub text_muted: Hsla,
|
||||||
pub text_placeholder: Hsla,
|
pub text_placeholder: Hsla,
|
||||||
pub text_accent: Hsla,
|
pub text_accent: Hsla,
|
||||||
|
pub text_danger: Hsla,
|
||||||
|
pub text_warning: Hsla,
|
||||||
|
|
||||||
// Icon colors
|
// Icon colors
|
||||||
pub icon: Hsla,
|
pub icon: Hsla,
|
||||||
@@ -77,9 +79,11 @@ pub struct ThemeColors {
|
|||||||
pub ghost_element_disabled: Hsla,
|
pub ghost_element_disabled: Hsla,
|
||||||
|
|
||||||
// Tab colors
|
// Tab colors
|
||||||
pub tab_inactive_background: Hsla,
|
pub tab_background: Hsla,
|
||||||
|
pub tab_foreground: Hsla,
|
||||||
pub tab_hover_background: Hsla,
|
pub tab_hover_background: Hsla,
|
||||||
pub tab_active_background: Hsla,
|
pub tab_active_background: Hsla,
|
||||||
|
pub tab_active_foreground: Hsla,
|
||||||
|
|
||||||
// Scrollbar colors
|
// Scrollbar colors
|
||||||
pub scrollbar_thumb_background: Hsla,
|
pub scrollbar_thumb_background: Hsla,
|
||||||
@@ -106,9 +110,9 @@ impl ThemeColors {
|
|||||||
background: neutral().light().step_1(),
|
background: neutral().light().step_1(),
|
||||||
surface_background: neutral().light().step_2(),
|
surface_background: neutral().light().step_2(),
|
||||||
elevated_surface_background: neutral().light().step_3(),
|
elevated_surface_background: neutral().light().step_3(),
|
||||||
panel_background: gpui::white(),
|
panel_background: neutral().light().step_1(),
|
||||||
overlay: neutral().light_alpha().step_3(),
|
overlay: neutral().light_alpha().step_3(),
|
||||||
title_bar: gpui::transparent_black(),
|
title_bar: neutral().light().step_3(),
|
||||||
title_bar_inactive: neutral().light().step_1(),
|
title_bar_inactive: neutral().light().step_1(),
|
||||||
window_border: hsl(240.0, 5.9, 78.0),
|
window_border: hsl(240.0, 5.9, 78.0),
|
||||||
|
|
||||||
@@ -123,7 +127,9 @@ impl ThemeColors {
|
|||||||
text: neutral().light().step_12(),
|
text: neutral().light().step_12(),
|
||||||
text_muted: neutral().light().step_11(),
|
text_muted: neutral().light().step_11(),
|
||||||
text_placeholder: neutral().light().step_10(),
|
text_placeholder: neutral().light().step_10(),
|
||||||
text_accent: brand().light().step_11(),
|
text_accent: brand().light().step_9(),
|
||||||
|
text_danger: danger().light().step_9(),
|
||||||
|
text_warning: warning().light().step_9(),
|
||||||
|
|
||||||
icon: neutral().light().step_11(),
|
icon: neutral().light().step_11(),
|
||||||
icon_muted: neutral().light().step_10(),
|
icon_muted: neutral().light().step_10(),
|
||||||
@@ -164,15 +170,17 @@ impl ThemeColors {
|
|||||||
ghost_element_selected: neutral().light().step_5(),
|
ghost_element_selected: neutral().light().step_5(),
|
||||||
ghost_element_disabled: neutral().light_alpha().step_2(),
|
ghost_element_disabled: neutral().light_alpha().step_2(),
|
||||||
|
|
||||||
tab_inactive_background: neutral().light().step_3(),
|
tab_background: neutral().light().step_3(),
|
||||||
tab_hover_background: neutral().light().step_4(),
|
tab_foreground: neutral().light().step_11(),
|
||||||
tab_active_background: neutral().light().step_5(),
|
tab_hover_background: neutral().light_alpha().step_4(),
|
||||||
|
tab_active_background: neutral().light().step_1(),
|
||||||
|
tab_active_foreground: neutral().light().step_12(),
|
||||||
|
|
||||||
scrollbar_thumb_background: neutral().light_alpha().step_3(),
|
scrollbar_thumb_background: neutral().light_alpha().step_3(),
|
||||||
scrollbar_thumb_hover_background: neutral().light_alpha().step_4(),
|
scrollbar_thumb_hover_background: neutral().light_alpha().step_4(),
|
||||||
scrollbar_thumb_border: gpui::transparent_black(),
|
scrollbar_thumb_border: gpui::transparent_black(),
|
||||||
scrollbar_track_background: gpui::transparent_black(),
|
scrollbar_track_background: gpui::transparent_black(),
|
||||||
scrollbar_track_border: neutral().light().step_5(),
|
scrollbar_track_border: gpui::transparent_black(),
|
||||||
|
|
||||||
drop_target_background: brand().light_alpha().step_2(),
|
drop_target_background: brand().light_alpha().step_2(),
|
||||||
cursor: hsl(200., 100., 50.),
|
cursor: hsl(200., 100., 50.),
|
||||||
@@ -188,9 +196,9 @@ impl ThemeColors {
|
|||||||
background: neutral().dark().step_1(),
|
background: neutral().dark().step_1(),
|
||||||
surface_background: neutral().dark().step_2(),
|
surface_background: neutral().dark().step_2(),
|
||||||
elevated_surface_background: neutral().dark().step_3(),
|
elevated_surface_background: neutral().dark().step_3(),
|
||||||
panel_background: gpui::black(),
|
panel_background: neutral().dark().step_1(),
|
||||||
overlay: neutral().dark_alpha().step_3(),
|
overlay: neutral().dark_alpha().step_3(),
|
||||||
title_bar: gpui::transparent_black(),
|
title_bar: neutral().dark().step_3(),
|
||||||
title_bar_inactive: neutral().dark().step_1(),
|
title_bar_inactive: neutral().dark().step_1(),
|
||||||
window_border: hsl(240.0, 3.7, 28.0),
|
window_border: hsl(240.0, 3.7, 28.0),
|
||||||
|
|
||||||
@@ -205,7 +213,9 @@ impl ThemeColors {
|
|||||||
text: neutral().dark().step_12(),
|
text: neutral().dark().step_12(),
|
||||||
text_muted: neutral().dark().step_11(),
|
text_muted: neutral().dark().step_11(),
|
||||||
text_placeholder: neutral().dark().step_10(),
|
text_placeholder: neutral().dark().step_10(),
|
||||||
text_accent: brand().dark().step_11(),
|
text_accent: brand().dark().step_9(),
|
||||||
|
text_danger: danger().dark().step_9(),
|
||||||
|
text_warning: warning().dark().step_9(),
|
||||||
|
|
||||||
icon: neutral().dark().step_11(),
|
icon: neutral().dark().step_11(),
|
||||||
icon_muted: neutral().dark().step_10(),
|
icon_muted: neutral().dark().step_10(),
|
||||||
@@ -246,15 +256,17 @@ impl ThemeColors {
|
|||||||
ghost_element_selected: neutral().dark().step_5(),
|
ghost_element_selected: neutral().dark().step_5(),
|
||||||
ghost_element_disabled: neutral().dark_alpha().step_2(),
|
ghost_element_disabled: neutral().dark_alpha().step_2(),
|
||||||
|
|
||||||
tab_inactive_background: neutral().dark().step_3(),
|
tab_background: neutral().dark().step_3(),
|
||||||
tab_hover_background: neutral().dark().step_4(),
|
tab_foreground: neutral().dark().step_11(),
|
||||||
tab_active_background: neutral().dark().step_5(),
|
tab_hover_background: neutral().dark_alpha().step_4(),
|
||||||
|
tab_active_background: neutral().dark().step_1(),
|
||||||
|
tab_active_foreground: neutral().dark().step_12(),
|
||||||
|
|
||||||
scrollbar_thumb_background: neutral().dark_alpha().step_3(),
|
scrollbar_thumb_background: neutral().dark_alpha().step_3(),
|
||||||
scrollbar_thumb_hover_background: neutral().dark_alpha().step_4(),
|
scrollbar_thumb_hover_background: neutral().dark_alpha().step_4(),
|
||||||
scrollbar_thumb_border: gpui::transparent_black(),
|
scrollbar_thumb_border: gpui::transparent_black(),
|
||||||
scrollbar_track_background: gpui::transparent_black(),
|
scrollbar_track_background: gpui::transparent_black(),
|
||||||
scrollbar_track_border: neutral().dark().step_5(),
|
scrollbar_track_border: gpui::transparent_black(),
|
||||||
|
|
||||||
drop_target_background: brand().dark_alpha().step_2(),
|
drop_target_background: brand().dark_alpha().step_2(),
|
||||||
cursor: hsl(200., 100., 50.),
|
cursor: hsl(200., 100., 50.),
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ impl Anchor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn other_side_corner_along(&self, axis: Axis) -> Anchor {
|
pub fn other_side_corner_along(&self, axis: Axis) -> Anchor {
|
||||||
match axis {
|
match axis {
|
||||||
Axis::Vertical => match self {
|
Axis::Vertical => match self {
|
||||||
Self::TopLeft => Self::BottomLeft,
|
Self::TopLeft => Self::BottomLeft,
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use gpui::{px, App, Global, Pixels, SharedString, Window};
|
use gpui::{App, Global, Pixels, SharedString, Window, px};
|
||||||
|
|
||||||
mod colors;
|
mod colors;
|
||||||
|
mod geometry;
|
||||||
|
mod notification;
|
||||||
mod platform_kind;
|
mod platform_kind;
|
||||||
mod registry;
|
mod registry;
|
||||||
mod scale;
|
mod scale;
|
||||||
@@ -11,6 +13,8 @@ mod scrollbar_mode;
|
|||||||
mod theme;
|
mod theme;
|
||||||
|
|
||||||
pub use colors::*;
|
pub use colors::*;
|
||||||
|
pub use geometry::*;
|
||||||
|
pub use notification::*;
|
||||||
pub use platform_kind::PlatformKind;
|
pub use platform_kind::PlatformKind;
|
||||||
pub use registry::*;
|
pub use registry::*;
|
||||||
pub use scale::*;
|
pub use scale::*;
|
||||||
@@ -29,6 +33,9 @@ pub const CLIENT_SIDE_DECORATION_BORDER: Pixels = px(1.0);
|
|||||||
/// Defines window titlebar height
|
/// Defines window titlebar height
|
||||||
pub const TITLEBAR_HEIGHT: Pixels = px(36.0);
|
pub const TITLEBAR_HEIGHT: Pixels = px(36.0);
|
||||||
|
|
||||||
|
/// Defines workspace tabbar height
|
||||||
|
pub const TABBAR_HEIGHT: Pixels = px(28.0);
|
||||||
|
|
||||||
/// Defines default sidebar width
|
/// Defines default sidebar width
|
||||||
pub const SIDEBAR_WIDTH: Pixels = px(240.);
|
pub const SIDEBAR_WIDTH: Pixels = px(240.);
|
||||||
|
|
||||||
@@ -79,6 +86,9 @@ pub struct Theme {
|
|||||||
/// Show the scrollbar mode, default: scrolling
|
/// Show the scrollbar mode, default: scrolling
|
||||||
pub scrollbar_mode: ScrollbarMode,
|
pub scrollbar_mode: ScrollbarMode,
|
||||||
|
|
||||||
|
/// Notification settings
|
||||||
|
pub notification: NotificationSettings,
|
||||||
|
|
||||||
/// Platform kind
|
/// Platform kind
|
||||||
pub platform: PlatformKind,
|
pub platform: PlatformKind,
|
||||||
}
|
}
|
||||||
@@ -197,10 +207,11 @@ impl From<ThemeFamily> for Theme {
|
|||||||
Theme {
|
Theme {
|
||||||
font_size: px(15.),
|
font_size: px(15.),
|
||||||
font_family: font_family.into(),
|
font_family: font_family.into(),
|
||||||
radius: px(5.),
|
radius: px(6.),
|
||||||
radius_lg: px(10.),
|
radius_lg: px(10.),
|
||||||
shadow: true,
|
shadow: true,
|
||||||
scrollbar_mode: ScrollbarMode::default(),
|
scrollbar_mode: ScrollbarMode::default(),
|
||||||
|
notification: NotificationSettings::default(),
|
||||||
mode,
|
mode,
|
||||||
colors: *colors,
|
colors: *colors,
|
||||||
theme: Rc::new(family),
|
theme: Rc::new(family),
|
||||||
|
|||||||
31
crates/theme/src/notification.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
use gpui::{Pixels, px};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::{Anchor, Edges, TITLEBAR_HEIGHT};
|
||||||
|
|
||||||
|
/// The settings for notifications.
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct NotificationSettings {
|
||||||
|
/// The placement of the notification, default: [`Anchor::TopRight`]
|
||||||
|
pub placement: Anchor,
|
||||||
|
/// The margins of the notification with respect to the window edges.
|
||||||
|
pub margins: Edges<Pixels>,
|
||||||
|
/// The maximum number of notifications to show at once, default: 10
|
||||||
|
pub max_items: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for NotificationSettings {
|
||||||
|
fn default() -> Self {
|
||||||
|
let offset = px(16.);
|
||||||
|
Self {
|
||||||
|
placement: Anchor::TopRight,
|
||||||
|
margins: Edges {
|
||||||
|
top: TITLEBAR_HEIGHT + offset, // avoid overlap with title bar
|
||||||
|
right: offset,
|
||||||
|
bottom: offset,
|
||||||
|
left: offset,
|
||||||
|
},
|
||||||
|
max_items: 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::ThemeColors;
|
use crate::ThemeColors;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd, Eq, Hash, Deserialize, Serialize)]
|
||||||
pub enum ThemeMode {
|
pub enum ThemeMode {
|
||||||
#[default]
|
#[default]
|
||||||
Light,
|
Light,
|
||||||
@@ -18,11 +18,11 @@ impl ThemeMode {
|
|||||||
matches!(self, Self::Dark)
|
matches!(self, Self::Dark)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return lower_case theme name: `light`, `dark`.
|
/// Return theme name: `light`, `dark`.
|
||||||
pub fn name(&self) -> &'static str {
|
pub fn name(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
ThemeMode::Light => "light",
|
ThemeMode::Light => "Light",
|
||||||
ThemeMode::Dark => "dark",
|
ThemeMode::Dark => "Dark",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,14 +153,14 @@ impl ThemeFamily {
|
|||||||
///
|
///
|
||||||
/// # fn main() -> anyhow::Result<()> {
|
/// # fn main() -> anyhow::Result<()> {
|
||||||
/// // Assuming the file exists at `assets/themes/my-theme.json`
|
/// // Assuming the file exists at `assets/themes/my-theme.json`
|
||||||
/// let theme = ThemeFamily::from_assets("my-theme")?;
|
/// let theme = ThemeFamily::from_assets("themes/my-theme.json")?;
|
||||||
///
|
///
|
||||||
/// println!("Loaded theme: {}", theme.name);
|
/// println!("Loaded theme: {}", theme.name);
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn from_assets(name: &str) -> anyhow::Result<Self> {
|
pub fn from_assets(target: &str) -> anyhow::Result<Self> {
|
||||||
let path = format!("assets/themes/{}.json", name);
|
let path = format!("assets/{target}");
|
||||||
Self::from_file(path)
|
Self::from_file(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
use gpui::prelude::FluentBuilder;
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
use gpui::MouseButton;
|
use gpui::MouseButton;
|
||||||
#[cfg(not(target_os = "windows"))]
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::Pixels;
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, px, AnyElement, Context, Decorations, Hsla, InteractiveElement as _, IntoElement,
|
AnyElement, Context, Decorations, Hsla, InteractiveElement as _, IntoElement, ParentElement,
|
||||||
ParentElement, Render, StatefulInteractiveElement as _, Styled, Window, WindowControlArea,
|
Pixels, Render, StatefulInteractiveElement as _, Styled, Window, WindowControlArea, px,
|
||||||
};
|
};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use theme::{ActiveTheme, PlatformKind, CLIENT_SIDE_DECORATION_ROUNDING};
|
use theme::{ActiveTheme, CLIENT_SIDE_DECORATION_ROUNDING, PlatformKind};
|
||||||
use ui::h_flex;
|
use ui::h_flex;
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
@@ -127,62 +125,48 @@ impl Render for TitleBar {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.when(!cx.theme().platform.is_mac(), |this| this.pr_2())
|
||||||
.children(children),
|
.children(children),
|
||||||
)
|
)
|
||||||
.child(
|
.when(!window.is_fullscreen(), |this| match cx.theme().platform {
|
||||||
h_flex()
|
PlatformKind::Linux => {
|
||||||
.absolute()
|
#[cfg(target_os = "linux")]
|
||||||
.top_0()
|
if matches!(decorations, Decorations::Client { .. }) {
|
||||||
.right_0()
|
this.child(LinuxWindowControls::new(None))
|
||||||
.pr_2()
|
.when(supported_controls.window_menu, |this| {
|
||||||
.h(height)
|
this.on_mouse_down(MouseButton::Right, move |ev, window, _| {
|
||||||
.child(
|
window.show_window_menu(ev.position)
|
||||||
div().when(!window.is_fullscreen(), |this| match cx.theme().platform {
|
})
|
||||||
PlatformKind::Linux => {
|
})
|
||||||
#[cfg(target_os = "linux")]
|
.on_mouse_move(cx.listener(move |this, _ev, window, _| {
|
||||||
if matches!(decorations, Decorations::Client { .. }) {
|
if this.should_move {
|
||||||
this.child(LinuxWindowControls::new(None))
|
this.should_move = false;
|
||||||
.when(supported_controls.window_menu, |this| {
|
window.start_window_move();
|
||||||
this.on_mouse_down(
|
|
||||||
MouseButton::Right,
|
|
||||||
move |ev, window, _| {
|
|
||||||
window.show_window_menu(ev.position)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.on_mouse_move(cx.listener(move |this, _ev, window, _| {
|
|
||||||
if this.should_move {
|
|
||||||
this.should_move = false;
|
|
||||||
window.start_window_move();
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
.on_mouse_down_out(cx.listener(
|
|
||||||
move |this, _ev, _window, _cx| {
|
|
||||||
this.should_move = false;
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.on_mouse_up(
|
|
||||||
MouseButton::Left,
|
|
||||||
cx.listener(move |this, _ev, _window, _cx| {
|
|
||||||
this.should_move = false;
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.on_mouse_down(
|
|
||||||
MouseButton::Left,
|
|
||||||
cx.listener(move |this, _ev, _window, _cx| {
|
|
||||||
this.should_move = true;
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "linux"))]
|
}))
|
||||||
this
|
.on_mouse_down_out(cx.listener(move |this, _ev, _window, _cx| {
|
||||||
}
|
this.should_move = false;
|
||||||
PlatformKind::Windows => this.child(WindowsWindowControls::new(height)),
|
}))
|
||||||
PlatformKind::Mac => this,
|
.on_mouse_up(
|
||||||
}),
|
MouseButton::Left,
|
||||||
),
|
cx.listener(move |this, _ev, _window, _cx| {
|
||||||
)
|
this.should_move = false;
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.on_mouse_down(
|
||||||
|
MouseButton::Left,
|
||||||
|
cx.listener(move |this, _ev, _window, _cx| {
|
||||||
|
this.should_move = true;
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
this
|
||||||
|
}
|
||||||
|
PlatformKind::Windows => this.child(WindowsWindowControls::new(height)),
|
||||||
|
PlatformKind::Mac => this,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
//! This is a fork of gpui's anchored element that adds support for offsetting
|
//! This is a fork of gpui's anchored element that adds support for offsetting
|
||||||
//! https://github.com/zed-industries/zed/blob/b06f4088a3565c5e30663106ff79c1ced645d87a/crates/gpui/src/elements/anchored.rs
|
//! https://github.com/zed-industries/zed/blob/b06f4088a3565c5e30663106ff79c1ced645d87a/crates/gpui/src/elements/anchored.rs
|
||||||
use gpui::{
|
use gpui::{
|
||||||
point, px, AnyElement, App, Axis, Bounds, Display, Edges, Element, GlobalElementId, Half,
|
AnyElement, App, Axis, Bounds, Display, Edges, Element, GlobalElementId, Half,
|
||||||
InspectorElementId, IntoElement, LayoutId, ParentElement, Pixels, Point, Position, Size, Style,
|
InspectorElementId, IntoElement, LayoutId, ParentElement, Pixels, Point, Position, Size, Style,
|
||||||
Window,
|
Window, point, px,
|
||||||
};
|
};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
use theme::Anchor;
|
||||||
use crate::Anchor;
|
|
||||||
|
|
||||||
/// The state that the anchored element element uses to track its children.
|
/// The state that the anchored element element uses to track its children.
|
||||||
pub struct AnchoredState {
|
pub struct AnchoredState {
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
use gpui::prelude::FluentBuilder;
|
use gpui::prelude::FluentBuilder;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, img, px, rems, AbsoluteLength, App, Hsla, ImageSource, Img, IntoElement, ParentElement,
|
AbsoluteLength, App, Div, Hsla, ImageSource, Img, InteractiveElement, Interactivity,
|
||||||
RenderOnce, Styled, StyledImage, Window,
|
IntoElement, ParentElement, RenderOnce, StyleRefinement, Styled, StyledImage, Window, div, img,
|
||||||
|
px,
|
||||||
};
|
};
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
|
|
||||||
|
use crate::{Selectable, Sizable, Size};
|
||||||
|
|
||||||
|
/// Returns the size of the avatar based on the given [`Size`].
|
||||||
|
pub(super) fn avatar_size(size: Size) -> AbsoluteLength {
|
||||||
|
match size {
|
||||||
|
Size::Large => px(64.).into(),
|
||||||
|
Size::Medium => px(32.).into(),
|
||||||
|
Size::Small => px(24.).into(),
|
||||||
|
Size::XSmall => px(20.).into(),
|
||||||
|
Size::Size(size) => size.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An element that renders a user avatar with customizable appearance options.
|
/// An element that renders a user avatar with customizable appearance options.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
@@ -18,18 +32,24 @@ use theme::ActiveTheme;
|
|||||||
/// ```
|
/// ```
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Avatar {
|
pub struct Avatar {
|
||||||
|
base: Div,
|
||||||
image: Img,
|
image: Img,
|
||||||
size: Option<AbsoluteLength>,
|
style: StyleRefinement,
|
||||||
|
size: Size,
|
||||||
border_color: Option<Hsla>,
|
border_color: Option<Hsla>,
|
||||||
|
selected: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Avatar {
|
impl Avatar {
|
||||||
/// Creates a new avatar element with the specified image source.
|
/// Creates a new avatar element with the specified image source.
|
||||||
pub fn new(src: impl Into<ImageSource>) -> Self {
|
pub fn new(src: impl Into<ImageSource>) -> Self {
|
||||||
Avatar {
|
Avatar {
|
||||||
|
base: div(),
|
||||||
image: img(src),
|
image: img(src),
|
||||||
size: None,
|
style: StyleRefinement::default(),
|
||||||
|
size: Size::Medium,
|
||||||
border_color: None,
|
border_color: None,
|
||||||
|
selected: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,14 +76,38 @@ impl Avatar {
|
|||||||
self.border_color = Some(color.into());
|
self.border_color = Some(color.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Size overrides the avatar size. By default they are 1rem.
|
impl Sizable for Avatar {
|
||||||
pub fn size<L: Into<AbsoluteLength>>(mut self, size: impl Into<Option<L>>) -> Self {
|
fn with_size(mut self, size: impl Into<Size>) -> Self {
|
||||||
self.size = size.into().map(Into::into);
|
self.size = size.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Styled for Avatar {
|
||||||
|
fn style(&mut self) -> &mut StyleRefinement {
|
||||||
|
&mut self.style
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Selectable for Avatar {
|
||||||
|
fn is_selected(&self) -> bool {
|
||||||
|
self.selected
|
||||||
|
}
|
||||||
|
|
||||||
|
fn selected(mut self, selected: bool) -> Self {
|
||||||
|
self.selected = selected;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl InteractiveElement for Avatar {
|
||||||
|
fn interactivity(&mut self) -> &mut Interactivity {
|
||||||
|
self.base.interactivity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl RenderOnce for Avatar {
|
impl RenderOnce for Avatar {
|
||||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||||
let border_width = if self.border_color.is_some() {
|
let border_width = if self.border_color.is_some() {
|
||||||
@@ -71,8 +115,7 @@ impl RenderOnce for Avatar {
|
|||||||
} else {
|
} else {
|
||||||
px(0.)
|
px(0.)
|
||||||
};
|
};
|
||||||
|
let image_size = avatar_size(self.size);
|
||||||
let image_size = self.size.unwrap_or_else(|| rems(1.).into());
|
|
||||||
let container_size = image_size.to_pixels(window.rem_size()) + border_width * 2.;
|
let container_size = image_size.to_pixels(window.rem_size()) + border_width * 2.;
|
||||||
|
|
||||||
div()
|
div()
|
||||||
|
|||||||