Skip to content

Commit

Permalink
feat: open database location
Browse files Browse the repository at this point in the history
settings page styling tweaks
  • Loading branch information
mrjackwills committed Feb 13, 2024
1 parent d1cf2f7 commit 28fe3d5
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 39 deletions.
33 changes: 32 additions & 1 deletion src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tauri-build = { version = "1.5", features = [] }
[dependencies]
auto-launch = "0.5"
dunce = "1.0"
open = "5.0.1"
parking_lot = "0.12"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
Expand Down
9 changes: 7 additions & 2 deletions src-tauri/src/application_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub struct ApplicationState {
pub tick_process: Option<JoinHandle<()>>,
pub pause_after_break: bool,
// TODO button on frontend to open this location?
_data_location: PathBuf,
data_location: PathBuf,
session_count: u8,
settings: ModelSettings,
strategies: Vec<String>,
Expand All @@ -92,7 +92,7 @@ impl ApplicationState {
.map(std::borrow::ToOwned::to_owned)
.collect::<Vec<_>>();
Ok(Self {
_data_location: local_dir,
data_location: local_dir,
pause_after_break: false,
session_count: 0,
session_status: SessionStatus::Work,
Expand Down Expand Up @@ -136,6 +136,11 @@ impl ApplicationState {
(self.current_timer_left(), self.random_strategy())
}

/// Get the directory where the database is stored
pub const fn get_data_location(&self) -> &PathBuf {
&self.data_location
}

/// Return, in seconds, the current amount left of the onoing work - or break - session
pub fn current_timer_left(&self) -> u16 {
let taken_since = match self.timer {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/internal_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ fn handle_break(
menu_enabled(app, true);
if state.lock().pause_after_break {
sx.send(InternalMessage::Pause).ok();
// if the app is in fullscreen mode, need to remove the fullscreen, normally this is hanlded by the hide_window function, but it's not being called here
// if the app is in fullscreen mode, need to remove the fullscreen, normally this is hanlded by the hide_window function, but it's not being called here
WindowAction::remove_fullscreen(app);
} else {
WindowAction::hide_window(app, fullscreen);
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ async fn main() -> Result<(), ()> {
}
Ok(app_state) => {
let state = Arc::new(Mutex::new(app_state));
// TODO change this to just an Arc<ApplicationState>, and use a message bus everywhere?

let init_state = Arc::clone(&state);
let internal_state = Arc::clone(&state);

Expand Down Expand Up @@ -151,6 +153,7 @@ async fn main() -> Result<(), ()> {
request_handlers::get_autostart,
request_handlers::init,
request_handlers::minimize,
request_handlers::open_database_location,
request_handlers::pause_after_break,
request_handlers::reset_settings,
request_handlers::set_autostart,
Expand Down
12 changes: 12 additions & 0 deletions src-tauri/src/request_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ pub fn set_setting_fullscreen(state: TauriState<'_>, value: bool) {
.ok();
}

/// Request to set the full screen setting to the given boolean value
#[tauri::command]
#[allow(clippy::needless_pass_by_value)]
pub fn open_database_location(state: TauriState<'_>) {
open::that(state.lock().get_data_location()).ok();
state
.lock()
.sx
.send(InternalMessage::Window(WindowVisibility::Hide))
.ok();
}

/// Request to set the session length to the given i64 value
#[tauri::command]
#[allow(clippy::needless_pass_by_value)]
Expand Down
43 changes: 22 additions & 21 deletions src/Views/SettingsView.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<template>
<v-row class='ma-0 pa-0 no-gutters fill-height' align='center'>
<!-- <v-container fluid class='ma-0 pa-0'> -->

<v-row align='center' justify='center' class=''>
<v-row align='center' justify='center' class='ma-0 pa-0'>
<v-col cols='9' class='ma-0 pa-0'>

<!-- TITLE -->
<v-row align='center' justify='center'>
<v-col cols='auto' class='text-h4 text-primary'>
<v-row align='center' justify='center' class='ma-0 pa-0'>
<v-col cols='auto' class='text-h4 ma-0 pa-0 text-primary'>
Settings
</v-col>
</v-row>

<hr class='my-4 hr' />

<!-- BREAK/PAUSE INFO -->
<v-row align='center' justify='space-around' class='ma-0 pa-0'>
<v-row align='center' justify='space-between' class='ma-0 pa-0'>

<v-col cols='5' class='ma-0 pa-0 text-primary text-left'>
<v-row align='center' justify='start' class='ma-0 pa-0'>
Expand All @@ -27,14 +26,11 @@
{{ next_in }}
</v-col>
</template>
<template v-else>
currently paused
</template>
</v-row>
</v-col>

<v-col cols='2' class='ma-0 pa-0'>
<v-btn @click='toggle_pause' :variant='pauseVariant' color='primary' size='small' block rounded='lg'>
<v-btn @click='toggle_pause' color='primary' block rounded='sm' class='ma-0 pa-0'>
<v-row align='center' justify='start' class='ma-0 pa-0'>
<v-col cols='auto' class='ma-0 pa-0 mr-1'>
<v-icon :icon='pauseIcon' class='' />
Expand Down Expand Up @@ -65,7 +61,7 @@
<v-form v-on:submit.prevent class='mt-4'>
<v-row class='ma-0 pa-0' justify='space-between'>

<v-col v-for='(item, index) in switches' :key='index' cols='auto'>
<v-col v-for='(item, index) in switches' :key='index' cols='auto' class='ma-0 pa-0'>
<v-switch
v-model='item.model.value'
:class='item.model.value ? "text-primary" : "text-offwhite"'
Expand All @@ -77,7 +73,7 @@
</v-col>

</v-row>

<!-- SLIDERS -->
<section v-for='(item, index) in sliders' :key='index'>

Expand All @@ -104,29 +100,33 @@
</v-form>

<!-- RESET BUTTON -->
<v-row class='ma-0 pa-0' justify='center'>
<v-col cols='auto' class='ma-0 pa-0'>
<v-btn @click='reset_settings' :disabled='paused' :variant='paused? "outlined" : undefined' color='primary' size='large' rounded='lg'>
<v-row class='ma-0 pa-0 mt-6' justify='space-between'>
<v-col cols='3' offset='auto' class='ma-0 pa-0'>
<v-btn @click='reset_settings' :disabled='paused' :variant='paused? "outlined" : undefined' color='primary' block rounded='sm'>
<v-icon :icon='mdiCogRefresh' class='mr-1' />
reset settings
</v-btn>

</v-col>
<!-- <v-spacer /> -->
<v-col cols='3' class='ma-0 pa-0 text-black' @click='opendb'>
<v-btn @click='opendb' color='primary' rounded='sm' block>
database location
<v-icon :icon='mdiOpenInNew' class='ml-1' />
</v-btn>
</v-col>
</v-row>

</v-col>
</v-row>

<!-- </v-container> -->
</v-row>
<!-- </v-container> -->
</template>
<script setup lang="ts">
import { sec_to_minutes, sec_to_minutes_only } from '../vanillaTS/second';
import { invoke } from '@tauri-apps/api/tauri';
import { InvokeMessage } from '../types';
import { snackError } from '../services/snack';
import { mdiCogRefresh, mdiCoffeeOutline, mdiWeatherNight, mdiPlay, mdiPause } from '@mdi/js';
import { mdiCogRefresh, mdiCoffeeOutline, mdiOpenInNew, mdiPlay, mdiPause, mdiWeatherNight } from '@mdi/js';
const settingStore = settingModule();
const next_in = computed((): string => {
Expand All @@ -143,9 +143,6 @@ const paused = computed((): boolean => {
const pauseIcon = computed((): string => {
return paused.value? mdiPlay:mdiPause;
});
const pauseVariant = computed((): undefined | 'outlined' => {
return paused.value? undefined :'outlined';
});
const pauseText = computed((): string => {
return paused.value? 'resume':'pause';
});
Expand Down Expand Up @@ -201,6 +198,10 @@ const sliders = computed(() => {
];
});
const opendb = async (): Promise<void> => {
await invoke(InvokeMessage.OpenDatabaseLocation);
};
const start_on_boot = computed({
get(): boolean {
return settingStore.autostart;
Expand Down
6 changes: 4 additions & 2 deletions src/Views/TimerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<v-container fluid class='pa-0'>

<v-row align='center' justify='center' class='mx-1 mb-12 switch_margin'>
<v-col cols='11' class='text-primary text-center ma-0 pa-0 px-2 mb-6' :class='text_size'>
<v-col cols='11' class='text-primary text-center ma-0 pa-0 px-2 ' :class='text_size'>
{{ strategy }}
</v-col>

Expand Down Expand Up @@ -71,6 +71,7 @@ const pauseAfterBreak = ref(false);
watch(pauseAfterBreak, async (pause) => {
await invoke(InvokeMessage.PauseAfterBreak, { pause });
settingModule().set_paused(pause);
});
watch(interval, async (i) => {
Expand All @@ -86,7 +87,8 @@ watch(interval, async (i) => {
/* This is to account for the the height of the switch row - it might not be perfect */
.switch_margin {
margin-top: 18%;
/* margin-top: 18%; */
margin-top: 65px;
}
</style>
8 changes: 4 additions & 4 deletions src/components/SnackBar.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<v-snackbar v-model='visible' timeout='-1'>
<v-snackbar v-model='visible' timeout='-1' class='mb-12' color='red' location='bottom'>
<v-row justify='center' align='center' no-gutters class='ma-0 pa-0'>
<v-col v-if='icon && !loading' cols='auto' class=''>
<v-icon color='red' :icon='icon' />
<v-icon color='black' :icon='icon' />
</v-col>
<v-col v-if='loading' cols='auto' class=''>
<v-progress-circular :size='18' :width='3' color='white' indeterminate />
<v-progress-circular :size='18' :width='3' color='black' indeterminate />
</v-col>
<v-col cols='auto' class='mx-3 ma-0 pa-0'>
<v-col cols='auto' class='mx-3 ma-0 pa-0 text-black'>
{{ message }}
</v-col>
</v-row>
Expand Down
17 changes: 9 additions & 8 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
export enum InvokeMessage {
ShowSettings = 'show_settings',
Minimize = 'minimize',
GetAutoStart = 'get_autostart',
GetPackageInfo = 'get_package_info',
Init = 'init',
ResetSettings = 'reset_settings',
TogglePause = 'toggle_pause',
Minimize = 'minimize',
OpenDatabaseLocation = 'open_database_location',
PauseAfterBreak = 'pause_after_break',
ResetSettings = 'reset_settings',
SetAutoStart = 'set_autostart',
SetSettingFullscreen = 'set_setting_fullscreen',
SetSettingLongBreak = 'set_setting_longbreak',
SetSettingNumberSession = 'set_setting_number_sessions',
SetSettingShortBreak = 'set_setting_shortbreak',
SetSettingSession = 'set_setting_session',
GetPackageInfo = 'get_package_info',
GetAutoStart = 'get_autostart',
SetAutoStart = 'set_autostart',
SetSettingShortBreak = 'set_setting_shortbreak',
ShowSettings = 'show_settings',
TogglePause = 'toggle_pause',
}

export enum FrontEndRoutes {
Expand Down

0 comments on commit 28fe3d5

Please sign in to comment.