Skip to content

Commit

Permalink
Merge pull request #255 from alley-rs/0.1.X
Browse files Browse the repository at this point in the history
feat: 使用 dialog 显示关于信息
  • Loading branch information
thep0y authored Sep 14, 2024
2 parents 09ef952 + bbd80a1 commit f549147
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 237 deletions.
14 changes: 0 additions & 14 deletions about.html

This file was deleted.

3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"recommended": true,
"correctness": {
"useJsxKeyInIterable": "off"
}
},
"style": { "noNonNullAssertion": "off" }
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@tauri-apps/api": "^1.6.0",
"alley-components": "^0.2.10",
"alley-components": "^0.3.6",
"solid-icons": "^1.1.0",
"solid-js": "^1.8.22"
},
Expand Down
77 changes: 0 additions & 77 deletions src-tauri/src/feedback.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src-tauri/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fs, path::PathBuf};
use local_ip_address::local_ip;

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

Expand Down
73 changes: 30 additions & 43 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

mod error;
mod feedback;
mod lazy;
#[cfg(target_os = "linux")]
mod linux;
Expand All @@ -29,7 +28,6 @@ use tokio::fs::File;
use tracing::Level;
use tracing_subscriber::fmt::time::OffsetTime;

use crate::feedback::{get_star_state, new_about_window, stared};
use crate::lazy::LOCAL_IP;
#[cfg(target_os = "macos")]
use crate::menu::{handle_menu_event, new_menu};
Expand Down Expand Up @@ -269,9 +267,6 @@ async fn main() -> FluxyResult<()> {
get_files_metadata,
get_send_files_url_qr_code,
is_linux,
get_star_state,
stared,
new_about_window
]);

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

