mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 06:49:50 +02:00
Cross platform window controls
This commit is contained in:
12
src-tauri/Cargo.lock
generated
12
src-tauri/Cargo.lock
generated
@@ -2320,6 +2320,17 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "os_info"
|
||||||
|
version = "3.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "overload"
|
name = "overload"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@@ -4025,6 +4036,7 @@ dependencies = [
|
|||||||
"objc",
|
"objc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"open",
|
"open",
|
||||||
|
"os_info",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ cocoa = "0.24.1"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
serde_json = { version = "1.0", features = ["raw_value"] }
|
serde_json = { version = "1.0", features = ["raw_value"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { version = "1.2", features = ["config-toml", "devtools", "fs-read-file", "protocol-asset", "shell-open", "system-tray", "updater", "window-start-dragging"] }
|
tauri = { version = "1.2", features = ["config-toml", "devtools", "fs-read-file", "os-all", "protocol-asset", "shell-open", "system-tray", "updater", "window-start-dragging"] }
|
||||||
http = "0.2.8"
|
http = "0.2.8"
|
||||||
reqwest = { version = "0.11.14", features = ["json"] }
|
reqwest = { version = "0.11.14", features = ["json"] }
|
||||||
tokio = { version = "1.25.0", features = ["sync"] }
|
tokio = { version = "1.25.0", features = ["sync"] }
|
||||||
|
|||||||
@@ -750,7 +750,6 @@ fn create_window(handle: &AppHandle<Wry>, url: Option<&str>) -> Window<Wry> {
|
|||||||
let win3 = win.clone();
|
let win3 = win.clone();
|
||||||
win.on_window_event(move |e| {
|
win.on_window_event(move |e| {
|
||||||
let apply_offset = || {
|
let apply_offset = || {
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
win3.position_traffic_lights();
|
win3.position_traffic_lights();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -765,9 +764,7 @@ fn create_window(handle: &AppHandle<Wry>, url: Option<&str>) -> Window<Wry> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
win.position_traffic_lights();
|
win.position_traffic_lights();
|
||||||
|
|
||||||
win
|
win
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use tauri::{Runtime, Window};
|
use tauri::{Runtime, Window};
|
||||||
|
|
||||||
const TRAFFIC_LIGHT_OFFSET_X: f64 = 10.0;
|
const TRAFFIC_LIGHT_OFFSET_X: f64 = 13.0;
|
||||||
const TRAFFIC_LIGHT_OFFSET_Y: f64 = 18.0;
|
const TRAFFIC_LIGHT_OFFSET_Y: f64 = 18.0;
|
||||||
|
|
||||||
pub trait WindowExt {
|
pub trait WindowExt {
|
||||||
@@ -8,6 +8,11 @@ pub trait WindowExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Runtime> WindowExt for Window<R> {
|
impl<R: Runtime> WindowExt for Window<R> {
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
fn position_traffic_lights(&self) {
|
||||||
|
// No-op
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn position_traffic_lights(&self) {
|
fn position_traffic_lights(&self) {
|
||||||
use cocoa::appkit::{NSView, NSWindow, NSWindowButton};
|
use cocoa::appkit::{NSView, NSWindow, NSWindowButton};
|
||||||
|
|||||||
@@ -14,6 +14,9 @@
|
|||||||
"windows": [],
|
"windows": [],
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
"all": false,
|
"all": false,
|
||||||
|
"os": {
|
||||||
|
"all": true
|
||||||
|
},
|
||||||
"protocol": {
|
"protocol": {
|
||||||
"assetScope": ["$APPDATA/responses/*"],
|
"assetScope": ["$APPDATA/responses/*"],
|
||||||
"asset": true
|
"asset": true
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import type {
|
|||||||
} from 'react';
|
} from 'react';
|
||||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { useWindowSize } from 'react-use';
|
import { useWindowSize } from 'react-use';
|
||||||
|
import { useOsInfo } from '../hooks/useOsInfo';
|
||||||
import { useSidebarHidden } from '../hooks/useSidebarHidden';
|
import { useSidebarHidden } from '../hooks/useSidebarHidden';
|
||||||
import { useSidebarWidth } from '../hooks/useSidebarWidth';
|
import { useSidebarWidth } from '../hooks/useSidebarWidth';
|
||||||
import { useTauriEvent } from '../hooks/useTauriEvent';
|
import { useTauriEvent } from '../hooks/useTauriEvent';
|
||||||
@@ -169,11 +170,15 @@ interface HeaderSizeProps extends HTMLAttributes<HTMLDivElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function HeaderSize({ className, ...props }: HeaderSizeProps) {
|
function HeaderSize({ className, ...props }: HeaderSizeProps) {
|
||||||
|
const platform = useOsInfo();
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classnames(
|
className={classnames(
|
||||||
className,
|
className,
|
||||||
'h-md pt-[1px] flex items-center w-full pr-3 pl-20 border-b',
|
'h-md pt-[1px] flex items-center w-full pr-3 pl-20 border-b',
|
||||||
|
platform?.osType === 'Darwin' && 'pl-20',
|
||||||
|
platform?.osType === 'Linux' && 'pr-20',
|
||||||
|
platform?.osType === 'Windows_NT' && 'pr-20',
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
12
src-web/hooks/useOsInfo.ts
Normal file
12
src-web/hooks/useOsInfo.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import type { OsType } from '@tauri-apps/api/os';
|
||||||
|
import { type } from '@tauri-apps/api/os';
|
||||||
|
|
||||||
|
export function useOsInfo() {
|
||||||
|
return useQuery<{ osType: OsType }>({
|
||||||
|
queryKey: ['platform'],
|
||||||
|
queryFn: async () => {
|
||||||
|
return { osType: await type() };
|
||||||
|
},
|
||||||
|
}).data;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user