Skip to content

Commit

Permalink
Feat/keepawake (#481)
Browse files Browse the repository at this point in the history
* bump version to 3.0.1 in tauri configuration

* feat: keep system awake

* feat: add Vulkan runtime to resources and refactor wget calls for platform compatibility

* feat: enhance wget command with progress bar and retry options

* refactor: remove unused file associations from tauri configuration

* feat: add function to clean updater files and integrate it into setup process

* fix: update app info logging to use the correct utility function

* style: update globals.css for print styling and remove header/footer margins

* chore: update tauri-plugin-keepawake to version 0.1.1

* fix: improve error handling in download_audio by using map_while for stderr output

* style: refine print styles in globals.css and improve button formatting in pdf

* refactor: remove unnecessary console logs related to keep awake functionality

* fix: don't use transparent effect on linux with settings

* style: enhance print styles to prevent blank pages and support dark/light mode

* fix: simplify default device checks using is_ok_and for better readability

* style: improve print styles for dark/light mode and prevent blank pages
  • Loading branch information
thewh1teagle authored Jan 17, 2025
1 parent 16d0b05 commit 67820a0
Show file tree
Hide file tree
Showing 18 changed files with 745 additions and 185 deletions.
602 changes: 538 additions & 64 deletions Cargo.lock

Large diffs are not rendered by default.

Binary file modified desktop/bun.lockb
Binary file not shown.
5 changes: 3 additions & 2 deletions desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"lint": "eslint ."
},
"dependencies": {
"@fontsource/roboto": "^5.1.0",
"@formatjs/intl-durationformat": "^0.6.3",
"@tauri-apps/api": "~2.1.1",
"@tauri-apps/plugin-clipboard-manager": "~2.0.0",
"@tauri-apps/plugin-deep-link": "~2.0.0",
Expand All @@ -23,8 +25,6 @@
"@tauri-apps/plugin-store": "~2.1.0",
"@tauri-apps/plugin-updater": "~2.0.0",
"@tauri-apps/plugin-window-state": "~2.0.0",
"@fontsource/roboto": "^5.1.0",
"@formatjs/intl-durationformat": "^0.6.3",
"docx": "^9.0.3",
"format-duration": "^3.0.2",
"i18next": "^23.16.5",
Expand All @@ -35,6 +35,7 @@
"react-hot-toast": "^2.4.1",
"react-i18next": "^15.1.1",
"react-router-dom": "^6.28.0",
"tauri-plugin-keepawake-api": "^0.1.0",
"usehooks-ts": "^3.1.0",
"vite-plugin-svgr": "^4.3.0"
},
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tauri-plugin-deep-link = "2"
tauri-plugin-store = "2"
tauri-plugin-single-instance = "2"
tauri-plugin-clipboard-manager = "2"
tauri-plugin-keepawake = "0.1.1"
# Unsafe headers required for Ollama (to set Origin)
tauri-plugin-http = { version = "2", features = ["unsafe-headers"] }

