Skip to content
Open
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
18 changes: 15 additions & 3 deletions NextcloudApp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public App()
}

public IActivatedEventArgs ActivatedEventArgs { get; private set; }
private readonly LocalSettings SettingsLocal = SettingsService.Default.Value.LocalSettings;

private async void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs args)
{
Expand Down Expand Up @@ -316,11 +317,22 @@ protected override Task OnSuspendingApplicationAsync()
var task = base.OnSuspendingApplicationAsync();
// Stop Background Sync Tasks
var activeSyncs = SyncDbUtils.GetActiveSyncInfos();
foreach (var fsi in activeSyncs)

if (SettingsLocal.PauseSyncInBackground)
{
foreach (var fsi in activeSyncs)
{
ToastNotificationService.ShowSyncSuspendedNotification(fsi);
SyncDbUtils.UnlockFolderSyncInfo(fsi);
}
} else
{
ToastNotificationService.ShowSyncSuspendedNotification(fsi);
SyncDbUtils.UnlockFolderSyncInfo(fsi);
foreach (var fsi in activeSyncs)
{
ToastNotificationService.ShowSyncInBackgroundNotification(fsi);
}
}

return task;
}

Expand Down
30 changes: 30 additions & 0 deletions NextcloudApp/Models/LocalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public PreviewImageDownloadMode PreviewImageDownloadMode
}
}

[DefaultSettingValue(Value = SyncMode.LocalToRemote)]
public SyncMode SyncMode
{
get
{
var strVal = Get<string>();

return string.IsNullOrEmpty(strVal) ? SyncMode.LocalToRemote : JsonConvert.DeserializeObject<SyncMode>(strVal);
}
set
{
var strVal = JsonConvert.SerializeObject(value);
Set(strVal);
}
}

[DefaultSettingValue(Value = 0)]
public int AppTotalRuns
{
Expand Down Expand Up @@ -100,6 +116,20 @@ public bool IgnoreServerCertificateErrors
set => Set(value);
}

[DefaultSettingValue(Value = false)]
public bool SyncDeletions
{
get => Get<bool>();
set => Set(value);
}

[DefaultSettingValue(Value = false)]
public bool PauseSyncInBackground
{
get => Get<bool>();
set => Set(value);
}

