Compare commits

...
27 Commits
Author SHA1 Message Date
levi 11015c7be1 doc: mac repair tip 2022-11-08 14:35:51 +08:00
monkeyWie 57befd2c03 fix: web download dir setting (#46) 2022-11-08 14:31:49 +08:00
monkeyWie 35156ed968 ci: remove windows zip root folder 2022-11-07 20:29:10 +08:00
levi ee6c36174f ci: fix version 2022-11-07 17:25:23 +08:00
levi fdfd95555d ci: fix docker build 2022-11-07 17:20:31 +08:00
levi 7ec824edda ci: fix 2022-11-07 17:13:00 +08:00
levi 1f8b1be669 ci: fix action version 2022-11-07 16:49:58 +08:00
levi b0bcfeae34 ci: fix action version 2022-11-07 16:48:02 +08:00
levi 10b346a326 ci: fix 2022-11-07 16:45:44 +08:00
levi a85af39b35 ci: fix build 2022-11-07 16:43:55 +08:00
levi 576f0d2e24 ci: fix docker tag 2022-11-07 16:41:52 +08:00
monkeyWie 95eb3a427c feat: docker support (#43) 2022-11-07 16:32:52 +08:00
monkeyWie e9442edd94 feat: support drag torrent file (#42) 2022-11-07 14:12:12 +08:00
monkeyWie 77e59f7376 feat: i18n support (#40) 2022-11-05 17:04:22 +08:00
monkeyWie 135fba1b54 doc: fix md 2022-11-05 13:16:57 +08:00
liwei ff813e3bc9 ci: build on published 2022-11-05 11:27:56 +08:00
Trim21 babfe79023 Update flags.go 2022-11-05 10:43:07 +08:00
liwei 89ac52bebd ci: path ignore 2022-11-04 21:48:22 +08:00
liwei 15e1c2f2d5 chore: git ignore generated_plugin 2022-11-04 21:43:31 +08:00
levi 203f0ccc82 chore: fix go version 2022-11-04 17:13:32 +08:00
levi 2422bd2c66 chore: update md 2022-11-04 16:38:07 +08:00
levi 0306a1ed6b chore: en link 2022-11-04 16:26:19 +08:00
levi 8a94650370 chore: en readme 2022-11-04 16:25:57 +08:00
levi 837a193e96 chore: add discord link 2022-11-04 15:40:31 +08:00
levi fcf0746f9a ci: fix version 2022-11-04 15:12:38 +08:00
levi 9eb466ccd3 ci: path ignore 2022-11-04 15:11:06 +08:00
levi c54f22613e chore: issue tpl 2022-11-04 15:06:54 +08:00
34 changed files with 894 additions and 633 deletions

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
<!--
请根据以下模版提issue
-->
### 问题描述(必要)
### 版本号(必要)
### 操作系统(必要)
### 相关截图
### 相关日志
+2 -2
View File
@@ -1,5 +1,5 @@
name-template: 'v1.0.0 🌈'
tag-template: 'v1.0.0'
name-template: 'v$NEXT_PATCH_VERSION 🌈'
tag-template: 'v$NEXT_PATCH_VERSION'
categories:
- title: '🆕 Features'
labels:
+336
View File
@@ -0,0 +1,336 @@
name: build
on:
workflow_dispatch:
release:
types: [published]
jobs:
get-release:
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.get-release.outputs.tag_name }}
upload_url: ${{ steps.get-release.outputs.upload_url }}
steps:
- uses: actions/checkout@v3
- uses: thebritican/[email protected]
id: get-release
build-windows:
runs-on: windows-latest
needs: [get-release]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "^1.19"
cache: true
- uses: subosito/flutter-action@v2
- name: Build
env:
VERSION: ${{ needs.get-release.outputs.tag_name }}
run: |
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o ui/flutter/windows/libgopeed.dll github.com/monkeyWie/gopeed/bind/desktop
cd ui/flutter
flutter build windows
$mingw = "C:\ProgramData\Chocolatey\lib\mingw\tools\install\mingw64\bin"
$system = "C:\Windows\System32"
$release = "build\windows\runner\Release\"
cp $mingw\libstdc++-6.dll $release
cp $mingw\libgcc_s_seh-1.dll $release
cp $mingw\libwinpthread-1.dll $release
cp $system\msvcp140.dll $release
cp $system\vcruntime140.dll $release
cp $system\vcruntime140_1.dll $release
New-Item -Path build\windows\Output -ItemType Directory
Compress-Archive -Path "$release*" -DestinationPath build\windows\Output\Gopeed-$env:VERSION-windows-amd64.zip
cd build/windows
echo @"
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Gopeed"
#define MyAppVersion "$($env:VERSION.substring(1))"
#define MyAppPublisher "monkeyWie"
#define MyAppURL "https://gopeed.com"
#define MyAppExeName "gopeed.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{5960F34D-1E42-402C-8C85-DE2FF24CBAE4}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\gopeed
DisableProgramGroupPage=yes
LicenseFile=..\..\..\..\LICENSE
; Remove the following line to run in administrative install mode (install for all users.)
PrivilegesRequired=lowest
OutputBaseFilename=gopeed
SetupIconFile=..\..\assets\icon\icon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: ".\runner\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[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
iscc.exe setup.iss
mv "Output\gopeed.exe" "Output\Gopeed-$env:VERSION-windows-amd64-install.exe"
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.get-release.outputs.upload_url }}
asset_path: ui/flutter/build/windows/Output/*
overwrite: true
build-macos-arm64-lib:
runs-on: ubuntu-latest
needs: [get-release]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "^1.19"
cache: true
- run: mkdir -p ~/image-cache
- id: image-cache
uses: actions/cache@v3
with:
path: ~/image-cache
key: image-cache-xgo-v1.19
- if: steps.image-cache.outputs.cache-hit != 'true'
run: |
docker pull techknowlogick/xgo:go-1.19.x
docker save -o ~/image-cache/xgo.tar techknowlogick/xgo:go-1.19.x
- if: steps.image-cache.outputs.cache-hit == 'true'
run: docker load -i ~/image-cache/xgo.tar
- name: Build
run: |
go install src.techknowlogick.com/xgo@latest
xgo --targets=darwin/arm64 -tags="nosqlite" -ldflags="-w -s" -buildmode=c-shared -pkg=bind/desktop -out=libgopeed .
mv libgopeed-*.dylib libgopeed.dylib
- uses: actions/upload-artifact@v3
with:
name: macos-arm64-lib
path: libgopeed.dylib
build-macos:
runs-on: macos-latest
needs: [get-release, build-macos-arm64-lib]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "^1.19"
cache: true
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: subosito/flutter-action@v2
- name: Install appdmg
run: npm install -g appdmg
- uses: actions/download-artifact@v3
with:
name: macos-arm64-lib
path: ui/flutter/macos/Frameworks
- name: Build
env:
VERSION: ${{ needs.get-release.outputs.tag_name }}
run: |
PROJECT_DIR=$(pwd)
cd ui/flutter
flutter build macos
cd build/macos/Build/Products/Release
cat>appdmg.json<<EOF
{
"title": "Gopeed",
"icon": "Gopeed.app/Contents/Resources/AppIcon.icns",
"contents": [
{ "x": 448, "y": 344, "type": "link", "path": "/Applications" },
{ "x": 192, "y": 344, "type": "file", "path": "Gopeed.app" }
]
}
EOF
mkdir dist
appdmg appdmg.json dist/Gopeed-$VERSION-macos-arm64.dmg
# amd64
cd $PROJECT_DIR
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o bin/libgopeed.dylib github.com/monkeyWie/gopeed/bind/desktop
cp bin/libgopeed.dylib ui/flutter/build/macos/Build/Products/Release/Gopeed.app/Contents/Frameworks/
cd ui/flutter/build/macos/Build/Products/Release
appdmg appdmg.json dist/Gopeed-$VERSION-macos-amd64.dmg
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.get-release.outputs.upload_url }}
asset_path: ui/flutter/build/macos/Build/Products/Release/dist/*
overwrite: true
build-linux:
runs-on: ubuntu-latest
needs: [get-release]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "^1.19"
cache: true
- uses: subosito/flutter-action@v2
- run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build libgtk-3-dev
- name: Build
env:
VERSION: ${{ needs.get-release.outputs.tag_name }}
run: |
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o ui/flutter/linux/bundle/lib/libgopeed.so github.com/monkeyWie/gopeed/bind/desktop
cd ui/flutter
flutter build linux
mkdir -p debian/gui
cp assets/icon/icon_1024.png debian/gui/gopeed.png
cat>debian/debian.yaml<<EOF
flutter_app:
command: gopeed
arch: x64
parent: /usr/local/lib
control:
Package: gopeed
Version: ${VERSION:1}
Architecture: amd64
Essential: no
Priority: optional
Depends:
Maintainer: monkeyWie
Description: High speed downloader that supports all platforms.
EOF
cat>debian/gui/gopeed.desktop<<EOF
[Desktop Entry]
Version=${VERSION:1}
Name=Gopeed
GenericName=Gopeed
Comment=High speed downloader that supports all platforms.
Terminal=false
Type=Application
Categories=Utility
Keywords=Flutter;Downloader;
EOF
dart pub global activate flutter_to_debian
flutter_to_debian
mv debian/packages/gopeed*.deb debian/packages/Gopeed-$VERSION-linux-amd64.deb
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.get-release.outputs.upload_url }}
asset_path: ui/flutter/debian/packages/*
overwrite: true
build-android:
runs-on: ubuntu-latest
needs: [get-release]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "^1.19"
cache: true
- uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "11"
- uses: subosito/flutter-action@v2
- name: Build
env:
VERSION: ${{ needs.get-release.outputs.tag_name }}
run: |
mkdir ui/flutter/android/app/libs
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
gomobile bind -tags nosqlite -ldflags="-w -s" -o ui/flutter/android/app/libs/libgopeed.aar -target=android -androidapi 19 -javapkg=com.gopeed github.com/monkeyWie/gopeed/bind/mobile
cd ui/flutter
flutter build apk
mkdir dist
cp build/app/outputs/flutter-apk/app-release.apk dist/Gopeed-$VERSION-android.apk
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.get-release.outputs.upload_url }}
asset_path: ui/flutter/dist/*
overwrite: true
build-web:
runs-on: ubuntu-latest
needs: [get-release]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "^1.19"
cache: true
- uses: subosito/flutter-action@v2
- name: Build
env:
VERSION: ${{ needs.get-release.outputs.tag_name }}
run: |
cd ui/flutter
flutter build web
cd ../../
cp -r ui/flutter/build/web cmd/web/dist
mkdir -p dist/zip
goos_arr=(windows darwin linux)
goarch_arr=(386 amd64 arm64)
export CGO_ENABLED=0
for goos in "${goos_arr[@]}"; do
for goarch in "${goarch_arr[@]}"; do
name=gopeed-web-$VERSION-$goos-$goarch
dir="dist/$name/"
(GOOS=$goos GOARCH=$goarch go build -tags nosqlite,web -ldflags="-s -w" -o $dir github.com/monkeyWie/gopeed/cmd/web \
&& cd $dir \
&& file=$(ls -AU | head -1) \
&& mkdir $name \
&& mv $file $name/$(echo $file | sed -e "s/web/gopeed/g") \
&& zip -r ../zip/$name.zip * \
&& cd ../..) \
|| true
done
done
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.get-release.outputs.upload_url }}
asset_path: dist/zip/*
overwrite: true
build-docker:
runs-on: ubuntu-latest
needs: [get-release]
steps:
- uses: actions/checkout@v3
- name: Build
env:
VERSION: ${{ needs.get-release.outputs.tag_name }}
run: |
tag=liwei2633/gopeed:${VERSION:1}
docker build -t $tag .
docker login -u liwei2633 -p ${{ secrets.DOCKER_PASSWORD }}
docker push $tag
docker tag $tag liwei2633/gopeed:latest
docker push liwei2633/gopeed:latest
+10 -306
View File
@@ -4,10 +4,15 @@ on:
push:
branches:
- main
paths-ignore:
- '_docs/**'
- '_examples/**'
- 'README*.md'
paths:
- "bind/**"
- "cmd/**"
- "internal/**"
- "pkg/**"
- "ui/**"
- ".github/workflows/release.yml"
- "go.mod"
- "go.sum"
jobs:
release:
@@ -20,309 +25,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
go-version: "^1.19"
- uses: release-drafter/release-drafter@v5
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-windows:
runs-on: windows-latest
needs: [ release ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
cache: true
- uses: subosito/flutter-action@v2
- name: Build
env:
VERSION: ${{ needs.release.outputs.tag_name }}
run: |
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o ui/flutter/windows/libgopeed.dll github.com/monkeyWie/gopeed/bind/desktop
cd ui/flutter
flutter build windows
$mingw = "C:\ProgramData\Chocolatey\lib\mingw\tools\install\mingw64\bin"
$system = "C:\Windows\System32"
$release = "build\windows\runner\Release\"
cp $mingw\libstdc++-6.dll $release
cp $mingw\libgcc_s_seh-1.dll $release
cp $mingw\libwinpthread-1.dll $release
cp $system\msvcp140.dll $release
cp $system\vcruntime140.dll $release
cp $system\vcruntime140_1.dll $release
cd build/windows
echo @"
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Gopeed"
#define MyAppVersion "$($env:VERSION.substring(1))"
#define MyAppPublisher "monkeyWie"
#define MyAppURL "https://gopeed.com"
#define MyAppExeName "gopeed.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{5960F34D-1E42-402C-8C85-DE2FF24CBAE4}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\gopeed
DisableProgramGroupPage=yes
LicenseFile=..\..\..\..\LICENSE
; Remove the following line to run in administrative install mode (install for all users.)
PrivilegesRequired=lowest
OutputBaseFilename=gopeed
SetupIconFile=..\..\assets\icon\icon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: ".\runner\Release\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[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
iscc.exe setup.iss
mv "Output\gopeed.exe" "Output\Gopeed-$env:VERSION-windows-amd64.exe"
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ui/flutter/build/windows/Output/*
overwrite: true
build-macos-arm64-lib:
runs-on: ubuntu-latest
needs: [ release ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
cache: true
- run: mkdir -p ~/image-cache
- id: image-cache
uses: actions/cache@v3
with:
path: ~/image-cache
key: image-cache-xgo-v1.19
- if: steps.image-cache.outputs.cache-hit != 'true'
run: |
docker pull techknowlogick/xgo:go-1.19.x
docker save -o ~/image-cache/xgo.tar techknowlogick/xgo:go-1.19.x
- if: steps.image-cache.outputs.cache-hit == 'true'
run: docker load -i ~/image-cache/xgo.tar
- name: Build
run: |
go install src.techknowlogick.com/xgo@latest
xgo --targets=darwin/arm64 -tags="nosqlite" -ldflags="-w -s" -buildmode=c-shared -pkg=bind/desktop -out=libgopeed .
mv libgopeed-*.dylib libgopeed.dylib
- uses: actions/upload-artifact@v3
with:
name: macos-arm64-lib
path: libgopeed.dylib
build-macos:
runs-on: macos-latest
needs: [ release, build-macos-arm64-lib ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
cache: true
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: subosito/flutter-action@v2
- name: Install appdmg
run: npm install -g appdmg
- uses: actions/download-artifact@v3
with:
name: macos-arm64-lib
path: ui/flutter/macos/Frameworks
- name: Build
env:
VERSION: ${{ needs.release.outputs.tag_name }}
run: |
PROJECT_DIR=$(pwd)
cd ui/flutter
flutter build macos
cd build/macos/Build/Products/Release
cat>appdmg.json<<EOF
{
"title": "Gopeed",
"icon": "Gopeed.app/Contents/Resources/AppIcon.icns",
"contents": [
{ "x": 448, "y": 344, "type": "link", "path": "/Applications" },
{ "x": 192, "y": 344, "type": "file", "path": "Gopeed.app" }
]
}
EOF
mkdir dist
appdmg appdmg.json dist/Gopeed-$VERSION-macos-arm64.dmg
# amd64
cd $PROJECT_DIR
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o bin/libgopeed.dylib github.com/monkeyWie/gopeed/bind/desktop
cp bin/libgopeed.dylib ui/flutter/build/macos/Build/Products/Release/Gopeed.app/Contents/Frameworks/
cd ui/flutter/build/macos/Build/Products/Release
appdmg appdmg.json dist/Gopeed-$VERSION-macos-amd64.dmg
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ui/flutter/build/macos/Build/Products/Release/dist/*
overwrite: true
build-linux:
runs-on: ubuntu-latest
needs: [ release ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
cache: true
- uses: subosito/flutter-action@v2
- run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build libgtk-3-dev
- name: Build
env:
VERSION: ${{ needs.release.outputs.tag_name }}
run: |
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o ui/flutter/linux/bundle/lib/libgopeed.so github.com/monkeyWie/gopeed/bind/desktop
cd ui/flutter
flutter build linux
mkdir -p debian/gui
cp assets/icon/icon_1024.png debian/gui/gopeed.png
cat>debian/debian.yaml<<EOF
flutter_app:
command: gopeed
arch: x64
parent: /usr/local/lib
control:
Package: gopeed
Version: ${VERSION:1}
Architecture: amd64
Essential: no
Priority: optional
Depends:
Maintainer: monkeyWie
Description: High speed downloader that supports all platforms.
EOF
cat>debian/gui/gopeed.desktop<<EOF
[Desktop Entry]
Version=${VERSION:1}
Name=Gopeed
GenericName=Gopeed
Comment=High speed downloader that supports all platforms.
Terminal=false
Type=Application
Categories=Utility
Keywords=Flutter;Downloader;
EOF
dart pub global activate flutter_to_debian
flutter_to_debian
mv debian/packages/gopeed*.deb debian/packages/Gopeed-$VERSION-linux-amd64.deb
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ui/flutter/debian/packages/*
overwrite: true
build-android:
runs-on: ubuntu-latest
needs: [ release ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
cache: true
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
- uses: subosito/flutter-action@v2
- name: Build
env:
VERSION: ${{ needs.release.outputs.tag_name }}
run: |
mkdir ui/flutter/android/app/libs
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
gomobile bind -tags nosqlite -ldflags="-w -s" -o ui/flutter/android/app/libs/libgopeed.aar -target=android -androidapi 19 -javapkg=com.gopeed github.com/monkeyWie/gopeed/bind/mobile
cd ui/flutter
flutter build apk
mkdir dist
cp build/app/outputs/flutter-apk/app-release.apk dist/Gopeed-$VERSION-android.apk
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ui/flutter/dist/*
overwrite: true
build-web:
runs-on: ubuntu-latest
needs: [ release ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
cache: true
- uses: subosito/flutter-action@v2
- name: Build
env:
VERSION: ${{ needs.release.outputs.tag_name }}
run: |
cd ui/flutter
flutter build web
cd ../../
cp -r ui/flutter/build/web cmd/web/dist
mkdir -p dist/zip
goos_arr=(windows darwin linux)
goarch_arr=(386 amd64 arm64)
export CGO_ENABLED=0
for goos in "${goos_arr[@]}"; do
for goarch in "${goarch_arr[@]}"; do
name=gopeed-web-$VERSION-$goos-$goarch
dir="dist/$name/"
(GOOS=$goos GOARCH=$goarch go build -tags nosqlite,web -ldflags="-s -w" -o $dir github.com/monkeyWie/gopeed/cmd/web \
&& cd $dir \
&& file=$(ls -AU | head -1) \
&& mkdir $name \
&& mv $file $name/$(echo $file | sed -e "s/web/gopeed/g") \
&& zip -r ../zip/$name.zip * \
&& cd ../..) \
|| true
done
done
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: dist/zip/*
overwrite: true
+35 -29
View File
@@ -4,36 +4,42 @@ on:
pull_request:
branches:
- main
paths-ignore:
- '.github/workflows/release.yml'
- '.github/release-drafter.yml'
- '_docs/**'
- '_examples/**'
- 'README*.md'
paths:
- "bind/**"
- "cmd/**"
- "internal/**"
- "pkg/**"
- "ui/**"
- ".github/workflows/test.yml"
- "go.mod"
- "go.sum"
push:
branches:
- main
paths-ignore:
- '.github/workflows/release.yml'
- '.github/release-drafter.yml'
- '_docs/**'
- '_examples/**'
- 'README*.md'
paths:
- "bind/**"
- "cmd/**"
- "internal/**"
- "pkg/**"
- "ui/**"
- ".github/workflows/test.yml"
- "go.mod"
- "go.sum"
jobs:
# lint:
# name: Lint
# runs-on: ubuntu-latest
# steps:
# - uses: actions/setup-go@v2
# with:
# go-version: '^1.19'
# - uses: actions/checkout@v2
# - name: Lint Go Code
# run: |
# export PATH=$PATH:$(go env GOPATH)/bin # temporary fix. See https://github.com/actions/setup-go/issues/14
# go get -u golang.org/x/lint/golint
# golint -set_exit_status ./...
# lint:
# name: Lint
# runs-on: ubuntu-latest
# steps:
# - uses: actions/setup-go@v2
# with:
# go-version: '^1.19'
# - uses: actions/checkout@v2
# - name: Lint Go Code
# run: |
# export PATH=$PATH:$(go env GOPATH)/bin # temporary fix. See https://github.com/actions/setup-go/issues/14
# go get -u golang.org/x/lint/golint
# golint -set_exit_status ./...
test:
name: Test
runs-on: ubuntu-latest
@@ -41,7 +47,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
go-version: "^1.19"
cache: true
- name: Run Unit tests.
run: go test $(go list ./... | grep -v /cmd/ | grep -v /bind/ ) -v -covermode=count -coverprofile=coverage.txt
@@ -52,13 +58,13 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
# needs: [lint, test]
# needs: [lint, test]
needs: [test]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
go-version: "^1.19"
cache: true
- name: Build
run: go build github.com/monkeyWie/gopeed/cmd/gopeed
run: go build github.com/monkeyWie/gopeed/cmd/gopeed
+21
View File
@@ -0,0 +1,21 @@
FROM cirrusci/flutter:3.3.7 AS flutter
WORKDIR /app
COPY ./ui/flutter/pubspec.yaml ./ui/flutter/pubspec.lock ./
RUN flutter pub get
COPY ./ui/flutter ./
RUN flutter build web
FROM golang:1.19.3 AS go
WORKDIR /app
COPY ./go.mod ./go.sum ./
RUN go mod download
COPY . .
COPY --from=flutter /app/build/web/* ./cmd/web/dist/
RUN go build -tags nosqlite,web -ldflags="-s -w" -o dist/gopeed github.com/monkeyWie/gopeed/cmd/web
FROM alpine:3.14.2
LABEL maintainer="monkeyWie"
WORKDIR /app
COPY --from=go /app/dist/gopeed ./
EXPOSE 9999
ENTRYPOINT ["./gopeed"]
+42 -27
View File
@@ -1,16 +1,19 @@
[![Test Status](https://github.com/monkeyWie/gopeed/workflows/test/badge.svg)](https://github.com/monkeyWie/gopeed/actions?query=workflow%3Atest)
[![Codecov](https://codecov.io/gh/monkeyWie/gopeed/branch/main/graph/badge.svg)](https://codecov.io/gh/monkeyWie/gopeed)
[![Release](https://img.shields.io/github/release/monkeyWie/gopeed.svg?style=flat-square)](https://github.com/monkeyWie/gopeed/releases)
[![Discord](https://img.shields.io/discord/1037992631881449472?label=Discord&logo=discord&style=social)](https://discord.gg/ZUJqJrwCGB)
![](_docs/img/banner.png)
## 介绍
[English](/README.md) | [中文](/README_zh-CN.md)
Gopeed 是一款由`Golang`+`Flutter`开发的高速下载器,支持(HTTP、BitTorrent、Magnet)协议下载,并且支持全平台使用。
## Introduction
## 下载
Gopeed is a high-speed downloader developed by `Golang`+`Flutter`, which supports (HTTP, BitTorrent, Magnet) protocol downloads and supports all platforms.
**已支持平台**
## Installation
**Supported platforms**
- [x] windows
- [x] macos
@@ -18,45 +21,57 @@ Gopeed 是一款由`Golang`+`Flutter`开发的高速下载器,支持(HTTP、
- [x] android
- [ ] ios
- [x] web
- [x] docker
[点击前往](https://github.com/monkeyWie/gopeed/releases/latest)
[To Release](https://github.com/monkeyWie/gopeed/releases/latest)
### 命令行工具
> Tips: If the macos open failed, please execute the `xattr -d com.apple.quarantine /Applications/gopeed.app` command in the terminal
使用`go install`安装:
### Command tool
use `go install`:
```bash
go install github.com/monkeyWie/gopeed/cmd/gopeed
```
## 界面展示
### Docker
```bash
docker run liwei2633/gopeed:latest -v /path/to/download:/download -p 9999:9999
```
When the docker container is running, you can access the web page through `http://localhost:9999`.
> Tip: Modify the download path to `/download` on the setting page to access the downloaded files on the host.
## Showcase
![](_docs/img/ui-demo.png)
## 开发
## Development
本项目分为前端和后端两个部分,前端使用`flutter`,后端使用`Golang`,两边通过`http`协议进行通讯,在 unix 系统下,使用的是`unix socket`,在 windows 系统下,使用的是`tcp`协议。
This project is divided into two parts, the front end uses `flutter`, the back end uses `Golang`, and the two sides communicate through the `http` protocol. On the unix system, `unix socket` is used, and on the windows system, `tcp` protocol is used.
> 前端代码位于`ui/flutter`目录下。
> The front code is located in the `ui/flutter` directory.
### 环境要求
### Environment
1. Golang 1.9+
1. Golang 1.19+
2. Flutter 3.0+
### 克隆项目
### Clone
```bash
git clone [email protected]:monkeyWie/gopeed.git
```
### 编译
### Build
#### 桌面端
#### Desktop
首先需要按照[flutter desktop 官网文档](https://docs.flutter.dev/development/platform-integration/desktop)进行环境配置,然后需要准备好`cgo`环境,具体可以自行搜索。
First, you need to configure the environment according to the [flutter desktop official website document](https://docs.flutter.dev/development/platform-integration/desktop), and then you need to prepare the `cgo` environment, which can be searched for yourself.
构建命令:
command:
- windows
@@ -82,16 +97,16 @@ cd ui/flutter
flutter build linux
```
#### 移动端
#### Mobile
同样的也是需要准备好`cgo`环境,接着安装`gomobile`:
Same as before, you also need to prepare the `cgo` environment, and then install `gomobile`:
```bash
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
```
构建命令:
command:
- android
@@ -101,11 +116,11 @@ cd ui/flutter
flutter build apk
```
#### Web 端(推荐本地调试使用)
#### Web
Web 端直接与后端 http 服务通讯,不需要额外准备环境。
Web platform communicates directly with the backend http server, no additional environment is required.
构建命令:
command:
```bash
cd ui/flutter
@@ -113,8 +128,8 @@ flutter build web
cd ../../
cp -r ui/flutter/build/web cmd/web/dist
go build -tags nosqlite,web -ldflags="-s -w" -o bin/ github.com/monkeyWie/gopeed/cmd/web
```
````
## 开源许可
## License
基于 [GPLv3](LICENSE) 协议开源。
[GPLv3](LICENSE)
+135
View File
@@ -0,0 +1,135 @@
[![Test Status](https://github.com/monkeyWie/gopeed/workflows/test/badge.svg)](https://github.com/monkeyWie/gopeed/actions?query=workflow%3Atest)
[![Codecov](https://codecov.io/gh/monkeyWie/gopeed/branch/main/graph/badge.svg)](https://codecov.io/gh/monkeyWie/gopeed)
[![Release](https://img.shields.io/github/release/monkeyWie/gopeed.svg?style=flat-square)](https://github.com/monkeyWie/gopeed/releases)
[![Discord](https://img.shields.io/discord/1037992631881449472?label=Discord&logo=discord&style=social)](https://discord.gg/ZUJqJrwCGB)
![](_docs/img/banner.png)
[English](/README.md) | [中文](/README_zh-CN.md)
## 介绍
Gopeed 是一款由`Golang`+`Flutter`开发的高速下载器,支持(HTTP、BitTorrent、Magnet)协议下载,并且支持全平台使用。
## 下载
**已支持平台**
- [x] windows
- [x] macos
- [x] linux
- [x] android
- [ ] ios
- [x] web
- [x] docker
[点击前往](https://github.com/monkeyWie/gopeed/releases/latest)
> 注:macos 版本运行如果提示损坏,请在终端执行 `xattr -d com.apple.quarantine /Applications/gopeed.app` 命令
### 命令行工具
使用`go install`安装:
```bash
go install github.com/monkeyWie/gopeed/cmd/gopeed
```
### Docker
```bash
docker run liwei2633/gopeed:latest -v /path/to/download:/download -p 9999:9999
```
当 docker 容器运行时,可以通过 `http://localhost:9999` 访问 web 页面。
> 提示:在设置页面把下载路径修改为 `/download` 以便在宿主机访问下载完的文件。
## 界面展示
![](_docs/img/ui-demo.png)
## 开发
本项目分为前端和后端两个部分,前端使用`flutter`,后端使用`Golang`,两边通过`http`协议进行通讯,在 unix 系统下,使用的是`unix socket`,在 windows 系统下,使用的是`tcp`协议。
> 前端代码位于`ui/flutter`目录下。
### 环境要求
1. Golang 1.19+
2. Flutter 3.0+
### 克隆项目
```bash
git clone [email protected]:monkeyWie/gopeed.git
```
### 编译
#### 桌面端
首先需要按照[flutter desktop 官网文档](https://docs.flutter.dev/development/platform-integration/desktop)进行环境配置,然后需要准备好`cgo`环境,具体可以自行搜索。
构建命令:
- windows
```bash
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o ui/flutter/windows/libgopeed.dll github.com/monkeyWie/gopeed/bind/desktop
cd ui/flutter
flutter build windows
```
- macos
```bash
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o ui/flutter/macos/Frameworks/libgopeed.dylib github.com/monkeyWie/gopeed/bind/desktop
cd ui/flutter
flutter build macos
```
- linux
```bash
go build -tags nosqlite -ldflags="-w -s" -buildmode=c-shared -o ui/flutter/linux/bundle/lib/libgopeed.so github.com/monkeyWie/gopeed/bind/desktop
cd ui/flutter
flutter build linux
```
#### 移动端
同样的也是需要准备好`cgo`环境,接着安装`gomobile`:
```bash
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
```
构建命令:
- android
```bash
gomobile bind -tags nosqlite -ldflags="-w -s" -o ui/flutter/android/app/libs/libgopeed.aar -target=android -androidapi 19 -javapkg=com.gopeed github.com/monkeyWie/gopeed/bind/mobile
cd ui/flutter
flutter build apk
```
#### Web 端(推荐本地调试使用)
Web 端直接与后端 http 服务通讯,不需要额外准备环境。
构建命令:
```bash
cd ui/flutter
flutter build web
cd ../../
cp -r ui/flutter/build/web cmd/web/dist
go build -tags nosqlite,web -ldflags="-s -w" -o bin/ github.com/monkeyWie/gopeed/cmd/web
```
## 开源许可
基于 [GPLv3](LICENSE) 协议开源。
+1 -2
View File
@@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
)
type args struct {
@@ -14,7 +13,7 @@ type args struct {
}
func parse() *args {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
dir, err := os.Getwd()
if err != nil {
panic(err)
}
+1 -1
View File
@@ -26,7 +26,7 @@ func main() {
cfg := &model.StartConfig{
Network: "tcp",
Address: "127.0.0.1:9999",
Storage: model.StorageMem,
Storage: model.StorageBolt,
WebEnable: true,
WebFS: sub,
}
+7 -3
View File
@@ -54,6 +54,10 @@ android/app/libs/libgopeed-sources.jar
debian/packages
generated_plugin_registrant.cc
generated_plugin_registrant.h
generated_plugins.cmake
linux/flutter/generated_plugin_registrant.cc
linux/flutter/generated_plugin_registrant.h
linux/flutter/generated_plugins.cmake
macos/Flutter/GeneratedPluginRegistrant.swift
windows/flutter/generated_plugin_registrant.cc
windows/flutter/generated_plugin_registrant.h
windows/flutter/generated_plugins.cmake
+4 -1
View File
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:dio/adapter.dart';
import 'package:dio/dio.dart';
import 'package:gopeed/util/util.dart';
import 'model/create_task.dart';
import 'model/request.dart';
import 'model/resource.dart';
@@ -26,7 +27,9 @@ class _Client {
final isUnixSocket = LibgopeedBoot.instance.config.network == 'unix';
dio.options.baseUrl = isUnixSocket
? 'http://127.0.0.1'
: 'http://${LibgopeedBoot.instance.config.address}';
: (Util.isWeb()
? ""
: 'http://${LibgopeedBoot.instance.config.address}');
_instance!.dio = dio;
if (isUnixSocket) {
(_instance!.dio.httpClientAdapter as DefaultHttpClientAdapter)
+1 -1
View File
@@ -9,7 +9,7 @@ class LibgopeedConfig {
LibgopeedConfig({
this.network = "tcp",
this.address = "127.0.0.1:9999",
this.address = "127.0.0.1:0",
this.refreshInterval = 500,
});
}
+82
View File
@@ -0,0 +1,82 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Locale toLocale(String key) {
final arr = key.split('_');
return Locale(arr[0], arr[1]);
}
String getLocaleKey(Locale locale) {
return '${locale.languageCode}_${locale.countryCode}';
}
final messages = _Messages();
const fallbackLocale = Locale('en', 'US');
class _Messages extends Translations {
@override
Map<String, Map<String, String>> get keys => {
'zh_CN': {
'error': '错误',
'confirm': '确认',
'cancel': '取消',
'home.task': '任务',
'home.setting': '设置',
'create.title': '创建任务',
'create.downloadLink': '下载链接',
'create.downloadLinkValid': '请输入下载链接',
'create.downloadLinkHit': '请输入下载链接,支持 HTTP/HTTPS/MAGNET@append',
'create.downloadLinkHitDesktop': ',也可以直接拖拽种子文件到此处',
'create.download': '下载',
'create.error.noStoragePermission': '需要开启存储权限',
'create.selectDir': '选择目录',
'setting.title': '设置',
'setting.basic': '基础设置',
'setting.theme': '主题',
'setting.themeSystem': '跟随系统',
'setting.themeLight': '明亮主题',
'setting.themeDark': '暗黑主题',
'setting.downloadDir': '下载目录',
'setting.downloadDirValid': '请选择下载目录',
'setting.connections': '连接数',
'setting.locale': '语言',
'setting.locale.zh_CN': '中文(简体)',
'setting.locale.en_US': '英文(美国)',
'task.deleteTask': '删除任务',
'task.deleteTaskTip': '保留已下载的文件',
'task.delete': '删除',
},
'en_US': {
'error': 'Error',
'confirm': 'Confirm',
'cancel': 'Cancel',
'home.task': 'Task',
'home.setting': 'Setting',
'create.title': 'Create Task',
'create.downloadLink': 'Download Link',
'create.downloadLinkValid': 'Please enter the download link',
'create.downloadLinkHit':
'Please enter the download link, HTTP/HTTPS/MAGNET supported@append',
'create.downloadLinkHitDesktop':
', or drag the torrent file here directly',
'create.download': 'Download',
'create.error.noStoragePermission': 'Storage permission required',
'create.selectDir': 'Select Directory',
'setting.title': 'Setting',
'setting.basic': 'Basic',
'setting.theme': 'Theme',
'setting.themeSystem': 'System',
'setting.themeLight': 'Light',
'setting.themeDark': 'Dark',
'setting.downloadDir': 'Download Directory',
'setting.downloadDirValid': 'Please select the download directory',
'setting.connections': 'Connections',
'setting.locale': 'Language',
'setting.locale.zh_CN': 'Chinese(Simplified)',
'setting.locale.en_US': 'English(US)',
'task.deleteTask': 'Delete Task',
'task.deleteTaskTip': 'Keep downloaded files',
'task.delete': 'Delete',
},
};
}
+4
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'core/libgopeed_boot.dart';
import 'i18n/messages.dart';
import 'routes/router.dart';
import 'setting/setting.dart';
import 'theme/theme.dart';
@@ -24,6 +25,9 @@ void main() async {
theme: GopeedTheme.light,
darkTheme: GopeedTheme.dark,
themeMode: Setting.instance.themeMode,
translations: messages,
locale: toLocale(Setting.instance.locale),
fallbackLocale: fallbackLocale,
getPages: Routes.routes,
));
}
@@ -1,5 +1,3 @@
import 'package:get/get.dart';
class CreateController extends GetxController {
var currentIndex = 0.obs;
}
class CreateController extends GetxController {}
+69 -55
View File
@@ -1,3 +1,4 @@
import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../api/api.dart';
@@ -30,65 +31,77 @@ class CreateView extends GetView<CreateController> {
icon: const Icon(Icons.arrow_back),
onPressed: () => Get.rootDelegate.offNamed(Routes.task)),
actions: [Container()],
title: const Text("创建任务"),
title: Text('create.title'.tr),
),
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
child: Form(
key: _resolveFormKey,
autovalidateMode: AutovalidateMode.always, //开启自动校验
child: Column(
children: [
TextFormField(
autofocus: true,
controller: _urlController,
minLines: 1,
maxLines: 15,
decoration: const InputDecoration(
hintText: "请输入下载链接,支持 HTTP/HTTPS/MAGNET",
labelText: "下载链接",
icon: Icon(Icons.link)),
validator: (v) {
return v!.trim().isNotEmpty ? null : "请输入下载链接";
}),
// 登录按钮
Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: ConstrainedBox(
constraints: const BoxConstraints.tightFor(
width: 150,
height: 40,
),
child: RoundedLoadingButton(
color: Get.theme.colorScheme.secondary,
onPressed: () async {
if (_resolveFormKey.currentState!.validate()) {
_confirmController.start();
try {
final res = await resolve(Request(
url: _urlController.text,
));
await _showResolveDialog(res);
} catch (e) {
Get.snackbar("错误", e.toString());
} finally {
_confirmController.reset();
body: DropTarget(
onDragDone: (details) {
_urlController.text = details.files[0].path;
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
child: Form(
key: _resolveFormKey,
autovalidateMode: AutovalidateMode.always,
child: Column(
children: [
TextFormField(
autofocus: true,
controller: _urlController,
minLines: 1,
maxLines: 15,
decoration: InputDecoration(
hintText: _hitText(),
labelText: 'create.downloadLink'.tr,
icon: const Icon(Icons.link)),
validator: (v) {
return v!.trim().isNotEmpty
? null
: 'create.downloadLinkValid'.tr;
}),
Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: ConstrainedBox(
constraints: const BoxConstraints.tightFor(
width: 150,
height: 40,
),
child: RoundedLoadingButton(
color: Get.theme.colorScheme.secondary,
onPressed: () async {
if (_resolveFormKey.currentState!.validate()) {
_confirmController.start();
try {
final res = await resolve(Request(
url: _urlController.text,
));
await _showResolveDialog(res);
} catch (e) {
Get.snackbar('error'.tr, e.toString());
} finally {
_confirmController.reset();
}
}
}
},
controller: _confirmController,
child: const Text("确认"),
),
)),
),
],
},
controller: _confirmController,
child: Text('confirm'.tr),
),
)),
),
],
),
),
),
),
);
}
String _hitText() {
return 'create.downloadLinkHit'.trParams({
'append': Util.isDesktop() ? 'create.downloadLinkHitDesktop'.tr : '',
});
}
Future<void> _showResolveDialog(Resource res) async {
final createFormKey = GlobalKey<FormState>();
final pathController =
@@ -142,7 +155,7 @@ class CreateView extends GetView<CreateController> {
onPressed: () {
Get.back();
},
child: const Text("取消"),
child: Text('cancel'.tr),
),
),
ConstrainedBox(
@@ -158,7 +171,8 @@ class CreateView extends GetView<CreateController> {
downloadController.start();
if (Util.isAndroid()) {
if (!await Permission.storage.request().isGranted) {
Get.snackbar("错误", "需要开启存储权限");
Get.snackbar('error'.tr,
'create.error.noStoragePermission'.tr);
return;
}
}
@@ -179,14 +193,14 @@ class CreateView extends GetView<CreateController> {
Get.rootDelegate.offNamed(Routes.task);
}
} catch (e) {
Get.snackbar("错误", e.toString());
Get.snackbar('error'.tr, e.toString());
rethrow;
} finally {
downloadController.reset();
}
},
controller: downloadController,
child: const Text("下载"),
child: Text('create.download'.tr),
),
),
],
+2 -2
View File
@@ -37,11 +37,11 @@ class HomeView extends GetView<HomeController> {
AnimatedBarItems(
icon: const Icon(Icons.list),
selectedColor: Get.theme.primaryColor,
title: const Text('任务')),
title: Text('home.task'.tr)),
AnimatedBarItems(
icon: const Icon(Icons.settings),
selectedColor: Get.theme.primaryColor,
title: const Text('设置')),
title: Text('home.setting'.tr)),
],
iconSize: 32,
barAnimation: BarAnimation.fade,
@@ -5,4 +5,8 @@ import '../../setting/setting.dart';
class SettingController extends GetxController {
final setting = Setting.instance.obs;
final tapStatues = <int, bool>{}.obs;
void clearTapStatus() {
tapStatues.clear();
}
}
+67 -17
View File
@@ -3,6 +3,8 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:gopeed/i18n/messages.dart';
import 'package:gopeed/util/util.dart';
import '../../setting/setting.dart';
import '../../widget/directory_selector.dart';
@@ -15,35 +17,42 @@ class SettingView extends GetView<SettingController> {
Widget build(BuildContext context) {
Timer? timer;
debounceSave() {
var completer = Completer<void>();
timer?.cancel();
timer = Timer(const Duration(milliseconds: 500), Setting.instance.save);
timer = Timer(const Duration(milliseconds: 500), () {
Setting.instance
.save()
.then(completer.complete)
.onError(completer.completeError);
});
return completer.future;
}
return Scaffold(
appBar: AppBar(
title: const Text('设置'),
title: Text('setting.title'.tr),
centerTitle: true,
),
body: Column(
// 左对齐
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("基本设置", style: Get.textTheme.titleLarge),
Text('setting.basic'.tr, style: Get.textTheme.titleLarge),
const SizedBox(height: 10),
Obx(() => Card(
child: Column(
children: _buildConfigItems([
_ConfigItem(
"主题",
'setting.theme'.tr,
() => _getThemeName(controller.setting.value.themeMode),
() => DropdownButton<ThemeMode>(
value: controller.setting.value.themeMode,
isDense: true,
onChanged: (value) {
onChanged: (value) async {
controller.setting.value.themeMode = value!;
controller.clearTapStatus();
Get.changeThemeMode(value);
debounceSave();
await debounceSave();
},
items: ThemeMode.values
.map((e) => DropdownMenuItem<ThemeMode>(
@@ -52,17 +61,20 @@ class SettingView extends GetView<SettingController> {
))
.toList(),
)),
_ConfigItem(
"下载目录", () => controller.setting.value.downloadDir, () {
_ConfigItem('setting.downloadDir'.tr,
() => controller.setting.value.downloadDir, () {
final downloadDirController = TextEditingController(
text: controller.setting.value.downloadDir);
downloadDirController.addListener(() {
downloadDirController.addListener(() async {
if (downloadDirController.text !=
controller.setting.value.downloadDir) {
controller.setting.value.downloadDir =
downloadDirController.text;
if (Util.isDesktop()) {
controller.clearTapStatus();
}
debounceSave();
await debounceSave();
}
});
return DirectorySelector(
@@ -70,19 +82,19 @@ class SettingView extends GetView<SettingController> {
showLabel: false,
);
}),
_ConfigItem("连接数",
_ConfigItem('setting.connections'.tr,
() => controller.setting.value.connections.toString(),
() {
final connectionsController = TextEditingController(
text: controller.setting.value.connections.toString());
connectionsController.addListener(() {
connectionsController.addListener(() async {
if (connectionsController.text.isNotEmpty &&
connectionsController.text !=
controller.setting.value.connections.toString()) {
controller.setting.value.connections =
int.parse(connectionsController.text);
debounceSave();
await debounceSave();
}
});
@@ -95,6 +107,27 @@ class SettingView extends GetView<SettingController> {
],
);
}),
_ConfigItem(
'setting.locale'.tr,
() => _getLocaleName(controller.setting.value.locale),
() => DropdownButton<String>(
value: controller.setting.value.locale,
isDense: true,
onChanged: (value) async {
controller.setting.value.locale = value!;
controller.clearTapStatus();
Get.updateLocale(toLocale(value));
await debounceSave();
},
items: _getLocales()
.map((e) => DropdownMenuItem<String>(
value:
e.substring(_settingLocaleKey.length),
child: Text(e.tr),
))
.toList(),
)),
]),
))),
],
@@ -130,13 +163,30 @@ class SettingView extends GetView<SettingController> {
String _getThemeName(ThemeMode themeMode) {
switch (themeMode) {
case ThemeMode.system:
return "跟随系统";
return 'setting.themeSystem'.tr;
case ThemeMode.light:
return "明亮主题";
return 'setting.themeLight'.tr;
case ThemeMode.dark:
return "暗黑主题";
return 'setting.themeDark'.tr;
}
}
final _settingLocaleKey = 'setting.locale.';
List<String> _getLocales() {
return messages.keys[getLocaleKey(fallbackLocale)]!.entries
.where((e) => e.key.startsWith(_settingLocaleKey))
.map((e) => e.key)
.toList();
}
String _getLocaleName(String locale) {
final localeKey = '$_settingLocaleKey${locale.toString()}';
if (messages.keys[locale]?.containsKey(localeKey) ?? false) {
return localeKey.tr;
}
return '$_settingLocaleKey$locale'.tr;
}
}
class _ConfigItem {
+9 -10
View File
@@ -65,8 +65,6 @@ class Item extends StatelessWidget {
@override
Widget build(BuildContext context) {
var controller = Get.find<TaskController>();
return Card(
elevation: 4.0,
child: InkWell(
@@ -153,22 +151,23 @@ class Item extends StatelessWidget {
context: Get.context!,
barrierDismissible: false,
builder: (_) => AlertDialog(
title: const Text("删除任务"),
title: Text('task.deleteTask'.tr),
content: Obx(() => CheckboxListTile(
value: keep.value,
title: Text("保留已下载的文件", style: Get.textTheme.bodyText1),
title: Text('task.deleteTaskTip'.tr,
style: Get.textTheme.bodyText1),
onChanged: (v) {
keep.value = v!;
})),
actions: [
TextButton(
child: const Text("取消"),
onPressed: () => Get.back(), //关闭对话框
child: Text('cancel'.tr),
onPressed: () => Get.back(),
),
TextButton(
child: const Text(
"删除",
style: TextStyle(color: Colors.redAccent),
child: Text(
'task.delete'.tr,
style: const TextStyle(color: Colors.redAccent),
),
onPressed: () async {
try {
@@ -176,7 +175,7 @@ class Item extends StatelessWidget {
Get.find<TaskController>().loadTab();
Get.back();
} catch (e) {
Get.snackbar("错误", e.toString());
Get.snackbar('error'.tr, e.toString());
}
},
),
+17 -17
View File
@@ -1,8 +1,11 @@
import 'package:external_path/external_path.dart';
import 'package:flutter/material.dart';
import 'package:gopeed/i18n/messages.dart';
import '../api/api.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:ui' as ui;
import '../api/model/server_config.dart';
import '../util/util.dart';
@@ -10,22 +13,17 @@ class Setting {
String host = "127.0.0.1";
int port = 0;
int connections = 0;
String downloadDir = "";
ThemeMode themeMode = ThemeMode.system;
Setting({
required this.host,
required this.port,
required this.connections,
required this.downloadDir,
required this.themeMode,
});
late String downloadDir;
late ThemeMode themeMode;
late String locale;
// singleton pattern
static Setting? _instance;
static Setting get instance {
_instance ??= Setting._internal();
_instance!.themeMode = ThemeMode.system;
_instance!.locale = getLocaleKey(ui.window.locale);
return _instance!;
}
@@ -38,16 +36,14 @@ class Setting {
connections = config.connections;
downloadDir = config.downloadDir;
final themeMode = config.extra?['themeMode'];
if (themeMode == null) {
this.themeMode = ThemeMode.system;
} else {
if (themeMode != null) {
this.themeMode = ThemeMode.values.byName(themeMode);
}
if (Util.isWeb()) {
downloadDir = "./";
return;
final locale = config.extra?['locale'];
if (locale != null) {
this.locale = locale;
}
if (Util.isAndroid()) {
downloadDir =
'${await ExternalPath.getExternalStoragePublicDirectory(ExternalPath.DIRECTORY_DOWNLOADS)}/com.gopeed';
@@ -55,6 +51,9 @@ class Setting {
}
if (downloadDir.isEmpty) {
if (Util.isWeb()) {
downloadDir = './';
}
if (Util.isDesktop()) {
downloadDir = (await getDownloadsDirectory())!.path;
}
@@ -69,6 +68,7 @@ class Setting {
downloadDir: downloadDir,
extra: {
'themeMode': themeMode.name,
'locale': locale,
},
);
await putConfig(config);
+19 -16
View File
@@ -1,6 +1,7 @@
import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:gopeed/util/util.dart';
import '../util/mac_secure_util.dart';
@@ -23,29 +24,31 @@ class _DirectorySelectorState extends State<DirectorySelector> {
children: [
Expanded(
child: TextFormField(
readOnly: true,
readOnly: Util.isWeb() ? false : true,
controller: widget.controller,
decoration: widget.showLabel
? const InputDecoration(
labelText: "下载目录",
? InputDecoration(
labelText: 'setting.downloadDir'.tr,
)
: null,
validator: (v) {
return v!.trim().isNotEmpty ? null : "请选择下载目录";
return v!.trim().isNotEmpty ? null : 'setting.downloadDirValid'.tr;
},
)),
IconButton(
icon: const Icon(Icons.folder_open),
onPressed: () async {
if (GetPlatform.isDesktop) {
var dir = await getDirectoryPath();
if (dir != null) {
widget.controller.text = dir;
MacSecureUtil.saveBookmark(dir);
}
}
})
],
!Util.isDesktop()
? null
: IconButton(
icon: const Icon(Icons.folder_open),
onPressed: () async {
if (GetPlatform.isDesktop) {
var dir = await getDirectoryPath();
if (dir != null) {
widget.controller.text = dir;
MacSecureUtil.saveBookmark(dir);
}
}
})
].where((e) => e != null).map((e) => e!).toList(),
);
}
}
+3 -1
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../util/util.dart';
import '../api/model/resource.dart';
@@ -29,7 +30,8 @@ class _FileListViewState extends State<FileListView> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(padding: EdgeInsets.only(top: 10)),
Text("选择文件", style: TextStyle(color: themeData.hintColor)),
Text('create.selectDir'.tr,
style: TextStyle(color: themeData.hintColor)),
Expanded(
child: Container(
margin: const EdgeInsets.only(top: 10),
@@ -1,19 +0,0 @@
//
// Generated file. Do not edit.
//
// clang-format off
#include "generated_plugin_registrant.h"
#include <file_selector_linux/file_selector_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
@@ -1,15 +0,0 @@
//
// Generated file. Do not edit.
//
// clang-format off
#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_
#include <flutter_linux/flutter_linux.h>
// Registers Flutter plugins.
void fl_register_plugins(FlPluginRegistry* registry);
#endif // GENERATED_PLUGIN_REGISTRANT_
@@ -1,25 +0,0 @@
#
# Generated file, do not edit.
#
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
url_launcher_linux
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
)
set(PLUGIN_BUNDLED_LIBRARIES)
foreach(plugin ${FLUTTER_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
@@ -1,20 +0,0 @@
//
// Generated file. Do not edit.
//
import FlutterMacOS
import Foundation
import file_selector_macos
import macos_secure_bookmarks
import path_provider_macos
import shared_preferences_macos
import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
SecureBookmarksPlugin.register(with: registry.registrar(forPlugin: "SecureBookmarksPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
+6
View File
@@ -1,4 +1,6 @@
PODS:
- desktop_drop (0.0.1):
- FlutterMacOS
- file_selector_macos (0.0.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
@@ -12,6 +14,7 @@ PODS:
- FlutterMacOS
DEPENDENCIES:
- desktop_drop (from `Flutter/ephemeral/.symlinks/plugins/desktop_drop/macos`)
- file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- macos_secure_bookmarks (from `Flutter/ephemeral/.symlinks/plugins/macos_secure_bookmarks/macos`)
@@ -20,6 +23,8 @@ DEPENDENCIES:
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
EXTERNAL SOURCES:
desktop_drop:
:path: Flutter/ephemeral/.symlinks/plugins/desktop_drop/macos
file_selector_macos:
:path: Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos
FlutterMacOS:
@@ -34,6 +39,7 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
SPEC CHECKSUMS:
desktop_drop: 69eeff437544aa619c8db7f4481b3a65f7696898
file_selector_macos: f1b08a781e66103e3ba279fd5d4024a2478b3af6
FlutterMacOS: ae6af50a8ea7d6103d888583d46bd8328a7e9811
macos_secure_bookmarks: cff041c4b377fa00941bb901aaec4d27fac5edf2
+7
View File
@@ -183,6 +183,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.4"
desktop_drop:
dependency: "direct main"
description:
name: desktop_drop
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.3"
dio:
dependency: "direct main"
description:
+1
View File
@@ -49,6 +49,7 @@ dependencies:
permission_handler: ^10.1.0
external_path: ^1.0.3
logger: ^1.1.0
desktop_drop: ^0.3.3
dev_dependencies:
flutter_test:
@@ -1,20 +0,0 @@
//
// Generated file. Do not edit.
//
// clang-format off
#include "generated_plugin_registrant.h"
#include <file_selector_windows/file_selector_windows.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
@@ -1,15 +0,0 @@
//
// Generated file. Do not edit.
//
// clang-format off
#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_
#include <flutter/plugin_registry.h>
// Registers Flutter plugins.
void RegisterPlugins(flutter::PluginRegistry* registry);
#endif // GENERATED_PLUGIN_REGISTRANT_
@@ -1,26 +0,0 @@
#
# Generated file, do not edit.
#
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
permission_handler_windows
url_launcher_windows
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
)
set(PLUGIN_BUNDLED_LIBRARIES)
foreach(plugin ${FLUTTER_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)