Skip to content

armgit / kokon

Public Imported from GitHub
0

Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.

2.8 KB
Raw Blame
// Kokon draws its own title bar: the window is one surface. On Windows and Linux the system
// bar is off (tauri.conf.json) and these are the window's buttons; on macOS the system keeps
// its traffic lights, drawn over Kokon's top bar (tauri.macos.conf.json), so there is nothing
// to draw here. Linux gets round GNOME-like buttons, Windows its own. The top bar and the sidebar's head are drag regions (data-tauri-drag-region).

import { Copy, Minus, Square, X } from "lucide-react";
import { useEffect, useState } from "react";
import { native } from "../lib/native";
import { inBrowser, isLinux, isMac } from "../lib/platform";

// macOS: room for the traffic lights on the left of the top bar (styles.css). In full screen
// macOS hides them, so the room goes too. `data-platform="mac"` alone (theme.js) is any Mac,
// Safari included: its colors, not this room.
if (isMac && !inBrowser && typeof document !== "undefined") {
  const root = document.documentElement;
  root.dataset.platform = "mac";
  root.dataset.trafficLights = "";
  const sync = () =>
    native.isFullscreen().then(
      (on) => (on ? (root.dataset.fullscreen = "") : delete root.dataset.fullscreen),
      () => {},
    );
  sync();
  native.onResized(sync).catch(() => {});
}

export function WindowControls() {
  const [maximized, setMaximized] = useState(false);
  useEffect(() => {
    if (isMac || inBrowser) return;
    let un: (() => void) | undefined;
    let gone = false;
    const sync = () => native.isMaximized().then((m) => !gone && setMaximized(m), () => {});
    sync();
    native.onResized(sync).then((u) => (gone ? u() : (un = u)), () => {});
    return () => {
      gone = true;
      un?.();
    };
  }, []);
  if (isMac || inBrowser) return null;
  return (
    <div className={`window-controls ${isLinux ? "linux" : ""}`}>
      <button className="win-btn" title="Minimize" aria-label="Minimize" onClick={() => native.minimize().catch(() => {})}>
        <Minus size={isLinux ? 14 : 16} strokeWidth={isLinux ? 2 : 1.6} />
      </button>
      <button className="win-btn" title={maximized ? "Restore" : "Maximize"} aria-label={maximized ? "Restore" : "Maximize"} onClick={() => native.toggleMaximize().catch(() => {})}>
        {maximized ? <Copy size={isLinux ? 11 : 13} strokeWidth={isLinux ? 2 : 1.6} style={{ transform: "scaleX(-1)" }} /> : <Square size={isLinux ? 11 : 13} strokeWidth={isLinux ? 2 : 1.6} />}
      </button>
      <button className="win-btn close" title="Close" aria-label="Close" onClick={() => native.close().catch(() => {})}>
        <X size={isLinux ? 14 : 17} strokeWidth={isLinux ? 2 : 1.6} />
      </button>
    </div>
  );
}

/** A bar to move the window by and its buttons, over screens without the top bar (startup). */
export function BareTitleBar() {
  return (
    <div className="bare-titlebar" data-tauri-drag-region>
      <WindowControls />
    </div>
  );
}