Skip to content

Commit b81e303

Browse files
committed
fix(onboarding): address review review findings for existing user detection, note provisioning, and routing effect timing
1 parent 2947cad commit b81e303

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

src-tauri/src/commands/fs.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,30 @@ pub fn remove_onboarding_files() -> Result<(), String> {
234234
Ok(())
235235
}
236236

237+
fn has_user_notes(dir: &Path) -> bool {
238+
if let Ok(entries) = fs::read_dir(dir) {
239+
for entry in entries.filter_map(Result::ok) {
240+
let path = entry.path();
241+
if path.is_dir() {
242+
if has_user_notes(&path) {
243+
return true;
244+
}
245+
} else if path.is_file() {
246+
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
247+
if name.ends_with(".md")
248+
&& !name.starts_with("Welcome")
249+
&& !name.starts_with("New Features")
250+
&& !name.starts_with("Shortcuts")
251+
{
252+
return true;
253+
}
254+
}
255+
}
256+
}
257+
}
258+
false
259+
}
260+
237261
pub fn run_onboarding(app: &AppHandle) {
238262
let is_hyprland = std::env::var("HYPRLAND_INSTANCE_SIGNATURE").is_ok() || std::env::var("HYPRLAND_CMD").is_ok();
239263
let mod_key = if is_hyprland { "Alt" } else { "Command/Ctrl" };
@@ -242,23 +266,7 @@ pub fn run_onboarding(app: &AppHandle) {
242266
let version = app.package_info().version.to_string();
243267
let version_marker = base.join(".onboarding_version");
244268
let last_version = fs::read_to_string(&version_marker).ok();
245-
let is_existing_user = version_marker.exists() || {
246-
let mut count = 0;
247-
if let Ok(entries) = fs::read_dir(&base) {
248-
for entry in entries.filter_map(Result::ok) {
249-
if let Some(name) = entry.path().file_name().and_then(|n| n.to_str()) {
250-
if name.ends_with(".md")
251-
&& !name.starts_with("Welcome")
252-
&& !name.starts_with("New Features")
253-
&& !name.starts_with("Shortcuts")
254-
{
255-
count += 1;
256-
}
257-
}
258-
}
259-
}
260-
count > 0
261-
};
269+
let is_existing_user = version_marker.exists() || has_user_notes(&base);
262270
let is_new_version = last_version.as_deref() != Some(&version);
263271

264272
if is_new_version {
@@ -449,7 +457,7 @@ pub fn run_onboarding(app: &AppHandle) {
449457
let note_filename = format!("New Features in v{}.md", version);
450458
let note_target_path = base.join(&note_filename);
451459

452-
if is_existing_user && !note_target_path.exists() {
460+
if is_existing_user && is_new_version && !note_target_path.exists() {
453461
if let Ok(entries) = fs::read_dir(&base) {
454462
for entry in entries.filter_map(Result::ok) {
455463
let path = entry.path();

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,22 @@ function App() {
110110
const lastSeenVersion = localStorage.getItem('papercache-last-seen-version')
111111

112112
if (lastSeenVersion !== currentVersion) {
113-
localStorage.setItem('papercache-last-seen-version', currentVersion)
114113
const targetId = `New Features in v${currentVersion}.md`
115114
const targetIndex = notes.findIndex((n) => {
116115
const filename = n.id.split('/').pop() || ''
117116
return filename === targetId
118117
})
119118

120119
if (targetIndex !== -1) {
120+
localStorage.setItem('papercache-last-seen-version', currentVersion)
121121
setCurrentNoteIndex(targetIndex)
122122
} else if (lastSeenVersion === null) {
123123
const welcomeIndex = notes.findIndex((n) => {
124124
const filename = n.id.split('/').pop() || ''
125125
return filename === 'Welcome.md'
126126
})
127127
if (welcomeIndex !== -1) {
128+
localStorage.setItem('papercache-last-seen-version', currentVersion)
128129
setCurrentNoteIndex(welcomeIndex)
129130
}
130131
}

0 commit comments

Comments
 (0)