[DefaultSettingValue(Value = false)]
public bool ExpertMode
{
Expand Down
7 changes: 4 additions & 3 deletions NextcloudApp/NextcloudApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<Compile Include="Utils\ObservableGroupingCollection.cs" />
<Compile Include="Utils\SortSequence.cs" />
<Compile Include="Utils\StringHelper.cs" />
<Compile Include="Utils\SyncMode.cs" />
<Compile Include="Utils\Theme.cs" />
<Compile Include="ViewModels\SharesLinkPageViewModel.cs" />
<Compile Include="ViewModels\SharesInPageViewModel.cs" />
Expand Down Expand Up @@ -442,9 +443,6 @@
<SDKReference Include="Microsoft.VCLibs, Version=14.0">
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
</SDKReference>
<SDKReference Include="SQLite.UWP.2015, Version=3.21.0">
<Name>SQLite for Universal Windows Platform %28SQLite.UWP.2015, Version=3.21.0%29</Name>
</SDKReference>
<SDKReference Include="WindowsMobile, Version=10.0.15063.0">
<Name>Windows Mobile Extensions for the UWP</Name>
</SDKReference>
Expand Down Expand Up @@ -477,6 +475,9 @@
<PackageReference Include="SQLite.Net-PCL">
<Version>3.1.1</Version>
</PackageReference>
<PackageReference Include="SQLite.uwp">
<Version>3.25.3</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
Expand Down
70 changes: 47 additions & 23 deletions NextcloudApp/Services/SyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class SyncService
private NextcloudClient.NextcloudClient _client;
private readonly List<SyncInfoDetail> _sidList;
private readonly IResourceLoader _resourceLoader;
private readonly LocalSettings SettingsLocal = SettingsService.Default.Value.LocalSettings;

public SyncService(StorageFolder startFolder, ResourceInfo resourceInfo, FolderSyncInfo syncInfo, IResourceLoader resourceLoader)
{
Expand Down Expand Up @@ -162,15 +163,24 @@ private async Task<int> SyncFolder(ResourceInfo resourceInfo, StorageFolder fold
if (subSid != null)
{
Debug.WriteLine("Sync folder (delete remotely) " + subInfo.Path);
if (await _client.Delete(subInfo.Path))
{
SyncDbUtils.DeleteSyncInfoDetail(subSid, true);

if (SettingsLocal.SyncDeletions)
{
if (await _client.Delete(subInfo.Path))
{
SyncDbUtils.DeleteSyncInfoDetail(subSid, true);
}
else
{
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_DeleteFolderRemotely), subInfo.Path);
// Error could be overridden by other errors
}
}
else
{
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_DeleteFolderRemotely), subInfo.Path);
// Error could be overridden by other errors
else
{
SyncDbUtils.DeleteSyncInfoDetail(subSid, true);
}

}
else
{
Expand Down Expand Up @@ -241,10 +251,15 @@ private async Task<int> SyncFolder(ResourceInfo resourceInfo, StorageFolder fold
var subSid = SyncDbUtils.GetSyncInfoDetail(localFolder, _folderSyncInfo);
if (subSid != null)
{
// Delete all sids and local folder
Debug.WriteLine("Sync folder (delete locally) " + localFolder.Path);
await localFolder.DeleteAsync();
SyncDbUtils.DeleteSyncInfoDetail(subSid, true);
if (SettingsLocal.SyncDeletions)
{
// Delete all sids and local folder
Debug.WriteLine("Sync folder (delete locally) " + localFolder.Path);
await localFolder.DeleteAsync();
}

SyncDbUtils.DeleteSyncInfoDetail(subSid, true);

}
else
{
Expand Down Expand Up @@ -341,7 +356,7 @@ private async Task<int> SyncFile(ResourceInfo info, StorageFile file, ResourceIn
sid.Error = string.Format(_resourceLoader.GetString(ResourceConstants.SyncService_Error_UploadFile), file.Name);
}
}
else if (info != null)
else if (info != null && (SettingsLocal.SyncMode == SyncMode.RemoteToLocal || SettingsLocal.SyncMode == SyncMode.TwoWay))
{
// Create sid and download file
var localFile = await parentFolder.CreateFileAsync(info.Name);
Expand Down Expand Up @@ -370,9 +385,12 @@ private async Task<int> SyncFile(ResourceInfo info, StorageFile file, ResourceIn
{
Debug.WriteLine("Sync file (Delete locally) " + sid.Path);
// Remove sid and local file
if (file != null)
{
await file.DeleteAsync();
if (SettingsLocal.SyncDeletions)
{
if (file != null)
{
await file.DeleteAsync();
}
}
SyncDbUtils.DeleteSyncInfoDetail(sid, false);
changed = true;
Expand Down Expand Up @@ -425,12 +443,16 @@ private async Task<int> SyncFile(ResourceInfo info, StorageFile file, ResourceIn
{
if (sid.ETag == null || info.ETag.Equals(sid.ETag))
{
Debug.WriteLine("Sync file (Delete remotely) " + sid.Path);
// Remove sid and remote file
await _client.Delete(info.Path + "/" + info.Name);
SyncDbUtils.DeleteSyncInfoDetail(sid, false);
deleted = true;
changed = true;
if (SettingsLocal.SyncDeletions)
{
Debug.WriteLine("Sync file (Delete remotely) " + sid.Path);
// Remove sid and remote file
if (SettingsLocal.SyncDeletions)
await _client.Delete(info.Path + "/" + info.Name);
SyncDbUtils.DeleteSyncInfoDetail(sid, false);
deleted = true;
changed = true;
}
}
else
{
Expand Down Expand Up @@ -474,7 +496,7 @@ private async Task<int> SyncFile(ResourceInfo info, StorageFile file, ResourceIn
{
if (currentModified.Equals(sid.DateModified))
{
if (!info.ETag.Equals(sid.ETag))
if (!info.ETag.Equals(sid.ETag) && (SettingsLocal.SyncMode == SyncMode.RemoteToLocal || SettingsLocal.SyncMode == SyncMode.TwoWay))
{
// Update local file
Debug.WriteLine("Sync file (update locally) " + info.Path + "/" + info.Name);
Expand All @@ -490,7 +512,7 @@ private async Task<int> SyncFile(ResourceInfo info, StorageFile file, ResourceIn
}
}
}
else if (info.ETag.Equals(sid.ETag))
else if (info.ETag.Equals(sid.ETag) && (SettingsLocal.SyncMode == SyncMode.LocalToRemote || SettingsLocal.SyncMode == SyncMode.TwoWay))
{
// update file on nextcloud
Debug.WriteLine("Sync file (update remotely) " + info.Path + "/" + info.Name);
Expand Down Expand Up @@ -600,6 +622,8 @@ private async Task<bool> UploadFile(IStorageFile localFile, string path)
IProgress<WebDavProgress> progress = new Progress<WebDavProgress>(ProgressHandler);
result = await _client.Upload(path, targetStream, localFile.ContentType, progress, cts.Token);
}

ToastNotificationService.ShowSyncedFileNotification(localFile.Name);
}
catch (ResponseError e2)
{
Expand Down
98 changes: 98 additions & 0 deletions NextcloudApp/Services/ToastNotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,103 @@ internal static void ShowSyncSuspendedNotification(FolderSyncInfo fsi)
// TODO groups/tags?
ToastNotificationManager.CreateToastNotifier().Show(toast);
}

internal static void ShowSyncInBackgroundNotification(FolderSyncInfo fsi)
{
if (fsi == null)
{
return;
}
var loader = new ResourceLoader();
var title = loader.GetString("SyncInBackgroundTitle");
var content = string.Format(loader.GetString("SyncInBackgroundDescription"), fsi.Path);
const string action = SyncAction;

// Construct the visuals of the toast
var visual = new ToastVisual
{
BindingGeneric = new ToastBindingGeneric
{
Children =
{
new AdaptiveText
{
Text = title
},
new AdaptiveText
{
Text = content
}
}
}
};
var toastContent = new ToastContent
{
Visual = visual,

// Arguments when the user taps body of toast
Launch = new QueryString
{
{ "action", action }
}.ToString()
};
var toast = new ToastNotification(toastContent.GetXml())
{
ExpirationTime = DateTime.Now.AddMinutes(30),
Group = action
};
// TODO Replace with syncinterval from settings.
// TODO groups/tags?
ToastNotificationManager.CreateToastNotifier().Show(toast);
}

internal static void ShowSyncedFileNotification(string fileName)
{
if (fileName == null)
{
return;
}
var loader = new ResourceLoader();
var title = loader.GetString("SyncedFileTitle");
var content = fileName;
const string action = SyncAction;

// Construct the visuals of the toast
var visual = new ToastVisual
{
BindingGeneric = new ToastBindingGeneric
{
Children =
{
new AdaptiveText
{
Text = title
},
new AdaptiveText
{
Text = content
}
}
}
};
var toastContent = new ToastContent
{
Visual = visual,

// Arguments when the user taps body of toast
Launch = new QueryString
{
{ "action", action }
}.ToString()
};
var toast = new ToastNotification(toastContent.GetXml())
{
ExpirationTime = DateTime.Now.AddMinutes(30),
Group = action
};
// TODO Replace with syncinterval from settings.
// TODO groups/tags?
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
}
}
11 changes: 10 additions & 1 deletion NextcloudApp/Strings/en/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -688,4 +688,13 @@ Please try again later.</value>
<data name="DeleteFiles_Description" xml:space="preserve">
<value>Are you sure, you want to delete the selected files?</value>
</data>
</root>
<data name="SyncedFileTitle" xml:space="preserve">
<value>File synced</value>
</data>
<data name="SyncInBackgroundDescription" xml:space="preserve">
<value>Synchronization in background</value>
</data>
<data name="SyncInBackgroundTitle" xml:space="preserve">
<value>Synchronization of folder {0} is running in background, yay!</value>
</data>
</root>
9 changes: 9 additions & 0 deletions NextcloudApp/Utils/SyncMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NextcloudApp.Utils
{
public enum SyncMode
{
LocalToRemote,
RemoteToLocal,
TwoWay
}
}
Loading