Coder Social home page Coder Social logo

agmmnn / tauri-controls Goto Github PK

View Code? Open in Web Editor NEW
603.0 8.0 25.0 3.52 MB

๐Ÿšฅ Native-looking window controls for Tauri 2. React, Solid, Vue, Svelte+Tailwind.

Home Page: https://npmjs.com/package/tauri-controls

License: MIT License

HTML 1.12% TypeScript 58.60% JavaScript 3.71% Rust 1.99% CSS 0.36% Svelte 17.19% Vue 17.02%
desktop desktop-app macos tauri tauri-app tauri-plugin windows cross-platform

tauri-controls's Introduction

Tauri Controls

SolidJS Vue.js

Tauri Controls is a library that provides native-looking window controls for Tauri 2 applications. You can enhance the user experience of your Tauri 2 applications with window controls that mimic the identical native controls on the current system.

tauri-controls uses Tauri's js/ts APIs to handle window events and just provides native-looking (designed according to official system design prototypes) html elements, not native, it does not rely on the system's native APIs.

The following designs are taken as reference:

How to use

Install Dependencies

# React:
bun add tauri-controls

# Svelte:
bun add @tauri-controls/svelte

# Solid.js:
bun add @tauri-controls/solid

# Vue.js:
bun add @tauri-controls/vue
# Install peer dependencies:
bun add @tauri-apps/plugin-os @tauri-apps/api
bun add -D clsx tailwind-merge

For Svelte projects, include the following line in the content section of your tailwind.config.js:

"./node_modules/@tauri-controls/svelte/**/*.{js,svelte,ts}"

Then, make sure to include the following tauri plugins in your src-tauri directory:

cargo add tauri-plugin-window tauri-plugin-os

