Skip to content

Commit

Permalink
feat: update the ui and add compact mode (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkristiansson authored Sep 6, 2024
1 parent 580c0c5 commit 222e67d
Show file tree
Hide file tree
Showing 14 changed files with 361 additions and 300 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gitbar</title>
</head>
<body class="bg-white text-slate-500 antialiased dark:bg-stone-900 dark:text-slate-400">
<div id="app"></div>
<body class="bg-white text-slate-500 antialiased dark:bg-stone-900 dark:text-slate-400 overflow-hidden">
<div id="app" class="h-screen"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gitbar",
"private": true,
"version": "0.4.4",
"version": "0.5.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
17 changes: 16 additions & 1 deletion src-tauri/Cargo.lock

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

19 changes: 14 additions & 5 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "gitbar"
version = "0.4.4"
version = "0.5.0"
description = "Github review counter"
authors = ["mikael.kristiansson"]
license = "MIT"
repository = "https://github.com/mikaelkristiansson/gitbar"
default-run = "gitbar"
edition = "2021"
rust-version = "1.57"
rust-version = "1.67"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -18,8 +18,17 @@ tauri-build = { version = "1.2.1", features = [] }
serde_json = "1.0"
auto-launch = "0.3"
thiserror = "1.0"
tauri-plugin-positioner = { version = "1.0.4", features = ["system-tray"] }
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2.3", features = [ "updater", "http-request", "icon-png", "notification-all", "shell-open", "system-tray"] }
tauri = { version = "1.2.3", features = [
"window-set-size",
"updater",
"http-request",
"icon-png",
"notification-all",
"shell-open",
"system-tray",
] }

[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.24"
Expand All @@ -28,7 +37,7 @@ objc = "0.2.7"
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
default = ["custom-protocol"]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]
custom-protocol = ["tauri/custom-protocol"]
202 changes: 104 additions & 98 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

use tauri::Manager;
use tauri::{CustomMenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu, PhysicalPosition};
use tauri::{CustomMenuItem, Menu, MenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu};
use tauri::{Manager, Submenu};
use tauri_plugin_positioner::{Position, WindowExt as WindowExtTrait};

mod auto_start;

Expand Down Expand Up @@ -42,7 +43,8 @@ impl<R: Runtime> WindowExt for Window<R> {
if remove_tool_bar {
let close_button = id.standardWindowButton_(NSWindowButton::NSWindowCloseButton);
let _: () = msg_send![close_button, setHidden: YES];
let min_button = id.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton);
let min_button =
id.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton);
let _: () = msg_send![min_button, setHidden: YES];
let zoom_button = id.standardWindowButton_(NSWindowButton::NSWindowZoomButton);
let _: () = msg_send![zoom_button, setHidden: YES];
Expand All @@ -65,100 +67,104 @@ impl<R: Runtime> WindowExt for Window<R> {

#[tauri::command]
fn set_review_count(app_handle: tauri::AppHandle, count: &str) {
let mut rev_count = count.to_string();
rev_count.insert_str(0, " ");
#[cfg(target_os = "macos")]
app_handle
.tray_handle()
.set_title(&rev_count)
.unwrap();
let mut rev_count = count.to_string();
let count_number = count.parse::<i32>().unwrap_or_default();
if count_number > 0 {
rev_count.insert_str(0, " ");
}
#[cfg(target_os = "macos")]
app_handle.tray_handle().set_title(&rev_count).unwrap();
}

fn main() {
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let tray_menu = SystemTrayMenu::new()
.add_item(quit);
let system_tray = SystemTray::new()
.with_menu(tray_menu);

tauri::Builder::default()
.system_tray(system_tray)
.on_system_tray_event(move |app, event| match event {
SystemTrayEvent::LeftClick {
position,
size,
..
} => {
let w = app.get_window("main").unwrap();
let visible = w.is_visible().unwrap();
if visible {
w.hide().unwrap();
} else {
let window_size = w.outer_size().unwrap();
let physical_pos = PhysicalPosition {
x: position.x as i32 + (size.width as i32 / 2) - (window_size.width as i32 / 2),
y: position.y as i32 - window_size.height as i32
};

let _ = w.set_position(tauri::Position::Physical(physical_pos));
w.show().unwrap();
w.set_focus().unwrap();
}
}
SystemTrayEvent::RightClick {
position: _,
size: _,
..
} => {
println!("system tray received a right click");
}
SystemTrayEvent::DoubleClick {
position: _,
size: _,
..
} => {
println!("system tray received a double click");
}
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"quit" => {
std::process::exit(0);
}
_ => {}
},
_ => {}
})
.on_window_event(|event| match event.event() {
tauri::WindowEvent::CloseRequested { api, .. } => {
// don't kill the app when the user clicks close. this is important
event.window().hide().unwrap();
api.prevent_close();
}
tauri::WindowEvent::Focused(false) => {
// hide the window automatically when the user
// clicks out. this is for a matter of taste.
event.window().hide().unwrap();
}
_ => {}
})
.invoke_handler(tauri::generate_handler![set_review_count])
.plugin(auto_start::init(
None,
))
.setup(|app| {
#[cfg(target_os = "macos")]
// don't show on the taskbar/springboard
app.set_activation_policy(tauri::ActivationPolicy::Accessory);

let window = app.get_window("main").unwrap();
#[cfg(target_os = "macos")]
window.set_transparent_titlebar(true, true);

// this is a workaround for the window to always show in current workspace.
// see https://github.com/tauri-apps/tauri/issues/2801
window.set_always_on_top(true).unwrap();

Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let tray_menu = SystemTrayMenu::new().add_item(quit);
let system_tray = SystemTray::new().with_menu(tray_menu);
let edit_menu = Submenu::new(
"Edit",
Menu::new()
.add_native_item(MenuItem::Undo)
.add_native_item(MenuItem::Redo)
.add_native_item(MenuItem::Separator)
.add_native_item(MenuItem::Cut)
.add_native_item(MenuItem::Copy)
.add_native_item(MenuItem::Paste)
.add_native_item(MenuItem::SelectAll),
);

let menu = Menu::new().add_submenu(edit_menu);

tauri::Builder::default()
.plugin(tauri_plugin_positioner::init())
.on_system_tray_event(|app, event| {
tauri_plugin_positioner::on_tray_event(app, &event);
})
.menu(menu)
.system_tray(system_tray)
.on_system_tray_event(move |app, event| match event {
SystemTrayEvent::LeftClick { .. } => {
let w = app.get_window("main").unwrap();
let visible = w.is_visible().unwrap();
if visible {
w.hide().unwrap();
} else {
let _ = w.move_window(Position::TrayCenter);
w.show().unwrap();
w.set_focus().unwrap();
}
}
SystemTrayEvent::RightClick {
position: _,
size: _,
..
} => {
println!("system tray received a right click");
}
SystemTrayEvent::DoubleClick {
position: _,
size: _,
..
} => {
println!("system tray received a double click");
}
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"quit" => {
std::process::exit(0);
}
_ => {}
},
_ => {}
})
.on_window_event(|event| match event.event() {
tauri::WindowEvent::CloseRequested { api, .. } => {
// don't kill the app when the user clicks close. this is important
event.window().hide().unwrap();
api.prevent_close();
}
tauri::WindowEvent::Focused(false) => {
// hide the window automatically when the user
// clicks out. this is for a matter of taste.
event.window().hide().unwrap();
}
_ => {}
})
.invoke_handler(tauri::generate_handler![set_review_count])
.plugin(auto_start::init(None))
.setup(|app| {
#[cfg(target_os = "macos")]
// don't show on the taskbar/springboard
app.set_activation_policy(tauri::ActivationPolicy::Accessory);

let window = app.get_window("main").unwrap();
#[cfg(target_os = "macos")]
window.set_transparent_titlebar(true, true);

// this is a workaround for the window to always show in current workspace.
// see https://github.com/tauri-apps/tauri/issues/2801
window.set_always_on_top(true).unwrap();

Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
6 changes: 4 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"distDir": "../dist"
},
"package": {
"productName": "GitBar",
"version": "0.4.4"
"productName": "GitBar"
},
"tauri": {
"allowlist": {
Expand All @@ -21,6 +20,9 @@
},
"shell": {
"open": true
},
"window": {
"setSize": true
}
},
"bundle": {
Expand Down
21 changes: 6 additions & 15 deletions src/components/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@
}
</script>

<footer
class="fixed bottom-0 left-0 dark:bg-gray-900 bg-gray-50 shadow-md w-full px-2 py-2"
>
<footer class="fixed bottom-0 left-0 dark:bg-gray-900 bg-gray-50 shadow-md w-full px-2 py-2">
<div class="flex justify-between">
<div class="p-2 flex items-center">
<Image
src={$auth.account?.user?.avatar_url}
class="h-6 w-6 flex-shrink-0 rounded-full"
>
<Image src={$auth.account?.user?.avatar_url} class="h-6 w-6 flex-shrink-0 rounded-full">
<svg
slot="error"
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -50,16 +45,12 @@
</svg>
</Image>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<span
<button
class={`${
$auth.account?.user?.html_url
? 'cursor-pointer hover:text-slate-600/70 dark:hover:text-white/70'
: ''
$auth.account?.user?.html_url ? 'cursor-pointer hover:text-slate-600/70 dark:hover:text-white/70' : ''
} ml-1 block truncate`}
on:click={() =>
$auth.account?.user?.html_url
? open($auth.account?.user?.html_url)
: null}>{$auth.account?.user?.name}</span
on:click={() => ($auth.account?.user?.html_url ? open($auth.account?.user?.html_url) : null)}
>{$auth.account?.user?.name || $auth.account?.user?.email || ''}</button
>
</div>
<div class="flex justify-between">
Expand Down
Loading

0 comments on commit 222e67d

Please sign in to comment.