app.run(|app_handle, event| match event {
tauri::RunEvent::Updater(e) => match e {
UpdaterEvent::UpdateAvailable {
body,
date,
version,
} => {
info!(message = "版本有更新", body = body, date = ?date, version = version);
}
UpdaterEvent::Pending => {
info!("准备下载新版本");
}
UpdaterEvent::DownloadProgress {
chunk_length,
content_length,
} => {
trace!("正在下载: {}/{:?}", chunk_length, content_length);
}
UpdaterEvent::Downloaded => {
info!("新版本已下载");
}
UpdaterEvent::Updated => {
info!("更新完成");
}
UpdaterEvent::AlreadyUpToDate => {
info!("当前已是最新版本");
}
UpdaterEvent::Error(e) => {
error!(message = "更新失败", error = e);
}
},
tauri::RunEvent::WindowEvent { label, event, .. } => {
if label == "main" {
if let tauri::WindowEvent::CloseRequested { .. } = event {
if let Some(w) = app_handle.get_window("about") {
w.close().unwrap();
}
app.run(|_app_handle, event| {
if let tauri::RunEvent::Updater(e) = event {
match e {
UpdaterEvent::UpdateAvailable {
body,
date,
version,
} => {
info!(message = "版本有更新", body = body, date = ?date, version = version);
}
UpdaterEvent::Pending => {
info!("准备下载新版本");
}
UpdaterEvent::DownloadProgress {
chunk_length,
content_length,
} => {
trace!("正在下载: {}/{:?}", chunk_length, content_length);
}
UpdaterEvent::Downloaded => {
info!("新版本已下载");
}
UpdaterEvent::Updated => {
info!("更新完成");
}
UpdaterEvent::AlreadyUpToDate => {
info!("当前已是最新版本");
}
UpdaterEvent::Error(e) => {
error!(message = "更新失败", error = e);
}
}
}
_ => {}
});

Ok(())
Expand Down
4 changes: 1 addition & 3 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
"endpoints": [
"https://app.thepoy.cc/alley-transfer/latest-mirror-1.json",
"https://app.thepoy.cc/alley-transfer/latest-mirror-2.json",
"https://app.thepoy.cc/alley-transfer/latest-mirror-3.json",
"https://app.thepoy.cc/alley-transfer/latest-mirror-4.json",
"https://github.com/thep0y/alley/releases/latest/download/latest.json"
"https://github.com/alley-rs/fluxy/releases/latest/download/latest.json"
],
"dialog": true,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDcxQTQ5NDZBNUIyMEVDRTUKUldUbDdDQmJhcFNrY2RYSkpGNUt0U3cvdEozMXJoN2pXeEFBcUQ4YmZMTi9MS2E2YjNQT1pSbTgK"
Expand Down
64 changes: 24 additions & 40 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Match, Switch, createSignal, onMount } from "solid-js";
import { Match, Switch, createSignal } from "solid-js";
import { TbArrowsTransferUp, TbArrowsTransferDown } from "solid-icons/tb";
import { BiRegularSun, BiSolidMoon } from "solid-icons/bi";
import {
LazyAboutButton,
LazyButton,
LazyDialog,
LazyReceive,
LazySend,
LazySwitch,
Expand All @@ -12,9 +13,8 @@ import {
import { suspense } from "./advance";
import "~/App.scss";
import useDark from "alley-components/lib/hooks/useDark";
import { getStarState, stared } from "./api";
import { confirm, message } from "@tauri-apps/api/dialog";
import { open } from "@tauri-apps/api/shell";
import About from "./about";
import { AppContext } from "./context";

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

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

onMount(() => {
const star = async () => {
const starState = await getStarState();
if (starState) return;

const ok = await confirm("点个 star 支持一下?", {
okLabel: "没问题",
cancelLabel: "以后再说",
});
if (!ok) {
return;
}

open("https://github.com/alley-rs/fluxy");

const confirmed = await confirm(
"本提示是君子协定,你点击确认后将不会再弹出本弹窗",
{ title: "你是否已 star?", okLabel: "是的", cancelLabel: "没有" },
);
if (!confirmed) return;

message("感谢您支持开源项目");

stared();
};

star();
});

const toHome = () => setMode(null);
const goHome = () => setMode(null);

return (
<>
<AppContext.Provider
value={{
goHome,
about: { show: showAbout, onShow: () => setShowAbout(true) },
}}
>
<LazyTooltip text={`切换为${isDark() ? "亮" : "暗"}色`} placement="left">
<LazySwitch
class="dark-switch"
Expand Down Expand Up @@ -103,13 +80,20 @@ const App = () => {
}
>
<Match when={mode() === Mode.Receive}>
{suspense(<LazyReceive toHome={toHome} />)}
</Match>
<Match when={mode() === Mode.Send}>
{suspense(<LazySend toHome={toHome} />)}
{suspense(<LazyReceive />)}
</Match>
<Match when={mode() === Mode.Send}>{suspense(<LazySend />)}</Match>
</Switch>
</>

<LazyDialog
show={showAbout()}
onClose={() => setShowAbout(false)}
showCloseIcon
showMask
>
<About />
</LazyDialog>
</AppContext.Provider>
);
};

Expand Down
10 changes: 0 additions & 10 deletions src/about.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
:root {
--about-backgroud-color: #eaeced;

background-color: var(--about-backgroud-color) !important;
}

#about {
height: 100vh;

Expand All @@ -12,7 +6,3 @@
-webkit-user-drag: none;
}
}

.dark {
--about-backgroud-color: var(--alley-color-bg);
}
15 changes: 2 additions & 13 deletions src/about.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* @refresh reload */
import { render } from "solid-js/web";
import "./index.scss";
import "./about.scss";
import "alley-components/lib/index.css";
import {
LazyButton,
LazyFlex,
Expand All @@ -18,6 +13,7 @@ import { app } from "@tauri-apps/api";
import { AiFillGithub } from "solid-icons/ai";
import { RiCommunicationFeedbackLine } from "solid-icons/ri";
import { open } from "@tauri-apps/api/shell";
import "./about.scss";

const About = () => {
const [name, setName] = createSignal("");
Expand Down Expand Up @@ -65,11 +61,4 @@ const About = () => {
);
};

const root = document.getElementById("about");

if (import.meta.env.MODE === "production") {
document.addEventListener("contextmenu", (event) => event.preventDefault());
}

// biome-ignore lint/style/noNonNullAssertion: <explanation>
render(() => <About />, root!);
export default About;
6 changes: 0 additions & 6 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,3 @@ export const getSendFilesUrlQrCode = async (files: SendFile[]) =>
await invoke<QrCode>("get_send_files_url_qr_code", { files });

export const isLinux = async () => await invoke<boolean>("is_linux");

export const getStarState = async () => await invoke<boolean>("get_star_state");

export const stared = async () => invoke<void>("stared");

export const newAboutWindow = async () => invoke<void>("new_about_window");
Loading

0 comments on commit f549147

Please sign in to comment.