Don't forget to register plugins in your main function.

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_os::init())
        .plugin(tauri_plugin_window::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

If you get the message "Not allowed by scope" in the terminal after a production build, try this.

Add to Your Code

And simply add the WindowTitlebar or WindowControls component to your code, depending on your needs:

WindowTitlebar

The WindowTitlebar component handles the window titlebar and dynamically adjusts the window control buttons and titlebar content order based on the current operating system.

import { WindowTitlebar } from "tauri-controls"

function MyTitlebar() {
  return (
    <WindowTitlebar>{/* Place your titlebar content here */}</WindowTitlebar>
  )
}

When no platform is specified, the current system will be detected and the matching element will be returned. This feature is a great solution for cross-platform releases.

WindowControls

Use the WindowControls component only for window controls.

import { WindowControls } from "tauri-controls"

function MyTitlebar() {
  return <WindowControls />
}

More examples:

Options

WindowTitlebar:

  • controlsOrder?: "right" | "left" | "platform" | "system": Specifies the order of window controls. platform: to get OS-based positioning specified in windowControlsProps. system: to automatically detect the platform and position the controls accordingly (default).
  • windowControlsProps?: WindowControlsProps: Additional props to pass to the WindowControls component.

WindowControls:

  • platform?: "windows" | "macos" | "gnome": Specifies which platform's window controls to display. If the platform property is not specified, the library will automatically detect the operating system the app is running on and display the appropriate element.
  • justify?: boolean: If set to true, WindowControls will justify/snap in the flexbox where it is located.
  • hide?: boolean: If set to true, the window controls will be hidden.
  • hideMethod?: "display" | "visibility": Determines how the window controls will be hidden.

You can also provide additional props to elements, such as data-tauri-drag-region, for further enhancements.

Example Example

Figma

Check out the design implementation on Figma for a visual reference. Desktop Native Window Controls - Figma.

These sources were utilized:

Development and Contribution

bun dev

bun tauri:dev

Project Structure:

.
โ”œโ”€โ”€ /apps
โ”‚   โ”œโ”€โ”€ /tauri-controls            # Main application (React)
โ”‚   โ”œโ”€โ”€ /tauri-controls-solid      # Solid.js implementation
โ”‚   โ””โ”€โ”€ /tauri-controls-svelte     # Svelte implementation
โ”œโ”€โ”€ /packages                       # Shared packages
โ”œโ”€โ”€ package.json                    # Project configuration
โ”œโ”€โ”€ pnpm-workspace.yaml             # Workspace configuration
โ””โ”€โ”€ turbo.json                      # TurboRepo configuration

If you're interested in contributing, check out our TODO list for tasks you can help with. Your contributions are appreciated!

Contributors

This project is made possible by the contributions of various individuals. Thank you to all the contributors who have helped make this project better.

Further Reading

License

MIT

tauri-controls's People

Contributors

a-kirami avatar agmmnn avatar allenli178 avatar annie444 avatar flerouwu avatar jbolda avatar ronanru avatar sdvina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tauri-controls's Issues

[bug]: weird icons on macOS

Hi, thank for great library

I just notify on macOS icons are displaying very weird, only fine on windows and linux

image

display of controls is different in macos/safari(13)

Hello,
Thank for great library
I'm trying integrate WindowTitleBar to my app, but it's look weird, maybe I use it wrong
image

<WindowTitlebar
          controlsOrder="platform"
          windowControlsProps={{ platform: 'macos' }}
        >
          <button
            type="button"
            onClick={() => goBack()}
            className="group inline-flex h-6 w-6 items-center justify-center rounded-md hover:bg-zinc-900"
          >
            <ArrowLeftIcon className="h-4 w-4 text-zinc-500 group-hover:text-zinc-300" />
          </button>
          <button
            type="button"
            onClick={() => goForward()}
            className="group inline-flex h-6 w-6 items-center justify-center rounded-md hover:bg-zinc-900"
          >
            <ArrowRightIcon className="h-4 w-4 text-zinc-500 group-hover:text-zinc-300" />
          </button>
        </WindowTitlebar>

Pure HTML/js version

Hi, sorry for this noob question and thanks for this lib.

Is there a plain HTML/js version of this library. We dont use any framework like react/angular/ any for htyps://brackets.io and having a plain HTML/js distribution will make this lib accessible to most web projects. Any hints on how to use in just plain web pages?

[bug] SolidJs windowControlsProps is not reactive

I try to use a SolidJs signal with my titlebar to make the controls hidden and not hidden. However, when I update the signal the taskbar doesn't update.

Code:
<WindowTitlebar class={'titlebar'} windowControlsProps={{"hide":getHide()}}></WindowTitlebar>

Breaking changes introduced on tauri-v2.0.0-beta.9 features

tauri v2.0.0-beta.9 introduced these breaking changes:

  • Renamed icon-ico and icon-png feature flags to image-ico and image-png respectively

tauri-controls still uses icon-ico and icon-png feature flags, breaking usage on versions on and after tauri v2.0.0-beta.9.

Fix

Rename icon-ico and icon-png feature flags to image-ico and image-png respectively.

error in production build

Uncaught (in promise) Not allowed by the scope
TypeError: Cannot read properties of null (reading 'useState')

Details

index-c376e050.js:40 TypeError: Cannot read properties of null (reading 'useState')
at Y.useState (index-c376e050.js:49:6350)
at Qv (index-c376e050.js:58:32088)
at zc (index-c376e050.js:38:19517)
at W0 (index-c376e050.js:40:43915)
at V0 (index-c376e050.js:40:39687)
at Lg (index-c376e050.js:40:39615)
at ml (index-c376e050.js:40:39470)
at Rs (index-c376e050.js:40:35850)
at D0 (index-c376e050.js:40:34801)
at C (index-c376e050.js:25:1558)
gs @ index-c376e050.js:40
index-c376e050.js:40 TypeError: Cannot read properties of null (reading 'useState')
at Y.useState (index-c376e050.js:49:6350)
at qv (index-c376e050.js:58:33843)
at zc (index-c376e050.js:38:19517)
at W0 (index-c376e050.js:40:43915)
at V0 (index-c376e050.js:40:39687)
at Lg (index-c376e050.js:40:39615)
at ml (index-c376e050.js:40:39470)
at Rs (index-c376e050.js:40:35850)
at D0 (index-c376e050.js:40:34801)
at C (index-c376e050.js:25:1558)
gs @ index-c376e050.js:40
index-c376e050.js:40 TypeError: Cannot read properties of null (reading 'useState')
at Y.useState (index-c376e050.js:49:6350)
at Xv (index-c376e050.js:58:30923)
at zc (index-c376e050.js:38:19517)
at W0 (index-c376e050.js:40:43915)
at V0 (index-c376e050.js:40:39687)
at Lg (index-c376e050.js:40:39615)
at ml (index-c376e050.js:40:39470)
at Rs (index-c376e050.js:40:35850)
at D0 (index-c376e050.js:40:34801)
at C (index-c376e050.js:25:1558)
gs @ index-c376e050.js:40
index-c376e050.js:40 Uncaught TypeError: Cannot read properties of null (reading 'useState')
at Y.useState (index-c376e050.js:49:6350)
at Qv (index-c376e050.js:58:32088)
at zc (index-c376e050.js:38:19517)
at W0 (index-c376e050.js:40:43915)
at V0 (index-c376e050.js:40:39687)
at Lg (index-c376e050.js:40:39615)
at ml (index-c376e050.js:40:39470)
at Rs (index-c376e050.js:40:35850)
at D0 (index-c376e050.js:40:34801)
at C (index-c376e050.js:25:1558)
tauri.localhost/:1 Uncaught (in promise) Not allowed by the scope
tauri.localhost/:1 Uncaught (in promise) Not allowed by the scope
tauri.localhost/:1 Uncaught (in promise) Not allowed by the scope
tauri.localhost/:1 Uncaught (in promise) Not allowed by the scope
tauri.localhost/:1 Uncaught (in promise) Not allowed by the scope
tauri.localhost/:1 Uncaught (in promise) Not allowed by the scope

๐Ÿ“ท

Native looking setting tabs ui

Great solution.
would it be in the scope of the project to create a native looking settings window also?

something like

im currently rebuilding this ui with tailwind css but its quite a challange to make it look native

Is linux supported?

Greetings,

I recently discovered this library while porting the Brackets.io project to Tauri. The UI of this library appears well-suited to our requirements.

Could you please confirm if this library supports Linux or have any plans to support linux?

Thank you in advance!

[MacOS] Shows windows controls on macos when platform is not specified

I was trying to debug why Windows controls were showing up on my project, but trying to run the SolidJS example yields similar results. As seen in the image, the first title bar, which, as per the code, should auto-detect the platform <WindowTitlebar class="border">content</WindowTitlebar> , detects the platform as windows.

image

I am on an M1 Pro Macbook.

Additionally, in my own project, I also get an error regarding a 400 error from the OS plugin. Note: I have the exact same cargo.toml, tauri.conf.json, and package.json versions for the dependencies.

image

Checking tauri-plugin-os, the rust code has no kind handler...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.