Skip to content

Commit

Permalink
fix: Fit window size to app content
Browse files Browse the repository at this point in the history
  • Loading branch information
dubisdev committed Apr 12, 2023
1 parent e50953f commit 790ad8a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tauri-build = { version = "1.2.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2", features = ["clipboard-write-text", "fs-create-dir", "fs-read-dir", "fs-read-file", "fs-write-file", "global-shortcut-all", "notification-all", "path-all", "process-exit", "system-tray", "window-close", "window-create", "window-hide", "window-set-focus", "window-show", "window-start-dragging", "window-unminimize"] }
tauri = { version = "1.2", features = ["clipboard-write-text", "fs-create-dir", "fs-read-dir", "fs-read-file", "fs-write-file", "global-shortcut-all", "notification-all", "path-all", "process-exit", "system-tray", "window-close", "window-create", "window-hide", "window-set-focus", "window-set-size", "window-show", "window-start-dragging", "window-unminimize"] }
tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }

Expand Down
5 changes: 3 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"unminimize": true,
"setFocus": true,
"show": true,
"startDragging": true
"startDragging": true,
"setSize": true
},
"fs": {
"createDir": true,
Expand Down Expand Up @@ -79,7 +80,7 @@
"title": "RunMath",
"alwaysOnTop": true,
"fullscreen": false,
"height": 100,
"height": 44,
"resizable": false,
"width": 700,
"center": true,
Expand Down
13 changes: 2 additions & 11 deletions src/components/ConsoleResult.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { useCalculatorStore } from "@state/calculator";
import styles from "./console.module.css";
import { useCopyToClipboardSubscription } from "../hooks/useCopyToClipboardSubscription";

const shouldDisplayInSubconsole = (input: string, result: string) => {
return input.length + 3 + result.length > 34;
};
import { shouldDisplayInSubconsole, SubConsoleResult } from "./SubConsoleResult";

const calculateConsoleResult = (input: string, result: any) => {
return " ".repeat(input.length) + " = " + result;
Expand All @@ -18,13 +15,7 @@ export const ConsoleResult = () => {
if (!result) return null;

if (shouldDisplayInSubconsole(input, String(result))) {
return (
<input
className={styles.subconsoleResult}
disabled
value={String(result)}
/>
);
return <SubConsoleResult value={String(result)} />
}

const value = calculateConsoleResult(input, result);
Expand Down
15 changes: 15 additions & 0 deletions src/components/SubConsoleResult.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useBiggerScreen } from "../hooks/useBiggerScreen";
import styles from "./console.module.css";

export const shouldDisplayInSubconsole = (input: string, result: string) => {
return input.length + 3 + result.length > 34;
};

export const SubConsoleResult = ({ value }: { value: string }) => {
useBiggerScreen()
return <input
className={styles.subconsoleResult}
disabled
value={value}
/>
}
12 changes: 12 additions & 0 deletions src/hooks/useBiggerScreen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect } from "react"
import { appWindow, LogicalSize } from "@tauri-apps/api/window"

export const useBiggerScreen = () => {
useEffect(() => {
appWindow.setSize(new LogicalSize(700, 88))

return () => {
appWindow.setSize(new LogicalSize(700, 44))
}
}, [])
}

0 comments on commit 790ad8a

Please sign in to comment.