Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Recovery #651

Open
wants to merge 66 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
65b9190
merge commit
LeSnake04 Jul 3, 2023
764435c
merge upstream
LeSnake04 Jun 1, 2023
ea5310d
fix merge
LeSnake04 Jun 1, 2023
b100a56
fix merge again
LeSnake04 Jun 1, 2023
f470327
reverse merge changes in settingspanel
LeSnake04 Jun 2, 2023
9b394f1
add recovery metadata
LeSnake04 Jun 5, 2023
bda4853
remove dublicate code
LeSnake04 Jun 5, 2023
fc9fd75
add dirs dependency
LeSnake04 Jun 5, 2023
2fea104
remove output_file_cache
LeSnake04 Jun 5, 2023
fa6d290
import RecoveryMetadata
LeSnake04 Jun 5, 2023
518e430
skip serializing and deserializing
LeSnake04 Jun 5, 2023
515525c
update last changed metadata when saving
LeSnake04 Jun 7, 2023
d40e2bd
switch to directories
LeSnake04 Jun 7, 2023
f736261
move recovery indicator
LeSnake04 Jun 7, 2023
ab11987
update recovery metadata
LeSnake04 Jun 20, 2023
315956b
added recoveryrow
LeSnake04 Jun 20, 2023
76f90c3
small changes
LeSnake04 Jun 20, 2023
e1264d0
update metadata doc
LeSnake04 Jun 29, 2023
0ae456a
add recovery row
LeSnake04 Jun 29, 2023
bf75a9b
dialog draft
LeSnake04 Jun 29, 2023
477af0c
add ui files to grecource
LeSnake04 Jul 3, 2023
d5b93d9
revert changes from merge
LeSnake04 Jul 4, 2023
c866d79
undo changed in settingspanel/mod.rs
LeSnake04 Jul 4, 2023
a239d3f
fix imports
LeSnake04 Jul 4, 2023
64ac284
move dialog to seperate file
LeSnake04 Jul 4, 2023
7ee25cb
use loader and saver for RecoveryMetadata
LeSnake04 Jul 12, 2023
2df16f2
update recoveryrow
LeSnake04 Jul 12, 2023
c159ed1
create recovery if it doesnt exists
LeSnake04 Jul 12, 2023
f579c39
add recovery ui
LeSnake04 Jul 12, 2023
09cf022
finish recovery dialog
LeSnake04 Jul 12, 2023
d3b0d1a
removed recoveryrow
LeSnake04 Jul 12, 2023
5cec28f
added recovery info dialog
LeSnake04 Jul 12, 2023
6006954
update recovery info dialog
LeSnake04 Jul 12, 2023
dc7d881
add open action, refactor
LeSnake04 Jul 13, 2023
ea73f14
fix open recovery action
LeSnake04 Jul 13, 2023
334504d
refactor recovery info dialog
LeSnake04 Jul 13, 2023
20b7f9e
rename recovery if nessary
LeSnake04 Jul 13, 2023
06afe8f
remove recovery metadata on graceful close
LeSnake04 Jul 13, 2023
db2c6a5
cleanup
LeSnake04 Jul 13, 2023
8030245
show errors and clean up broken recovery artifacts
LeSnake04 Jul 13, 2023
91d90e2
try to format timestamps using local timezone
LeSnake04 Jul 14, 2023
5db4f51
set rnote extension for files selected with save_as button
LeSnake04 Jul 14, 2023
229b504
clean recovery artifacts when closing saved tab
LeSnake04 Jul 14, 2023
f481f0f
only create buttons if metadata valid
LeSnake04 Jul 15, 2023
4ffc266
added confirm_overwrite_document dialog
LeSnake04 Jul 15, 2023
ce348b9
only remove metadata when recovery_file moved/invalid
LeSnake04 Jul 15, 2023
834810e
ask before overwriting when saving recovered file
LeSnake04 Jul 15, 2023
40a7d29
allow meson to monitor changes in recovery.rs
LeSnake04 Jul 16, 2023
bbab660
Merge upstream
LeSnake04 Jul 16, 2023
ec3c779
adaot to upstream changes
LeSnake04 Jul 16, 2023
e77f802
renamed overwrite dialog fn to match ui definiton
LeSnake04 Jul 16, 2023
51e1ea0
Merge branch 'main' of github.com:flxzt/rnote into file-recovery
LeSnake04 Jul 29, 2023
84878df
fix merge
LeSnake04 Jul 29, 2023
844ec55
Merge branch 'main' of github.com:flxzt/rnote into file-recovery
LeSnake04 Oct 2, 2023
b8a0e1a
update lockfile
LeSnake04 Oct 2, 2023
513e4dc
added crash item to developer menu
LeSnake04 Nov 5, 2023
2a4a114
small changes
LeSnake04 Nov 13, 2023
470120c
Merge branch 'main' of github.com:flxzt/rnote into file-recovery
LeSnake04 Nov 13, 2023
b92f5ba
fix merge
LeSnake04 Nov 13, 2023
e7d2c8c
fmt
LeSnake04 Nov 13, 2023
3154c03
move recoverymetadata
LeSnake04 Nov 13, 2023
8be57fe
renamed recovery metadata
LeSnake04 Nov 17, 2023
364849b
add rnoterecoveryformat based on bincode
LeSnake04 Nov 27, 2023
a638301
Merge branch 'main' of github.com:flxzt/rnote into file-recovery
LeSnake04 Nov 27, 2023
f0316fe
fix: import clone
LeSnake04 Nov 27, 2023
c1f504c
use recovery format when restoring
LeSnake04 Feb 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 118 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ poppler-rs = { version = "0.22", features = ["v20_9"] }
gtk4 = { version = "0.7.3", features = ["v4_12"] }
adw = { version = "0.5.3", package="libadwaita", features = ["v1_4"] }
numeric-sort = "0.1"
time = { version = "0.3.22", default-features = false, features = ["formatting", "local-offset"] }
directories = "5.0.1"
bincode = "1.3.3"

