Skip to content

Commit

Permalink
Merge pull request #20 from chroxify/chroxify/hap-58-add-linux-support
Browse files Browse the repository at this point in the history
  • Loading branch information
chroxify authored Sep 15, 2024
2 parents e7387a4 + 8b2903e commit c2649a0
Show file tree
Hide file tree
Showing 24 changed files with 271 additions and 196 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/dockerize-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ jobs:
build:
runs-on: ubuntu-latest

# Only if there are changes in apps/web/** or packages/ui/**
if: |
github.event.release &&
(
contains(github.event.release.body, '[web]') ||
contains(github.event.release.body, '[ui]')
)
steps:
- uses: actions/checkout@v3

Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/publish-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ jobs:
permissions:
contents: write

# Only if there are changes in apps/desktop/** or packages/ui/**
if: |
github.event.release &&
(
contains(github.event.release.body, '[desktop]') ||
contains(github.event.release.body, '[ui]')
)
strategy:
fail-fast: false
matrix:
Expand All @@ -20,12 +28,21 @@ jobs:
- platform: 'macos-latest' # for Intel based macs.
args: '--target x86_64-apple-darwin'
rust_targets: 'x86_64-apple-darwin'
- platform: 'ubuntu-22.04' # for Linux
args: ''
rust_targets: ''

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v4

- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: setup node
uses: actions/setup-node@v4
with:
Expand All @@ -38,6 +55,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: add Rust targets
if: matrix.rust_targets != ''
run: rustup target add ${{ matrix.rust_targets }}

- name: install frontend dependencies
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/test-build-only.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: 'test-on-pr'

on: [pull_request]
on:
pull_request:
paths:
- 'apps/desktop/**'
- 'packages/ui/**'

# This workflow will build the app without publishing
jobs:
Expand All @@ -15,11 +19,20 @@ jobs:
- platform: 'macos-latest' # for Intel based macs.
args: '--target x86_64-apple-darwin'
rust_targets: 'x86_64-apple-darwin'
- platform: 'ubuntu-22.04' # for Linux
args: ''
rust_targets: ''

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4

- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
- name: setup node
uses: actions/setup-node@v4
with:
Expand All @@ -32,6 +45,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: add Rust targets
if: matrix.rust_targets != ''
run: rustup target add ${{ matrix.rust_targets }}

- name: install frontend dependencies
Expand All @@ -40,6 +54,8 @@ jobs:
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
with:
projectPath: apps/desktop
args: ${{ matrix.args }}
5 changes: 4 additions & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.5.4", features = [ "updater", "api-all"] }
regex = "1.5"
cocoa = "0.25.0"
objc = "0.2.7"
hex_color = "3.0.0"
tauri-plugin-fs-watch = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-fs-extra = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-theme = "0.2.0"

# MacOS dependencies
[target.'cfg(target_os = "macos")'.dependencies]
cocoa = "0.25.0"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes.
Expand Down
34 changes: 7 additions & 27 deletions apps/desktop/src-tauri/src/commands/folder.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#[cfg(target_os = "linux")]
use std::{fs::metadata, path::PathBuf};
use std::path::Path;
use std::process::Command;
#[cfg(target_os = "linux")]
use fork::{daemon, Fork}; // dep: fork = "0.1"

