mirror of
https://github.com/snltty/linker.git
synced 2025-10-06 01:26:54 +08:00
app在线更新
This commit is contained in:
@@ -16,6 +16,15 @@
|
|||||||
android:icon="@mipmap/appicon"
|
android:icon="@mipmap/appicon"
|
||||||
android:supportsRtl="true" android:usesCleartextTraffic="true">
|
android:supportsRtl="true" android:usesCleartextTraffic="true">
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="${applicationId}.fileprovider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_paths" />
|
||||||
|
</provider>
|
||||||
<service
|
<service
|
||||||
android:name="com.snltty.linker.app.VpnServiceLinker"
|
android:name="com.snltty.linker.app.VpnServiceLinker"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
@@ -32,4 +41,6 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@@ -9,7 +9,6 @@ using AndroidX.Core.App;
|
|||||||
using AndroidX.Core.Content;
|
using AndroidX.Core.Content;
|
||||||
using AndroidX.Core.View;
|
using AndroidX.Core.View;
|
||||||
using Java.IO;
|
using Java.IO;
|
||||||
using Java.Nio.Channels;
|
|
||||||
using linker.app.Services;
|
using linker.app.Services;
|
||||||
using linker.libs;
|
using linker.libs;
|
||||||
using linker.libs.extends;
|
using linker.libs.extends;
|
||||||
@@ -534,13 +533,71 @@ namespace linker.app
|
|||||||
|
|
||||||
public override async Task Install(Action<long, long> processs)
|
public override async Task Install(Action<long, long> processs)
|
||||||
{
|
{
|
||||||
|
await MainThread.InvokeOnMainThreadAsync(async () =>
|
||||||
|
{
|
||||||
|
await RequestRequiredPermissions(Platform.CurrentActivity);
|
||||||
|
await InstallApk(Platform.CurrentActivity);
|
||||||
processs(100, 100);
|
processs(100, 100);
|
||||||
await Task.CompletedTask;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Clear()
|
public override void Clear()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task InstallApk(Context context)
|
||||||
|
{
|
||||||
|
await MainThread.InvokeOnMainThreadAsync(() =>
|
||||||
|
{
|
||||||
|
var file = new Java.IO.File(Path.Join(FileSystem.Current.AppDataDirectory, "linker.apk"));
|
||||||
|
|
||||||
|
if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
|
||||||
|
{
|
||||||
|
// Android 7.0及以上版本需要使用FileProvider
|
||||||
|
var apkUri = AndroidX.Core.Content.FileProvider.GetUriForFile(context,
|
||||||
|
$"{context.ApplicationContext.PackageName}.fileprovider", file);
|
||||||
|
|
||||||
|
var installIntent = new Intent(Intent.ActionInstallPackage);
|
||||||
|
installIntent.SetDataAndType(apkUri, "application/vnd.android.package-archive");
|
||||||
|
installIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
|
||||||
|
installIntent.AddFlags(ActivityFlags.NewTask);
|
||||||
|
context.StartActivity(installIntent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 传统安装方式
|
||||||
|
var apkUri = Android.Net.Uri.FromFile(file);
|
||||||
|
var installIntent = new Intent(Intent.ActionView);
|
||||||
|
installIntent.SetDataAndType(apkUri, "application/vnd.android.package-archive");
|
||||||
|
installIntent.SetFlags(ActivityFlags.NewTask);
|
||||||
|
context.StartActivity(installIntent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private async Task<bool> RequestRequiredPermissions(Context context)
|
||||||
|
{
|
||||||
|
return await MainThread.InvokeOnMainThreadAsync(async () =>
|
||||||
|
{
|
||||||
|
// 检查并请求存储权限
|
||||||
|
var status = await Permissions.CheckStatusAsync<Permissions.StorageWrite>();
|
||||||
|
if (status != PermissionStatus.Granted)
|
||||||
|
{
|
||||||
|
status = await Permissions.RequestAsync<Permissions.StorageWrite>();
|
||||||
|
if (status != PermissionStatus.Granted)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查安装未知应用权限(针对Android 8.0+)
|
||||||
|
if (Build.VERSION.SdkInt >= BuildVersionCodes.O && !context.PackageManager.CanRequestPackageInstalls())
|
||||||
|
{
|
||||||
|
var intent = new Intent(Android.Provider.Settings.ActionManageUnknownAppSources)
|
||||||
|
.SetData(Android.Net.Uri.Parse($"package:{context.PackageName}"));
|
||||||
|
context.StartActivity(intent);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<!-- 指向应用的私有文件目录 -->
|
||||||
|
<files-path name="private_files" path="." />
|
||||||
|
</paths>
|
@@ -153,6 +153,7 @@ namespace linker.messenger.updater
|
|||||||
|
|
||||||
public async Task Subscribe(ApiControllerParamsInfo param)
|
public async Task Subscribe(ApiControllerParamsInfo param)
|
||||||
{
|
{
|
||||||
|
updaterTransfer.Subscribe();
|
||||||
await messengerSender.SendOnly(new MessageRequestWrap
|
await messengerSender.SendOnly(new MessageRequestWrap
|
||||||
{
|
{
|
||||||
Connection = signInClientState.Connection,
|
Connection = signInClientState.Connection,
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using linker.messenger.signin;
|
using linker.messenger.signin;
|
||||||
using linker.libs.timer;
|
using linker.libs.timer;
|
||||||
using linker.libs.extends;
|
|
||||||
|
|
||||||
namespace linker.messenger.updater
|
namespace linker.messenger.updater
|
||||||
{
|
{
|
||||||
@@ -67,6 +66,8 @@ namespace linker.messenger.updater
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Update(UpdaterInfo info)
|
public void Update(UpdaterInfo info)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(info.MachineId) == false)
|
||||||
{
|
{
|
||||||
UpdaterInfo170 _info = new UpdaterInfo170
|
UpdaterInfo170 _info = new UpdaterInfo170
|
||||||
{
|
{
|
||||||
@@ -76,8 +77,6 @@ namespace linker.messenger.updater
|
|||||||
Current = info.Current,
|
Current = info.Current,
|
||||||
MachineId = info.MachineId
|
MachineId = info.MachineId
|
||||||
};
|
};
|
||||||
if (string.IsNullOrWhiteSpace(_info.MachineId) == false)
|
|
||||||
{
|
|
||||||
updateInfos.AddOrUpdate(_info.MachineId, _info, (a, b) => _info);
|
updateInfos.AddOrUpdate(_info.MachineId, _info, (a, b) => _info);
|
||||||
Version.Increment();
|
Version.Increment();
|
||||||
}
|
}
|
||||||
@@ -104,6 +103,16 @@ namespace linker.messenger.updater
|
|||||||
updateInfo.Update();
|
updateInfo.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void Subscribe()
|
||||||
|
{
|
||||||
|
if(updateInfo.Status == UpdaterStatus.Downloading || updateInfo.Status == UpdaterStatus.Extracting)
|
||||||
|
{
|
||||||
|
updateInfo.MachineId = signInClientStore.Id;
|
||||||
|
Update(updateInfo);
|
||||||
|
Version.Increment();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateTask()
|
private void UpdateTask()
|
||||||
{
|
{
|
||||||
TimerHelper.SetIntervalLong(async () =>
|
TimerHelper.SetIntervalLong(async () =>
|
||||||
@@ -134,7 +143,7 @@ namespace linker.messenger.updater
|
|||||||
}
|
}
|
||||||
Update(updateInfo);
|
Update(updateInfo);
|
||||||
}
|
}
|
||||||
}, () => lastTicksManager.DiffLessEqual(5000) ? 1000 : 15000);
|
}, () => lastTicksManager.DiffLessEqual(5000) ? 3000 : 15000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -74,6 +74,13 @@ namespace linker.messenger.updater
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(savePath);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
}
|
||||||
LoggerHelper.Instance.Warning($"updater {url}");
|
LoggerHelper.Instance.Warning($"updater {url}");
|
||||||
|
|
||||||
using HttpClient httpClient = new HttpClient();
|
using HttpClient httpClient = new HttpClient();
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
v1.7.5
|
v1.7.5
|
||||||
2025-04-26 19:35:50
|
2025-04-26 22:59:58
|
||||||
1. 一些优化
|
1. 一些优化
|
||||||
2. 安卓APP勉强能用
|
2. 安卓APP勉强能用
|
||||||
3. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它
|
3. 如果你设备很多,请尝试升级其中一个成功重启后再升级其它
|
Reference in New Issue
Block a user