Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 37 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The app is destined to stay simple. If anything there is already too much in the
Roadmap:
- Document stuff
- Fix an annoying memory leak where deleted notes linger in memory
- Bin the whole saving infra and use Gtk 4.24 save-state new thing
- Use Gtk 4.24 save-state new thing if it ever lands
- More icon variants
- Better list/bullets
- Co-maintainers would be nice
Expand All @@ -68,25 +68,51 @@ On the right you can donate to various contributors:

## 💾 Notes Storage

"saved_state.json" contains all notes in JSON format. The structure is quite simple, it is an array of objects, each representing the data of a sticky note

Notes are stored in `~/.var/app/io.github.elly_code.jorts/data`
if from flathub, `~/.var/app/io.github.ellie_commons.jorts/data`
The app reads from it only during startup (rest of the time it writes in) so you could quite easily swap it up to swap between sets of notes.

The app writes to it everytime there is a sticky note change



### If installed from flathub (if you are not on elementary OS)

You can get it all by entering in a terminal:
You can get it all by entering in the search bar of your file explorer:

~/.var/app/io.github.ellie_commons.jorts/data/io.github.ellie_commons.jorts/

Or typing the below in a terminal, to move it to your Home folder:

```bash
cp ~/.var/app/io.github.elly_code.jorts/data ~/
cp ~/.var/app/io.github.ellie_commons.jorts/data/io.github.ellie_commons.jorts/saved_data.json ~/
```

"saved_state.json" contains all notes in JSON format. The structure is quite simple, if not pretty.

The app reads from it only during startup (rest of the time it writes in) so you could quite easily swap it up to swap between sets of notes.
### If installed from elementary OS appcenter

The app id is slightly different

Enter the path:

~/.var/app/io.github.elly_code.jorts/data/io.github.elly_code.jorts/

Or the command:

```bash
cp ~/.var/app/io.github.elly_code.jorts/data/io.github.elly_code.jorts/saved_data.json ~/
```


### WINDOWS

Paste in the explorer window:

%localappdata%\io.github.elly_code.jorts\


ON WINDOWS: It's in:
### UNSUPPORTED PACKAGINGS

YourUserFolder \AppData\Local\io.github.elly_code.jorts
Check out in ~/.local/share

AppData is a hidden folder. Either you paste the above path in the path bar, from your user folder
Or you do a "Show hidden files"
It likely is there
59 changes: 33 additions & 26 deletions src/Services/Storage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
public class Jorts.Storage : Object {

private const string FILENAME = "saved_state.json";
private string data_directory;
private string storage_file;
private File datadir;
private string savefile_path;

/**
* Convenience property wrapping load() and save()
Expand All @@ -30,38 +30,45 @@ public class Jorts.Storage : Object {

/*************************************************/
construct {
var path_data = GLib.Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_data_dir (), APP_ID);
datadir = File.new_for_path (path_data);
savefile_path = GLib.Path.build_path (Path.DIR_SEPARATOR_S, path_data, FILENAME);

#if WINDOWS
// In Windows we arent in a sandbox, so we need to have some courtesy and not dump in the allfolder
data_directory = GLib.Path.build_path("/", Environment.get_user_data_dir (), APP_ID);
#else
data_directory = Environment.get_user_data_dir ();
#endif
ensure_datadir ();

storage_file = GLib.Path.build_path("/", data_directory, FILENAME);
print (storage_file);
// TODO: Remove the below cruft after a while
var old_storage_path = GLib.Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_data_dir (), FILENAME);
var old_storage_file = File.new_for_path (old_storage_path);
var savefile = File.new_for_path (savefile_path);

check_if_stash ();
if (old_storage_file.query_exists ()) {
try {
old_storage_file.move (savefile, GLib.FileCopyFlags.OVERWRITE);
print ("Sucessfully moved old storage");

} catch (Error e) {
warning ("Failed to move storage %s\n", e.message);
}
}
}

/*************************************************/
/**
* Persistently check for the data directory and create if there is none
*/
private void check_if_stash () {
private void ensure_datadir () {
debug ("do we have a data directory?");
var dir = File.new_for_path (data_directory);

if (dir.query_exists ()) {
if (datadir.query_exists ()) {
debug ("Yes, nevermind");
return;
}

try {
dir.make_directory_with_parents ();
datadir.make_directory_with_parents ();
debug ("yes we do now");

} catch (Error e) {
warning ("Failed to prepare target data directory %s\n", e.message);
warning ("Failed to prepare target data directory %s", e.message);
}
}

Expand All @@ -70,43 +77,43 @@ public class Jorts.Storage : Object {
* Converts a Json.Node into a string and take care of saving it
*/
public void save (Json.Array json_data) {
debug("Writing...");
check_if_stash ();
ensure_datadir ();
debug("Writing %ui elements... (Should be same number as sticky notes)", json_data.get_length ());

try {
var generator = new Json.Generator ();
var node = new Json.Node (Json.NodeType.ARRAY);
node.set_array (json_data);
generator.set_root (node);
generator.to_file (storage_file);
generator.to_file (savefile_path);

} catch (Error e) {
warning ("[STORAGE] Failed to save notes %s", e.message);
warning ("Failed to save notes %s", e.message);
}

print ("\n (Everything saved)");
print ("\n (%ui notes saved)", json_data.get_length ());
}

/*************************************************/
/**
* Grab from storage, into a Json.Node we can parse. Insist if necessary
*/
public Json.Array load () {
debug("Loading from storage letsgo");
check_if_stash ();
debug ("Loading from storage letsgo");
var parser = new Json.Parser ();
var array = new Json.Array ();

try {
parser.load_from_mapped_file (storage_file);
parser.load_from_mapped_file (savefile_path);
var node = parser.get_root ();
array = node.get_array ();

} catch (Error e) {
warning ("Failed to load from storage " + e.message.to_string());
warning ("Failed to load from storage %s", e.message);

}

debug ("Retrieved %ui elements", array.get_length ());
return array;
}
}
Loading