Skip to content

Commit

Permalink
修复配置修改下次才生效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeric-X committed Sep 24, 2020
1 parent 02813bc commit 945d479
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.1.3
- add mutex when writing/reading remote files
- optimize architecture

v1.1.2
- change profile file's syntax
- update ios workflow
Expand Down
1 change: 1 addition & 0 deletions SyncClipboard/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static void Save()
Properties.Settings.Default.RetryTimes = RetryTimes;
Properties.Settings.Default.TimeOut = TimeOut;
Properties.Settings.Default.Save();
Load();
}

private static string FormatHttpAuthHeader(string user, string password)
Expand Down
8 changes: 4 additions & 4 deletions SyncClipboard/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static class Program
public static MainController mainController;
public static ClipboardListener ClipboardListener;

public static PullService syncService;
public static PullService pullService;
public static PushService pushService;

/// <summary>
Expand All @@ -39,7 +39,7 @@ static void Main()
mainController = new MainController();
ClipboardListener = new ClipboardListener();

syncService = new PullService(mainController.GetNotifyFunction());
pullService = new PullService(mainController.GetNotifyFunction());
pushService = new PushService(mainController.GetNotifyFunction());

Application.Run();
Expand All @@ -56,9 +56,9 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc
}
private static void Application_ApplicationExit(object sender, EventArgs e)
{
if (syncService != null)
if (pullService != null)
{
syncService.Stop();
pullService.Stop();
}
if (pushService != null)
{
Expand Down
15 changes: 12 additions & 3 deletions SyncClipboard/PullService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,21 @@ private void PullLoop()
errorTimes += 1;
Console.WriteLine(ex.ToString());
Notify(false, true, ex.Message.ToString(), Config.GetProfileUrl() + "\n重试次数:" + errorTimes.ToString(), "重试次数:" + errorTimes.ToString(), "erro");
if (errorTimes > Config.RetryTimes)
{
Config.IfPull = false;
Config.Save();
Notify(true, false, "剪切板同步失败,已达到最大重试次数", ex.Message.ToString(), null, "erro");
}
continue;
}
finally
{
RemoteClipboardLocker.Unlock();
Thread.Sleep((int)Config.IntervalTime);
}

RemoteClipboardLocker.Unlock();

errorTimes = 0;
Profile remoteProfile = new Profile(strReply);
Profile localProfile = Profile.CreateFromLocalClipboard();
Expand All @@ -88,8 +99,6 @@ private void PullLoop()
Notify(true, false, "剪切板同步成功", remoteProfile.Text, null, "info");
}
Notify(false, true, "服务器连接成功", null, "正在同步", "info");

Thread.Sleep((int)Config.IntervalTime);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion SyncClipboard/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ private void SettingChangingEventHandler(object sender, System.Configuration.Set
}

private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
Program.syncService.Load();
Program.pullService.Load();
Program.pushService.Load();
Program.mainController.LoadConfig();
}
}
}
2 changes: 1 addition & 1 deletion SyncClipboard/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SyncClipboard
{
class UpdateChecker
{
public const string Version = "1.1.2";
public const string Version = "1.1.3";
public const string UpdateUrl = "https://api.github.com/repos/Jeric-X/SyncClipboard/releases/latest";
public const string ReleaseUrl = "https://github.com/Jeric-X/SyncClipboard/releases/latest";

Expand Down

0 comments on commit 945d479

Please sign in to comment.