diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 70463be5c..c2afca1e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,53 +6,53 @@ on: merge_group: jobs: - ios-build: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - with: - ref: dev - - uses: subosito/flutter-action@v2 - with: - # flutter-version: '2.5.2' - channel: 'stable' - - uses: actions/setup-python@v2 - with: - python-version: '3.8' - - name: Preprocess - run: | - # cd lib/server - # wget -q ${{ secrets.SECRET_SALT }} - # wget -q ${{ secrets.SECRET_WSALT }} - # cd ../.. - cat << EOF > lib/server/salt.dart - String getValid(foo) {return foo;} - EOF - cat << EOF > lib/server/wsalt.dart - String getValid(foo) {return foo;} - EOF - python3 preprocess-ios.py - - name: Podfile - run: | - cd ios - rm Podfile.lock - flutter clean - flutter pub get - pod install - pod update - cd .. - - name: Build - run: | - flutter build ios --release --no-codesign - mkdir -p Payload - mv ./build/ios/iphoneos/Runner.app Payload - zip -r -y Payload.zip Payload/Runner.app - mv Payload.zip Payload.ipa - - name: Upload IPA - uses: actions/upload-artifact@v2 - with: - name: ipa-build - path: Payload.ipa + # ios-build: + # runs-on: macos-latest + # steps: + # - uses: actions/checkout@v2 + # with: + # ref: dev + # - uses: subosito/flutter-action@v2 + # with: + # # flutter-version: '2.5.2' + # channel: 'stable' + # - uses: actions/setup-python@v2 + # with: + # python-version: '3.8' + # - name: Preprocess + # run: | + # # cd lib/server + # # wget -q ${{ secrets.SECRET_SALT }} + # # wget -q ${{ secrets.SECRET_WSALT }} + # # cd ../.. + # cat << EOF > lib/server/salt.dart + # String getValid(foo) {return foo;} + # EOF + # cat << EOF > lib/server/wsalt.dart + # String getValid(foo) {return foo;} + # EOF + # python3 preprocess-ios.py + # - name: Podfile + # run: | + # cd ios + # rm Podfile.lock + # flutter clean + # flutter pub get + # pod install + # pod update + # cd .. + # - name: Build + # run: | + # flutter build ios --release --no-codesign + # mkdir -p Payload + # mv ./build/ios/iphoneos/Runner.app Payload + # zip -r -y Payload.zip Payload/Runner.app + # mv Payload.zip Payload.ipa + # - name: Upload IPA + # uses: actions/upload-artifact@v2 + # with: + # name: ipa-build + # path: Payload.ipa # https://github.com/AppImageCrafters/appimage-builder-flutter-example/blob/main/.github/workflows/appimage.yml linux-build: @@ -103,41 +103,41 @@ jobs: # files: './*.AppImage*' # repo_token: ${{ secrets.GITHUB_TOKEN }} - android-build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: dev - - uses: actions/setup-java@v1 - with: - java-version: '12.x' - - uses: subosito/flutter-action@v1 - with: - # flutter-version: '2.5.2' - channel: 'stable' - - uses: actions/setup-python@v2 - with: - python-version: '3.8' - - name: Preprocess - run: | - # cd lib/server - # wget -q ${{ secrets.SECRET_SALT }} - # wget -q ${{ secrets.SECRET_WSALT }} - # cd ../.. - cat << EOF > lib/server/salt.dart - String getValid(foo) {return foo;} - EOF - cat << EOF > lib/server/wsalt.dart - String getValid(foo) {return foo;} - EOF - python3 preprocess-android.py - - name: Build - run: | - flutter clean - flutter build apk --release - - name: Upload APK - uses: actions/upload-artifact@v2 - with: - name: apk-build - path: ./build/app/outputs/apk/release/app-release.apk + # android-build: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v2 + # with: + # ref: dev + # - uses: actions/setup-java@v1 + # with: + # java-version: '12.x' + # - uses: subosito/flutter-action@v1 + # with: + # # flutter-version: '2.5.2' + # channel: 'stable' + # - uses: actions/setup-python@v2 + # with: + # python-version: '3.8' + # - name: Preprocess + # run: | + # # cd lib/server + # # wget -q ${{ secrets.SECRET_SALT }} + # # wget -q ${{ secrets.SECRET_WSALT }} + # # cd ../.. + # cat << EOF > lib/server/salt.dart + # String getValid(foo) {return foo;} + # EOF + # cat << EOF > lib/server/wsalt.dart + # String getValid(foo) {return foo;} + # EOF + # python3 preprocess-android.py + # - name: Build + # run: | + # flutter clean + # flutter build apk --release + # - name: Upload APK + # uses: actions/upload-artifact@v2 + # with: + # name: apk-build + # path: ./build/app/outputs/apk/release/app-release.apk diff --git a/lib/component/hitomi/hitomi.dart b/lib/component/hitomi/hitomi.dart index 5284e8a88..15d73ee5e 100644 --- a/lib/component/hitomi/hitomi.dart +++ b/lib/component/hitomi/hitomi.dart @@ -27,8 +27,18 @@ class HitomiManager { static int? getArticleCount(String classification, String name) { if (tagmap == null) { final subdir = Platform.isAndroid ? '/data' : ''; - final path = - File('${Variables.applicationDocumentsDirectory}$subdir/index.json'); + late final path; + if(Platform.isAndroid || Platform.isIOS){ + path = File('${Variables.applicationDocumentsDirectory}$subdir/index.json'); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + path = File('${home}/.violet$subdir/index.json'); + } final text = path.readAsStringSync(); tagmap = jsonDecode(text); } @@ -38,8 +48,18 @@ class HitomiManager { static void reloadIndex() { final subdir = Platform.isAndroid ? '/data' : ''; - final path = - File('${Variables.applicationDocumentsDirectory}$subdir/index.json'); + late final path; + if(Platform.isAndroid || Platform.isIOS){ + path = File('${Variables.applicationDocumentsDirectory}$subdir/index.json'); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + path = File('${home}/.violet$subdir/index.json'); + } final text = path.readAsStringSync(); tagmap = jsonDecode(text); } @@ -81,8 +101,21 @@ class HitomiManager { tagmap = jsonDecode(await file.readAsString()); } else { final subdir = Platform.isAndroid ? '/data' : ''; - final directory = await getApplicationDocumentsDirectory(); - final path = File('${directory.path}$subdir/index.json'); + late final directory; + late final path; + if(Platform.isAndroid || Platform.isIOS){ + directory = await getApplicationDocumentsDirectory(); + path = File('${directory.path}$subdir/index.json'); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + path = File('${directory}$subdir/index.json'); + } final text = path.readAsStringSync(); tagmap = jsonDecode(text); } diff --git a/lib/component/hitomi/indexs.dart b/lib/component/hitomi/indexs.dart index 03a529547..bdb488a5f 100644 --- a/lib/component/hitomi/indexs.dart +++ b/lib/component/hitomi/indexs.dart @@ -40,32 +40,44 @@ class HitomiIndexs { static late Map relatedTag; static Future init() async { - final directory = await getApplicationDocumentsDirectory(); + late final directory; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + directory = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + } final subdir = Platform.isAndroid ? '/data' : ''; // No data on first run. - final path2 = File('${directory.path}$subdir/tag-artist.json'); + final path2 = File('${directory}$subdir/tag-artist.json'); if (!await path2.exists()) return; tagArtist = jsonDecode(await path2.readAsString()); - final path3 = File('${directory.path}$subdir/tag-group.json'); + final path3 = File('${directory}$subdir/tag-group.json'); tagGroup = jsonDecode(await path3.readAsString()); - final path4 = File('${directory.path}$subdir/tag-index.json'); + final path4 = File('${directory}$subdir/tag-index.json'); tagIndex = jsonDecode(await path4.readAsString()); - final path5 = File('${directory.path}$subdir/tag-uploader.json'); + final path5 = File('${directory}$subdir/tag-uploader.json'); tagUploader = jsonDecode(await path5.readAsString()); try { - final path6 = File('${directory.path}$subdir/tag-series.json'); + final path6 = File('${directory}$subdir/tag-series.json'); tagSeries = jsonDecode(await path6.readAsString()); - final path7 = File('${directory.path}$subdir/tag-character.json'); + final path7 = File('${directory}$subdir/tag-character.json'); tagCharacter = jsonDecode(await path7.readAsString()); - final path8 = File('${directory.path}$subdir/character-series.json'); + final path8 = File('${directory}$subdir/character-series.json'); characterSeries = jsonDecode(await path8.readAsString()); - final path9 = File('${directory.path}$subdir/series-character.json'); + final path9 = File('${directory}$subdir/series-character.json'); seriesCharacter = jsonDecode(await path9.readAsString()); - final path10 = File('${directory.path}$subdir/character-character.json'); + final path10 = File('${directory}$subdir/character-character.json'); characterCharacter = jsonDecode(await path10.readAsString()); - final path11 = File('${directory.path}$subdir/series-series.json'); + final path11 = File('${directory}$subdir/series-series.json'); seriesSeries = jsonDecode(await path11.readAsString()); } catch (e, st) { Logger.error('[Hitomi-Indexs] E: $e\n' diff --git a/lib/component/hitomi/series_finder.dart b/lib/component/hitomi/series_finder.dart index aa6e7165b..7e23aff91 100644 --- a/lib/component/hitomi/series_finder.dart +++ b/lib/component/hitomi/series_finder.dart @@ -13,8 +13,21 @@ import 'package:violet/database/query.dart'; class SeriesFinder { static Future doFind1() async { final subdir = Platform.isAndroid ? '/data' : ''; - final directory = await getApplicationDocumentsDirectory(); - final path = File('${directory.path}$subdir/index.json'); + late final directory; + late final path; + if(Platform.isAndroid || Platform.isIOS){ + directory = await getApplicationDocumentsDirectory(); + path = File('${directory.path}$subdir/index.json'); + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + path = '${directory}$subdir/index.json'; + } final text = path.readAsStringSync(); final tagmap = jsonDecode(text); final artists = tagmap['artist'] as Map; diff --git a/lib/log/log.dart b/lib/log/log.dart index d5bb7a2dd..d68fb3ece 100644 --- a/lib/log/log.dart +++ b/lib/log/log.dart @@ -62,6 +62,7 @@ class Logger { if (!Platform.environment.containsKey('FLUTTER_TEST')) { await lock.synchronized(() async { + await init(); await logFile.writeAsString('[${DateTime.now().toUtc()}] $msg\n', mode: FileMode.append); }); diff --git a/lib/pages/database_download/database_download_page.dart b/lib/pages/database_download/database_download_page.dart index c5e3ab443..2782e652e 100644 --- a/lib/pages/database_download/database_download_page.dart +++ b/lib/pages/database_download/database_download_page.dart @@ -662,30 +662,42 @@ class DataBaseDownloadPageState extends State { 'class': classes, }; - final directory = await getApplicationDocumentsDirectory(); - final path1 = File('${directory.path}/index.json'); + late final directory; + if(Platform.isAndroid || Platform.isIOS){ + var d = await getApplicationDocumentsDirectory(); + directory = d.path; + } else if(Platform.isLinux){ + var home = ''; + Platform.environment.forEach((key, value) { + if(key == 'HOME'){ + home = value; + } + }); + directory = '${home}/.violet'; + } + final path1 = File('${directory}/index.json'); path1.writeAsString(jsonEncode(index)); - final path2 = File('${directory.path}/tag-artist.json'); + final path2 = File('${directory}/tag-artist.json'); path2.writeAsString(jsonEncode(tagArtist)); - final path3 = File('${directory.path}/tag-group.json'); + final path3 = File('${directory}/tag-group.json'); path3.writeAsString(jsonEncode(tagGroup)); - final path4 = File('${directory.path}/tag-index.json'); + final path4 = File('${directory}/tag-index.json'); path4.writeAsString(jsonEncode(tagIndex)); - final path5 = File('${directory.path}/tag-uploader.json'); + final path5 = File('${directory}/tag-uploader.json'); path5.writeAsString(jsonEncode(tagUploader)); - final path6 = File('${directory.path}/tag-series.json'); + final path6 = File('${directory}/tag-series.json'); path6.writeAsString(jsonEncode(tagSeries)); - final path7 = File('${directory.path}/tag-character.json'); + final path7 = File('${directory}/tag-character.json'); path7.writeAsString(jsonEncode(tagCharacter)); - final path8 = File('${directory.path}/character-series.json'); + final path8 = File('${directory}/character-series.json'); path8.writeAsString(jsonEncode(characterSeries)); - final path9 = File('${directory.path}/series-character.json'); + final path9 = File('${directory}/series-character.json'); path9.writeAsString(jsonEncode(seriesCharacter)); - final path10 = File('${directory.path}/character-character.json'); + final path10 = File('${directory}/character-character.json'); path10.writeAsString(jsonEncode(characterCharacter)); - final path11 = File('${directory.path}/series-series.json'); + final path11 = File('${directory}/series-series.json'); path11.writeAsString(jsonEncode(seriesSeries)); setState(() { diff --git a/lib/script/script_manager.dart b/lib/script/script_manager.dart index 7fe56d375..9ebdd7ec1 100644 --- a/lib/script/script_manager.dart +++ b/lib/script/script_manager.dart @@ -119,6 +119,9 @@ class ScriptManager { if (_scriptCache == null) return null; try { + if(_runtime == null){ + _initRuntime(); + } var downloadUrl = _runtime.evaluate("create_download_url('$id')").stringResult; var headers = await runHitomiGetHeaderContent(id.toString());