From 92e8422cb0455ca412357b75a7dcdd1319d76c4b Mon Sep 17 00:00:00 2001 From: Yuri Karamian Date: Mon, 8 Jun 2026 20:56:28 +0200 Subject: [PATCH] Add 'Start week on' setting (Monday default / Sunday) for daily and tasks calendars --- src-tauri/src/commands.rs | 2 ++ src-tauri/src/types.rs | 7 +++++++ src/lib/api.ts | 2 ++ src/lib/components/NoteList.svelte | 9 +++++---- src/lib/components/SettingsPanel.svelte | 13 ++++++++++++- src/lib/components/TasksView.svelte | 10 ++++++---- src/lib/types.ts | 1 + 7 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 32413c6..1e8bb7d 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1067,6 +1067,7 @@ pub fn set_general_settings( state: State<'_, AppState>, compact_notes: bool, time_format: String, + week_start: String, gpu_acceleration: bool, autostart: bool, pdf_preview: bool, @@ -1086,6 +1087,7 @@ pub fn set_general_settings( config.show_note_dates = show_note_dates; config.restore_last_session = restore_last_session; config.time_format = time_format; + config.week_start = week_start; config.gpu_acceleration = gpu_acceleration; config.autostart = autostart; config.pdf_preview = pdf_preview; diff --git a/src-tauri/src/types.rs b/src-tauri/src/types.rs index a328a9c..1a69cf7 100644 --- a/src-tauri/src/types.rs +++ b/src-tauri/src/types.rs @@ -77,6 +77,8 @@ pub struct AppConfig { pub show_note_dates: bool, #[serde(default)] pub time_format: String, + #[serde(default = "default_week_start")] + pub week_start: String, #[serde(default)] pub gpu_acceleration: bool, #[serde(default)] @@ -172,6 +174,10 @@ fn default_title_mode() -> String { "input".to_string() } +fn default_week_start() -> String { + "monday".to_string() +} + fn default_max_versions() -> u32 { 20 } @@ -194,6 +200,7 @@ impl Default for AppConfig { compact_notes: false, show_note_dates: true, time_format: "relative".to_string(), + week_start: "monday".to_string(), gpu_acceleration: true, autostart: false, pdf_preview: false, diff --git a/src/lib/api.ts b/src/lib/api.ts index 09fb49e..34bf5c5 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -215,6 +215,7 @@ export async function setNotebookIcon( export async function setGeneralSettings( compactNotes: boolean, timeFormat: string, + weekStart: string, gpuAcceleration: boolean, autostart: boolean, pdfPreview: boolean, @@ -232,6 +233,7 @@ export async function setGeneralSettings( return invoke("set_general_settings", { compactNotes, timeFormat, + weekStart, gpuAcceleration, autostart, pdfPreview, diff --git a/src/lib/components/NoteList.svelte b/src/lib/components/NoteList.svelte index bf179f8..b8ee7e4 100644 --- a/src/lib/components/NoteList.svelte +++ b/src/lib/components/NoteList.svelte @@ -64,14 +64,15 @@ let dailyDates = $state>(new Set()); const calMonthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; - const calDayNames = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']; + // 0 = Sunday, 1 = Monday (default). Day names + grid offset follow the setting. + const weekStartsOn = $derived($appConfig?.week_start === 'sunday' ? 0 : 1); + const DOW = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']; + const calDayNames = $derived([...DOW.slice(weekStartsOn), ...DOW.slice(0, weekStartsOn)]); function calDays(): Array<{ day: number; date: string; current: boolean }> { const first = new Date(calYear, calMonth, 1); const lastDay = new Date(calYear, calMonth + 1, 0).getDate(); - // Monday=0 offset - let startDow = first.getDay() - 1; - if (startDow < 0) startDow = 6; + const startDow = (first.getDay() - weekStartsOn + 7) % 7; const cells: Array<{ day: number; date: string; current: boolean }> = []; for (let i = 0; i < startDow; i++) cells.push({ day: 0, date: '', current: false }); for (let d = 1; d <= lastDay; d++) { diff --git a/src/lib/components/SettingsPanel.svelte b/src/lib/components/SettingsPanel.svelte index 3c2c04f..3f0e986 100644 --- a/src/lib/components/SettingsPanel.svelte +++ b/src/lib/components/SettingsPanel.svelte @@ -460,6 +460,7 @@ let showNoteDates = $state($appConfig?.show_note_dates ?? true); let restoreLastSession = $state($appConfig?.restore_last_session ?? false); let timeFormat = $state($appConfig?.time_format ?? 'relative'); + let weekStart = $state($appConfig?.week_start ?? 'monday'); let gpuAcceleration = $state($appConfig?.gpu_acceleration ?? true); let autostart = $state($appConfig?.autostart ?? false); @@ -517,6 +518,7 @@ $appConfig.show_note_dates = showNoteDates; $appConfig.restore_last_session = restoreLastSession; $appConfig.time_format = timeFormat; + $appConfig.week_start = weekStart; $appConfig.gpu_acceleration = gpuAcceleration; $appConfig.autostart = autostart; $appConfig.pdf_preview = pdfPreview; @@ -529,7 +531,7 @@ $appConfig.close_to_tray = closeToTray; $appConfig.enable_wiki_links = enableWikiLinks; } - setGeneralSettings(compactNotes, timeFormat, gpuAcceleration, autostart, pdfPreview, pdfHeight, titleMode, hideTitleInBody, showLineNumbers, defaultViewMode, showTrayIcon, closeToTray, enableWikiLinks, showNoteDates, restoreLastSession) + setGeneralSettings(compactNotes, timeFormat, weekStart, gpuAcceleration, autostart, pdfPreview, pdfHeight, titleMode, hideTitleInBody, showLineNumbers, defaultViewMode, showTrayIcon, closeToTray, enableWikiLinks, showNoteDates, restoreLastSession) .catch((e) => console.error('Failed to save general settings:', e)); } @@ -653,6 +655,7 @@ showNoteDates = $appConfig.show_note_dates ?? true; restoreLastSession = $appConfig.restore_last_session ?? false; timeFormat = $appConfig.time_format ?? 'relative'; + weekStart = $appConfig.week_start ?? 'monday'; gpuAcceleration = $appConfig.gpu_acceleration ?? true; autostart = $appConfig.autostart ?? false; pdfPreview = $appConfig.pdf_preview ?? false; @@ -790,6 +793,14 @@ +
+

