Skip to content

Commit

Permalink
Merge pull request #21 from EastSun5566/feat/add-tray
Browse files Browse the repository at this point in the history
feat: add items to tray
  • Loading branch information
EastSun5566 authored Nov 10, 2023
2 parents 7bff0c6 + 23f0f9f commit 372f6e1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Testing build

on:
pull_request:
types: [labeled]
workflow_dispatch:

jobs:
build:
if: ${{ github.event.label.name == 'build' }}
if: ${{ contains(github.event.pull_request.labels.*.name, 'build') || github.event_name == 'workflow_dispatch' }}

strategy:
fail-fast: false
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
tags:
- "v*"

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ And You can also follow me on [HackMD](https://hackmd.io/@EastSun5566) 😎

### Prerequisites

- [Rust v1.71](https://www.rust-lang.org/learn/get-started)
- [Node.js v16+](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating)
- [Rust v1.71+](https://www.rust-lang.org/learn/get-started)
- [Node.js v18+](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating)
- [Pnpm v8+](https://pnpm.io/installation#using-corepack)

### Getting Started
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"private": true,
"version": "0.0.6",
"type": "module",
"engines": {
"node": ">=18",
"pnpm": ">=8"
},
"scripts": {
"dev": "tauri dev",
"build": "tauri build",
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod cmd;
pub mod conf;
pub mod menu;
pub mod setup;
pub mod tray;

#[cfg(target_os = "macos")]
pub mod mac;
20 changes: 20 additions & 0 deletions src-tauri/src/app/tray.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use tauri::{AppHandle, CustomMenuItem, SystemTray, SystemTrayEvent, SystemTrayMenu};

pub fn init() -> SystemTray {
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let tray_menu = SystemTrayMenu::new().add_item(quit);

SystemTray::new().with_menu(tray_menu)
}

pub fn handler(app: &AppHandle, event: SystemTrayEvent) {
match event {
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"quit" => {
app.exit(0);
}
_ => {}
},
_ => {}
}
}
5 changes: 3 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
mod app;
mod utils;

use app::{cmd, menu, setup};
use app::{cmd, menu, setup, tray};

#[tokio::main]
async fn main() {
Expand All @@ -23,7 +23,8 @@ async fn main() {
.setup(setup::init)
.menu(menu::init(&context))
.on_menu_event(menu::handler)
.system_tray(tauri::SystemTray::default())
.system_tray(tray::init())
.on_system_tray_event(tray::handler)
.run(context)
.expect("error while running HackDesk application");
}
7 changes: 5 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
"open": true
},
"fs": {
"scope": ["$HOME/.hackdesk/*"]
"all": false,
"scope": ["$HOME/.hackdesk/*"],
"readFile": true,
"writeFile": true
},
"globalShortcut": {
"all": true
"all": false
}
},
"systemTray": {
Expand Down

0 comments on commit 372f6e1

Please sign in to comment.