Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial running version on Windows #9

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ on:

jobs:
build:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
name: macOS
targets: app,dmg
- host: windows-latest
name: Windows
targets: msi,nsis
name: Build for ${{ matrix.settings.name }}
runs-on: ${{ matrix.settings.host }}
steps:
- name: Checkout the code
uses: actions/checkout@v3
Expand Down Expand Up @@ -49,17 +60,37 @@ jobs:

- name: Build the app
uses: tauri-apps/tauri-action@v0
with:
args: --bundles ${{ matrix.settings.targets }}

- name: 🚀 Upload macOS dmg
if: matrix.settings.host == 'macos-latest'
uses: actions/upload-artifact@v3
with:
name: Commit.dmg
path: |
target/release/bundle/dmg/Commit*.dmg

- name: 🚀 Upload macOS App
- name: 🚀 Upload macOS app
if: matrix.settings.host == 'macos-latest'
uses: actions/upload-artifact@v3
with:
name: Commit.app
path: |
target/release/bundle/macos/

- name: 🚀 Upload Windows NSIS
if: matrix.settings.host == 'windows-latest'
uses: actions/upload-artifact@v3
with:
name: Commit.exe
path: |
target/release/bundle/nsis/Commit*.exe

- name: 🚀 Upload Windows MSI
if: matrix.settings.host == 'windows-latest'
uses: actions/upload-artifact@v3
with:
name: Commit.msi
path: |
target/release/bundle/msi/Commit*.msi
8 changes: 2 additions & 6 deletions frontend/src/components/ShortcutPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ const ShortcutPicker: FC<Props> = ({ value, onChange }) => {
setShortcut(parseShortcut(value))
}, [value])

// useEffect(() => {
// onChange(buildShortcut(shortcut))
// }, [shortcut])