Expand Down
116 changes: 59 additions & 57 deletions desktop/src-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,68 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "migrated",
"description": "permissions that were migrated from v1",
"identifier": "default",
"description": "default permissions",
"local": true,
"windows": [
"main"
],
"permissions": [
"keepawake:allow-start",
"keepawake:allow-stop",
"http:default",
"http:allow-fetch",
"store:allow-set",
"store:allow-get",
"store:allow-has",
"store:allow-reset",
"store:allow-clear",
"store:allow-save",
"store:allow-load",
"store:allow-get-store",
"core:path:default",
"core:event:default",
"core:resources:default",
"core:menu:default",
"core:tray:default",
"fs:allow-remove",
"fs:allow-read-dir",
"fs:allow-read-text-file",
"fs:allow-app-write",
"os:allow-arch",
"os:allow-platform",
"os:allow-version",
"os:allow-os-type",
"os:allow-locale",
"core:window:default",
"core:window:allow-unminimize",
"core:window:allow-set-focus",
"core:window:allow-close",
"core:window:allow-destroy",
"core:window:allow-show",
"core:window:allow-is-visible",
"window-state:allow-restore-state",
"window-state:allow-save-window-state",
"core:webview:default",
"core:webview:allow-print",
"dialog:default",
"dialog:allow-open",
"dialog:allow-save",
"dialog:allow-ask",
"dialog:allow-message",
"process:allow-restart",
"core:app:default",
"core:app:allow-version",
"core:app:allow-name",
"updater:default",
"shell:allow-open",
"shell:allow-execute",
"shell:allow-kill",
"shell:allow-spawn",
"fs:default",
"fs:allow-exists",
"core:path:allow-basename",
"deep-link:allow-get-current",
"clipboard-manager:allow-write-text",
{
"identifier": "fs:scope",
"allow": [
Expand Down Expand Up @@ -65,60 +121,6 @@
"url": "http{s}?://localhost:*/*"
}
]
},
"http:default",
"http:allow-fetch",
"store:allow-set",
"store:allow-get",
"store:allow-has",
"store:allow-reset",
"store:allow-clear",
"store:allow-save",
"store:allow-load",
"store:allow-get-store",
"core:path:default",
"core:event:default",
"core:resources:default",
"core:menu:default",
"core:tray:default",
"fs:allow-remove",
"fs:allow-read-dir",
"fs:allow-read-text-file",
"fs:allow-app-write",
"os:allow-arch",
"os:allow-platform",
"os:allow-version",
"os:allow-os-type",
"os:allow-locale",
"core:window:default",
"core:window:allow-unminimize",
"core:window:allow-set-focus",
"core:window:allow-close",
"core:window:allow-destroy",
"core:window:allow-show",
"core:window:allow-is-visible",
"window-state:allow-restore-state",
"window-state:allow-save-window-state",
"core:webview:default",
"core:webview:allow-print",
"dialog:default",
"dialog:allow-open",
"dialog:allow-save",
"dialog:allow-ask",
"dialog:allow-message",
"process:allow-restart",
"core:app:default",
"core:app:allow-version",
"core:app:allow-name",
"updater:default",
"shell:allow-open",
"shell:allow-execute",
"shell:allow-kill",
"shell:allow-spawn",
"fs:default",
"fs:allow-exists",
"core:path:allow-basename",
"deep-link:allow-get-current",
"clipboard-manager:allow-write-text"
}
]
}
27 changes: 27 additions & 0 deletions desktop/src-tauri/src/cleaner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,30 @@ pub fn clean_old_files() -> Result<()> {
}
Ok(())
}

