Skip to content

Commit

Permalink
feat: ✨ many changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrnoch committed Aug 17, 2023
1 parent 533d8f4 commit 080bdad
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 97 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@tauri-apps/plugin-updater": "^2.0.0-alpha.1",
"@tauri-apps/plugin-window": "2.0.0-alpha.1",
"solid-headless": "^0.13.1",
"solid-icons": "^1.0.11",
"solid-js": "^1.7",
"solid-toast": "^0.5.0"
},
Expand Down
12 changes: 12 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust
# "typescript",
# ], branch = "v2" }
tokio = { version = "1.29.1", features = ["macros"] }
window-vibrancy = { git = "https://github.com/tauri-apps/window-vibrancy", branch = "dev" }
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-updater = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
Expand Down
22 changes: 22 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

#[cfg(target_os = "macos")]
extern crate objc;

#[cfg(target_os = "macos")]
mod window_ext;

#[allow(warnings, unused)]
mod db;

use db::*;
use prisma_client_rust::QueryError;
use serde::Deserialize;
use window_ext::{ToolbarThickness, WindowExt};
// use specta::{collect_types, Type};
use std::sync::Arc;
use tauri::{Manager, State};
use tauri_plugin_autostart::MacosLauncher;
use window_vibrancy::{apply_mica, apply_vibrancy, NSVisualEffectMaterial};
// use tauri_specta::ts;

#[derive(Clone, serde::Serialize)]
Expand Down Expand Up @@ -93,6 +101,20 @@ async fn main() {
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_window::init())
.setup(|app| {
let window = app.get_window("main").unwrap();
window.set_transparent_titlebar(ToolbarThickness::Thick);

#[cfg(target_os = "macos")]
apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, None)
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");

#[cfg(target_os = "windows")]
apply_mica(&window, Some(true))
.expect("Unsupported platform! 'apply_mica' is only supported on Windows");

Ok(())
})
.invoke_handler(tauri::generate_handler![check_db, get_company, create_post])
.manage(Arc::new(db))
.run(tauri::generate_context!())
Expand Down
76 changes: 32 additions & 44 deletions src-tauri/src/window_ext.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,49 @@
use tauri::{Runtime, Window};

#[allow(dead_code)]
pub enum ToolbarThickness {
Thick,
Medium,
Thin,
}

pub trait WindowExt {
#[cfg(target_os = "macos")]
fn set_transparent_titlebar(&self, transparent: bool);
fn position_traffic_lights(&self, x: f64, y: f64);
fn set_transparent_titlebar(&self, thickness: ToolbarThickness);
}

