Skip to content

Commit

Permalink
fix(react,solid): temp disable isWindowMaximized on macOS #10
Browse files Browse the repository at this point in the history
  • Loading branch information
agmmnn committed Aug 12, 2023
1 parent 35cfb2b commit 532b9a5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
27 changes: 16 additions & 11 deletions apps/tauri-controls-solid/src/tauri-controls/libs/plugin-window.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { WebviewWindow } from "@tauri-apps/plugin-window"
import { createEffect, createSignal, onCleanup } from "solid-js"
import { getOsType } from "./plugin-os"

export const [appWindow, setAppWindow] = createSignal<WebviewWindow | null>(
null
Expand All @@ -20,18 +21,22 @@ const updateIsWindowMaximized = async () => {
}

createEffect(async () => {
updateIsWindowMaximized()
let unlisten: () => void = () => {}

const window = appWindow()
if (window) {
unlisten = await window.onResized(() => {
updateIsWindowMaximized()
})
const osname = await getOsType()
// temporary: https://github.com/agmmnn/tauri-controls/issues/10#issuecomment-1675884962
if (osname !== "Darwin") {
updateIsWindowMaximized()
let unlisten: () => void = () => {}

const window = appWindow()
if (window) {
unlisten = await window.onResized(() => {
updateIsWindowMaximized()
})
}

// Cleanup the listener when the component unmounts
unlisten && onCleanup(unlisten)
}

// Cleanup the listener when the component unmounts
unlisten && onCleanup(unlisten)
})

export const minimizeWindow = async () => {
Expand Down
36 changes: 23 additions & 13 deletions apps/tauri-controls/src/tauri-controls/contexts/plugin-window.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { WebviewWindow } from "@tauri-apps/plugin-window"
import React, { createContext, useCallback, useEffect, useState } from "react"
import { getOsType } from "../libs/plugin-os"

interface TauriAppWindowContextType {
appWindow: WebviewWindow | null
Expand All @@ -23,6 +24,10 @@ interface TauriAppWindowProviderProps {
children: React.ReactNode
}

// dynamically import tauri plugins for next.js, sveltekit, nuxt etc. support:
// https://github.com/agmmnn/tauri-controls/issues/6
// https://github.com/tauri-apps/plugins-workspace/issues/217

export const TauriAppWindowProvider: React.FC<TauriAppWindowProviderProps> = ({
children,
}: any) => {
Expand All @@ -47,20 +52,25 @@ export const TauriAppWindowProvider: React.FC<TauriAppWindowProviderProps> = ({
}, [appWindow])

useEffect(() => {
updateIsWindowMaximized()
let unlisten: () => void = () => {}

const listen = async () => {
if (appWindow) {
unlisten = await appWindow.onResized(() => {
updateIsWindowMaximized()
})
}
}
listen()
getOsType().then((osname) => {
// temporary: https://github.com/agmmnn/tauri-controls/issues/10#issuecomment-1675884962
if (osname !== "Darwin") {
updateIsWindowMaximized()
let unlisten: () => void = () => {}

// Cleanup the listener when the component unmounts
return () => unlisten && unlisten()
const listen = async () => {
if (appWindow) {
unlisten = await appWindow.onResized(() => {
updateIsWindowMaximized()
})
}
}
listen()

// Cleanup the listener when the component unmounts
return () => unlisten && unlisten()
}
})
}, [appWindow, updateIsWindowMaximized])

const minimizeWindow = async () => {
Expand Down

0 comments on commit 532b9a5

Please sign in to comment.