pub fn clean_updater_files() -> Result<()> {
let current_temp_dir = get_vibe_temp_folder();
let temp_dir = std::env::temp_dir();
let temp_dir = temp_dir.to_str().unwrap_or_default();
// Remove suffix
let temp_dir = temp_dir.strip_suffix('/').unwrap_or(temp_dir);
let temp_dir = temp_dir.strip_suffix('\\').unwrap_or(temp_dir);
let pattern = format!("{}/vibe*-updater*", temp_dir);
tracing::debug!("searching old files in {}", pattern);
for path in glob::glob(&pattern)? {
let path = path?;
if path == current_temp_dir {
tracing::debug!("Skip deletion of {}", current_temp_dir.display());
continue;
}
if path.is_dir() {
tracing::debug!("Clean old folder {}", path.display());
std::fs::remove_dir_all(&path)
.map_err(|e| eyre!("failed to delete {}: {:?}", path.display(), e))
.log_error();
} else {
tracing::debug!("Skipping non-directory path {}", path.display());
}
}
Ok(())
}
4 changes: 2 additions & 2 deletions desktop/src-tauri/src/cmd/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ pub fn get_audio_devices() -> Result<Vec<AudioDevice>> {
tracing::debug!("Devices: ");
for (device_index, device) in devices.enumerate() {
let name = device.name()?;
let is_default_in = default_in.as_ref().map_or(false, |d| d == &name);
let is_default_in = default_in.as_ref().is_ok_and(|d| d == &name);
let is_default_out = if cfg!(target_os = "macos") {
false
} else {
default_out.as_ref().map_or(false, |d| d == &name)
default_out.as_ref().is_ok_and(|d| d == &name)
};

let is_input = device.default_input_config().is_ok();
Expand Down
2 changes: 1 addition & 1 deletion desktop/src-tauri/src/cmd/ytdlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub async fn download_audio(app_handle: AppHandle, url: String, out_path: String
if let Some(stderr) = child.stderr.take() {
stderr_output = BufReader::new(stderr)
.lines()
.filter_map(|line| line.ok())
.map_while(Result::ok)
.collect::<Vec<_>>()
.join("\n");
eprintln!("Error: {}", stderr_output);
Expand Down
1 change: 1 addition & 0 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn main() -> Result<()> {
.plugin(tauri_plugin_updater::Builder::default().build())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_keepawake::init())
.invoke_handler(tauri::generate_handler![
cmd::download_file,
cmd::get_cargo_features,
Expand Down
2 changes: 2 additions & 0 deletions desktop/src-tauri/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn setup(app: &App) -> Result<(), Box<dyn std::error::Error>> {
crate::logging::setup_logging(app.handle(), store).unwrap();
crate::cleaner::clean_old_logs(app.handle()).log_error();
crate::cleaner::clean_old_files().log_error();
crate::cleaner::clean_updater_files().log_error();
tracing::debug!("Vibe App Running");

// Crash handler
Expand Down Expand Up @@ -111,6 +112,7 @@ pub fn setup(app: &App) -> Result<(), Box<dyn std::error::Error>> {

tracing::debug!("APP VERSION: {}", app.package_info().version.to_string());
tracing::debug!("COMMIT HASH: {}", env!("COMMIT_HASH"));
tracing::debug!("App Info: {}", crate::utils::get_app_info());

let app_handle = app.app_handle().clone();
if is_cli_detected() {
Expand Down
30 changes: 2 additions & 28 deletions desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./gen/schemas/desktop-schema.json",
"productName": "vibe",
"version": "3.0.0",
"version": "3.0.1",
"identifier": "github.aaakk.us.kg.thewh1teagle.vibe",
"app": {
"windows": [],
Expand Down Expand Up @@ -45,33 +45,7 @@
],
"resources": {
"locales": "locales"
},
"fileAssociations": [
{
"description": "Video files",
"ext": [
"mp4",
"mkv",
"avi",
"mov",
"wmv",
"webm"
]
},
{
"description": "Audio files",
"ext": [
"mp3",
"wav",
"aac",
"flac",
"oga",
"ogg",
"opic",
"opus"
]
}
]
}
},
"plugins": {
"updater": {
Expand Down
4 changes: 3 additions & 1 deletion desktop/src/components/SettingsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ModifyState, cx } from '~/lib/utils'
import SettingsPage from '~/pages/settings/Page'
import * as os from '@tauri-apps/plugin-os'

interface SettingsModalProps {
visible: boolean
Expand All @@ -8,7 +9,8 @@ interface SettingsModalProps {
export default function SettingsModal({ visible, setVisible }: SettingsModalProps) {
if (visible) {
return (
<div className={cx('modal modal-open backdrop-blur-3xl !bg-base-100 dark:!bg-transparent overflow-y-auto')}>
// Don't use transparent background on Linux since the backdrop doesn't work!
<div className={cx('modal modal-open backdrop-blur-3xl !bg-base-100 overflow-y-auto', os.platform() != 'linux' && 'dark:!bg-transparent')}>
<SettingsPage setVisible={setVisible} />
</div>
)
Expand Down
60 changes: 56 additions & 4 deletions desktop/src/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
}

@media print {
html,
body * {
visibility: hidden;
}

.printable {
visibility: visible;
}

.printable,
.printable * {
visibility: visible;
}
Expand All @@ -31,5 +29,59 @@
left: 0;
top: 0;
height: 100vh;
width: 100vw;
}

/* remove header and footer */
@page {
margin: 0;
padding: 0;
}

.segment {
padding-left: 5px;
padding-right: 5px;
}

/* keep exact HTML colors! */
* {
print-color-adjust: exact;
}

/* Prevent blank page */
html,
body {
height: 100vh;
margin: 0 !important;
padding: 0 !important;
overflow: hidden;
}

body:last-child {
page-break-after: auto;
}

/* Dark mode */

[data-theme='dark'] * {
background: #181818 !important;
}

[data-theme='dark'] .segment {
color: white !important;
}

/* Light mode */
[data-theme='light'] * {
background: white !important;
}

[data-theme='light'] .segment {
color: black !important;
}

#footer,
#header {
all: unset;
}
}
Loading

0 comments on commit 67820a0

Please sign in to comment.