impl<R: Runtime> WindowExt for Window<R> {
#[cfg(target_os = "macos")]
fn set_transparent_titlebar(&self, transparent: bool) {
fn set_transparent_titlebar(&self, thickness: ToolbarThickness) {
use cocoa::appkit::{NSWindow, NSWindowTitleVisibility};

let window = self.ns_window().unwrap() as cocoa::base::id;

unsafe {
window.setTitleVisibility_(NSWindowTitleVisibility::NSWindowTitleHidden);

if transparent {
window.setTitlebarAppearsTransparent_(cocoa::base::YES);
} else {
window.setTitlebarAppearsTransparent_(cocoa::base::NO);
let id = self.ns_window().unwrap() as cocoa::base::id;

id.setTitlebarAppearsTransparent_(cocoa::base::YES);

match thickness {
ToolbarThickness::Thick => {
self.set_title("").expect("Title wasn't set to ''");
make_toolbar(id);
}
ToolbarThickness::Medium => {
id.setTitleVisibility_(NSWindowTitleVisibility::NSWindowTitleHidden);
make_toolbar(id);
}
ToolbarThickness::Thin => {
id.setTitleVisibility_(NSWindowTitleVisibility::NSWindowTitleHidden);
}
}
}
}
}

#[cfg(target_os = "macos")]
fn position_traffic_lights(&self, x: f64, y: f64) {
use cocoa::appkit::{NSView, NSWindow, NSWindowButton};
use cocoa::foundation::NSRect;

let window = self.ns_window().unwrap() as cocoa::base::id;

unsafe {
let close = window.standardWindowButton_(NSWindowButton::NSWindowCloseButton);
let miniaturize =
window.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton);
let zoom = window.standardWindowButton_(NSWindowButton::NSWindowZoomButton);

let title_bar_container_view = close.superview().superview();

let close_rect: NSRect = msg_send![close, frame];
let button_height = close_rect.size.height;

let title_bar_frame_height = button_height + y;
let mut title_bar_rect = NSView::frame(title_bar_container_view);
title_bar_rect.size.height = title_bar_frame_height;
title_bar_rect.origin.y = NSView::frame(window).size.height - title_bar_frame_height;
let _: () = msg_send![title_bar_container_view, setFrame: title_bar_rect];

let window_buttons = vec![close, miniaturize, zoom];
let space_between = NSView::frame(miniaturize).origin.x - NSView::frame(close).origin.x;
#[cfg(target_os = "macos")]
unsafe fn make_toolbar(id: cocoa::base::id) {
use cocoa::appkit::{NSToolbar, NSWindow};

for (i, button) in window_buttons.into_iter().enumerate() {
let mut rect: NSRect = NSView::frame(button);
rect.origin.x = x + (i as f64 * space_between);
button.setFrameOrigin(rect.origin);
}
}
}
let new_toolbar = NSToolbar::alloc(id);
new_toolbar.init_();
id.setToolbar_(new_toolbar);
}
4 changes: 2 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
"fullscreen": false,
"resizable": true,
"title": "accounting",
"width": 800,
"width": 900,
"height": 600,
"minWidth": 800,
"minHeight": 600,
"minHeight": 550,
"titleBarStyle": "Overlay",
"hiddenTitle": true
}
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const dict = {
sidebar_button_clients: "Clients",
sidebar_button_expenses: "Expenses",
sidebar_button_reports: "Reports",
sidebar_settings: "Settings",

sidebar_section_sales: "Sales",
sidebar_section_purchase: "Purchase",
Expand All @@ -27,6 +28,7 @@ export const dict = {
sidebar_button_clients: "Klienti",
sidebar_button_expenses: "Výdaje",
sidebar_button_reports: "Reporty",
sidebar_settings: "Nastavení",

sidebar_section_sales: "Prodej",
sidebar_section_purchase: "Nákup",
Expand Down
32 changes: 11 additions & 21 deletions src/screens/Dashboard/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@ import SidebarButton from "./Button";
import SidebarSection from "./Section";
import { useSelector } from "@/store";
import { useI18n } from "@/i18n";
import SettingsIcon from "@/shared/icons/Settings";
import Popover from "@/shared/components/Popover";
//@ts-expect-error
import { Presence } from "@motionone/solid";

enum PopoverList {
Profile = "profile",
Settings = "settings",
}
import { FiSettings } from "solid-icons/fi";

const Sidebar: Component = () => {
const [t] = useI18n();
const [currentPopover, setCurrentPopover] = createSignal<PopoverList | null>(null);
const [settingsOpen, setSettingsOpen] = createSignal(false);

const {
companyService: { company },
} = useSelector();

return (
<div class="flex relative flex-col justify-between px-4 pt-10 pb-4 w-1/5 h-screen lg:max-w-[220px] min-w-[140px] bg-gray shrink-0">
<div class="flex relative flex-col justify-between px-4 pt-14 pb-4 w-1/5 h-screen lg:max-w-[220px] min-w-[140px] bg-gray-400 shrink-0">
<div>
<SidebarButton target="/">{t.sidebar_button_overview()}</SidebarButton>

Expand All @@ -38,25 +33,20 @@ const Sidebar: Component = () => {
</SidebarSection>
</div>

{/* profile */}
<div class="flex flex-row gap-3 justify-start items-center">
<div class="w-5 h-5 lg:w-10 lg:h-10 rounded-full bg-gray-300 flex items-center justify-center">
<SettingsIcon />
{/* profile */}
<div class="flex flex-row gap-3 justify-start items-center lg:gap-4">
<div class="flex justify-center items-center w-8 h-8 bg-gray-300 rounded-full lg:w-10 lg:h-10">
<FiSettings />
</div>
<div class="flex flex-col leading-4">
<span class="text">{company.name}</span>
<div class="flex flex-col">
<span class="text-sm leading-3 lg:text-md lg:leading-5 lg:text-base">{company.name}</span>
<span class="text-sm text-gray-700">{company.email}</span>
</div>
</div>

<Presence exitBeforeEnter>
<Show when={currentPopover() === PopoverList.Profile}>
<Popover onClose={() => setCurrentPopover(null)} title="Profile">
Cus
</Popover>
</Show>
<Show when={currentPopover() === PopoverList.Settings}>
<Popover onClose={() => setCurrentPopover(null)} title="Settings">
<Show when={settingsOpen()}>
<Popover onClose={() => setSettingsOpen} title="Settings">
Nastaveni
</Popover>
</Show>
Expand Down
21 changes: 17 additions & 4 deletions src/screens/Dashboard/components/TitleBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, For, Show, createEffect, createSignal } from "solid-js";
import { Platform, platform } from "@tauri-apps/plugin-os";
import { useLocation } from "@solidjs/router";
import { useI18n } from "@/i18n";
import { FiBell, FiSearch, FiSettings, FiSidebar } from "solid-icons/fi";

const TitleBar: Component = () => {
const [os, setOs] = createSignal<Platform | null>(null);
Expand Down Expand Up @@ -36,12 +37,14 @@ const TitleBar: Component = () => {
});

return (
<div class="flex fixed top-0 left-0 flex-row w-screen h-[30px] z-50 ">
<div class="flex fixed top-0 left-0 flex-row w-screen h-[40px] z-50 cursor-default select-none border-b border-black/10">
<div
class="flex items-center w-1/5 h-full bg-green-500 lg:max-w-[220px] min-w-[140px] shrink-0"
class="flex items-center justify-end w-1/5 h-full lg:max-w-[220px] min-w-[140px] shrink-0 px-2"
data-tauri-drag-region
/>
<div class="flex items-center w-4/5 h-full lg:w-full bg-yellow-500" data-tauri-drag-region>
>
<FiSidebar />
</div>
<div class="flex justify-between items-center px-5 w-4/5 h-full lg:px-8 lg:w-full" data-tauri-drag-region>
<div class="flex gap-2 items-center h-full">
<For each={matchPathname(location.pathname)}>
{(item, index) => (
Expand All @@ -59,6 +62,16 @@ const TitleBar: Component = () => {
)}
</For>
</div>
<div class="flex flex-row gap-5 items-center py-1 h-full">
{/* search bar */}
<div class="flex justify-between items-center px-3 ml-16 w-72 h-full text-gray-500 bg-gray-200 rounded-lg">
<div class="flex gap-2 items-center">
<FiSearch /> Hledat
</div>
</div>
<FiSettings />
<FiBell />
</div>
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Dashboard: Component = () => {
<TitleBar />
<div class="flex flex-row items-start w-screen">
<Sidebar />
<div class="container px-4 pt-10 mx-auto w-full h-screen">
<div class="container px-4 pt-14 mx-auto w-full h-screen">
<Routes>
<Route path="/" element={<Overview />} />
<Route path="/sales/invoices" element={<Invoices />} />
Expand Down
24 changes: 0 additions & 24 deletions src/shared/icons/Settings.tsx

This file was deleted.

7 changes: 6 additions & 1 deletion src/styles/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind utilities;


* {
background: transparent;
}

0 comments on commit 080bdad

Please sign in to comment.