Skip to content

Commit 5c33dbd

Browse files
authored
Merge pull request #44 from VariableThe/fix/v0.5.0-beta-fixes
fix: final v0.5.0-beta fixes and pipeline repair
2 parents c10990f + 1b84df0 commit 5c33dbd

15 files changed

Lines changed: 150 additions & 122 deletions

File tree

.github/workflows/release.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,20 @@ jobs:
7676
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
7777
path: homebrew-tap
7878

79-
- name: Download macOS DMG
79+
- name: Download macOS App
8080
env:
8181
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8282
run: |
8383
VERSION=${{ needs.create-tag.outputs.new_version }}
84-
gh release download v$VERSION --pattern "*.dmg" --repo $GITHUB_REPOSITORY
84+
gh release download v$VERSION --pattern "*aarch64.tar.gz" --repo $GITHUB_REPOSITORY
8585
86-
# Calculate SHA256 of the downloaded DMG
87-
DMG_FILE=$(ls *.dmg | head -n 1)
88-
SHA256=$(shasum -a 256 "$DMG_FILE" | awk '{ print $1 }')
86+
# Calculate SHA256 of the downloaded archive
87+
APP_FILE=$(ls *aarch64.tar.gz | head -n 1)
88+
SHA256=$(shasum -a 256 "$APP_FILE" | awk '{ print $1 }')
8989
9090
# Update the rb file
9191
cd homebrew-tap
92+
sed -i '' "s/url .*/url \"https:\/\/github.com\/VariableThe\/PaperCache\/releases\/download\/v$VERSION\/$APP_FILE\"/" Casks/papercache.rb
9293
sed -i '' "s/version \".*\"/version \"$VERSION\"/" Casks/papercache.rb
9394
sed -i '' "s/sha256 arm: * \".*\"/sha256 arm: \"$SHA256\"/" Casks/papercache.rb
9495

src-tauri/src/commands/fs.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,36 @@ pub fn get_safe_path(id: &str) -> Result<PathBuf, String> {
4646
}
4747
}
4848