[patch.crates-io]
# once a new piet (current v0.6.2) is released with the updated cairo, this can be removed
Expand Down
1 change: 1 addition & 0 deletions crates/rnote-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ poppler-rs = { workspace = true }
# the long-term plan is to remove the gtk4 dependency entirely after switching to another renderer.
gtk4 = { workspace = true, optional = true }
clap = { workspace = true, optional = true }
bincode = { workspace = true }

[dev-dependencies]
approx = { workspace = true }
Expand Down
19 changes: 19 additions & 0 deletions crates/rnote-engine/src/engine/export.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Imports
use super::{Engine, EngineConfig, StrokeContent};
use crate::fileformats::rnoteformat::RnoteFile;
use crate::fileformats::rnoterecoveryformat::RnoteRecoveryFile;
use crate::fileformats::{xoppformat, FileFormatSaver};
use anyhow::Context;
use futures::channel::oneshot;
Expand Down Expand Up @@ -334,6 +335,24 @@ impl Engine {
});
oneshot_receiver
}
/// Save the current document as a .rnote~ file.
pub fn save_as_rnote_recovery_bytes(
&self,
file_name: String,
) -> oneshot::Receiver<anyhow::Result<Vec<u8>>> {
let (oneshot_sender, oneshot_receiver) = oneshot::channel::<anyhow::Result<Vec<u8>>>();
let engine_snapshot = self.take_snapshot();
rayon::spawn(move || {
let result = || -> anyhow::Result<Vec<u8>> {
let rnote_file = RnoteRecoveryFile { engine_snapshot };
rnote_file.save_as_bytes(&file_name)
};
if let Err(_data) = oneshot_sender.send(result()) {
log::error!("Sending result to receiver in save_as_rnote_bytes() failed. Receiver was already dropped.");
}
});
oneshot_receiver
}

/// Extract the current engine configuration.
pub fn extract_engine_config(&self) -> EngineConfig {
Expand Down
21 changes: 20 additions & 1 deletion crates/rnote-engine/src/engine/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Imports
use crate::document::background;
use crate::engine::import::XoppImportPrefs;
use crate::fileformats::{rnoteformat, xoppformat, FileFormatLoader};
use crate::fileformats::{rnoteformat, rnoterecoveryformat, xoppformat, FileFormatLoader};
use crate::store::{ChronoComponent, StrokeKey};
use crate::strokes::Stroke;
use crate::{Camera, Document, Engine};
Expand Down Expand Up @@ -60,6 +60,25 @@ impl EngineSnapshot {

snapshot_receiver.await?
}

pub async fn load_from_rnote_recovery_bytes(bytes: Vec<u8>) -> anyhow::Result<Self> {
let (snapshot_sender, snapshot_receiver) = oneshot::channel::<anyhow::Result<Self>>();

rayon::spawn(move || {
let result = || -> anyhow::Result<Self> {
let rnote_recovery_file =
rnoterecoveryformat::RnoteRecoveryFile::load_from_bytes(&bytes)
.context("loading RnoteRecoveryFile failed")?;
Ok(rnote_recovery_file.engine_snapshot)
};

if let Err(_data) = snapshot_sender.send(result()) {
log::error!("Sending result to receiver in open_from_rnote_bytes() failed. Receiver was already dropped.");
}
});

snapshot_receiver.await?
}
/// Loads from the bytes of a Xournal++ .xopp file.
///
/// To import this snapshot into the current engine, use [`Engine::load_snapshot()`].
Expand Down
2 changes: 2 additions & 0 deletions crates/rnote-engine/src/fileformats/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Modules
pub mod recoverymetadataformat;
pub mod rnoteformat;
pub mod rnoterecoveryformat;
pub mod xoppformat;

// Imports
Expand Down
Loading