mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 10:00:27 +00:00
auto install host
This commit is contained in:
1 parent
509e5c9f5e
commit
606f93e885
7 files changed
+92
-34
No files matched your search
@@ -52,6 +52,7 @@ jobs:
|
||||
mv ChineseSimplified.isl "C:\Program Files (x86)\Inno Setup 6\Languages\"
|
||||
|
||||
go build -tags nosqlite -ldflags="-w -s -X github.com/GopeedLab/gopeed/pkg/base.Version=$env:VERSION" -buildmode=c-shared -o ui/flutter/windows/libgopeed.dll github.com/GopeedLab/gopeed/bind/desktop
|
||||
go build -ldflags="-w -s" -o ui/flutter/assets/host/host.exe github.com/GopeedLab/gopeed/cmd/host
|
||||
cd ui/flutter
|
||||
$TAG = "v$env:VERSION"
|
||||
flutter build windows
|
||||
@@ -122,7 +123,7 @@ jobs:
|
||||
[Icons]
|
||||
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
|
||||
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
|
||||
|
||||
|
||||
[Run]
|
||||
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
|
||||
"@ > setup.iss
|
||||
@@ -150,10 +151,13 @@ jobs:
|
||||
VERSION: ${{ needs.get-release.outputs.version }}
|
||||
run: |
|
||||
go build -tags nosqlite -ldflags="-w -s -X github.com/GopeedLab/gopeed/pkg/base.Version=$VERSION" -buildmode=c-shared -o libgopeed.dylib github.com/GopeedLab/gopeed/bind/desktop
|
||||
go build -ldflags="-w -s" github.com/GopeedLab/gopeed/cmd/host
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: macos-arm64-lib
|
||||
path: libgopeed.dylib
|
||||
path: |
|
||||
libgopeed.dylib
|
||||
host
|
||||
build-macos:
|
||||
if: ${{ github.event.inputs.platform == 'all' || github.event.inputs.platform == 'macos' }}
|
||||
runs-on: macos-13
|
||||
@@ -185,12 +189,18 @@ jobs:
|
||||
|
||||
# amd64 lib
|
||||
go build -tags nosqlite -ldflags="-w -s -X github.com/GopeedLab/gopeed/pkg/base.Version=$VERSION" -buildmode=c-shared -o ui/flutter/lib-amd64/libgopeed.dylib github.com/GopeedLab/gopeed/bind/desktop
|
||||
go build -ldflags="-w -s" -o ui/flutter/lib-amd64/host github.com/GopeedLab/gopeed/cmd/host
|
||||
# universal binary
|
||||
mkdir -p ui/flutter/macos/Frameworks
|
||||
cp ui/flutter/lib-amd64/libgopeed.dylib ui/flutter/macos/Frameworks/amd64-lib
|
||||
cp ui/flutter/lib-arm64/libgopeed.dylib ui/flutter/macos/Frameworks/arm64-lib
|
||||
cp ui/flutter/lib-amd64/host ui/flutter/macos/Frameworks/amd64-host
|
||||
cp ui/flutter/lib-arm64/host ui/flutter/macos/Frameworks/arm64-host
|
||||
cd ui/flutter/macos/Frameworks
|
||||
lipo -create -output libgopeed.dylib amd64-lib arm64-lib
|
||||
lipo -create -output host amd64-host arm64-host
|
||||
rm -rf amd64-lib arm64-lib amd64-host arm64-host
|
||||
mv host ui/flutter/assets/host/host
|
||||
|
||||
cd $PROJECT_DIR/ui/flutter
|
||||
flutter build macos
|
||||
@@ -239,6 +249,7 @@ jobs:
|
||||
VERSION: ${{ needs.get-release.outputs.version }}
|
||||
run: |
|
||||
go build -tags nosqlite -ldflags="-w -s -X github.com/GopeedLab/gopeed/pkg/base.Version=$VERSION" -buildmode=c-shared -o ui/flutter/linux/bundle/lib/libgopeed.so github.com/GopeedLab/gopeed/bind/desktop
|
||||
go build -ldflags="-w -s" -o ui/flutter/assets/host/host github.com/GopeedLab/gopeed/cmd/host
|
||||
cd ui/flutter
|
||||
dart pub global activate -sgit https://github.com/GopeedLab/flutter_distributor.git --git-path packages/flutter_distributor
|
||||
flutter_distributor package --platform linux --targets appimage,deb
|
||||
@@ -269,6 +280,7 @@ jobs:
|
||||
VERSION: ${{ needs.get-release.outputs.version }}
|
||||
run: |
|
||||
go build -tags nosqlite -ldflags="-w -s -X github.com/GopeedLab/gopeed/pkg/base.Version=$VERSION" -buildmode=c-shared -o ui/flutter/linux/bundle/lib/libgopeed.so github.com/GopeedLab/gopeed/bind/desktop
|
||||
go build -ldflags="-w -s" -o ui/flutter/assets/host/host github.com/GopeedLab/gopeed/cmd/host
|
||||
cd ui/flutter
|
||||
|
||||
sudo snap install snapcraft --classic
|
||||
@@ -357,13 +369,13 @@ jobs:
|
||||
\${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404
|
||||
prime:
|
||||
- bin/gpu-2404-wrapper
|
||||
|
||||
|
||||
plugs:
|
||||
gpu-2404:
|
||||
interface: content
|
||||
target: \$SNAP/gpu-2404
|
||||
default-provider: mesa-2404
|
||||
|
||||
|
||||
layout:
|
||||
/usr/share/libdrm:
|
||||
bind: \$SNAP/gpu-2404/libdrm
|
||||
@@ -513,7 +525,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.8.18'
|
||||
python-version: "3.8.18"
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: web-dist
|
||||
@@ -527,12 +539,12 @@ jobs:
|
||||
wget -O qdk2_0.32.bionic_amd64.deb "https://github.com/qnap-dev/qdk2/releases/download/v0.32/qdk2_0.32.bionic_amd64.deb"
|
||||
dpkg -X qdk2_0.32.bionic_amd64.deb qdk2 # Direct installs will fail due to missing dependencies!
|
||||
[[ -d qdk2 ]] || exit 1
|
||||
|
||||
|
||||
export PATH=$(pwd)/qdk2/usr/bin:$(pwd)/qdk2/usr/share/qdk2/QDK/bin:${PATH}
|
||||
wget -O Gopeed.template.tar.gz "https://github.com/GopeedLab/QpkgBuild/raw/refs/heads/master/template/Gopeed.template.tar.gz"
|
||||
tar -zxf Gopeed.template.tar.gz
|
||||
[[ -d Gopeed ]] || exit 1
|
||||
|
||||
|
||||
goos=linux
|
||||
goarch_arr=(amd64 arm64)
|
||||
for goarch in "${goarch_arr[@]}"; do
|
||||
@@ -545,7 +557,7 @@ jobs:
|
||||
cd Gopeed
|
||||
sed -i -e 's/__QPKG_VER__/${VERSION}/g' qpkg.cfg
|
||||
qbuild || exit 1
|
||||
|
||||
|
||||
mkdir -p ../dist/qnap
|
||||
goos=qnap
|
||||
for goarch in "${goarch_arr[@]}"; do
|
||||
|
||||
@@ -67,4 +67,6 @@ windows/flutter/generated_plugins.cmake
|
||||
|
||||
# Hive database files
|
||||
database.hive
|
||||
database.lock
|
||||
database.lock
|
||||
|
||||
assets/host/*
|
||||
+25
-17
@@ -82,28 +82,36 @@ Future<void> init(Args args) async {
|
||||
logger.e("libgopeed init fail", e);
|
||||
}
|
||||
|
||||
try {
|
||||
registerUrlScheme("gopeed");
|
||||
if (controller.downloaderConfig.value.extra.defaultBtClient) {
|
||||
registerDefaultTorrentClient();
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e("register scheme fail", e);
|
||||
}
|
||||
|
||||
for (final browser in Browser.values) {
|
||||
try {
|
||||
await installManifest(browser);
|
||||
} catch (e) {
|
||||
logger.e("browser [${browser.name}] extension host integration fail", e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await controller.loadDownloaderConfig();
|
||||
} catch (e) {
|
||||
logger.e("load config fail", e);
|
||||
}
|
||||
|
||||
() async {
|
||||
try {
|
||||
registerUrlScheme("gopeed");
|
||||
if (controller.downloaderConfig.value.extra.defaultBtClient) {
|
||||
registerDefaultTorrentClient();
|
||||
}
|
||||
} catch (e) {
|
||||
logger.e("register scheme fail", e);
|
||||
}
|
||||
|
||||
try {
|
||||
await installHost();
|
||||
} catch (e) {
|
||||
logger.e("browser extension host binary install fail", e);
|
||||
}
|
||||
for (final browser in Browser.values) {
|
||||
try {
|
||||
await installManifest(browser);
|
||||
} catch (e) {
|
||||
logger.e(
|
||||
"browser [${browser.name}] extension host integration fail", e);
|
||||
}
|
||||
}
|
||||
}();
|
||||
}
|
||||
|
||||
Future<void> onStart() async {
|
||||
|
||||
@@ -3,6 +3,9 @@ import 'browser_extension_host_stub.dart'
|
||||
|
||||
enum Browser { chrome, edge, firefox }
|
||||
|
||||
/// Install host binary for browser extension
|
||||
Future<void> installHost() => doInstallHost();
|
||||
|
||||
/// Check if specified browser is installed
|
||||
Future<bool> checkBrowserInstalled(Browser browser) =>
|
||||
doCheckBrowserInstalled(browser);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'browser_extension_host.dart';
|
||||
|
||||
Future<void> doInstallHost() => throw UnimplementedError();
|
||||
Future<bool> doCheckBrowserInstalled(Browser browser) =>
|
||||
throw UnimplementedError();
|
||||
Future<bool> doCheckManifestInstalled(Browser browser) =>
|
||||
|
||||
+38
-8
@@ -1,21 +1,53 @@
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:win32_registry/win32_registry.dart';
|
||||
|
||||
import '../../win32.dart';
|
||||
import '../browser_extension_host.dart';
|
||||
|
||||
final _hostExecName = 'host${Platform.isWindows ? '.exe' : ''}';
|
||||
|
||||
const _hostName = 'com.gopeed.gopeed';
|
||||
const _chromeExtensionId = 'mijpgljlfcapndmchhjffkpckknofcnd';
|
||||
const _edgeExtensionId = 'dkajnckekendchdleoaenoophcobooce';
|
||||
const _firefoxExtensionId = '{c5d69a8f-2ed0-46a7-afa4-b3a00dc58088}';
|
||||
const _debugExtensionIds = ['gjddllnejledbfaeondocjpejpamclkk'];
|
||||
|
||||
// Windows NativeMessagingHosts registry constants
|
||||
const _chromeNativeHostsKey = r'Software\Google\Chrome\NativeMessagingHosts';
|
||||
const _edgeNativeHostsKey = r'Software\Microsoft\Edge\NativeMessagingHosts';
|
||||
const _firefoxNativeHostsKey = r'Software\Mozilla\NativeMessagingHosts';
|
||||
|
||||
/// Install host binary for browser extension
|
||||
Future<void> doInstallHost() async {
|
||||
final hostPath =
|
||||
path.join((await getApplicationSupportDirectory()).path, _hostExecName);
|
||||
|
||||
Future<List<int>> getHostAssetData() async {
|
||||
final hostAsset = await rootBundle.load('assets/host/$_hostExecName');
|
||||
return hostAsset.buffer
|
||||
.asUint8List(hostAsset.offsetInBytes, hostAsset.lengthInBytes);
|
||||
}
|
||||
|
||||
// Check if host binary is not installed
|
||||
if (!await File(hostPath).exists()) {
|
||||
final hostData = await getHostAssetData();
|
||||
await File(hostPath).writeAsBytes(hostData);
|
||||
return;
|
||||
}
|
||||
// Check if host binary is outdated
|
||||
final hostAssetData = await getHostAssetData();
|
||||
final hostFileData = await File(hostPath).readAsBytes();
|
||||
if (hostAssetData.length != hostFileData.length) {
|
||||
await File(hostPath).writeAsBytes(hostAssetData);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if specified browser is installed
|
||||
Future<bool> doCheckBrowserInstalled(Browser browser) async {
|
||||
if (Platform.isWindows) {
|
||||
@@ -62,7 +94,7 @@ Future<bool> doCheckManifestInstalled(Browser browser) async {
|
||||
}
|
||||
|
||||
final existingContent = await File(manifestPath).readAsString();
|
||||
final expectedContent = _getManifestContent();
|
||||
final expectedContent = await _getManifestContent();
|
||||
return existingContent == expectedContent;
|
||||
}
|
||||
|
||||
@@ -72,7 +104,7 @@ Future<void> doInstallManifest(Browser browser) async {
|
||||
if (await checkManifestInstalled(browser)) return;
|
||||
|
||||
final manifestPath = _getManifestPath(browser)!;
|
||||
final manifestContent = _getManifestContent();
|
||||
final manifestContent = await _getManifestContent();
|
||||
final manifestDir = path.dirname(manifestPath);
|
||||
await Directory(manifestDir).create(recursive: true);
|
||||
await File(manifestPath).writeAsString(manifestContent);
|
||||
@@ -243,20 +275,18 @@ Future<bool> _checkWindowsRegistry(String keyPath) async {
|
||||
}
|
||||
}
|
||||
|
||||
String _getManifestContent() {
|
||||
final execPath = Platform.resolvedExecutable;
|
||||
final execDir = path.dirname(execPath);
|
||||
Future<String> _getManifestContent() async {
|
||||
final hostPath =
|
||||
path.join(execDir, 'host') + (Platform.isWindows ? '.exe' : '');
|
||||
path.join((await getApplicationSupportDirectory()).path, _hostExecName);
|
||||
final manifest = {
|
||||
'name': _hostName,
|
||||
'description': 'Gopeed browser extension host',
|
||||
'path': hostPath,
|
||||
'type': 'stdio',
|
||||
'allowed_origins': [
|
||||
'chrome-extension://gjddllnejledbfaeondocjpejpamclkk/',
|
||||
'chrome-extension://$_chromeExtensionId/',
|
||||
'chrome-extension://$_edgeExtensionId/',
|
||||
..._debugExtensionIds.map((id) => 'chrome-extension://$id/'),
|
||||
],
|
||||
'allowed_extensions': [_firefoxExtensionId],
|
||||
};
|
||||
|
||||
@@ -107,6 +107,8 @@ flutter:
|
||||
assets:
|
||||
- assets/tray_icon/
|
||||
- assets/extension/
|
||||
# Browser extension native host binary, see https://github.com/GopeedLab/gopeed/tree/main/cmd/host
|
||||
- assets/host/
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/assets-and-images/#resolution-aware
|
||||
|
||||
Reference in new issue
Block a user