49-
fn walk_dir(dir: &Path, notes: &mut Vec<Note>, base_path: &Path) {
50-
if let Ok(entries) = fs::read_dir(dir) {
51-
for entry in entries.flatten() {
52-
let path = entry.path();
53-
if path.is_dir() {
54-
walk_dir(&path, notes, base_path);
55-
} else if path.is_file() {
56-
let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("");
57-
if ext == "md" || ext == "json" {
58-
// Ignore legacy Electron window-state files
59-
if path.file_name().and_then(|n| n.to_str()) == Some("window-state.json") {
60-
continue;
61-
}
62-
63-
if let Ok(content) = fs::read_to_string(&path) {
64-
let metadata = fs::metadata(&path).ok();
65-
let mtime = metadata
66-
.and_then(|m| m.modified().ok())
67-
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
68-
.map(|d| d.as_millis() as u64)
69-
.unwrap_or(0);
70-
let id = path
71-
.strip_prefix(base_path)
72-
.unwrap_or(&path)
73-
.to_string_lossy()
74-
.to_string();
75-
notes.push(Note { id, content, mtime });
76-
}
77-
}
49+
fn walk_dir(dir: &Path, notes: &mut Vec<Note>, base_path: &Path) -> Result<(), String> {
50+
let entries = fs::read_dir(dir).map_err(|e| e.to_string())?;
51+
for entry in entries {
52+
let entry = entry.map_err(|e| e.to_string())?;
53+
let path = entry.path();
54+
if path.is_dir() {
55+
walk_dir(&path, notes, base_path)?;
56+
} else if path.is_file() {
57+
let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("");
58+
if ext == "md" || ext == "json" {
59+
let content = fs::read_to_string(&path)
60+
.map_err(|e| format!("Failed to read {}: {}", path.display(), e))?;
61+
62+
let metadata = fs::metadata(&path).ok();
63+
let mtime = metadata
64+
.and_then(|m| m.modified().ok())
65+
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
66+
.map(|d| d.as_millis() as u64)
67+
.unwrap_or_default();
68+
69+
let id = path
70+
.strip_prefix(base_path)
71+
.unwrap_or(&path)
72+
.to_string_lossy()
73+
.to_string();
74+
notes.push(Note { id, content, mtime });
7875
}
7976
}
8077
}
78+
Ok(())
8179
}
8280

8381
fn clean_empty_parents(file_path: &Path, base: &Path) {
@@ -104,7 +102,7 @@ fn clean_empty_parents(file_path: &Path, base: &Path) {
104102
pub fn get_notes() -> Result<Vec<Note>, String> {
105103
let base = get_papercache_dir()?;
106104
let mut notes = Vec::new();
107-
walk_dir(&base, &mut notes, &base);
105+
walk_dir(&base, &mut notes, &base)?;
108106
Ok(notes)
109107
}
110108

src-tauri/src/commands/keychain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const SERVICE_NAME: &str = "com.variablethe.papercache";
1212
pub fn set_api_key(key: String) -> Result<bool, String> {
1313
let entry = Entry::new(SERVICE_NAME, "openai_api_key")
1414
.map_err(|e| format!("Failed to access keyring: {}", e))?;
15+
if key.is_empty() {
16+
entry.delete_credential().ok();
17+
return Ok(true);
18+
}
1519
entry
1620
.set_password(&key)
1721
.map_err(|e| format!("Failed to set API key: {}", e))?;

src-tauri/src/commands/shortcuts.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,7 @@ pub fn update_global_shortcut(
3939
app.global_shortcut()
4040
.on_shortcut(shortcut, move |app, _shortcut, event| {
4141
if event.state() == ShortcutState::Pressed {
42-
if let Some(window) = app.get_webview_window("main") {
43-
let is_visible = window.is_visible().unwrap_or(false);
44-
if is_visible {
45-
let _ = window.hide();
46-
} else {
47-
let _ = window.show();
48-
let _ = window.set_focus();
49-
#[cfg(target_os = "macos")]
50-
crate::macos::force_focus();
51-
}
52-
}
42+
crate::commands::system::toggle_window(app);
5343
let _ = app.emit(&format!("trigger-{}", action_clone), ());
5444
}
5545
})
@@ -83,17 +73,7 @@ pub fn resume_shortcuts(app: AppHandle) -> Result<(), String> {
8373
.global_shortcut()
8474
.on_shortcut(shortcut, move |app, _, event| {
8575
if event.state() == ShortcutState::Pressed {
86-
if let Some(window) = app.get_webview_window("main") {
87-
let is_visible = window.is_visible().unwrap_or(false);
88-
if is_visible {
89-
let _ = window.hide();
90-
} else {
91-
let _ = window.show();
92-
let _ = window.set_focus();
93-
#[cfg(target_os = "macos")]
94-
crate::macos::force_focus();
95-
}
96-
}
76+
crate::commands::system::toggle_window(app);
9777
let _ = app.emit(&format!("trigger-{}", action_clone), ());
9878
}
9979
});

src-tauri/src/commands/system.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use tauri::{AppHandle, WebviewWindow};
1+
use tauri::{AppHandle, Manager, WebviewWindow};
22
use tauri_plugin_opener::OpenerExt;
33

44
#[tauri::command]
@@ -14,6 +14,20 @@ pub fn close_window(window: WebviewWindow) -> Result<(), String> {
1414
Ok(())
1515
}
1616

17+
pub fn toggle_window(app: &AppHandle) {
18+
if let Some(window) = app.get_webview_window("main") {
19+
let is_visible = window.is_visible().unwrap_or(false);
20+
if is_visible {
21+
let _ = window.hide();
22+
} else {
23+
let _ = window.show();
24+
let _ = window.set_focus();
25+
#[cfg(target_os = "macos")]
26+
crate::macos::force_focus();
27+
}
28+
}
29+
}
30+
1731
#[tauri::command]
1832
pub fn quit_app(app: AppHandle) {
1933
app.exit(0);

src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod commands;
66
#[cfg(target_os = "macos")]
77
mod macos;
88
mod tray;
9+
mod window_utils;
910

1011
use commands::shortcuts::GlobalShortcutState;
1112
use std::sync::atomic::{AtomicBool, Ordering};

src-tauri/src/tray.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ pub fn create_tray(app: &App) -> Result<(), Box<dyn std::error::Error>> {
99
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
1010
let menu = Menu::with_items(app, &[&show_hide, &quit])?;
1111

12-
let icon = tauri::image::Image::from_bytes(include_bytes!("../icons/tray.png"))
13-
.expect("Failed to load tray icon");
12+
let icon_result = tauri::image::Image::from_bytes(include_bytes!("../icons/tray.png"));
13+
let icon = match icon_result {
14+
Ok(icon) => icon,
15+
Err(e) => {
16+
eprintln!("Failed to load tray icon: {}", e);
17+
return Ok(());
18+
}
19+
};
1420

1521
TrayIconBuilder::new()
1622
.icon(icon)
@@ -20,17 +26,7 @@ pub fn create_tray(app: &App) -> Result<(), Box<dyn std::error::Error>> {
2026
.show_menu_on_left_click(false)
2127
.on_menu_event(|app, event| {
2228
if event.id == "show_hide" {
23-
if let Some(window) = app.get_webview_window("main") {
24-
let is_visible = window.is_visible().unwrap_or(false);
25-
if is_visible {
26-
let _ = window.hide();
27-
} else {
28-
let _ = window.show();
29-
let _ = window.set_focus();
30-
#[cfg(target_os = "macos")]
31-
crate::macos::force_focus();
32-
}
33-
}
29+
crate::commands::system::toggle_window(app);
3430
} else if event.id == "quit" {
3531
app.exit(0);
3632
}
@@ -43,17 +39,7 @@ pub fn create_tray(app: &App) -> Result<(), Box<dyn std::error::Error>> {
4339
} = event
4440
{
4541
let app = tray.app_handle();
46-
if let Some(window) = app.get_webview_window("main") {
47-
let is_visible = window.is_visible().unwrap_or(false);
48-
if is_visible {
49-
let _ = window.hide();
50-
} else {
51-
let _ = window.show();
52-
let _ = window.set_focus();
53-
#[cfg(target_os = "macos")]
54-
crate::macos::force_focus();
55-
}
56-
}
42+
crate::commands::system::toggle_window(&app);
5743
}
5844
})
5945
.build(app)?;

src-tauri/src/window_utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use tauri::AppHandle;
2+
use tauri::Manager;
3+
4+
pub fn show_and_focus_window(app: &AppHandle) {
5+
if let Some(window) = app.get_webview_window("main") {
6+
let _ = window.show();
7+
let _ = window.set_focus();
8+
#[cfg(target_os = "macos")]
9+
crate::macos::force_focus();
10+
}
11+
}

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"bundle": {
3030
"active": true,
31-
"targets": ["nsis", "msi", "appimage", "deb", "dmg", "app"],
31+
"targets": ["nsis", "msi", "appimage", "deb", "app"],
3232
"icon": [
3333
"icons/32x32.png",
3434
"icons/128x128.png",

src/App.css

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ body {
5858
width: 150px;
5959
}
6060

61-
.settings-btn-container {
62-
}
63-
6461
.open-settings-btn {
6562
background: transparent;
6663
border: none;
@@ -73,9 +70,6 @@ body {
7370
opacity: 1;
7471
}
7572

76-
.theme-selector {
77-
}
78-
7973
.theme-selector button {
8074
margin-left: 8px;
8175
font-family: var(--font-family);
@@ -178,7 +172,9 @@ body {
178172
border-radius: 4px;
179173
outline: none;
180174
font-size: 11px;
181-
transition: all 0.2s ease;
175+
transition:
176+
background-color 0.2s,
177+
opacity 0.2s;
182178
width: 120px;
183179
}
184180

@@ -198,7 +194,9 @@ body {
198194
text-transform: capitalize;
199195
font-size: 11px;
200196
font-weight: 500;
201-
transition: all 0.2s ease;
197+
transition:
198+
background-color 0.2s,
199+
opacity 0.2s;
202200
}
203201

204202
.cm-panel.cm-search button:hover {
@@ -234,7 +232,9 @@ body {
234232
display: flex;
235233
align-items: center;
236234
justify-content: center;
237-
transition: all 0.2s ease;
235+
transition:
236+
background-color 0.2s,
237+
opacity 0.2s;
238238
margin-left: 2px;
239239
}
240240

@@ -705,7 +705,9 @@ body {
705705
vertical-align: middle;
706706
color: transparent;
707707
background-color: transparent;
708-
transition: all 0.2s ease;
708+
transition:
709+
background-color 0.2s,
710+
opacity 0.2s;
709711
user-select: none;
710712
margin-top: -2px;
711713
}
@@ -746,7 +748,9 @@ body {
746748
vertical-align: middle;
747749
color: transparent;
748750
background-color: transparent;
749-
transition: all 0.2s ease;
751+
transition:
752+
background-color 0.2s,
753+
opacity 0.2s;
750754
user-select: none;
751755
margin-top: -2px;
752756
}

0 commit comments

Comments
 (0)