Skip to content

Commit

Permalink
zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
ahqsoftwares committed Dec 6, 2024
1 parent e7ea276 commit 248ec38
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src-tauri/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ pub fn main() {
get_dev_data,
get_app_asset,
get_devs_apps,
get_arch
get_arch,
set_scale
])
.menu(|handle| Menu::new(handle))
.build(context)
Expand Down Expand Up @@ -343,6 +344,11 @@ pub fn main() {

static mut COMMIT: Option<Commits> = None;

#[tauri::command(async)]
async fn set_scale(window: tauri::WebviewWindow, scale: f64) {
let _ = window.set_zoom(scale);
}

#[tauri::command(async)]
async fn set_commit(commit: Commits) {
unsafe {
Expand Down
3 changes: 1 addition & 2 deletions src/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Native API
*/
import { useEffect, useState } from "react";
import { JSX, useEffect, useState } from "react";
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";

const appWindow = getCurrentWebviewWindow();
Expand Down Expand Up @@ -55,7 +55,6 @@ function Render(props: AppProps) {
[autoUpdate, setUpdate] = useState(false),
[debug, setDebug] = useState(false),
[apps, setApps] = useState<any>([]),
[zoom, setZoom] = useState(localStorage.getItem("zoom") || "100%"),
app: JSX.Element = <></>;

useEffect(() => {
Expand Down
18 changes: 16 additions & 2 deletions src/app/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { TbZoomInArea } from "react-icons/tb";

import "./styles.css";
import { SiDaisyui, SiTailwindcss } from "react-icons/si";
import setScale from "../zoom";

interface InitProps {
dark: boolean;
Expand All @@ -48,9 +49,21 @@ interface InitProps {
}

const zoom = [
"50%",
"55%",
"60%",
"65%",
"70%",
"75%",
"80%",
"85%",
"90%",
"95%",
"100%",
"125%",
"150%",
"175%",
"200%"
];

export default function Init(props: InitProps) {
Expand Down Expand Up @@ -163,9 +176,10 @@ export default function Init(props: InitProps) {
klist="scale"
list={zoom}
Icon={TbZoomInArea}
initial={props.theme}
initial={localStorage.getItem("scale") || "100%"}
onChange={(e) => {
(document.querySelector("html") as HTMLElement).style.zoom = e;
localStorage.setItem("scale", e);
setScale(e);
}}
/>

Expand Down
15 changes: 15 additions & 0 deletions src/app/zoom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { invoke } from "@tauri-apps/api/core";

export default function setScale(scale?: string) {
let val = 1.0;

try {
val = eval((scale || "100%").replace("%", "/100"));
} catch (_) {

}

invoke("set_scale", {
scale: val
});
}
4 changes: 4 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { TbExternalLink } from "react-icons/tb";
import { GrUpdate } from "react-icons/gr";
import { FaGithub } from "react-icons/fa6";
import { MdLabelImportant } from "react-icons/md";
import setScale from "./app/zoom";

document.body.setAttribute("native-scrollbar", "0");

Expand Down Expand Up @@ -117,6 +118,9 @@ if ((window as { __TAURI_INTERNALS__?: string }).__TAURI_INTERNALS__ == null) {
loadRender(true);
} else {
if (appWindow.label == "main") {
const scale = localStorage.getItem("scale") || "100%";
setScale(scale);

initDeveloperConfiguration();

(async () => {
Expand Down

0 comments on commit 248ec38

Please sign in to comment.