Skip to content

Commit

Permalink
Better 1.7.0 migration handling (simply full sync if possible without…
Browse files Browse the repository at this point in the history
… complications)
  • Loading branch information
Mikescher committed Jan 20, 2021
1 parent bb222c3 commit d523a74
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
52 changes: 39 additions & 13 deletions Source/AlephNote.App/WPF/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,27 +867,39 @@ public void SetFocus(FocusTarget dst)

public void OnAfterMigrate(Version versionFrom, Version versionTo)
{
if (versionFrom != default && versionFrom < new Version(1, 7, 0))
#region 1.7.0
if (versionFrom != default && versionFrom < new Version(1, 7, 0))
{
App.Logger.Debug("MainWindow", $"Trigger Migration [[StandardNote.FullResync after 004]] by migration from {versionFrom} to {versionTo}");
App.Logger.Info("MainWindow", $"Trigger Migration [[StandardNote.FullResync after 004]] by migration from {versionFrom} to {versionTo}");

var guidStandardNotes = Guid.Parse("30d867a4-cbdc-45c5-950a-c119bf2f2845");

if (Settings.Accounts.Any(a => a.Plugin.GetUniqueID() == guidStandardNotes && a.ID != Settings.ActiveAccount.ID))
{
if (Settings.ActiveAccount.Plugin.GetUniqueID() == guidStandardNotes && Settings.Accounts.Count(p => p.Plugin.GetUniqueID() == guidStandardNotes) == 1 && _viewmodel.Repository.Notes.All(n => n.IsLocalSaved && n.IsRemoteSaved))
{
// Best case, the only SN account is active and all notes are saved & synced

WPFHelper.ExecDelayed(100, () => { _viewmodel.FullResync(false); });
}
else if (Settings.ActiveAccount.Plugin.GetUniqueID() == guidStandardNotes && _viewmodel.Repository.Notes.All(n => n.IsLocalSaved && n.IsRemoteSaved))
{
// Medium case, the active account is SN and all notes are saved & synced, but there exist other SN accounts

WPFHelper.ExecDelayed(100, () => { _viewmodel.FullResync(false); });

System.Windows.MessageBox.Show(
this,
"It appears you are having one or more accounts that sync with StandardNotes.\nDue to changes with the StandardNotes API it is recommended to do a full resync of your data (via the [Edit] -> [Delete local data and sync new] menu option).\nThis is necessary for all StandardNotes accounts but only for this update. Failing to do so can result in sync problems",
"Important Notification about the StandardNotes plugin",
MessageBoxButton.OK,
MessageBoxImage.Exclamation,
"Important Notification about the StandardNotes plugin",
MessageBoxButton.OK,
MessageBoxImage.Exclamation,
MessageBoxResult.OK,
System.Windows.MessageBoxOptions.None);

// we can't auto-FullResync here, because at least one StandardNote account is not active
}
}
else if (Settings.ActiveAccount.Plugin.GetUniqueID() == guidStandardNotes)
{
{
// Bad case, the active account is SN, but some notes are not synced

var r = System.Windows.MessageBox.Show(
this,
"Due to an update in the StandardNotes API and an accompanying update of the StandardNotes plugin (v1.7.0) it is necessary to do a full resync of your data to prevent synchronization problems.\nThis will clear all your local data and download notes and tags from the StandardNotes server anew.\nIf all your data is synchronized (which it should always be) this won't change any notes or tags.\n\nIf you don't do that now you can always do the same action later via the menu item:\n[Edit] -> [Delete local data and sync new].",
Expand All @@ -896,12 +908,26 @@ public void OnAfterMigrate(Version versionFrom, Version versionTo)
MessageBoxImage.Exclamation,
MessageBoxResult.OK,
System.Windows.MessageBoxOptions.None);

if (r == MessageBoxResult.OK)
{
{
WPFHelper.ExecDelayed(1000, () => { _viewmodel.FullResyncCommand.Execute(null); });
}
}
}
else if (Settings.Accounts.Any(p => p.Plugin.GetUniqueID() == guidStandardNotes))
{
// There are some SN accounts - but they are not active

System.Windows.MessageBox.Show(
this,
"It appears you are having one or more accounts that sync with StandardNotes.\nDue to changes with the StandardNotes API it is recommended to do a full resync of your data (via the [Edit] -> [Delete local data and sync new] menu option).\nThis is necessary for all StandardNotes accounts but only for this update. Failing to do so can result in sync problems",
"Important Notification about the StandardNotes plugin",
MessageBoxButton.OK,
MessageBoxImage.Exclamation,
MessageBoxResult.OK,
System.Windows.MessageBoxOptions.None);
}
#endregion
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class MainWindowViewmodel
public ICommand ShowAboutCommand => new RelayCommand(ShowAbout);
public ICommand ShowLogCommand => new RelayCommand(ShowLog);
public ICommand SaveAndSyncCommand => new RelayCommand(SaveAndSync);
public ICommand FullResyncCommand => new RelayCommand(FullResync);
public ICommand FullResyncCommand => new RelayCommand(_ => FullResync(true));
public ICommand FullUploadCommand => new RelayCommand(FullUpload);
public ICommand ManuallyCheckForUpdatesCommand => new RelayCommand(ManuallyCheckForUpdates);
public ICommand HideCommand => new RelayCommand(HideMainWindow);
Expand Down Expand Up @@ -151,13 +151,15 @@ private void SaveAndSync()
}
}

private void FullResync()
public void FullResync(bool ask)
{
if (Repository.ProviderUID == Guid.Parse("37de6de1-26b0-41f5-b252-5e625d9ecfa3")) return; // no full resync in headless

try
{
if (MessageBox.Show(Owner, "Do you really want to delete all local data and download the server data?", "Full resync?", MessageBoxButton.YesNo) != MessageBoxResult.Yes) return;
if (ask && MessageBox.Show(Owner, "Do you really want to delete all local data and download the server data?", "Full resync?", MessageBoxButton.YesNo) != MessageBoxResult.Yes) return;

App.Logger.Info("Main", "Deleting local data and executing a full re-download of remote state");

Repository.Shutdown(false);

Expand All @@ -183,7 +185,9 @@ private void FullUpload()
{
if (MessageBox.Show(Owner, "Do you really want to trigger a full upload of your local data?\nNormally this should never be necessary, because modified notes will be automatically marked as dirty and uploaded", "Full upload?", MessageBoxButton.YesNo) != MessageBoxResult.Yes) return;

foreach (var n in Repository.Notes) n.SetDirty(null);
App.Logger.Info("Main", "Forcing a full re-upload of local state to remote");

foreach (var n in Repository.Notes) n.SetDirty(null);

Repository.SyncNow();
}
Expand Down
2 changes: 2 additions & 0 deletions Source/AlephNote.Common/Repository/SynchronizationThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ private void ThreadRun()
{
_running = true;

Thread.Sleep(5*1000); // 5 secs initial delay

for (;;)
{
lock (_syncobj)
Expand Down

0 comments on commit d523a74

Please sign in to comment.