-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code to decouple view and viewmodel
- Loading branch information
Showing
14 changed files
with
304 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using v2rayN.Models; | ||
|
||
namespace v2rayN.Handler | ||
{ | ||
internal class TaskHandler | ||
{ | ||
private static readonly Lazy<TaskHandler> _instance = new(() => new()); | ||
public static TaskHandler Instance => _instance.Value; | ||
|
||
public TaskHandler() | ||
{ | ||
} | ||
|
||
public void RegUpdateTask(Config config, Action<bool, string> update) | ||
{ | ||
Task.Run(() => UpdateTaskRunSubscription(config, update)); | ||
Task.Run(() => UpdateTaskRunGeo(config, update)); | ||
} | ||
|
||
private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> update) | ||
{ | ||
await Task.Delay(60000); | ||
Logging.SaveLog("UpdateTaskRunSubscription"); | ||
|
||
var updateHandle = new UpdateHandler(); | ||
while (true) | ||
{ | ||
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds(); | ||
var lstSubs = LazyConfig.Instance.SubItems() | ||
.Where(t => t.autoUpdateInterval > 0) | ||
.Where(t => updateTime - t.updateTime >= t.autoUpdateInterval * 60) | ||
.ToList(); | ||
|
||
foreach (var item in lstSubs) | ||
{ | ||
updateHandle.UpdateSubscriptionProcess(config, item.id, true, (bool success, string msg) => | ||
{ | ||
update(success, msg); | ||
if (success) | ||
Logging.SaveLog("subscription" + msg); | ||
}); | ||
item.updateTime = updateTime; | ||
ConfigHandler.AddSubItem(config, item); | ||
|
||
await Task.Delay(5000); | ||
} | ||
await Task.Delay(60000); | ||
} | ||
} | ||
|
||
private async Task UpdateTaskRunGeo(Config config, Action<bool, string> update) | ||
{ | ||
var autoUpdateGeoTime = DateTime.Now; | ||
|
||
await Task.Delay(1000 * 120); | ||
Logging.SaveLog("UpdateTaskRunGeo"); | ||
|
||
var updateHandle = new UpdateHandler(); | ||
while (true) | ||
{ | ||
var dtNow = DateTime.Now; | ||
if (config.guiItem.autoUpdateInterval > 0) | ||
{ | ||
if ((dtNow - autoUpdateGeoTime).Hours % config.guiItem.autoUpdateInterval == 0) | ||
{ | ||
updateHandle.UpdateGeoFileAll(config, (bool success, string msg) => | ||
{ | ||
update(false, msg); | ||
}); | ||
autoUpdateGeoTime = dtNow; | ||
} | ||
} | ||
|
||
await Task.Delay(1000 * 3600); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.