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

Autosaving and upgraded to .NET 8 #582

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open

Autosaving and upgraded to .NET 8 #582

wants to merge 64 commits into from

Conversation

CPKreu
Copy link
Member

@CPKreu CPKreu commented Nov 28, 2023

Added periodic autosaving and upgraded to .NET 8

TODO

  • Add periodic autosaving
  • Allow disabling autosaving for the current document session
  • Add icons to the UI
  • Tighter integration with crash system
  • Last command before crash log
  • Fix "Open from clipboard" causes a crash #581

@CPKreu CPKreu added the enhancement New feature or request label Nov 28, 2023
@CPKreu CPKreu self-assigned this Nov 28, 2023
@CPKreu CPKreu requested a review from flabbet November 29, 2023 14:28
@flabbet
Copy link
Member

flabbet commented Nov 29, 2023

Also I'm thinking, why save every x setting is a dropdown not number input?

@flabbet
Copy link
Member

flabbet commented Nov 29, 2023

Also seems like autosave timer isn't working?

@CPKreu CPKreu requested a review from flabbet December 1, 2023 14:51
Copy link
Member

@flabbet flabbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PixiEditor doesn't restore files that are manually saved after closing, while autosaved files are. I think this should work like VS Code, last session is restored no matter if it's unsaved by user or not.

Copy link
Member

@flabbet flabbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autosave worked for me once and then stopped, no matter if I restarted the app or paused and resumed via AutosaveControl. Timer seems to be frozen

@flabbet
Copy link
Member

flabbet commented Dec 3, 2023

  • Open PNG
  • Draw something on it
  • Close PixiEditor
  • Reopen PixiEditor, recovered png doesn't have a name

Also unsaved documents lose thier translated name, so instead of "Bez Nazwy" (pl) on recover it becomes "Unnamed" nvm I'm dumb, I never had Polish set

…seems unnecessary as SendExceptionInfoToWebhook is already async, but imma assume it has a purpose)
Copy link
Member

@Equbuxu Equbuxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an infinite loop
triggered by transform selection, and close without applying
seems like it infinitely autosaves 
and it also seems like Document.UpdateableChangeActive isn't set properly for transforming selection 

Equbuxu — 今日 01:24
and now I can't repro it
also for some reason files that were saved right before closing are marked as unsaved after reopening
while Untitled files that were never saved are marked as saved
but only sometimes

also passthrough action and modified/deleted on disk labels are still todo

@Equbuxu Equbuxu mentioned this pull request Dec 13, 2023
@flabbet flabbet requested a review from Equbuxu January 13, 2024 11:09
Copy link
Member

@Equbuxu Equbuxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CrashHelper.SendExceptionInfoToWebhook must not use Task.Run (or anything with a separate thread), supposedly the reason for adding it was this:

I remember it not sending the exception in certain scenerios cause it wasn't awaited
weird, it shouldn't matter whether you await it or not. I can only imagine it happening if the app shuts down before it has a chance to run
I think that was it

Also it seems like a good idea to go through the entire project and closely examite each Task.Run, they are dangerous

#if DEBUG
throw exception;
#else
exception.GenerateStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd crash here, as that's what WPF normally does when it detects a non-ui thread

"Cancel"
};

dialog.ShowDialog();
}

[Command.Debug("PixiEditor.Debug.BackupUserPreferences", @"%appdata%\PixiEditor\user_preferences.json", "BACKUP_USR_PREFS", "BACKUP_USR_PREFS")]
[Command.Debug("PixiEditor.Debug.BackupEditorData", @"%localappdata%\PixiEditor\editor_data.json", "BACKUP_EDITOR_DATA", "BACKUP_EDITOR_DATA")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can break on ms store #495; use Environment.GetFolderPath(... instead

}