Start week on

+
+ + +
+
+ {#if isMobile}

Vault

diff --git a/src/lib/components/TasksView.svelte b/src/lib/components/TasksView.svelte index 4b8ec96..620b537 100644 --- a/src/lib/components/TasksView.svelte +++ b/src/lib/components/TasksView.svelte @@ -3,7 +3,7 @@ import { listen } from '@tauri-apps/api/event'; import { getTasks } from '$lib/api'; import { debounce } from '$lib/utils/debounce'; - import { tasksLayout } from '$lib/stores/app'; + import { tasksLayout, appConfig } from '$lib/stores/app'; import { isAndroid } from '$lib/platform'; import type { TaskItem, FileEvent } from '$lib/types'; @@ -104,7 +104,10 @@ let selectedDate = $state(today); const calMonthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; - const calDayNames = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']; + // 0 = Sunday, 1 = Monday (default). Day names + grid offset follow the setting. + const weekStartsOn = $derived($appConfig?.week_start === 'sunday' ? 0 : 1); + const DOW = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']; + const calDayNames = $derived([...DOW.slice(weekStartsOn), ...DOW.slice(0, weekStartsOn)]); // Calendar tasks share the list's hide-completed filter (no sort). const calBase = $derived(tasks.filter((t) => !hideCompleted || !t.completed)); @@ -133,8 +136,7 @@ ); function calDays() { - // Monday-first: shift so Mon=0 ... Sun=6 - const firstWeekday = (new Date(calYear, calMonth, 1).getDay() + 6) % 7; + const firstWeekday = (new Date(calYear, calMonth, 1).getDay() - weekStartsOn + 7) % 7; const lastDate = new Date(calYear, calMonth + 1, 0).getDate(); const cells: { day: number; date: string; current: boolean }[] = []; for (let i = 0; i < firstWeekday; i++) cells.push({ day: 0, date: '', current: false }); diff --git a/src/lib/types.ts b/src/lib/types.ts index 66e0146..bd20048 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -58,6 +58,7 @@ export interface AppConfig { compact_notes: boolean; show_note_dates: boolean; time_format: string; + week_start: string; gpu_acceleration: boolean; autostart: boolean; pdf_preview: boolean;