Skip to content

Commit

Permalink
chore: refactored on top of master changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 20, 2023
1 parent 6eefce9 commit a9b1761
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 101 deletions.
81 changes: 56 additions & 25 deletions app/tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#[cfg(debug_assertions)]
use tauri::Manager;
use tauri::RunEvent;
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

#[cfg(desktop)]
use tauri::{Manager};
use tauri::{RunEvent};
#[cfg(desktop)]
use tauri_plugin_autostart::MacosLauncher;
#[cfg(desktop)]
use tauri_plugin_updater::Builder;
use tauri_plugin_window;

use tauri_plugin_shell;

#[cfg(desktop)]
mod desktop;

Expand All @@ -16,48 +20,75 @@ use desktop::{
commands::PomatezCommands,
global_shortcuts::{PomatezGlobalShortcutsRegister, PomatezGlobalShortcutsSetup},
system_tray::PomatezTray,
updater,
};

#[cfg(target_os = "macos")]
use crate::commands::try_set_native_titlebar;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let builder = tauri::Builder::default();
let mut context = tauri::generate_context!();

#[cfg(desktop)]
let builder = builder
.plugin(tauri_plugin_autostart::init(
let config = context.config_mut();

let app = tauri::Builder::default();

#[cfg(desktop)]
let app = app.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
None,
))
.plugin(tauri_plugin_window::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_updater::Builder::new().build());
));

let builder = builder.plugin(tauri_plugin_shell::init());
let app = app.plugin(tauri_plugin_window::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_notification::init());

#[cfg(desktop)]
let builder = builder.register_pomatez_commands();
let mut app = app;

#[cfg(desktop)]
let builder = builder.setup(|app| {
app.setup_global_shortcuts();
app.set_pomatez_system_tray();
if config.tauri.bundle.updater.active {
app = app.plugin(Builder::new().build());
}

Ok(())
});
#[cfg(desktop)]
let app = app.register_pomatez_commands();

#[allow(unused_variables)]
let app = app.setup(|app| {
#[cfg(desktop)]
{
app.setup_global_shortcuts();
app.set_pomatez_system_tray();
}

let app = builder
.build(tauri::generate_context!())
Ok(())
});

let app = app.build(context)
.expect("error while running tauri application");

#[allow(unused_variables)]
app.run(|app_handle, e| match e {
RunEvent::Ready => {
#[cfg(desktop)]
app_handle.register_global_shortcuts();
{
app_handle.register_global_shortcuts();

let window = app_handle.get_window("main").unwrap();

// There is a bug on mac where the size is not properly respected initially, though this seems to fix it.
#[cfg(target_os = "macos")]
{
try_set_native_titlebar(false, &window);
try_set_native_titlebar(true, &window);
}

#[cfg(debug_assertions)]
window.open_devtools();
}

#[cfg(debug_assertions)]
app_handle.get_window("main").unwrap().open_devtools();

println!("Pomatez is ready");
}
Expand Down
79 changes: 4 additions & 75 deletions app/tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,79 +1,8 @@
#![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::{RunEvent};
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_window;

#[macro_use]
mod commands;
mod global_shortcuts;
mod system_tray;
mod updater;

#[cfg(target_os = "macos")]
use crate::commands::try_set_native_titlebar;

use commands::PomatezCommands;
use global_shortcuts::{PomatezGlobalShortcutsRegister, PomatezGlobalShortcutsSetup};
use system_tray::PomatezTray;

fn main() {
let mut context = tauri::generate_context!();

let config = context.config_mut();

let mut app = tauri::Builder::default()
.plugin(tauri_plugin_autostart::init(
MacosLauncher::LaunchAgent,
None,
))
.plugin(tauri_plugin_window::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_notification::init());



if config.tauri.bundle.updater.active {
app = app.plugin(tauri_plugin_updater::Builder::new().build());
}

let app = app
.register_pomatez_commands()
.setup(|app| {
#[cfg(desktop)]
{
app.setup_global_shortcuts();
app.set_pomatez_system_tray();
}

Ok(())
})
.build(context)
.expect("error while running tauri application");

#[cfg(desktop)]
app.run(|app_handle, e| match e {
RunEvent::Ready => {
app_handle.register_global_shortcuts();

let window = app_handle.get_window("main").unwrap();

// There is a bug on mac where the size is not properly respected initially, though this seems to fix it.
#[cfg(target_os = "macos")]
{
try_set_native_titlebar(false, &window);
try_set_native_titlebar(true, &window);
}

#[cfg(debug_assertions)]
window.open_devtools();

println!("Pomatez is ready");
}
_ => {}
});
}
pomatez_lib::run()
}
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
"tauri": "tauri",
"tauri:dev": "tauri dev",
"tauri:dev-with-updater": "tauri dev --config ./app/tauri/release.conf.json",
"tauri:updateversion": "node ./app/tauri/util/cargo-version-updater.js"
"tauri:updateversion": "node ./app/tauri/util/cargo-version-updater.js",
"tauri:android:dev": "tauri android dev",
"tauri:android:open": "tauri android open",
"tauri:android:build": "tauri android build",
"tauri:ios:dev": "tauri ios dev",
"tauri:ios:open": "tauri ios open",
"tauri:ios:build": "tauri ios build"
},
"config": {
"commitizen": {
Expand Down

0 comments on commit a9b1761

Please sign in to comment.