Skip to content

Commit

Permalink
fix: fullscreen bug on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed Dec 14, 2022
1 parent a54ce66 commit dd542a9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 48 deletions.
6 changes: 3 additions & 3 deletions src-tauri/src/db/models/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sqlx::{FromRow, Pool, Sqlite};

use crate::app_error::AppError;

const ONE_MINUTE: i64 = 60;
const ONE_MINUTE_AS_SEC: i64 = 60;

#[derive(FromRow, Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Serialize, Deserialize)]
pub struct ModelSettings {
Expand All @@ -18,8 +18,8 @@ impl ModelSettings {
const fn default() -> Self {
Self {
short_break_as_sec: 30,
long_break_as_sec: ONE_MINUTE * 5,
session_as_sec: ONE_MINUTE * 25,
long_break_as_sec: ONE_MINUTE_AS_SEC * 5,
session_as_sec: ONE_MINUTE_AS_SEC * 25,
number_session_before_break: 4,
fullscreen: false,
}
Expand Down
92 changes: 58 additions & 34 deletions src-tauri/src/internal_message_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct PackageInfo {
impl Default for PackageInfo {
fn default() -> Self {
Self {
// split at obliqoro, and take first split
homepage: env!("CARGO_PKG_REPOSITORY").to_owned(),
version: env!("CARGO_PKG_VERSION").to_owned(),
build_date: env!("BUILD_DATE").to_owned(),
Expand Down Expand Up @@ -83,41 +84,71 @@ pub enum InternalMessage {
/// Control the frontend window component visibility
struct WindowAction;
impl WindowAction {
// Show, and/or unminimize, the window
fn show(window: &tauri::Window) {
/// Show the window
/// Linux v Windows, need to handle fullscreen & resize on each platform differently
#[cfg(target_os = "windows")]
fn show(window: &tauri::Window, fullscreen: bool) {
window.set_fullscreen(fullscreen).unwrap_or(());
window.show().unwrap_or(());
window.unminimize().unwrap_or(());
window.center().unwrap_or(());
}

/// Hide window, update tray menu
fn hide(window: &tauri::Window) {
window.hide().unwrap_or(());
/// Show the window
/// see github issue #1
#[cfg(not(target_os = "windows"))]
fn show(window: &tauri::Window, fullscreen: bool) {
if fullscreen {
if window.is_visible().unwrap_or_default() {
window.hide().unwrap();
}
window.set_resizable(true).unwrap();
window.set_fullscreen(fullscreen).unwrap();
// This is the linux fix
std::thread::sleep(std::time::Duration::from_millis(25));
window.show().unwrap();
} else {
if window.is_resizable().unwrap() {
window.set_resizable(false).unwrap();
}
window.show().unwrap();
}
window.center().unwrap();
}

/// Hide window
fn hide(window: &tauri::Window, fullscreen: bool) {
if fullscreen {
window.set_resizable(true).unwrap();
window.set_fullscreen(false).unwrap();
}
window.hide().unwrap();
window.center().unwrap();
}

/// hide window
pub fn hide_window(app: &AppHandle) {
pub fn hide_window(app: &AppHandle, fullscreen: bool) {
if let Some(window) = app.get_window(ObliqoroWindow::Main.as_str()) {
Self::hide(&window);
Self::hide(&window, fullscreen);
}
}

/// Toggle the visible of the main window based on current visibility
pub fn toggle_visibility(app: &AppHandle) {
pub fn toggle_visibility(app: &AppHandle, fullscreen: bool) {
if let Some(window) = app.get_window(ObliqoroWindow::Main.as_str()) {
match window.is_visible() {
Ok(true) => Self::hide(&window),
Ok(false) => Self::show(&window),
Ok(true) => Self::hide(&window, fullscreen),
Ok(false) => Self::show(&window, fullscreen),
Err(_) => app.exit(1),
}
}
}

/// unminimize the main window
pub fn unminimize(app: &AppHandle) {
if let Some(window) = app.get_window(ObliqoroWindow::Main.as_str()) {
window.unminimize().unwrap_or_default();
}
}
// unminimize the main window
// pub fn unminimize(app: &AppHandle) {
// if let Some(window) = app.get_window(ObliqoroWindow::Main.as_str()) {
// window.unminimize().unwrap_or_default();
// }
// }
}

// Update the taskbar to display how many sessions before next long break,
Expand Down Expand Up @@ -275,19 +306,19 @@ fn handle_visibility(
}
WindowVisibility::Hide => {
if !on_break {
WindowAction::hide_window(app);
WindowAction::hide_window(app, false);
}
}
WindowVisibility::Minimize => {
if on_break {
WindowAction::unminimize(app);
} else {
WindowAction::hide_window(app);
}
// if on_break {
// WindowAction::unminimize(app);
// } else {
WindowAction::hide_window(app, false);
// }
}
WindowVisibility::Toggle => {
if !on_break {
WindowAction::toggle_visibility(app);
WindowAction::toggle_visibility(app, false);
}
}
}
Expand All @@ -305,7 +336,7 @@ fn handle_emitter(app: &AppHandle, emitter: Emitter, state: &Arc<Mutex<Applicati
(),
)
.unwrap_or(());
WindowAction::toggle_visibility(app);
WindowAction::toggle_visibility(app, false);
}
}

Expand Down Expand Up @@ -396,21 +427,14 @@ fn handle_break(
sx.send(InternalMessage::Emit(Emitter::Timer))
.unwrap_or_default();
if let Some(window) = app.get_window(ObliqoroWindow::Main.as_str()) {
if fullscreen {
window.set_fullscreen(true).unwrap_or_default();
}
WindowAction::show(&window);
WindowAction::show(&window, fullscreen);
}
}
BreakMessage::End => {
state.lock().start_work_session();
menu_enabled(app, true);
if let Some(window) = app.get_window(ObliqoroWindow::Main.as_str()) {
let fullscreen = state.lock().get_fullscreen();
if fullscreen {
window.set_fullscreen(false).unwrap_or_default();
}
WindowAction::hide(&window);
WindowAction::hide(&window, fullscreen);
}
update_menu(app, state, sx);
}
Expand Down
10 changes: 5 additions & 5 deletions src-tauri/src/tick/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};

const ONE_SECOND_AS_MS: u64 = 1000;

const ONE_MINUTE_AS_MS: u64 = ONE_SECOND_AS_MS * 60;
/// Spawn off a tokio thread, that loops continually, is essentially the internal timer that powers the whole application
/// Is save in the state struct, so that it can be aborted when settings change etc
pub fn tick_process(state: &Arc<Mutex<ApplicationState>>, sx: Sender<InternalMessage>) {
Expand All @@ -30,15 +30,15 @@ pub fn tick_process(state: &Arc<Mutex<ApplicationState>>, sx: Sender<InternalMes
let paused = spawn_state.lock().get_paused();
if !paused && last_updated.elapsed().as_secs() >= 1 {
let to_run = spawn_state.lock().session_status;
let next_break_in = spawn_state.lock().tick();
let tick_count = spawn_state.lock().tick();
match to_run {
SessionStatus::Break(_) => {
spawn_state
.lock()
.sx
.send(InternalMessage::Emit(Emitter::OnBreak))
.unwrap_or_default();
if next_break_in < 1 {
if tick_count < 1 {
spawn_state
.lock()
.sx
Expand All @@ -47,15 +47,15 @@ pub fn tick_process(state: &Arc<Mutex<ApplicationState>>, sx: Sender<InternalMes
}
}
SessionStatus::Work => {
if menu_updated.elapsed().as_secs() >= 60 {
if menu_updated.elapsed().as_millis() >= u128::from(ONE_MINUTE_AS_MS) {
spawn_state
.lock()
.sx
.send(InternalMessage::UpdateMenuTimer)
.unwrap_or_default();
menu_updated = std::time::Instant::now();
}
if next_break_in < 1 {
if tick_count < 1 {
sx.send(InternalMessage::Break(BreakMessage::Start))
.unwrap_or_default();
}
Expand Down
8 changes: 4 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<v-app class='ma-0 pa-0 fill-height unselectable' id='obliqoro'>
<AppBar v-if='!on_timer' />
<AppBar v-if='on_settings' />
<v-main>
<router-view />
</v-main>
<TheSnackbar />
<TheFooter v-if='!on_timer' />
<TheFooter v-if='on_settings' />
</v-app>
</template>

Expand All @@ -25,8 +25,8 @@ const intervalStore = intervalModule();
const settingStore = settingModule();
const packageinfoStore = packageinfoModule();
const on_timer = computed(():boolean => {
return route.fullPath === FrontEndRoutes.Timer;
const on_settings = computed(():boolean => {
return route.fullPath === FrontEndRoutes.Settings;
});
onBeforeMount(async () => {
Expand Down
12 changes: 10 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRouter, createWebHistory } from 'vue-router';
import { FrontEndRoutes } from '../types';
// import BlankViewVue from '../Views/BlankView.vue';
import Settings from '../Views/SettingsView.vue';
import Timer from '../Views/TimerView.vue';

Expand All @@ -8,11 +9,18 @@ const router = createRouter({
routes: [
{
path: FrontEndRoutes.Settings,
name: 'home',
name: 'settings',
component: Settings
},
// {
// path: FrontEndRoutes.Home,
// name: 'blank',
// component: BlankViewVue
// },
{
path: FrontEndRoutes.Timer, component: Timer
path: FrontEndRoutes.Timer,
name: 'timer',
component: Timer
}
],

Expand Down

0 comments on commit dd542a9

Please sign in to comment.