Skip to content

Commit bbd80a1

Browse files
committed
feat: 使用 dialog 显示关于信息
1 parent 52256a7 commit bbd80a1

File tree

20 files changed

+107
-237
lines changed

20 files changed

+107
-237
lines changed

about.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"recommended": true,
1414
"correctness": {
1515
"useJsxKeyInIterable": "off"
16-
}
16+
},
17+
"style": { "noNonNullAssertion": "off" }
1718
}
1819
}
1920
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"dependencies": {
2020
"@tauri-apps/api": "^1.6.0",
21-
"alley-components": "^0.2.10",
21+
"alley-components": "^0.3.6",
2222
"solid-icons": "^1.1.0",
2323
"solid-js": "^1.8.22"
2424
},

src-tauri/src/feedback.rs

Lines changed: 0 additions & 77 deletions
This file was deleted.

src-tauri/src/lazy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{fs, path::PathBuf};
33
use local_ip_address::local_ip;
44

55
lazy_static! {
6-
pub(super) static ref LOCAL_IP: String = local_ip().unwrap().to_string();
6+
pub(super) static ref LOCAL_IP: String = local_ip().expect("获取本地ip失败").to_string();
77
pub(super) static ref APP_CONFIG_DIR: PathBuf = {
88
let config_dir = dirs::config_dir().unwrap();
99

src-tauri/src/main.rs

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

44
mod error;
5-
mod feedback;
65
mod lazy;
76
#[cfg(target_os = "linux")]
87
mod linux;
@@ -29,7 +28,6 @@ use tokio::fs::File;
2928
use tracing::Level;
3029
use tracing_subscriber::fmt::time::OffsetTime;
3130

32-
use crate::feedback::{get_star_state, new_about_window, stared};
3331
use crate::lazy::LOCAL_IP;
3432
#[cfg(target_os = "macos")]
3533
use crate::menu::{handle_menu_event, new_menu};
@@ -269,9 +267,6 @@ async fn main() -> FluxyResult<()> {
269267
get_files_metadata,
270268
get_send_files_url_qr_code,
271269
is_linux,
272-
get_star_state,
273-
stared,
274-
new_about_window
275270
]);
276271

277272
// windows 和 linux 的菜单在窗口内, 无法自动切换暗色, 所以不使用菜单
@@ -287,47 +282,39 @@ async fn main() -> FluxyResult<()> {
287282
e
288283
})?;
289284