[Command.Debug("PixiEditor.Debug.LoadUserPreferencesBackup", @"%appdata%\PixiEditor\user_preferences.json", "LOAD_USR_PREFS_BACKUP", "LOAD_USR_PREFS_BACKUP")]
[Command.Debug("PixiEditor.Debug.LoadEditorDataBackup", @"%localappdata%\PixiEditor\editor_data.json", "LOAD_EDITOR_DATA_BACKUP", "LOAD_EDITOR_DATA_BACKUP")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can break on ms store #495; use Environment.GetFolderPath(... instead

@@ -39,6 +39,7 @@ public void AddFinishedActions(params IAction[] actions)
queuedActions.AddRange(actions);
queuedActions.Add(new ChangeBoundary_Action());
TryExecuteAccumulatedActions();
document.AutosaveViewModel.HintFinishedAction();
Copy link
Member

@Equbuxu Equbuxu Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can still pass ChangeBoundary_Action into AddActions manually, and it won't get picked up. Although it is a bit hard to account for

Actually, this also won't work because TryExecuteAccumulatedActions doesn't guarantee the actions will be executed right away, so HintFinishedActions can get called when in fact we are still mid-change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided that this doesn't really matter, saving during an updateable change shouldn't cause any issues apart from a potential lag spike, and this is fine for preventing the lag spike

@Equbuxu
Copy link
Member

Equbuxu commented Feb 4, 2024

Looks like DocumentViewModel.MarkAsSaved(); should be called using a passthough action, otherwise there is a problem of "you've added some actions, marked document as saved, then actions get processed, last change guid changes, document is no longer considered saved". This is the cause of * indicator appearing on images you've just opened

@Equbuxu
Copy link
Member

Equbuxu commented Feb 8, 2024

Strange inconsistency:

  1. open an existing .pixi, draw a rectangle and close pixieditor without applying transform -> Pixieditor closes without saving the rectangle
  2. create a new .pixi, draw a rectangle, close without applying -> Pixieditor asks if you want to save the document
  3. and ofc if you do apply the change, pixieditor will just save properly without asking in both cases
    what's described in 1 also happens to never-saved-by-user files restored from previous session

I have also noticed pixieditor hanging and getting into an infinite autosaving loop during 2, but not sure if it's specific to 2 (probably not) or just something that can randomly happen. Ironically it happens inside "SafeAutosave". Might be caused by the -1 from AutosavePeriodMinutes ending up in the timer, with that timer then being enabled in RestartTimers and immediately firing (?) when an autosave happens during close

@Equbuxu
Copy link
Member

Equbuxu commented Feb 8, 2024

image
I just spent like 5 minutes trying to remember what the last checkbox does (wdym autosave if I already said I want to backup every 5 minutes? is it an unrelated feature? autosave when then?) so apparently this wording sucks. I think all three features should have labels that are a lot more descriptive

@Equbuxu
Copy link
Member

Equbuxu commented Feb 8, 2024

Seems like autosave files never get deleted? I made some new documents, closed pixieditor, reopened it, then closed all documents without saving, closed pixieditor, and now I have zombie .pixi files laying in Temp\PixiEditor\Autosave

@Equbuxu
Copy link
Member

Equbuxu commented Feb 8, 2024

set your settings to this:
image
create a new document and wait for it to get autosaved. Then close pixieditor. You don't get prompted about having unsaved stuff, but nothing is restored after you reopen pixieditor (no shit, restore opened files on startup is disabled). So effectively you'be just lost your document, unless you know you can look for it in the temp/pixieditor/autosave directory

@Equbuxu
Copy link
Member

Equbuxu commented Feb 8, 2024

  • With backup timer running, quickly create a few documents and close them right away. Wait for the interval of the timer. Once it elapses, the closed documents write autosaves into autosave directory. They must be sticking around in memory because of avalondock
  • I want a seconds counter
  • Would be nice to handle the case where pixieditor is killed (without it crashing), backups aren't restored in this case even though nothing is stopping us from restoring them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Open from clipboard" causes a crash
3 participants