#[tauri::command]
pub async fn show_in_folder(path: String) {
Expand All @@ -16,30 +14,12 @@ pub async fn show_in_folder(path: String) {

#[cfg(target_os = "linux")]
{
if path.contains(",") {
// see https://gitlab.freedesktop.org/dbus/dbus/-/issues/76
let new_path = match metadata(&path).unwrap().is_dir() {
true => path,
false => {
let mut path2 = PathBuf::from(path);
path2.pop();
path2.into_os_string().into_string().unwrap()
}
};
Command::new("xdg-open")
.arg(&new_path)
.spawn()
.unwrap();
} else {
if let Ok(Fork::Child) = daemon(false, false) {
Command::new("dbus-send")
.args(["--session", "--dest=org.freedesktop.FileManager1", "--type=method_call",
"/org/freedesktop/FileManager1", "org.freedesktop.FileManager1.ShowItems",
format!("array:string:\"file://{path}\"").as_str(), "string:\"\""])
.spawn()
.unwrap();
}
}
let path = Path::new(&path);
let parent = path.parent().unwrap_or(path);
Command::new("xdg-open")
.arg(parent)
.spawn()
.unwrap();
}

#[cfg(target_os = "macos")]
Expand Down
24 changes: 15 additions & 9 deletions apps/desktop/src/lib/api/folders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { OS_TRASH_DIR } from '@/constants';
import { collection, collectionSettings, platform } from '@/store';
import { getNextUntitledName } from '@/utils';
import { createDir, readDir, renameFile } from '@tauri-apps/api/fs';
import { createDir, readDir, removeFile, renameFile } from '@tauri-apps/api/fs';
import { homeDir } from '@tauri-apps/api/path';
import { get } from 'svelte/store';

// Create a new folder
export const createFolder = async (dirPath: string) => {
Expand All @@ -18,7 +21,7 @@ export const createFolder = async (dirPath: string) => {

// Delete a folder
export const deleteFolder = async (path: string, recursive = false) => {
let folderName = path.split('/').pop()!;
const folderName = path.split('/').pop()!;

if (!recursive) {
let children = await readDir(path);
Expand All @@ -33,13 +36,16 @@ export const deleteFolder = async (path: string, recursive = false) => {
}
}

try {
await renameFile(path, `${await homeDir()}/.trash/${folderName}`);
} catch (error) {
if ((error as string).includes('os error 66')) {
folderName = `${folderName}-${Date.now()}`;
await renameFile(path, `${await homeDir()}/.trash/${folderName}`);
}
switch (get(collectionSettings).notes.trash_dir) {
case 'system':
await renameFile(path, `${await homeDir()}${OS_TRASH_DIR[get(platform)]}${folderName}`);
break;
case 'haptic':
await renameFile(path, `${get(collection)}/.haptic/trash/${path.split('/').pop()!}`);
break;
case 'delete':
await removeFile(path);
break;
}
};

Expand Down
9 changes: 6 additions & 3 deletions apps/desktop/src/lib/api/notes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { activeFile, collection, collectionSettings, editor, noteHistory } from '@/store';
import { OS_TRASH_DIR } from '@/constants';
import { activeFile, collection, collectionSettings, editor, noteHistory, platform } from '@/store';
import type { NoteMetadataParams } from '@/types';
import { calculateReadingTime, getNextUntitledName, setEditorContent } from '@/utils';
import { readDir, readTextFile, removeFile, renameFile, writeTextFile } from '@tauri-apps/api/fs';
Expand Down Expand Up @@ -40,10 +41,12 @@ export async function openNote(path: string, skipHistory = false) {

// Delete a note
export const deleteNote = async (path: string) => {
// TODO: Wont work on Windows
switch (get(collectionSettings).notes.trash_dir) {
case 'system':
await renameFile(path, `${await homeDir()}.trash/${path.split('/').pop()!}`);
await renameFile(
path,
`${await homeDir()}${OS_TRASH_DIR[get(platform)]}${path.split('/').pop()!}`
);
break;
case 'haptic':
await renameFile(path, `${get(collection)}/.haptic/trash/${path.split('/').pop()!}`);
Expand Down
7 changes: 5 additions & 2 deletions apps/desktop/src/lib/components/layout/sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import SettingsModal from '../settings/settings-modal.svelte';
import { SHORTCUTS } from '@/constants';
import { goto } from '$app/navigation';
import { collection } from '@/store';
import { collection, platform } from '@/store';
let selected: 'notes' | 'daily' | 'tasks' | null = null;
Expand All @@ -29,7 +29,10 @@
</script>

<div
class="fixed left-0 h-full flex flex-col justify-between items-center w-12 py-12 border-r z-10 bg-background"
class={cn(
'fixed left-0 h-full flex flex-col justify-between items-center w-12 py-12 border-r z-10 bg-background',
$platform !== 'darwin' && 'pt-3'
)}
>
<div class="flex flex-col items-center gap-2">
<Tooltip text="Notes" side="right">
Expand Down
56 changes: 29 additions & 27 deletions apps/desktop/src/lib/components/notes/details.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
editor,
isNoteDetailSidebarOpen,
noteDetailSidebarWidth,
platform,
resizingNoteDetailSidebar
} from '@/store';
import { type NoteMetadataParams } from '@/types';
Expand All @@ -26,61 +27,59 @@
let modifiedTimeAgo: string;
let timeUpdateInterval: NodeJS.Timeout;
// Sidebar handlers
let startX: number | null;
let startWidth: number;
const handleMouseMove = (e: MouseEvent) => {
if (startX === null) return;
resizingNoteDetailSidebar.set(true);
console.log(document.body.clientWidth);
const x = e.x;
const x = e.clientX;
const clientWidth = document.body.clientWidth;
// Set collapsing bounds
if (clientWidth - x < 100) {
resizingNoteDetailSidebar.set(false);
isNoteDetailSidebarOpen.set(false);
return;
} else if (x > 100 && !$isNoteDetailSidebarOpen) {
} else if (clientWidth - x > 100 && !$isNoteDetailSidebarOpen) {
resizingNoteDetailSidebar.set(false);
isNoteDetailSidebarOpen.set(true);
return;
}
const diff = startX - x;
const newWidth = Math.max(210, Math.min(500, startWidth + diff));
// Set cursor resize bounds to prevent resizing when cursor is outside of the width bounds
if (clientWidth - x < 245 || clientWidth - x > 500) {
if (clientWidth - x < 245 || clientWidth - x > 550) {
return;
}
// Resize sidebar
if (
$noteDetailSidebarWidth - e.movementX >= 210 &&
$noteDetailSidebarWidth - e.movementX <= 500
) {
noteDetailSidebarWidth.update((value) => value - e.movementX);
}
noteDetailSidebarWidth.set(newWidth);
};
// Resize sidebar handler
const resizeHandler = () => {
// Set resizing state
resizingNoteDetailSidebar.set(true);
const resizeHandler = (e: MouseEvent) => {
e.preventDefault();
startX = e.clientX;
startWidth = $noteDetailSidebarWidth;
// Blur the editor
resizingNoteDetailSidebar.set(true);
$editor.commands.blur();
document.body.classList.add('cursor-col-resize');
// Set cusor-col-resize class to body
document.body.classList.toggle('cursor-col-resize');
// Mouse up event listener
const handleMouseUp = () => {
startX = null;
document.removeEventListener('mousemove', handleMouseMove);
document.removeEventListener('mouseup', handleMouseUp);
// Remove cursor-col-resize class from body
document.body.classList.remove('cursor-col-resize');
resizingNoteDetailSidebar.set(false);
if ($noteDetailSidebarWidth < 100) {
isNoteDetailSidebarOpen.set(false);
}
};
// Add event listeners
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', handleMouseUp);
};
Expand Down Expand Up @@ -144,8 +143,9 @@

<div
class={cn(
'fixed right-0 h-[calc(100vh-4.5rem)] flex flex-col justify-start items-center bg-background overflow-y-auto transform transition-transform duration-300',
!$isNoteDetailSidebarOpen && 'translate-x-full'
'fixed right-0 flex flex-col justify-start items-center bg-background overflow-y-auto transform transition-transform duration-300',
!$isNoteDetailSidebarOpen && 'translate-x-full',
$platform === 'darwin' ? 'h-[calc(100vh-4.5rem)]' : 'h-[calc(100vh-2.25rem)]'
)}
style={`width: ${$noteDetailSidebarWidth}px`}
>
Expand Down Expand Up @@ -297,6 +297,8 @@

<style>
:global(body.cursor-col-resize) {
cursor: col-resize !important;
user-select: none !important;
pointer-events: none;
}
</style>
Loading

0 comments on commit c2649a0

Please sign in to comment.