Skip to content

Commit 218866f

Browse files
committed
fix: #177 窗口卷起功能并固定的功能
1 parent 25cc550 commit 218866f

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

app/src-tauri/capabilities/default.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"core:window:allow-destroy",
2020
"core:window:allow-hide",
2121
"core:window:allow-set-skip-taskbar",
22+
"core:window:allow-set-size",
23+
"core:window:allow-set-always-on-top",
2224
"clipboard-manager:allow-clear",
2325
"clipboard-manager:allow-read-image",
2426
"clipboard-manager:allow-write-text",

app/src/pages/_app.tsx

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import { useAtom } from "jotai";
2-
import { ChevronDown, ChevronLeft, ChevronUp, Cpu, Diamond, Menu, RectangleEllipsis, Tag, X, Zap } from "lucide-react";
2+
import {
3+
ChevronDown,
4+
ChevronLeft,
5+
ChevronUp,
6+
Cpu,
7+
Diamond,
8+
Menu,
9+
RectangleEllipsis,
10+
SquareArrowUp,
11+
Tag,
12+
X,
13+
Zap,
14+
} from "lucide-react";
315
import React from "react";
416
import { useTranslation } from "react-i18next";
517
import { Outlet, useLocation, useNavigate } from "react-router-dom";
@@ -10,7 +22,7 @@ import { StageSaveManager } from "../core/service/dataFileService/StageSaveManag
1022
import { Settings } from "../core/service/Settings";
1123
import { Stage } from "../core/stage/Stage";
1224
import { StageDumper } from "../core/stage/StageDumper";
13-
import { fileAtom } from "../state";
25+
import { fileAtom, isWindowCollapsingAtom } from "../state";
1426
import { cn } from "../utils/cn";
1527
import { PathString } from "../utils/pathString";
1628
import { appScale, getCurrentWindow, isDesktop, isMac, isMobile, isWeb } from "../utils/platform";
@@ -21,6 +33,7 @@ import LogicNodePanel from "./_logic_node_panel";
2133
import RecentFilesPanel from "./_recent_files_panel";
2234
import StartFilePanel from "./_start_file_panel";
2335
import TagPanel from "./_tag_panel";
36+
import { LogicalSize } from "@tauri-apps/api/dpi";
2437

2538
export default function App() {
2639
const [maxmized, setMaxmized] = React.useState(false);
@@ -37,6 +50,8 @@ export default function App() {
3750
const [file, setFile] = useAtom(fileAtom);
3851
const filename = React.useMemo(() => PathString.absolute2file(file), [file]);
3952
const [useNativeTitleBar, setUseNativeTitleBar] = React.useState(false);
53+
const [isWindowCollapsing, setIsWindowCollapsing] = useAtom(isWindowCollapsingAtom);
54+
4055
const { t } = useTranslation("app");
4156

4257
React.useEffect(() => {
@@ -320,17 +335,40 @@ export default function App() {
320335
)}
321336
</>
322337
)}
323-
324-
{/* 右上角图钉按钮 */}
338+
{/* 右上角闪电按钮 */}
325339
<IconButton
326340
onClick={(e) => {
327341
e.stopPropagation();
328342
setIsStartFilePanelOpen(!isStartFilePanelOpen);
329343
}}
330344
tooltip="设置启动时打开的文件"
345+
disabled={isMobile}
331346
>
332347
<Zap className={cn("cursor-pointer", isStartFilePanelOpen ? "rotate-45 scale-125" : "")} />
333348
</IconButton>
349+
{isDesktop && (
350+
<IconButton
351+
onClick={async (e) => {
352+
e.stopPropagation();
353+
// const size = await getCurrentWindow().outerSize();
354+
const tauriWindow = getCurrentWindow();
355+
if (isWindowCollapsing) {
356+
// 纵向展开
357+
tauriWindow.setSize(new LogicalSize(1100, 800));
358+
tauriWindow.setAlwaysOnTop(false);
359+
} else {
360+
// 纵向收起
361+
tauriWindow.setSize(new LogicalSize(1100, 100));
362+
tauriWindow.setAlwaysOnTop(true);
363+
}
364+
setIsWindowCollapsing(!isWindowCollapsing);
365+
}}
366+
tooltip={isWindowCollapsing ? "展开并取消顶置窗口" : "卷起并顶置窗口"}
367+
>
368+
<SquareArrowUp className={cn("cursor-pointer", isWindowCollapsing ? "rotate-180 scale-125" : "")} />
369+
</IconButton>
370+
)}
371+
334372
{/* 右上角窗口控制按钮 */}
335373
{isDesktop && !useNativeTitleBar && !isMac && !isWeb && (
336374
<Button className="right-4 top-4 flex items-center gap-1 active:scale-100">

app/src/pages/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import DetailsEditSidePanel from "./_details_edit_side_panel";
1414
import HintText from "./_hint_text";
1515
import SearchingNodePanel from "./_searching_node_panel";
1616
import Toolbar from "./_toolbar";
17+
import { useAtom } from "jotai";
18+
import { isWindowCollapsingAtom } from "../state";
1719

1820
export default function Home() {
1921
const canvasRef: React.RefObject<HTMLCanvasElement | null> = useRef(null);
@@ -24,6 +26,7 @@ export default function Home() {
2426
// const [nodeDetailsPanel, setNodeDetailsPanel] = React.useState("vditor");
2527
const [nodeDetailsPanel] = Settings.use("nodeDetailsPanel");
2628
const [isProtectPrivacy, setIsProtectPrivacy] = React.useState(false);
29+
const [isWindowCollapsing] = useAtom(isWindowCollapsingAtom);
2730

2831
useEffect(() => {
2932
const handleResize = () => {
@@ -104,11 +107,11 @@ export default function Home() {
104107

105108
return (
106109
<>
107-
<Toolbar />
110+
{!isWindowCollapsing && <Toolbar />}
108111
<SearchingNodePanel />
109112
{/* 这个打算被取代 */}
110113
{nodeDetailsPanel === "small" ? <DetailsEditSmallPanel /> : <DetailsEditSidePanel />}
111-
<HintText />
114+
{!isWindowCollapsing && <HintText />}
112115
{isMobile && (
113116
<Button
114117
className="z-5 absolute bottom-10 left-4"

app/src/state.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ export const isRecentFilePanelOpenAtom = atom(false);
1717
* 是否显示导出树形纯文本节点面板
1818
*/
1919
export const isExportTreeTextPanelOpenAtom = atom(false);
20+
21+
export const isWindowCollapsingAtom = atom(false);

0 commit comments

Comments
 (0)