290-
app.run(|app_handle, event| match event {
291-
tauri::RunEvent::Updater(e) => match e {
292-
UpdaterEvent::UpdateAvailable {
293-
body,
294-
date,
295-
version,
296-
} => {
297-
info!(message = "版本有更新", body = body, date = ?date, version = version);
298-
}
299-
UpdaterEvent::Pending => {
300-
info!("准备下载新版本");
301-
}
302-
UpdaterEvent::DownloadProgress {
303-
chunk_length,
304-
content_length,
305-
} => {
306-
trace!("正在下载: {}/{:?}", chunk_length, content_length);
307-
}
308-
UpdaterEvent::Downloaded => {
309-
info!("新版本已下载");
310-
}
311-
UpdaterEvent::Updated => {
312-
info!("更新完成");
313-
}
314-
UpdaterEvent::AlreadyUpToDate => {
315-
info!("当前已是最新版本");
316-
}
317-
UpdaterEvent::Error(e) => {
318-
error!(message = "更新失败", error = e);
319-
}
320-
},
321-
tauri::RunEvent::WindowEvent { label, event, .. } => {
322-
if label == "main" {
323-
if let tauri::WindowEvent::CloseRequested { .. } = event {
324-
if let Some(w) = app_handle.get_window("about") {
325-
w.close().unwrap();
326-
}
285+
app.run(|_app_handle, event| {
286+
if let tauri::RunEvent::Updater(e) = event {
287+
match e {
288+
UpdaterEvent::UpdateAvailable {
289+
body,
290+
date,
291+
version,
292+
} => {
293+
info!(message = "版本有更新", body = body, date = ?date, version = version);
294+
}
295+
UpdaterEvent::Pending => {
296+
info!("准备下载新版本");
297+
}
298+
UpdaterEvent::DownloadProgress {
299+
chunk_length,
300+
content_length,
301+
} => {
302+
trace!("正在下载: {}/{:?}", chunk_length, content_length);
303+
}
304+
UpdaterEvent::Downloaded => {
305+
info!("新版本已下载");
306+
}
307+
UpdaterEvent::Updated => {
308+
info!("更新完成");
309+
}
310+
UpdaterEvent::AlreadyUpToDate => {
311+
info!("当前已是最新版本");
312+
}
313+
UpdaterEvent::Error(e) => {
314+
error!(message = "更新失败", error = e);
327315
}
328316
}
329317
}
330-
_ => {}
331318
});
332319

333320
Ok(())

src-tauri/tauri.conf.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
"endpoints": [
4848
"https://app.thepoy.cc/alley-transfer/latest-mirror-1.json",
4949
"https://app.thepoy.cc/alley-transfer/latest-mirror-2.json",
50-
"https://app.thepoy.cc/alley-transfer/latest-mirror-3.json",
51-
"https://app.thepoy.cc/alley-transfer/latest-mirror-4.json",
52-
"https://github.com/thep0y/alley/releases/latest/download/latest.json"
50+
"https://github.com/alley-rs/fluxy/releases/latest/download/latest.json"
5351
],
5452
"dialog": true,
5553
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDcxQTQ5NDZBNUIyMEVDRTUKUldUbDdDQmJhcFNrY2RYSkpGNUt0U3cvdEozMXJoN2pXeEFBcUQ4YmZMTi9MS2E2YjNQT1pSbTgK"

src/App.tsx

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Match, Switch, createSignal, onMount } from "solid-js";
1+
import { Match, Switch, createSignal } from "solid-js";
22
import { TbArrowsTransferUp, TbArrowsTransferDown } from "solid-icons/tb";
33
import { BiRegularSun, BiSolidMoon } from "solid-icons/bi";
44
import {
55
LazyAboutButton,
66
LazyButton,
7+
LazyDialog,
78
LazyReceive,
89
LazySend,
910
LazySwitch,
@@ -12,9 +13,8 @@ import {
1213
import { suspense } from "./advance";
1314
import "~/App.scss";
1415
import useDark from "alley-components/lib/hooks/useDark";
15-
import { getStarState, stared } from "./api";
16-
import { confirm, message } from "@tauri-apps/api/dialog";
17-
import { open } from "@tauri-apps/api/shell";
16+
import About from "./about";
17+
import { AppContext } from "./context";
1818

1919
enum Mode {
2020
Send = 1,
@@ -25,40 +25,17 @@ const App = () => {
2525
const [isDark, setIsDark] = useDark();
2626

2727
const [mode, setMode] = createSignal<Mode | null>(null);
28+
const [showAbout, setShowAbout] = createSignal<boolean>(false);
2829

29-
onMount(() => {
30-
const star = async () => {
31-
const starState = await getStarState();
32-
if (starState) return;
33-
34-
const ok = await confirm("点个 star 支持一下?", {
35-
okLabel: "没问题",
36-
cancelLabel: "以后再说",
37-
});
38-
if (!ok) {
39-
return;
40-
}
41-
42-
open("https://github.com/alley-rs/fluxy");
43-
44-
const confirmed = await confirm(
45-
"本提示是君子协定,你点击确认后将不会再弹出本弹窗",
46-
{ title: "你是否已 star?", okLabel: "是的", cancelLabel: "没有" },
47-
);
48-
if (!confirmed) return;
49-
50-
message("感谢您支持开源项目");
51-
52-
stared();
53-
};
54-
55-
star();
56-
});
57-
58-
const toHome = () => setMode(null);
30+
const goHome = () => setMode(null);
5931

6032
return (
61-
<>
33+
<AppContext.Provider
34+
value={{
35+
goHome,
36+
about: { show: showAbout, onShow: () => setShowAbout(true) },
37+
}}
38+
>
6239
<LazyTooltip text={`切换为${isDark() ? "亮" : "暗"}色`} placement="left">
6340
<LazySwitch
6441
class="dark-switch"
@@ -103,13 +80,20 @@ const App = () => {
10380
}
10481
>
10582
<Match when={mode() === Mode.Receive}>
106-
{suspense(<LazyReceive toHome={toHome} />)}
107-
</Match>
108-
<Match when={mode() === Mode.Send}>
109-
{suspense(<LazySend toHome={toHome} />)}
83+
{suspense(<LazyReceive />)}
11084
</Match>
85+
<Match when={mode() === Mode.Send}>{suspense(<LazySend />)}</Match>
11186
</Switch>
112-
</>
87+
88+
<LazyDialog
89+
show={showAbout()}
90+
onClose={() => setShowAbout(false)}
91+
showCloseIcon
92+
showMask
93+
>
94+
<About />
95+
</LazyDialog>
96+
</AppContext.Provider>
11397
);
11498
};
11599

src/about.scss

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
:root {
2-
--about-backgroud-color: #eaeced;
3-
4-
background-color: var(--about-backgroud-color) !important;
5-
}
6-
71
#about {
82
height: 100vh;
93

@@ -12,7 +6,3 @@
126
-webkit-user-drag: none;
137
}
148
}
15-
16-
.dark {
17-
--about-backgroud-color: var(--alley-color-bg);
18-
}

src/about.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/* @refresh reload */
2-
import { render } from "solid-js/web";
3-
import "./index.scss";
4-
import "./about.scss";
5-
import "alley-components/lib/index.css";
61
import {
72
LazyButton,
83
LazyFlex,
@@ -18,6 +13,7 @@ import { app } from "@tauri-apps/api";
1813
import { AiFillGithub } from "solid-icons/ai";
1914
import { RiCommunicationFeedbackLine } from "solid-icons/ri";
2015
import { open } from "@tauri-apps/api/shell";
16+
import "./about.scss";
2117

2218
const About = () => {
2319
const [name, setName] = createSignal("");
@@ -65,11 +61,4 @@ const About = () => {
6561
);
6662
};
6763

68-
const root = document.getElementById("about");
69-
70-
if (import.meta.env.MODE === "production") {
71-
document.addEventListener("contextmenu", (event) => event.preventDefault());
72-
}
73-
74-
// biome-ignore lint/style/noNonNullAssertion: <explanation>
75-
render(() => <About />, root!);
64+
export default About;

src/api.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,3 @@ export const getSendFilesUrlQrCode = async (files: SendFile[]) =>
2424
await invoke<QrCode>("get_send_files_url_qr_code", { files });
2525

2626
export const isLinux = async () => await invoke<boolean>("is_linux");
27-
28-
export const getStarState = async () => await invoke<boolean>("get_star_state");
29-
30-
export const stared = async () => invoke<void>("stared");
31-
32-
export const newAboutWindow = async () => invoke<void>("new_about_window");

0 commit comments

Comments
 (0)