const handleKeyDown = useCallback(
(event: KeyboardEvent<HTMLDivElement>) => {
event.preventDefault()
Expand Down Expand Up @@ -75,10 +71,10 @@ const parseShortcut = (shortcut: string): ParsedShortcut => {

return {
isAlt: parts.includes('Alt'),
isCmd: parts.includes('Cmd'),
isCtrl: parts.includes('Ctrl'),
isShift: parts.includes('Shift'),
natural: parts[parts.length - 1].toUpperCase(),
isCmd: parts.includes('CommandOrControl') || parts.includes('Cmd'),
}
}

Expand All @@ -100,10 +96,10 @@ const displayShortcut = (shortcut: ParsedShortcut): string => {
const buildShortcut = (shortcut: ParsedShortcut): string => {
let parts = []

if (shortcut.isCmd) parts.push('Cmd')
if (shortcut.isAlt) parts.push('Alt')
if (shortcut.isCtrl) parts.push('Ctrl')
if (shortcut.isShift) parts.push('Shift')
if (shortcut.isCmd) parts.push('CommandOrControl')

parts.push(shortcut.natural.toUpperCase())

Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
use anyhow::anyhow;
use config::{Config, ConfigExt};
use std::error::Error;
use tauri::{generate_context, ActivationPolicy, Builder as Tauri};
use tauri::{generate_context, Builder as Tauri};

#[cfg(target_os = "macos")]
use tauri::ActivationPolicy;

use tauri_autostart::ManagerExt;
use tauri_plugin_autostart::{self as tauri_autostart};

Expand Down Expand Up @@ -33,6 +37,7 @@ fn main() {
}

fn setup_tauri(app: &mut tauri::App) -> Result<(), Box<(dyn Error + 'static)>> {
#[cfg(target_os = "macos")]
app.set_activation_policy(ActivationPolicy::Accessory);

window::main_window::create(&app.handle())?;
Expand Down
7 changes: 4 additions & 3 deletions src/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use tauri::{AppHandle, GlobalShortcutManager, Manager, Window};

use crate::window;

pub const DEFAULT_SHORTCUT: &str = "Cmd+Alt+Shift+C";
pub const DEFAULT_SHORTCUT: &str = "CommandOrControl+Alt+Shift+C";
pub const SETTINGS_SHORTCUT: &str = "CommandOrControl+,";

pub fn update_default(
app: &AppHandle,
Expand All @@ -28,7 +29,7 @@ pub fn register_settings(app: &AppHandle) -> Result<(), anyhow::Error> {
let mut shortcuts = app.global_shortcut_manager();

let settings_window = window::settings::get(app).unwrap();
shortcuts.register("Cmd+,", move || {
shortcuts.register(SETTINGS_SHORTCUT, move || {
settings_window.show().unwrap();
settings_window.set_focus().unwrap();
})?;
Expand All @@ -39,7 +40,7 @@ pub fn register_settings(app: &AppHandle) -> Result<(), anyhow::Error> {
pub fn unregister_settings(app: &AppHandle) -> Result<(), anyhow::Error> {
let mut shortcuts = app.global_shortcut_manager();

shortcuts.unregister("Cmd+,")?;
shortcuts.unregister(SETTINGS_SHORTCUT)?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ pub enum TrayMenu {

pub fn build() -> SystemTray {
let tray_menu = SystemTrayMenu::new()
.add_item(CustomMenuItem::new(TrayMenu::Settings, "Settings...").accelerator("Cmd+,"))
.add_item(CustomMenuItem::new(TrayMenu::Settings, "Settings...").accelerator("CommandOrControl+,"))
.add_native_item(SystemTrayMenuItem::Separator);

#[cfg(debug_assertions)]
let tray_menu = tray_menu
.add_item(
CustomMenuItem::new(TrayMenu::DevTools, "Open DevTools").accelerator("Cmd+Shift+I"),
CustomMenuItem::new(TrayMenu::DevTools, "Open DevTools").accelerator("CommandOrControl+Shift+I"),
)
.add_native_item(SystemTrayMenuItem::Separator);

Expand Down
4 changes: 3 additions & 1 deletion src/window/main_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub fn hide(window: &Window) -> Result<(), tauri_plugin_spotlight::Error> {

pub fn on_open(window: Window) {
shortcuts::register_escape(window.clone()).unwrap();
shortcuts::register_settings(&window.app_handle()).unwrap();
shortcuts::register_settings(&window.app_handle()).unwrap_or_else(|_| {
eprintln!("Failed to register settings shortcut");
});

tauri::async_runtime::spawn(async move {
let app = window.app_handle();
Expand Down
24 changes: 18 additions & 6 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ use tauri::{
plugin::TauriPlugin, AppHandle, GlobalWindowEvent, Manager, RunEvent, Window, WindowEvent,
};
use tauri_plugin_spotlight::{PluginConfig, WindowConfig};

#[cfg(target_os = "macos")]
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial, NSVisualEffectState};

#[cfg(target_os = "windows")]
use window_vibrancy::apply_mica;

use crate::shortcuts;

pub const MAIN: &str = "main";
Expand Down Expand Up @@ -66,11 +71,18 @@ pub trait TransparentWindow {

impl TransparentWindow for Window {
fn make_transparent(&self) -> Result<(), window_vibrancy::Error> {
apply_vibrancy(
self,
NSVisualEffectMaterial::HudWindow,
Some(NSVisualEffectState::Active),
Some(10.0),
)
{
#[cfg(target_os = "macos")]
apply_vibrancy(
self,
NSVisualEffectMaterial::HudWindow,
Some(NSVisualEffectState::Active),
Some(10.0),
)
}

// not working
#[cfg(target_os = "windows")]
apply_mica(self, Some(false))
}
}
17 changes: 16 additions & 1 deletion src/window/settings.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use anyhow::anyhow;
use tauri::{AppHandle, Manager, TitleBarStyle, Window, WindowBuilder, WindowUrl};
use tauri::{AppHandle, Manager, Window, WindowBuilder, WindowUrl};
#[cfg(target_os = "macos")]
use tauri::TitleBarStyle;

use crate::window;

use super::TransparentWindow;

pub fn create(app: &AppHandle) -> anyhow::Result<Window> {
#[cfg(target_os = "macos")]
let settings_window =
WindowBuilder::new(app, window::SETTINGS, WindowUrl::App(Default::default()))
.visible(false)
Expand All @@ -17,6 +20,18 @@ pub fn create(app: &AppHandle) -> anyhow::Result<Window> {
.initialization_script("window.__COMMIT__ = { page: 'settings' };")
.build()?;

// not macos
#[cfg(not(target_os = "macos"))]
let settings_window =
WindowBuilder::new(app, window::SETTINGS, WindowUrl::App(Default::default()))
.visible(false)
.closable(true)
.transparent(true)
.always_on_top(true)
.title("Settings - Commit")
.initialization_script("window.__COMMIT__ = { page: 'settings' };")
.build()?;

settings_window.make_transparent().map_err(|_| {
anyhow!("Unsupported platform! 'apply_vibrancy' is only supported on macOS")
})?;
Expand Down