├── .github └── workflows │ ├── ci.yml │ ├── release.yml │ └── tag.yml ├── .gitignore ├── .metadata ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── analysis_options.yaml ├── docs ├── DeepFaceLabClientWorkspace.png └── windows-protected-your-pc.png ├── lib ├── class │ ├── action │ │ └── switch_theme_action.dart │ ├── answer.dart │ ├── answer.g.dart │ ├── app_state.dart │ ├── conda_env_list.dart │ ├── conda_env_list.g.dart │ ├── deepfacelab_command_group.dart │ ├── device.dart │ ├── folder_property.dart │ ├── folder_property.g.dart │ ├── locale_storage_question.dart │ ├── locale_storage_question.g.dart │ ├── locale_storage_question_child.dart │ ├── locale_storage_question_child.g.dart │ ├── question.dart │ ├── question.g.dart │ ├── release.dart │ ├── release.g.dart │ ├── release_asset.dart │ ├── release_asset.g.dart │ ├── source.dart │ ├── start_process.dart │ ├── storage.dart │ ├── storage.g.dart │ ├── valid_answer_regex.dart │ ├── valid_answer_regex.g.dart │ ├── window_command.dart │ ├── window_command.g.dart │ ├── workspace.dart │ └── workspace.g.dart ├── main.dart ├── screens │ ├── dashboard_screen.dart │ ├── help_screen.dart │ ├── loading_screen.dart │ ├── settings_screen.dart │ ├── window_command_screen.dart │ └── workspace_screen.dart ├── service │ ├── file_manager_service.dart │ ├── locale_storage_service.dart │ ├── platform_service.dart │ ├── process_service.dart │ ├── python_service.dart │ ├── window_command_service.dart │ └── workspace_service.dart └── widget │ ├── common │ ├── context_menu_region.dart │ ├── deepfacelab_command_widget.dart │ ├── devices_widget.dart │ ├── divider_with_text_widget.dart │ ├── file_manager_widget.dart │ ├── form │ │ ├── checkbox_form_fiel_widget.dart │ │ └── deepfacelab_command_form_widget.dart │ ├── open_issue_widget.dart │ ├── release_widget.dart │ ├── select_theme_widget.dart │ ├── self_promotion_widget.dart │ └── start_process_widget.dart │ ├── form │ └── workspace │ │ ├── delete_workspace_form_widget.dart │ │ └── workspace_form_widget.dart │ └── installation │ ├── has_requirements_widget.dart │ ├── installation_widget.dart │ ├── requirement_linux_widget.dart │ └── requirement_windows_widget.dart ├── linux ├── .gitignore ├── CMakeLists.txt ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake ├── main.cc ├── my_application.cc └── my_application.h ├── pubspec.lock ├── pubspec.yaml ├── requirements ├── linux │ └── import_lib.sh └── windows │ ├── .gitkeep │ ├── msvcp140.dll │ ├── vcruntime140.dll │ └── vcruntime140_1.dll ├── script ├── linux │ └── install_release.sh ├── python │ └── getDevices.py └── windows │ └── install_release.bat └── windows ├── .gitignore ├── CMakeLists.txt ├── flutter ├── CMakeLists.txt ├── generated_plugin_registrant.cc ├── generated_plugin_registrant.h └── generated_plugins.cmake └── runner ├── CMakeLists.txt ├── Runner.rc ├── flutter_window.cpp ├── flutter_window.h ├── main.cpp ├── resource.h ├── resources └── app_icon.ico ├── runner.exe.manifest ├── utils.cpp ├── utils.h ├── win32_window.cpp └── win32_window.h /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | branches: [ "dev" ] 6 | 7 | jobs: 8 | linux-ci: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: subosito/flutter-action@v2 # https://github.com/marketplace/actions/flutter-action 13 | with: 14 | channel: 'stable' # or: 'beta', 'dev' or 'master' 15 | - name: Install dependencies 16 | run: flutter pub get 17 | windows-ci: 18 | runs-on: windows-latest 19 | steps: 20 | - uses: actions/checkout@v3 21 | - uses: subosito/flutter-action@v2 # https://github.com/marketplace/actions/flutter-action 22 | with: 23 | channel: 'stable' # or: 'beta', 'dev' or 'master' 24 | - name: Install dependencies 25 | run: flutter pub get 26 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Create releases 2 | 3 | on: 4 | # https://github.com/orgs/community/discussions/27028#discussioncomment-3254360 5 | workflow_dispatch: 6 | 7 | jobs: 8 | release-ubuntu-20: 9 | runs-on: ubuntu-20.04 10 | permissions: 11 | contents: write 12 | steps: 13 | - uses: actions/checkout@v3 14 | with: 15 | fetch-depth: 0 # https://github.com/marketplace/actions/get-latest-tag 16 | - uses: subosito/flutter-action@v2 # https://github.com/marketplace/actions/flutter-action 17 | with: 18 | channel: 'stable' # or: 'beta', 'dev' or 'master' 19 | - name: Install dependencies 20 | run: flutter pub get 21 | - name: Install build dependencies 22 | run: sudo apt install -y ninja-build libgtk-3-dev 23 | - run: flutter doctor 24 | - name: Get tag for release 25 | id: currentTag 26 | uses: WyriHaximus/github-action-get-previous-tag@v1 # https://github.com/marketplace/actions/get-latest-tag 27 | - name: Build release linux 28 | run: flutter build linux --release 29 | - name: Copy script files 30 | run: | 31 | cp -R script build/linux/x64/release/bundle/script 32 | - name: Copy ldd files 33 | run: | 34 | ldd build/linux/x64/release/bundle/DeepFaceLabClient 35 | mv build/linux/x64/release/bundle DeepFaceLabClient-linux 36 | bash requirements/linux/import_lib.sh 37 | - name: Zip release linux 38 | run: | 39 | zip -r DeepFaceLabClient-ubuntu-20-${{ steps.currentTag.outputs.tag }}.zip DeepFaceLabClient-linux 40 | - name: Extract release notes # https://github.com/marketplace/actions/extract-release-notes 41 | id: extract-release-notes 42 | uses: ffurrer2/extract-release-notes@v1 43 | - uses: ncipollo/release-action@v1 # https://github.com/marketplace/actions/create-release 44 | with: 45 | artifacts: DeepFaceLabClient-ubuntu-20-${{ steps.currentTag.outputs.tag }}.zip 46 | tag: ${{ steps.currentTag.outputs.tag }} 47 | name: DeepFaceLabClient-${{ steps.currentTag.outputs.tag }} 48 | allowUpdates: true 49 | body: ${{ steps.extract-release-notes.outputs.release_notes }} 50 | release-ubuntu-22: 51 | runs-on: ubuntu-22.04 52 | permissions: 53 | contents: write 54 | steps: 55 | - uses: actions/checkout@v3 56 | with: 57 | fetch-depth: 0 # https://github.com/marketplace/actions/get-latest-tag 58 | - uses: subosito/flutter-action@v2 # https://github.com/marketplace/actions/flutter-action 59 | with: 60 | channel: 'stable' # or: 'beta', 'dev' or 'master' 61 | - name: Install dependencies 62 | run: flutter pub get 63 | - name: Install build dependencies 64 | run: sudo apt install -y ninja-build libgtk-3-dev 65 | - run: flutter doctor 66 | - name: Get tag for release 67 | id: currentTag 68 | uses: WyriHaximus/github-action-get-previous-tag@v1 # https://github.com/marketplace/actions/get-latest-tag 69 | - name: Build release linux 70 | run: flutter build linux --release 71 | - name: Copy script files 72 | run: | 73 | cp -R script build/linux/x64/release/bundle/script 74 | - name: Copy ldd files 75 | run: | 76 | ldd build/linux/x64/release/bundle/DeepFaceLabClient 77 | mv build/linux/x64/release/bundle DeepFaceLabClient-linux 78 | bash requirements/linux/import_lib.sh 79 | - name: Zip release linux 80 | run: | 81 | zip -r DeepFaceLabClient-ubuntu-22-${{ steps.currentTag.outputs.tag }}.zip DeepFaceLabClient-linux 82 | - name: Extract release notes # https://github.com/marketplace/actions/extract-release-notes 83 | id: extract-release-notes 84 | uses: ffurrer2/extract-release-notes@v1 85 | - uses: ncipollo/release-action@v1 # https://github.com/marketplace/actions/create-release 86 | with: 87 | artifacts: DeepFaceLabClient-ubuntu-22-${{ steps.currentTag.outputs.tag }}.zip 88 | tag: ${{ steps.currentTag.outputs.tag }} 89 | name: DeepFaceLabClient-${{ steps.currentTag.outputs.tag }} 90 | allowUpdates: true 91 | body: ${{ steps.extract-release-notes.outputs.release_notes }} 92 | release-ubuntu-24: 93 | runs-on: ubuntu-24.04 94 | permissions: 95 | contents: write 96 | steps: 97 | - uses: actions/checkout@v3 98 | with: 99 | fetch-depth: 0 # https://github.com/marketplace/actions/get-latest-tag 100 | - uses: subosito/flutter-action@v2 # https://github.com/marketplace/actions/flutter-action 101 | with: 102 | channel: 'stable' # or: 'beta', 'dev' or 'master' 103 | - name: Install dependencies 104 | run: flutter pub get 105 | - name: Install build dependencies 106 | run: sudo apt install -y ninja-build libgtk-3-dev 107 | - run: flutter doctor 108 | - name: Get tag for release 109 | id: currentTag 110 | uses: WyriHaximus/github-action-get-previous-tag@v1 # https://github.com/marketplace/actions/get-latest-tag 111 | - name: Build release linux 112 | run: flutter build linux --release 113 | - name: Copy script files 114 | run: | 115 | cp -R script build/linux/x64/release/bundle/script 116 | - name: Copy ldd files 117 | run: | 118 | ldd build/linux/x64/release/bundle/DeepFaceLabClient 119 | mv build/linux/x64/release/bundle DeepFaceLabClient-linux 120 | bash requirements/linux/import_lib.sh 121 | - name: Zip release linux 122 | run: | 123 | zip -r DeepFaceLabClient-ubuntu-24-${{ steps.currentTag.outputs.tag }}.zip DeepFaceLabClient-linux 124 | - name: Extract release notes # https://github.com/marketplace/actions/extract-release-notes 125 | id: extract-release-notes 126 | uses: ffurrer2/extract-release-notes@v1 127 | - uses: ncipollo/release-action@v1 # https://github.com/marketplace/actions/create-release 128 | with: 129 | artifacts: DeepFaceLabClient-ubuntu-24-${{ steps.currentTag.outputs.tag }}.zip 130 | tag: ${{ steps.currentTag.outputs.tag }} 131 | name: DeepFaceLabClient-${{ steps.currentTag.outputs.tag }} 132 | allowUpdates: true 133 | body: ${{ steps.extract-release-notes.outputs.release_notes }} 134 | release-windows: 135 | runs-on: windows-latest 136 | permissions: 137 | contents: write 138 | steps: 139 | - uses: actions/checkout@v3 140 | with: 141 | fetch-depth: 0 # https://github.com/marketplace/actions/get-latest-tag 142 | - uses: subosito/flutter-action@v2 # https://github.com/marketplace/actions/flutter-action 143 | with: 144 | channel: 'stable' # or: 'beta', 'dev' or 'master' 145 | - name: Install dependencies 146 | run: flutter pub get 147 | - run: flutter doctor 148 | - name: Get tag for release 149 | id: currentTag 150 | uses: WyriHaximus/github-action-get-previous-tag@v1 # https://github.com/marketplace/actions/get-latest-tag 151 | - name: Build release windows 152 | run: flutter build windows --release 153 | - name: Copy dll files 154 | run: | 155 | copy C:\Windows\System32\msvcp140.dll build\windows\x64\runner\Release 156 | copy C:\Windows\System32\vcruntime140.dll build\windows\x64\runner\Release 157 | copy C:\Windows\System32\vcruntime140_1.dll build\windows\x64\runner\Release 158 | - name: Copy script files 159 | run: | 160 | mkdir .\build\windows\x64\runner\Release\script\ 161 | xcopy .\script\ .\build\windows\x64\runner\Release\script\ /e 162 | - name: Zip release windows 163 | run: | 164 | move build/windows/x64/runner/Release DeepFaceLabClient-windows 165 | 7z a -r DeepFaceLabClient-windows-${{ steps.currentTag.outputs.tag }}.zip DeepFaceLabClient-windows 166 | - name: Extract release notes # https://github.com/marketplace/actions/extract-release-notes 167 | id: extract-release-notes 168 | uses: ffurrer2/extract-release-notes@v1 169 | - uses: ncipollo/release-action@v1 # https://github.com/marketplace/actions/create-release 170 | with: 171 | artifacts: DeepFaceLabClient-windows-${{ steps.currentTag.outputs.tag }}.zip 172 | tag: ${{ steps.currentTag.outputs.tag }} 173 | name: DeepFaceLabClient-${{ steps.currentTag.outputs.tag }} 174 | allowUpdates: true 175 | body: ${{ steps.extract-release-notes.outputs.release_notes }} 176 | -------------------------------------------------------------------------------- /.github/workflows/tag.yml: -------------------------------------------------------------------------------- 1 | name: Create tag 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | 7 | jobs: 8 | create-tag: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | with: 13 | fetch-depth: 2 # https://github.com/marketplace/actions/detect-and-tag-new-version#usage 14 | - uses: salsify/action-detect-and-tag-new-version@v2 # https://github.com/marketplace/actions/detect-and-tag-new-version#usage 15 | with: 16 | version-command: | 17 | yq '.version' pubspec.yaml 18 | 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/api/ 26 | **/ios/Flutter/.last_build_id 27 | .dart_tool/ 28 | .flutter-plugins 29 | .flutter-plugins-dependencies 30 | .packages 31 | .pub-cache/ 32 | .pub/ 33 | /build/ 34 | 35 | # Symbolication related 36 | app.*.symbols 37 | 38 | # Obfuscation related 39 | app.*.map.json 40 | 41 | # Android Studio will place build artifacts here 42 | /android/app/debug 43 | /android/app/profile 44 | /android/app/release 45 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled. 5 | 6 | version: 7 | revision: 2ad6cd72c040113b47ee9055e722606a490ef0da 8 | channel: stable 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da 17 | base_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da 18 | - platform: linux 19 | create_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da 20 | base_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da 21 | - platform: windows 22 | create_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da 23 | base_revision: 2ad6cd72c040113b47ee9055e722606a490ef0da 24 | 25 | # User provided section 26 | 27 | # List of Local paths (relative to this file) that should be 28 | # ignored by the migrate tool. 29 | # 30 | # Files that are not part of the templates will be ignored by default. 31 | unmanaged_files: 32 | - 'lib/main.dart' 33 | - 'ios/Runner.xcodeproj/project.pbxproj' 34 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [Unreleased] 4 | 5 | ### Added 6 | 7 | ### Fixed 8 | 9 | ### Changed 10 | 11 | ### Removed 12 | 13 | ## [0.4.4] - 2024-10-21 14 | 15 | ### Fixed 16 | 17 | - Can click the links on the releases. 18 | 19 | ## [0.4.3] - 2024-10-21 20 | 21 | ### Fixed 22 | 23 | - Fix GPU not showing up on Windows, thanks to [Lumerica](https://github.com/Lenny4/DeepFaceLabClient/issues/73#issuecomment-2424318499). 24 | 25 | ## [0.4.2] - 2023-09-16 26 | 27 | ### Fixed 28 | 29 | - Fix release windows. 30 | 31 | ## [0.4.1] - 2023-09-16 32 | 33 | ### Added 34 | 35 | - Add release for ubuntu 24. 36 | 37 | 38 | ## [0.4.0] - 2023-09-16 39 | 40 | ### Changed 41 | 42 | - On Linux source files are no longer downloaded from [DeepFaceLab](https://github.com/iperov/DeepFaceLab) as project as been shutdown by github. 43 | 44 | ## [0.3.0] - 2023-06-20 45 | 46 | ### Added 47 | 48 | - Add self promotion on the home screen and help screen 49 | - Add more info on release (download count, release date) 50 | 51 | ### Changed 52 | 53 | - Copy `msvcp140.dll` `vcruntime140.dll` and `vcruntime140_1.dll` directly from the github host ( 54 | windows) 55 | 56 | see `Copy dll files` in `.github/workflows/release.yml` 57 | - Change screen `Tutorials` to `Help` and add more useful links 58 | 59 | ## [0.2.0] - 2023-06-18 60 | 61 | ### Added 62 | 63 | - Show the size of all folders in workspace 64 | 65 | ## [0.1.2] - 2023-06-14 66 | 67 | Note: need to install it manually from the github if on windows. 68 | 69 | ### Fixed 70 | 71 | - Fix the bug on windows which erased DeepFaceLabClient when trying to install a release (/!\ the 72 | bug is still present in earlier versions) 73 | 74 | ## [0.1.1] - 2023-06-13 75 | 76 | Note: on this version installing another release doesn't work (on windows), you need to install it 77 | manually from the github. 78 | 79 | ### Fixed 80 | 81 | - Fix download Miniconda3-latest-Linux-x86_64.sh with no certificate 82 | 83 | ## [0.1.0] - 2023-06-12 84 | 85 | Note: on this version installing another release doesn't work (on windows), you need to install it 86 | manually from the github. 87 | 88 | ### Added 89 | 90 | - Install requirements (linux) 91 | - Install Deepfacelab 92 | - Create workspaces 93 | - Delete workspaces 94 | - Filesystem navigation (rename, delete, navigate in folders) + Shortcuts 95 | - Show GPUs of the host 96 | - Can change theme appearance (dark theme, light theme) 97 | - Launch Deepfacelab scripts 98 | - See and install releases 99 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/:vendor/:package_name). 6 | 7 | ## How to run the project 8 | 9 | - Please follow the [instructions](https://docs.flutter.dev/get-started/install) to install flutter 10 | - Fork the project 11 | - Clone the project locally `git@github.com:%yourUser%/%yourTepo%.git` 12 | - Install dependencies `flutter pub get` 13 | - It is recommended to run `flutter pub run build_runner watch --delete-conflicting-outputs` each 14 | time you run the app ( 15 | [more info](https://pub.dev/packages/json_serializable#running-the-code-generator)) 16 | - Run the code in Android studio 17 | 18 | ## Pull Requests 19 | 20 | - All pull requests must be made on `dev` branch. 21 | 22 | ## Running Tests 23 | 24 | todo 25 | 26 | **Happy coding**! -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DeepFaceLabClient 2 | 3 | Just an app to use [DeepFaceLab](https://github.com/iperov/DeepFaceLab) with a user interface. 4 | 5 | ![DeepFaceLabClient preview](docs/DeepFaceLabClientWorkspace.png) 6 | 7 | ## Requirements 8 | 9 | Linux or Windows 10/11 10 | 11 | ## Install 12 | 13 | Go to the [release page](https://github.com/Lenny4/DeepFaceLabClient/releases) and download the 14 | latest release in the `Assets` section. Once downloaded just start `DeepFaceLabClient.exe` on windows 15 | or `DeepFaceLabClient` on linux. 16 | 17 | On windows you might have this message when starting DeepFaceLabClient 18 | 19 | Click on "More info" and click on "Run anyway" 20 | 21 | ![windows protected your pc](docs/windows-protected-your-pc.png) 22 | 23 | ## Change log 24 | 25 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 26 | 27 | ## Testing 28 | 29 | todo 30 | 31 | ## Contributing 32 | 33 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 34 | 35 | ## License 36 | 37 | The GPL License. Please see [License File](LICENSE.md) for more information. 38 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /docs/DeepFaceLabClientWorkspace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lenny4/DeepFaceLabClient/8323c9df12d39624b030572784c977985dd2ee3b/docs/DeepFaceLabClientWorkspace.png -------------------------------------------------------------------------------- /docs/windows-protected-your-pc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lenny4/DeepFaceLabClient/8323c9df12d39624b030572784c977985dd2ee3b/docs/windows-protected-your-pc.png -------------------------------------------------------------------------------- /lib/class/action/switch_theme_action.dart: -------------------------------------------------------------------------------- 1 | class SwitchThemeAction {} 2 | -------------------------------------------------------------------------------- /lib/class/answer.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'answer.g.dart'; 4 | 5 | @JsonSerializable() 6 | class Answer { 7 | String value; 8 | String question; 9 | 10 | Answer({ 11 | required this.value, 12 | required this.question, 13 | }); 14 | 15 | factory Answer.fromJson(Map json) => _$AnswerFromJson(json); 16 | 17 | Map toJson() => _$AnswerToJson(this); 18 | } 19 | -------------------------------------------------------------------------------- /lib/class/answer.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'answer.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | Answer _$AnswerFromJson(Map json) => Answer( 10 | value: json['value'] as String, 11 | question: json['question'] as String, 12 | ); 13 | 14 | Map _$AnswerToJson(Answer instance) => { 15 | 'value': instance.value, 16 | 'question': instance.question, 17 | }; 18 | -------------------------------------------------------------------------------- /lib/class/app_state.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/action/switch_theme_action.dart'; 2 | import 'package:deepfacelab_client/class/device.dart'; 3 | import 'package:deepfacelab_client/class/release.dart'; 4 | import 'package:deepfacelab_client/class/storage.dart'; 5 | import 'package:flutter/material.dart'; 6 | import 'package:package_info_plus/package_info_plus.dart'; 7 | import 'package:redux/redux.dart' as redux; 8 | 9 | @immutable 10 | class AppState { 11 | final bool init; 12 | final bool hasRequirements; 13 | final int selectedScreenIndex; 14 | final List? devices; 15 | final Storage? storage; 16 | final PackageInfo? packageInfo; 17 | final List? releases; 18 | final bool canLoadMoreReleases; 19 | final int pageRelease; 20 | 21 | const AppState({ 22 | required this.init, 23 | required this.hasRequirements, 24 | required this.selectedScreenIndex, 25 | required this.storage, 26 | required this.devices, 27 | required this.packageInfo, 28 | required this.releases, 29 | required this.canLoadMoreReleases, 30 | required this.pageRelease, 31 | }); 32 | 33 | factory AppState.initial() { 34 | return const AppState( 35 | init: false, 36 | hasRequirements: false, 37 | storage: null, 38 | devices: null, 39 | selectedScreenIndex: 0, 40 | packageInfo: null, 41 | releases: null, 42 | canLoadMoreReleases: false, 43 | pageRelease: 1, 44 | ); 45 | } 46 | 47 | AppState copyWith(newState) { 48 | return AppState( 49 | init: newState['init'] ?? init, 50 | hasRequirements: newState['hasRequirements'] ?? hasRequirements, 51 | selectedScreenIndex: 52 | newState['selectedScreenIndex'] ?? selectedScreenIndex, 53 | storage: newState['storage'] ?? storage, 54 | devices: newState['devices'] ?? devices, 55 | packageInfo: newState['packageInfo'] ?? packageInfo, 56 | releases: newState['releases'] ?? releases, 57 | canLoadMoreReleases: 58 | newState['canLoadMoreReleases'] ?? canLoadMoreReleases, 59 | pageRelease: newState['pageRelease'] ?? pageRelease, 60 | ); 61 | } 62 | } 63 | 64 | AppState appStateReducer(AppState state, action) { 65 | if (action is SwitchThemeAction) { 66 | var storage = state.storage; 67 | if (storage != null) { 68 | storage.darkMode = !(storage.darkMode ?? true); 69 | } 70 | return state; 71 | } else { 72 | return state.copyWith(action); 73 | } 74 | } 75 | 76 | final store = redux.Store( 77 | appStateReducer, 78 | initialState: AppState.initial(), 79 | ); 80 | -------------------------------------------------------------------------------- /lib/class/conda_env_list.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'conda_env_list.g.dart'; 4 | 5 | @JsonSerializable() 6 | class CondaEnvList { 7 | CondaEnvList(this.envs); 8 | 9 | List envs; 10 | 11 | factory CondaEnvList.fromJson(Map json) => 12 | _$CondaEnvListFromJson(json); 13 | 14 | Map toJson() => _$CondaEnvListToJson(this); 15 | } 16 | -------------------------------------------------------------------------------- /lib/class/conda_env_list.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'conda_env_list.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | CondaEnvList _$CondaEnvListFromJson(Map json) => CondaEnvList( 10 | (json['envs'] as List).map((e) => e as String).toList(), 11 | ); 12 | 13 | Map _$CondaEnvListToJson(CondaEnvList instance) => 14 | { 15 | 'envs': instance.envs, 16 | }; 17 | -------------------------------------------------------------------------------- /lib/class/deepfacelab_command_group.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/window_command.dart'; 2 | import 'package:flutter/widgets.dart'; 3 | 4 | class DeepfacelabCommandGroup { 5 | String name; 6 | List windowCommands; 7 | Widget icon; 8 | 9 | DeepfacelabCommandGroup({ 10 | required this.name, 11 | required this.windowCommands, 12 | required this.icon, 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /lib/class/device.dart: -------------------------------------------------------------------------------- 1 | class Device { 2 | Device(this.index, this.tfDevType, this.name, this.totalMem, this.totalMemGb, 3 | this.freeMem, this.freeMemGb); 4 | 5 | int index; 6 | String tfDevType; 7 | String name; 8 | double totalMem; 9 | double totalMemGb; 10 | double freeMem; 11 | double freeMemGb; 12 | 13 | factory Device.fromJson(Map json) => Device( 14 | json['index'] as int, 15 | json['tf_dev_type'] as String, 16 | json['name'] as String, 17 | (json['total_mem'] as num).toDouble(), 18 | (json['total_mem_gb'] as num).toDouble(), 19 | (json['free_mem'] as num).toDouble(), 20 | (json['free_mem_gb'] as num).toDouble(), 21 | ); 22 | 23 | Map toJson() => { 24 | 'index': index, 25 | 'tf_dev_type': tfDevType, 26 | 'name': name, 27 | 'total_mem': totalMem, 28 | 'total_mem_gb': totalMemGb, 29 | 'free_mem': freeMem, 30 | 'free_mem_gb': freeMemGb, 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /lib/class/folder_property.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'folder_property.g.dart'; 4 | 5 | @JsonSerializable() 6 | class FolderProperty { 7 | int? size; 8 | String path; 9 | int? nbChildren; 10 | List folderProperties; 11 | 12 | FolderProperty( 13 | {this.size, 14 | required this.path, 15 | this.nbChildren, 16 | required this.folderProperties}); 17 | 18 | factory FolderProperty.fromJson(Map json) => 19 | _$FolderPropertyFromJson(json); 20 | 21 | Map toJson() => _$FolderPropertyToJson(this); 22 | } 23 | -------------------------------------------------------------------------------- /lib/class/folder_property.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'folder_property.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | FolderProperty _$FolderPropertyFromJson(Map json) => 10 | FolderProperty( 11 | size: json['size'] as int?, 12 | path: json['path'] as String, 13 | nbChildren: json['nbChildren'] as int?, 14 | folderProperties: (json['folderProperties'] as List) 15 | .map((e) => FolderProperty.fromJson(e as Map)) 16 | .toList(), 17 | ); 18 | 19 | Map _$FolderPropertyToJson(FolderProperty instance) => 20 | { 21 | 'size': instance.size, 22 | 'path': instance.path, 23 | 'nbChildren': instance.nbChildren, 24 | 'folderProperties': instance.folderProperties, 25 | }; 26 | -------------------------------------------------------------------------------- /lib/class/locale_storage_question.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/locale_storage_question_child.dart'; 2 | import 'package:json_annotation/json_annotation.dart'; 3 | 4 | part 'locale_storage_question.g.dart'; 5 | 6 | @JsonSerializable() 7 | class LocaleStorageQuestion { 8 | String key; 9 | List questions; 10 | 11 | LocaleStorageQuestion({ 12 | required this.key, 13 | required this.questions, 14 | }); 15 | 16 | factory LocaleStorageQuestion.fromJson(Map json) => 17 | _$LocaleStorageQuestionFromJson(json); 18 | 19 | Map toJson() => _$LocaleStorageQuestionToJson(this); 20 | } 21 | -------------------------------------------------------------------------------- /lib/class/locale_storage_question.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'locale_storage_question.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | LocaleStorageQuestion _$LocaleStorageQuestionFromJson( 10 | Map json) => 11 | LocaleStorageQuestion( 12 | key: json['key'] as String, 13 | questions: (json['questions'] as List) 14 | .map((e) => 15 | LocaleStorageQuestionChild.fromJson(e as Map)) 16 | .toList(), 17 | ); 18 | 19 | Map _$LocaleStorageQuestionToJson( 20 | LocaleStorageQuestion instance) => 21 | { 22 | 'key': instance.key, 23 | 'questions': instance.questions, 24 | }; 25 | -------------------------------------------------------------------------------- /lib/class/locale_storage_question_child.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'locale_storage_question_child.g.dart'; 4 | 5 | @JsonSerializable() 6 | class LocaleStorageQuestionChild { 7 | String question; 8 | String answer; 9 | 10 | LocaleStorageQuestionChild({ 11 | required this.question, 12 | required this.answer, 13 | }); 14 | 15 | factory LocaleStorageQuestionChild.fromJson(Map json) => 16 | _$LocaleStorageQuestionChildFromJson(json); 17 | 18 | Map toJson() => _$LocaleStorageQuestionChildToJson(this); 19 | } 20 | -------------------------------------------------------------------------------- /lib/class/locale_storage_question_child.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'locale_storage_question_child.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | LocaleStorageQuestionChild _$LocaleStorageQuestionChildFromJson( 10 | Map json) => 11 | LocaleStorageQuestionChild( 12 | question: json['question'] as String, 13 | answer: json['answer'] as String, 14 | ); 15 | 16 | Map _$LocaleStorageQuestionChildToJson( 17 | LocaleStorageQuestionChild instance) => 18 | { 19 | 'question': instance.question, 20 | 'answer': instance.answer, 21 | }; 22 | -------------------------------------------------------------------------------- /lib/class/question.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/valid_answer_regex.dart'; 2 | import 'package:json_annotation/json_annotation.dart'; 3 | 4 | part 'question.g.dart'; 5 | 6 | @JsonSerializable() 7 | class Question { 8 | String text; 9 | String question; 10 | String help; 11 | List? validAnswerRegex; 12 | String? answer; 13 | String defaultAnswer; 14 | List? options; 15 | 16 | Question({ 17 | required this.text, 18 | required this.question, 19 | required this.help, 20 | this.validAnswerRegex, 21 | this.answer = '', 22 | required this.defaultAnswer, 23 | this.options, 24 | }); 25 | 26 | factory Question.fromJson(Map json) => 27 | _$QuestionFromJson(json); 28 | 29 | Map toJson() => _$QuestionToJson(this); 30 | } 31 | -------------------------------------------------------------------------------- /lib/class/question.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'question.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | Question _$QuestionFromJson(Map json) => Question( 10 | text: json['text'] as String, 11 | question: json['question'] as String, 12 | help: json['help'] as String, 13 | validAnswerRegex: (json['validAnswerRegex'] as List?) 14 | ?.map((e) => ValidAnswerRegex.fromJson(e as Map)) 15 | .toList(), 16 | answer: json['answer'] as String? ?? '', 17 | defaultAnswer: json['defaultAnswer'] as String, 18 | options: 19 | (json['options'] as List?)?.map((e) => e as String).toList(), 20 | ); 21 | 22 | Map _$QuestionToJson(Question instance) => { 23 | 'text': instance.text, 24 | 'question': instance.question, 25 | 'help': instance.help, 26 | 'validAnswerRegex': instance.validAnswerRegex, 27 | 'answer': instance.answer, 28 | 'defaultAnswer': instance.defaultAnswer, 29 | 'options': instance.options, 30 | }; 31 | -------------------------------------------------------------------------------- /lib/class/release.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/release_asset.dart'; 2 | import 'package:json_annotation/json_annotation.dart'; 3 | 4 | part 'release.g.dart'; 5 | 6 | @JsonSerializable() 7 | class Release { 8 | String body; 9 | @JsonKey(name: 'tag_name') 10 | String tagName; 11 | List assets; 12 | @JsonKey(name: 'published_at') 13 | DateTime publishedAt; 14 | 15 | Release({ 16 | required this.body, 17 | required this.assets, 18 | required this.tagName, 19 | required this.publishedAt, 20 | }); 21 | 22 | factory Release.fromJson(Map json) => 23 | _$ReleaseFromJson(json); 24 | 25 | Map toJson() => _$ReleaseToJson(this); 26 | } 27 | -------------------------------------------------------------------------------- /lib/class/release.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'release.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | Release _$ReleaseFromJson(Map json) => Release( 10 | body: json['body'] as String, 11 | assets: (json['assets'] as List) 12 | .map((e) => ReleaseAsset.fromJson(e as Map)) 13 | .toList(), 14 | tagName: json['tag_name'] as String, 15 | publishedAt: DateTime.parse(json['published_at'] as String), 16 | ); 17 | 18 | Map _$ReleaseToJson(Release instance) => { 19 | 'body': instance.body, 20 | 'tag_name': instance.tagName, 21 | 'assets': instance.assets, 22 | 'published_at': instance.publishedAt.toIso8601String(), 23 | }; 24 | -------------------------------------------------------------------------------- /lib/class/release_asset.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'release_asset.g.dart'; 4 | 5 | @JsonSerializable() 6 | class ReleaseAsset { 7 | @JsonKey(name: 'browser_download_url') 8 | String browserDownloadUrl; 9 | String name; 10 | @JsonKey(name: 'download_count') 11 | int downloadCount; 12 | 13 | ReleaseAsset({ 14 | required this.browserDownloadUrl, 15 | required this.name, 16 | required this.downloadCount, 17 | }); 18 | 19 | factory ReleaseAsset.fromJson(Map json) => 20 | _$ReleaseAssetFromJson(json); 21 | 22 | Map toJson() => _$ReleaseAssetToJson(this); 23 | } 24 | -------------------------------------------------------------------------------- /lib/class/release_asset.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'release_asset.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | ReleaseAsset _$ReleaseAssetFromJson(Map json) => ReleaseAsset( 10 | browserDownloadUrl: json['browser_download_url'] as String, 11 | name: json['name'] as String, 12 | downloadCount: json['download_count'] as int, 13 | ); 14 | 15 | Map _$ReleaseAssetToJson(ReleaseAsset instance) => 16 | { 17 | 'browser_download_url': instance.browserDownloadUrl, 18 | 'name': instance.name, 19 | 'download_count': instance.downloadCount, 20 | }; 21 | -------------------------------------------------------------------------------- /lib/class/source.dart: -------------------------------------------------------------------------------- 1 | class Source { 2 | static List types = ['src', 'dst']; 3 | static String replace = "%source%"; 4 | } 5 | -------------------------------------------------------------------------------- /lib/class/start_process.dart: -------------------------------------------------------------------------------- 1 | class StartProcess { 2 | String executable; 3 | List arguments; 4 | List? similarMessageRegex; 5 | 6 | StartProcess( 7 | {required this.executable, 8 | required this.arguments, 9 | this.similarMessageRegex}); 10 | 11 | @override 12 | String toString() { 13 | return "$executable ${arguments.join(' ')}"; 14 | } 15 | } 16 | 17 | class StartProcessConda { 18 | String command; 19 | String? Function(String)? getAnswer; 20 | List? similarMessageRegex; 21 | 22 | StartProcessConda( 23 | {required this.command, this.getAnswer, this.similarMessageRegex}); 24 | 25 | @override 26 | String toString() { 27 | return command; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/class/storage.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/workspace.dart'; 2 | import 'package:json_annotation/json_annotation.dart'; 3 | 4 | part 'storage.g.dart'; 5 | 6 | @JsonSerializable() 7 | class Storage { 8 | String? deepFaceLabFolder; 9 | String? workspaceDefaultPath; 10 | List? workspaces; 11 | bool? darkMode; 12 | 13 | Storage({this.deepFaceLabFolder, this.workspaceDefaultPath, this.workspaces, this.darkMode}); 14 | 15 | factory Storage.fromJson(Map json) => 16 | _$StorageFromJson(json); 17 | 18 | Map toJson() => _$StorageToJson(this); 19 | } 20 | -------------------------------------------------------------------------------- /lib/class/storage.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'storage.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | Storage _$StorageFromJson(Map json) => Storage( 10 | deepFaceLabFolder: json['deepFaceLabFolder'] as String?, 11 | workspaceDefaultPath: json['workspaceDefaultPath'] as String?, 12 | workspaces: (json['workspaces'] as List?) 13 | ?.map((e) => Workspace.fromJson(e as Map)) 14 | .toList(), 15 | darkMode: json['darkMode'] as bool?, 16 | ); 17 | 18 | Map _$StorageToJson(Storage instance) => { 19 | 'deepFaceLabFolder': instance.deepFaceLabFolder, 20 | 'workspaceDefaultPath': instance.workspaceDefaultPath, 21 | 'workspaces': instance.workspaces, 22 | 'darkMode': instance.darkMode, 23 | }; 24 | -------------------------------------------------------------------------------- /lib/class/valid_answer_regex.dart: -------------------------------------------------------------------------------- 1 | import 'package:json_annotation/json_annotation.dart'; 2 | 3 | part 'valid_answer_regex.g.dart'; 4 | 5 | @JsonSerializable() 6 | class ValidAnswerRegex { 7 | String? regex; 8 | double? min; 9 | double? max; 10 | String errorMessage; 11 | 12 | ValidAnswerRegex({ 13 | this.regex, 14 | this.min, 15 | this.max, 16 | required this.errorMessage, 17 | }); 18 | 19 | factory ValidAnswerRegex.fromJson(Map json) => 20 | _$ValidAnswerRegexFromJson(json); 21 | 22 | Map toJson() => _$ValidAnswerRegexToJson(this); 23 | } 24 | -------------------------------------------------------------------------------- /lib/class/valid_answer_regex.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'valid_answer_regex.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | ValidAnswerRegex _$ValidAnswerRegexFromJson(Map json) => 10 | ValidAnswerRegex( 11 | regex: json['regex'] as String?, 12 | min: (json['min'] as num?)?.toDouble(), 13 | max: (json['max'] as num?)?.toDouble(), 14 | errorMessage: json['errorMessage'] as String, 15 | ); 16 | 17 | Map _$ValidAnswerRegexToJson(ValidAnswerRegex instance) => 18 | { 19 | 'regex': instance.regex, 20 | 'min': instance.min, 21 | 'max': instance.max, 22 | 'errorMessage': instance.errorMessage, 23 | }; 24 | -------------------------------------------------------------------------------- /lib/class/window_command.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/question.dart'; 2 | import 'package:deepfacelab_client/class/workspace.dart'; 3 | import 'package:json_annotation/json_annotation.dart'; 4 | 5 | part 'window_command.g.dart'; 6 | 7 | @JsonSerializable() 8 | class WindowCommand { 9 | String windowTitle; 10 | String title; 11 | String key; 12 | String documentationLink; 13 | String command; 14 | bool loading; 15 | String source; 16 | bool multipleSource; 17 | List questions; 18 | List similarMessageRegex; 19 | Workspace? workspace; 20 | 21 | WindowCommand({ 22 | required this.windowTitle, 23 | required this.title, 24 | required this.key, 25 | required this.documentationLink, 26 | required this.command, 27 | required this.loading, 28 | this.source = "", 29 | required this.multipleSource, // if command can be launch on src and dst (display src and dst buttons) 30 | required this.questions, 31 | required this.similarMessageRegex, 32 | required this.workspace, 33 | }); 34 | 35 | factory WindowCommand.fromJson(Map json) => 36 | _$WindowCommandFromJson(json); 37 | 38 | Map toJson() => _$WindowCommandToJson(this); 39 | } 40 | -------------------------------------------------------------------------------- /lib/class/window_command.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'window_command.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | WindowCommand _$WindowCommandFromJson(Map json) => 10 | WindowCommand( 11 | windowTitle: json['windowTitle'] as String, 12 | title: json['title'] as String, 13 | key: json['key'] as String, 14 | documentationLink: json['documentationLink'] as String, 15 | command: json['command'] as String, 16 | loading: json['loading'] as bool, 17 | source: json['source'] as String? ?? "", 18 | multipleSource: json['multipleSource'] as bool, 19 | questions: (json['questions'] as List) 20 | .map((e) => Question.fromJson(e as Map)) 21 | .toList(), 22 | similarMessageRegex: (json['similarMessageRegex'] as List) 23 | .map((e) => e as String) 24 | .toList(), 25 | workspace: json['workspace'] == null 26 | ? null 27 | : Workspace.fromJson(json['workspace'] as Map), 28 | ); 29 | 30 | Map _$WindowCommandToJson(WindowCommand instance) => 31 | { 32 | 'windowTitle': instance.windowTitle, 33 | 'title': instance.title, 34 | 'key': instance.key, 35 | 'documentationLink': instance.documentationLink, 36 | 'command': instance.command, 37 | 'loading': instance.loading, 38 | 'source': instance.source, 39 | 'multipleSource': instance.multipleSource, 40 | 'questions': instance.questions, 41 | 'similarMessageRegex': instance.similarMessageRegex, 42 | 'workspace': instance.workspace, 43 | }; 44 | -------------------------------------------------------------------------------- /lib/class/workspace.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/folder_property.dart'; 2 | import 'package:deepfacelab_client/class/locale_storage_question.dart'; 3 | import 'package:json_annotation/json_annotation.dart'; 4 | 5 | part 'workspace.g.dart'; 6 | 7 | @JsonSerializable() 8 | class Workspace { 9 | String name; 10 | String path; 11 | List? localeStorageQuestions; 12 | FolderProperty? folderProperty; 13 | 14 | Workspace( 15 | {required this.name, 16 | required this.path, 17 | this.localeStorageQuestions, 18 | this.folderProperty}); 19 | 20 | factory Workspace.fromJson(Map json) => 21 | _$WorkspaceFromJson(json); 22 | 23 | Map toJson() => _$WorkspaceToJson(this); 24 | } 25 | -------------------------------------------------------------------------------- /lib/class/workspace.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'workspace.dart'; 4 | 5 | // ************************************************************************** 6 | // JsonSerializableGenerator 7 | // ************************************************************************** 8 | 9 | Workspace _$WorkspaceFromJson(Map json) => Workspace( 10 | name: json['name'] as String, 11 | path: json['path'] as String, 12 | localeStorageQuestions: (json['localeStorageQuestions'] as List?) 13 | ?.map( 14 | (e) => LocaleStorageQuestion.fromJson(e as Map)) 15 | .toList(), 16 | folderProperty: json['folderProperty'] == null 17 | ? null 18 | : FolderProperty.fromJson( 19 | json['folderProperty'] as Map), 20 | ); 21 | 22 | Map _$WorkspaceToJson(Workspace instance) => { 23 | 'name': instance.name, 24 | 'path': instance.path, 25 | 'localeStorageQuestions': instance.localeStorageQuestions, 26 | 'folderProperty': instance.folderProperty, 27 | }; 28 | -------------------------------------------------------------------------------- /lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:collection/collection.dart'; 4 | import 'package:deepfacelab_client/class/app_state.dart'; 5 | import 'package:deepfacelab_client/class/storage.dart'; 6 | import 'package:deepfacelab_client/class/window_command.dart'; 7 | import 'package:deepfacelab_client/class/workspace.dart'; 8 | import 'package:deepfacelab_client/screens/dashboard_screen.dart'; 9 | import 'package:deepfacelab_client/screens/help_screen.dart'; 10 | import 'package:deepfacelab_client/screens/loading_screen.dart'; 11 | import 'package:deepfacelab_client/screens/settings_screen.dart'; 12 | import 'package:deepfacelab_client/screens/window_command_screen.dart'; 13 | import 'package:deepfacelab_client/screens/workspace_screen.dart'; 14 | import 'package:deepfacelab_client/service/locale_storage_service.dart'; 15 | import 'package:deepfacelab_client/widget/installation/has_requirements_widget.dart'; 16 | import 'package:file_sizes/file_sizes.dart'; 17 | import 'package:filesystem_picker/filesystem_picker.dart'; 18 | import 'package:flutter/material.dart'; 19 | import 'package:flutter_hooks/flutter_hooks.dart'; 20 | import 'package:flutter_markdown/flutter_markdown.dart'; 21 | import 'package:flutter_redux_hooks/flutter_redux_hooks.dart'; 22 | import 'package:package_info_plus/package_info_plus.dart'; 23 | import 'package:redux/redux.dart' as redux; 24 | import 'package:url_launcher/url_launcher.dart'; 25 | 26 | void main(List args) { 27 | if (args.firstOrNull == 'multi_window') { 28 | var windowCommand = 29 | WindowCommand.fromJson(jsonDecode(args[2]) as Map); 30 | runApp(WindowCommandScreen( 31 | store: store, 32 | windowCommand: windowCommand, 33 | )); 34 | return; 35 | } 36 | store.onChange.listen((AppState appState) { 37 | if (appState.init == true && appState.storage != null) { 38 | LocaleStorageService().writeStorage(appState.storage!.toJson()); 39 | } 40 | }); 41 | 42 | runApp(MyApp( 43 | store: store, 44 | )); 45 | } 46 | 47 | class MyApp extends HookWidget { 48 | final redux.Store store; 49 | 50 | const MyApp({Key? key, required this.store}) : super(key: key); 51 | 52 | @override 53 | Widget build(BuildContext context) { 54 | return FilesystemPickerDefaultOptions( 55 | fileTileSelectMode: FileTileSelectMode.wholeTile, 56 | child: StoreProvider( 57 | store: store, 58 | child: const Root(), 59 | ), 60 | ); 61 | } 62 | } 63 | 64 | class NavigationRailElement { 65 | NavigationRailDestination destination; 66 | Widget widget; 67 | 68 | NavigationRailElement({required this.destination, required this.widget}); 69 | } 70 | 71 | class Root extends HookWidget { 72 | const Root({Key? key}) : super(key: key); 73 | 74 | // This widget is the root of your application. 75 | @override 76 | Widget build(BuildContext context) { 77 | final darkMode = 78 | useSelector((state) => state.storage?.darkMode); 79 | final workspaces = useSelector?>( 80 | (state) => state.storage?.workspaces); 81 | final init = useSelector((state) => state.init); 82 | final selectedScreenIndex = 83 | useSelector((state) => state.selectedScreenIndex); 84 | final hasRequirements = 85 | useSelector((state) => state.hasRequirements); 86 | final deepFaceLabFolder = useSelector( 87 | (state) => state.storage?.deepFaceLabFolder); 88 | final packageInfo = 89 | useSelector((state) => state.packageInfo); 90 | final dispatch = useDispatch(); 91 | 92 | List getViews() { 93 | List result = [ 94 | NavigationRailElement( 95 | destination: const NavigationRailDestination( 96 | icon: Icon(Icons.dashboard), 97 | selectedIcon: Icon(Icons.dashboard), 98 | label: Text('Dashboard'), 99 | ), 100 | widget: const DashboardScreen()), 101 | NavigationRailElement( 102 | destination: const NavigationRailDestination( 103 | icon: Icon(Icons.add), 104 | selectedIcon: Icon(Icons.add), 105 | label: Text('Create a workspace'), 106 | ), 107 | widget: const WorkspaceScreen()), 108 | ]; 109 | if (init == true && workspaces != null) { 110 | for (Workspace workspace in workspaces) { 111 | result.add( 112 | NavigationRailElement( 113 | destination: NavigationRailDestination( 114 | icon: const Icon(Icons.movie), 115 | selectedIcon: const Icon(Icons.movie), 116 | label: Text( 117 | '${workspace.name}\n${FileSize.getSize(workspace.folderProperty?.size ?? 0)}'), 118 | ), 119 | widget: WorkspaceScreen(initWorkspace: workspace)), 120 | ); 121 | } 122 | } 123 | result.add( 124 | NavigationRailElement( 125 | destination: const NavigationRailDestination( 126 | icon: Icon(Icons.settings), 127 | selectedIcon: Icon(Icons.settings), 128 | label: Text('Settings'), 129 | ), 130 | widget: const SettingsScreen()), 131 | ); 132 | result.add( 133 | NavigationRailElement( 134 | destination: const NavigationRailDestination( 135 | icon: Icon(Icons.lightbulb), 136 | selectedIcon: Icon(Icons.lightbulb), 137 | label: Text('Help'), 138 | ), 139 | widget: const HelpScreen()), 140 | ); 141 | return result; 142 | } 143 | 144 | var views = useState>(getViews()); 145 | 146 | initWidget() async { 147 | dispatch({ 148 | 'init': true, 149 | 'storage': Storage.fromJson(await LocaleStorageService().readStorage()), 150 | 'packageInfo': await PackageInfo.fromPlatform(), 151 | }); 152 | } 153 | 154 | useEffect(() { 155 | initWidget(); 156 | return null; 157 | }, []); 158 | 159 | useEffect(() { 160 | views.value = getViews(); 161 | return null; 162 | }, [workspaces]); 163 | 164 | return MaterialApp( 165 | theme: darkMode != false ? ThemeData.dark() : ThemeData.light(), 166 | themeMode: darkMode != false ? ThemeMode.dark : ThemeMode.light, 167 | home: init == true 168 | ? Row( 169 | children: [ 170 | LayoutBuilder( 171 | builder: (context, constraint) { 172 | return SingleChildScrollView( 173 | child: ConstrainedBox( 174 | constraints: BoxConstraints( 175 | minHeight: constraint.maxHeight, maxWidth: 150), 176 | child: IntrinsicHeight( 177 | // https://api.flutter.dev/flutter/material/NavigationRail-class.html 178 | child: NavigationRail( 179 | trailing: Expanded( 180 | child: Align( 181 | alignment: Alignment.bottomCenter, 182 | child: Padding( 183 | padding: const EdgeInsets.only(bottom: 8.0), 184 | child: MarkdownBody( 185 | selectable: true, 186 | data: 187 | "[${packageInfo?.version ?? ''}](https://github.com/Lenny4/DeepFaceLabClient/releases)", 188 | onTapLink: (text, url, title) { 189 | if (url != null) { 190 | launchUrl(Uri.parse(url)); 191 | } 192 | }), 193 | ), 194 | ), 195 | ), 196 | selectedIndex: selectedScreenIndex, 197 | groupAlignment: -1.0, 198 | onDestinationSelected: (int index) { 199 | dispatch({'selectedScreenIndex': index}); 200 | }, 201 | labelType: NavigationRailLabelType.all, 202 | destinations: views.value 203 | .map((view) => view.destination) 204 | .toList(), 205 | ), 206 | ), 207 | ), 208 | ); 209 | }, 210 | ), 211 | const VerticalDivider(thickness: 1, width: 1), 212 | // This is the main content. 213 | Expanded( 214 | child: hasRequirements == true && 215 | deepFaceLabFolder != null 216 | ? views.value.elementAt(selectedScreenIndex!).widget 217 | : const Scaffold( 218 | body: SingleChildScrollView( 219 | child: HasRequirementsWidget(), 220 | ), 221 | )), 222 | ], 223 | ) 224 | : const Scaffold(body: LoadingScreen())); 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /lib/screens/dashboard_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/widget/common/release_widget.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_hooks/flutter_hooks.dart'; 4 | 5 | class DashboardScreen extends HookWidget { 6 | const DashboardScreen({Key? key}) : super(key: key); 7 | 8 | @override 9 | Widget build(BuildContext context) { 10 | return Scaffold( 11 | appBar: AppBar( 12 | title: const SelectableText('Dashboard'), 13 | ), 14 | body: const ReleaseWidget()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lib/screens/help_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/widget/common/self_promotion_widget.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_hooks/flutter_hooks.dart'; 4 | import 'package:flutter_markdown/flutter_markdown.dart'; 5 | import 'package:url_launcher/url_launcher.dart'; 6 | 7 | class HelpScreen extends HookWidget { 8 | const HelpScreen({Key? key}) : super(key: key); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return Scaffold( 13 | appBar: AppBar( 14 | title: const SelectableText('Help'), 15 | ), 16 | body: SingleChildScrollView( 17 | child: Container( 18 | margin: const EdgeInsets.all(10.0), 19 | child: Column( 20 | crossAxisAlignment: CrossAxisAlignment.start, 21 | children: [ 22 | const Padding( 23 | padding: EdgeInsets.only(bottom: 16), 24 | child: SelfPromotionWidget(), 25 | ), 26 | Padding( 27 | padding: const EdgeInsets.only(bottom: 8.0), 28 | child: MarkdownBody( 29 | selectable: true, 30 | data: """ 31 | ## Video tutorials 32 | 33 | Watching all videos takes time (about 7h20) but worth it. 34 | 35 | Please note that none of these tutorials have been made with DeepFaceLabClient but only with DeepFaceLab. 36 | 37 | 1. [DeepFace Lab Tutorial: How to make a DeepFake](https://www.youtube.com/watch?v=QSmHho1uHFM) by Druuzil [Dec 17, 2021] 38 | 2. [Deepface Live Tutorial - How to make your own Live Model!](https://www.youtube.com/watch?v=_bc3SPbCdW8) by Druuzil [Apr 14, 2022] 39 | 3. [Deepface Lab Tutorial - Advanced Training Methods](https://www.youtube.com/watch?v=1Bt5wyGqdk4) by Druuzil [Aug 29, 2022] 40 | """, 41 | onTapLink: (text, url, title) { 42 | if (url != null) launchUrl(Uri.parse(url)); 43 | }), 44 | ), 45 | Padding( 46 | padding: const EdgeInsets.only(top: 8.0), 47 | child: MarkdownBody( 48 | selectable: true, 49 | data: """ 50 | ## DeepfakeVFX 51 | 52 | If you don't know where to start we suggest you to visit [deepfakevfx.com](https://www.deepfakevfx.com/) 53 | - [Deepfake Guides](https://www.deepfakevfx.com/guides/) 54 | - [Deepfake Tutorials](https://www.deepfakevfx.com/tutorials/) 55 | - [Deepfake Downloads](https://www.deepfakevfx.com/downloads/) 56 | """, 57 | onTapLink: (text, url, title) { 58 | if (url != null) launchUrl(Uri.parse(url)); 59 | }), 60 | ), 61 | ], 62 | )), 63 | ), 64 | ); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /lib/screens/loading_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_hooks/flutter_hooks.dart'; 3 | 4 | class LoadingScreen extends HookWidget { 5 | const LoadingScreen({Key? key}) : super(key: key); 6 | 7 | @override 8 | Widget build(BuildContext context) { 9 | return const Center( 10 | child: CircularProgressIndicator(), 11 | ); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/screens/settings_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/widget/common/open_issue_widget.dart'; 2 | import 'package:deepfacelab_client/widget/common/select_theme_widget.dart'; 3 | import 'package:deepfacelab_client/widget/installation/has_requirements_widget.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_hooks/flutter_hooks.dart'; 6 | 7 | class SettingsScreen extends HookWidget { 8 | const SettingsScreen({Key? key}) : super(key: key); 9 | 10 | @override 11 | Widget build(BuildContext context) { 12 | return Scaffold( 13 | appBar: AppBar( 14 | title: const SelectableText('Settings'), 15 | ), 16 | body: SingleChildScrollView( 17 | child: Container( 18 | margin: const EdgeInsets.all(10.0), 19 | child: Column( 20 | crossAxisAlignment: CrossAxisAlignment.start, 21 | children: const [ 22 | SelectThemeWidget(), 23 | OpenIssueWidget(), 24 | Padding( 25 | padding: EdgeInsets.only(top: 8.0), 26 | child: HasRequirementsWidget(), 27 | ), 28 | ], 29 | )), 30 | ), 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/screens/window_command_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:collection/collection.dart'; 2 | import 'package:deepfacelab_client/class/app_state.dart'; 3 | import 'package:deepfacelab_client/class/start_process.dart'; 4 | import 'package:deepfacelab_client/class/storage.dart'; 5 | import 'package:deepfacelab_client/class/window_command.dart'; 6 | import 'package:deepfacelab_client/screens/loading_screen.dart'; 7 | import 'package:deepfacelab_client/service/locale_storage_service.dart'; 8 | import 'package:deepfacelab_client/service/window_command_service.dart'; 9 | import 'package:deepfacelab_client/widget/common/start_process_widget.dart'; 10 | import 'package:flutter/material.dart'; 11 | import 'package:flutter_hooks/flutter_hooks.dart'; 12 | import 'package:flutter_redux_hooks/flutter_redux_hooks.dart'; 13 | import 'package:redux/redux.dart' as redux; 14 | 15 | class WindowCommandScreen extends HookWidget { 16 | final redux.Store store; 17 | final WindowCommand windowCommand; 18 | 19 | const WindowCommandScreen( 20 | {Key? key, required this.store, required this.windowCommand}) 21 | : super(key: key); 22 | 23 | @override 24 | Widget build(BuildContext context) { 25 | return StoreProvider( 26 | store: store, 27 | child: WindowCommand2Screen(windowCommand: windowCommand), 28 | ); 29 | } 30 | } 31 | 32 | class WindowCommand2Screen extends HookWidget { 33 | final WindowCommand windowCommand; 34 | 35 | const WindowCommand2Screen({Key? key, required this.windowCommand}) 36 | : super(key: key); 37 | 38 | // This widget is the root of your application. 39 | @override 40 | Widget build(BuildContext context) { 41 | final darkMode = 42 | useSelector((state) => state.storage?.darkMode); 43 | final init = useSelector((state) => state.init); 44 | final dispatch = useDispatch(); 45 | 46 | initWidget() async { 47 | dispatch({ 48 | 'init': true, 49 | 'storage': Storage.fromJson(await LocaleStorageService().readStorage()), 50 | }); 51 | } 52 | 53 | useEffect(() { 54 | initWidget(); 55 | return null; 56 | }, []); 57 | 58 | return MaterialApp( 59 | theme: darkMode != false ? ThemeData.dark() : ThemeData.light(), 60 | themeMode: darkMode != false ? ThemeMode.dark : ThemeMode.light, 61 | home: init == true 62 | ? WindowCommand3Screen(windowCommand: windowCommand) 63 | : const Scaffold(body: LoadingScreen())); 64 | } 65 | } 66 | 67 | class WindowCommand3Screen extends HookWidget { 68 | final WindowCommand windowCommand; 69 | 70 | const WindowCommand3Screen({Key? key, required this.windowCommand}) 71 | : super(key: key); 72 | 73 | // This widget is the root of your application. 74 | @override 75 | Widget build(BuildContext context) { 76 | final dispatch = useDispatch(); 77 | 78 | initWidget() async { 79 | dispatch({ 80 | 'init': true, 81 | 'storage': Storage.fromJson(await LocaleStorageService().readStorage()), 82 | }); 83 | } 84 | 85 | useEffect(() { 86 | initWidget(); 87 | return null; 88 | }, []); 89 | 90 | return Scaffold( 91 | body: SingleChildScrollView( 92 | child: StartProcessWidget( 93 | workspace: windowCommand.workspace, 94 | autoStart: true, 95 | closeIcon: false, 96 | usePrototypeItem: false, 97 | forceScrollDown: true, 98 | startProcessesConda: [ 99 | StartProcessConda( 100 | command: windowCommand.command, 101 | similarMessageRegex: windowCommand.similarMessageRegex, 102 | getAnswer: (String questionString) { 103 | String regex = Questions.autoEnterQuestions; 104 | String? match = RegExp(r'' '$regex' '') 105 | .firstMatch(questionString) 106 | ?.group(0); 107 | if (match != null) { 108 | return "\n"; 109 | } 110 | return windowCommand.questions 111 | .firstWhereOrNull((question) => 112 | questionString.contains(question.question)) 113 | ?.answer; 114 | }) 115 | ], 116 | callback: (int code) { 117 | ScaffoldMessenger.of(context).showSnackBar(SnackBar( 118 | showCloseIcon: true, 119 | backgroundColor: Theme.of(context).colorScheme.background, 120 | content: SelectableText( 121 | code == 0 122 | ? 'Command finished with success' 123 | : 'Command exit with error code $code', 124 | style: const TextStyle(color: Colors.white), 125 | ), 126 | duration: const Duration(days: 1), 127 | )); 128 | }, 129 | ), 130 | )); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /lib/screens/workspace_screen.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/workspace.dart'; 2 | import 'package:deepfacelab_client/widget/common/deepfacelab_command_widget.dart'; 3 | import 'package:deepfacelab_client/widget/common/devices_widget.dart'; 4 | import 'package:deepfacelab_client/widget/common/file_manager_widget.dart'; 5 | import 'package:deepfacelab_client/widget/form/workspace/workspace_form_widget.dart'; 6 | import 'package:flutter/material.dart'; 7 | import 'package:flutter_hooks/flutter_hooks.dart'; 8 | 9 | import '../widget/form/workspace/delete_workspace_form_widget.dart'; 10 | 11 | class UpdateChildController { 12 | late void Function() updateFromParent; 13 | } 14 | 15 | class RunningCommand { 16 | String key; 17 | Widget condaProcess; 18 | 19 | RunningCommand({required this.key, required this.condaProcess}); 20 | } 21 | 22 | class WorkspaceScreen extends HookWidget { 23 | final Workspace? initWorkspace; 24 | 25 | const WorkspaceScreen({Key? key, this.initWorkspace}) : super(key: key); 26 | 27 | @override 28 | Widget build(BuildContext context) { 29 | // https://stackoverflow.com/a/53706941/6824121 30 | var mainController = 31 | useState(UpdateChildController()); 32 | var fileMissingController = 33 | useState(UpdateChildController()); 34 | getAppBarText() { 35 | return "${initWorkspace == null ? "Create a workspace" : initWorkspace?.name}"; 36 | } 37 | 38 | var appBarText = useState(getAppBarText()); 39 | 40 | updateFileMissingController() { 41 | fileMissingController.value.updateFromParent(); 42 | } 43 | 44 | updateMainController() { 45 | mainController.value.updateFromParent(); 46 | } 47 | 48 | useEffect(() { 49 | appBarText.value = getAppBarText(); 50 | return null; 51 | }, [initWorkspace]); 52 | 53 | return Scaffold( 54 | appBar: AppBar( 55 | title: SelectableText(appBarText.value), 56 | ), 57 | body: Container( 58 | margin: const EdgeInsets.all(10.0), 59 | child: Row( 60 | crossAxisAlignment: CrossAxisAlignment.start, 61 | children: [ 62 | Expanded( 63 | flex: 7, 64 | child: Column( 65 | crossAxisAlignment: CrossAxisAlignment.start, 66 | children: [ 67 | WorkspaceFormWidget(initWorkspace: initWorkspace), 68 | if (initWorkspace != null) ...[ 69 | const Divider(), 70 | FileManagerWidget( 71 | workspace: initWorkspace, 72 | controller: mainController.value, 73 | updateFileMissing: updateFileMissingController, 74 | ), 75 | ] 76 | ], 77 | ), 78 | ), 79 | Container( 80 | margin: const EdgeInsets.only(left: 10, right: 10), 81 | child: const VerticalDivider( 82 | thickness: 1, width: 1, color: Colors.white)), 83 | Expanded( 84 | flex: 3, 85 | child: SingleChildScrollView( 86 | child: Column( 87 | crossAxisAlignment: CrossAxisAlignment.start, 88 | children: [ 89 | DevicesWidget(workspace: initWorkspace), 90 | if (initWorkspace != null) ...[ 91 | const FileManagerShortcutWidget(), 92 | ], 93 | DeepfacelabCommandWidget(workspace: initWorkspace), 94 | if (initWorkspace != null) ...[ 95 | FileManagerMissingFolderWidget( 96 | workspace: initWorkspace, 97 | controller: fileMissingController.value, 98 | updateMain: updateMainController, 99 | ), 100 | ], 101 | DeleteWorkspaceFormWidget(workspace: initWorkspace) 102 | ], 103 | )), 104 | ), 105 | ], 106 | )), 107 | ); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /lib/service/file_manager_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:collection/collection.dart'; 4 | import 'package:deepfacelab_client/class/folder_property.dart'; 5 | import 'package:deepfacelab_client/service/workspace_service.dart'; 6 | 7 | import '../class/workspace.dart'; 8 | 9 | class FileManagerService { 10 | Future _updateFolderProperty( 11 | {required FolderProperty folderProperty, 12 | required List fileSystemEntities}) async { 13 | folderProperty.nbChildren = fileSystemEntities.length; 14 | var size = 0; 15 | List foldersFound = []; 16 | for (var fileSystemEntity in fileSystemEntities) { 17 | if (fileSystemEntity is File) { 18 | size += await fileSystemEntity.length(); 19 | } 20 | if (fileSystemEntity is Directory) { 21 | var thisFileSystemEntities = 22 | await Directory(fileSystemEntity.path).list().toList(); 23 | foldersFound.add(fileSystemEntity.path); 24 | var thisFolderProperty = folderProperty.folderProperties 25 | .firstWhereOrNull( 26 | (FolderProperty f) => f.path == fileSystemEntity.path); 27 | if (thisFolderProperty == null) { 28 | thisFolderProperty = 29 | FolderProperty(path: fileSystemEntity.path, folderProperties: []); 30 | folderProperty.folderProperties.add(thisFolderProperty); 31 | } 32 | await _updateFolderProperty( 33 | folderProperty: thisFolderProperty, 34 | fileSystemEntities: thisFileSystemEntities); 35 | size += thisFolderProperty.size!; 36 | } 37 | } 38 | folderProperty.folderProperties = folderProperty.folderProperties 39 | .where((f) => foldersFound.contains(f.path)) 40 | .toList(); 41 | folderProperty.size = size; 42 | return folderProperty; 43 | } 44 | 45 | Future updateFolderProperty( 46 | {required String path, 47 | required Workspace workspace, 48 | List? fileSystemEntities, 49 | bool force = false}) async { 50 | // region get thisFolderProperty 51 | workspace.folderProperty ??= 52 | FolderProperty(path: workspace.path, folderProperties: []); 53 | FolderProperty? thisFolderProperty = workspace.folderProperty; 54 | var pathArray = path 55 | .replaceAll(workspace.path, '') 56 | .split(Platform.pathSeparator) 57 | .where((element) => element != '') 58 | .toList(); 59 | var i = 0; 60 | while (thisFolderProperty != null && thisFolderProperty.path != path) { 61 | thisFolderProperty = thisFolderProperty.folderProperties.firstWhereOrNull( 62 | (f) => f.path.endsWith(Platform.pathSeparator + pathArray[i])); 63 | i++; 64 | } 65 | // endregion 66 | if (thisFolderProperty == null) { 67 | return await updateFolderProperty( 68 | path: workspace.path, workspace: workspace, force: true); 69 | } 70 | fileSystemEntities ??= await Directory(path).list().toList(); 71 | if (!force && thisFolderProperty.nbChildren == fileSystemEntities.length) { 72 | return thisFolderProperty; 73 | } 74 | if (thisFolderProperty.path != workspace.path) { 75 | return await updateFolderProperty( 76 | path: workspace.path, workspace: workspace, force: true); 77 | } 78 | thisFolderProperty = await _updateFolderProperty( 79 | folderProperty: thisFolderProperty, 80 | fileSystemEntities: fileSystemEntities); 81 | workspace.folderProperty = thisFolderProperty; 82 | WorkspaceService().createUpdateWorkspace( 83 | oldWorkspace: workspace, newWorkspace: workspace); 84 | return thisFolderProperty; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /lib/service/locale_storage_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:convert'; 3 | import 'dart:io'; 4 | 5 | import 'package:path_provider/path_provider.dart'; 6 | 7 | // https://docs.flutter.dev/cookbook/persistence/reading-writing-files#complete-example 8 | class LocaleStorageService { 9 | Future get _localPath async { 10 | if (Platform.isWindows) { 11 | var directory = Directory( 12 | "${Platform.pathSeparator}ProgramData${Platform.pathSeparator}DeepFaceLabClient"); 13 | if (!(await directory.exists())) { 14 | await directory.create(recursive: true); 15 | } 16 | return directory.path; 17 | } 18 | return (await getApplicationDocumentsDirectory()).path; 19 | } 20 | 21 | Future get _localFile async { 22 | final path = await _localPath; 23 | return File('$path${Platform.pathSeparator}.deepfacelab_client_data.json'); 24 | } 25 | 26 | createFile(File file) async { 27 | await file.create(); 28 | await file.writeAsString('{}'); 29 | } 30 | 31 | Future> readStorage() async { 32 | final file = await _localFile; 33 | 34 | if (!(await file.exists())) { 35 | await createFile(file); 36 | } 37 | // Read the file 38 | try { 39 | return json.decode(await file.readAsString()); 40 | } catch (e) { 41 | await file.delete(); 42 | await createFile(file); 43 | return json.decode(await file.readAsString()); 44 | } 45 | } 46 | 47 | Future writeStorage(Map data) async { 48 | final file = await _localFile; 49 | 50 | // Write the file 51 | return await file.writeAsString(json.encode(data)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/service/platform_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | class PlatformService { 4 | static String getHomeDirectory() { 5 | String path = 'HOME'; 6 | if (Platform.isWindows) { 7 | path = 'HOMEPATH'; 8 | } 9 | return Platform.environment[path] ?? Platform.pathSeparator; 10 | } 11 | 12 | static getReleaseFilename() { 13 | var fileName = 'install_release.sh'; 14 | if (Platform.isWindows) { 15 | fileName = 'install_release.bat'; 16 | } 17 | return fileName; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/service/process_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:convert'; 3 | import 'dart:io'; 4 | import 'dart:math'; 5 | 6 | import 'package:deepfacelab_client/class/app_state.dart'; 7 | import 'package:deepfacelab_client/class/conda_env_list.dart'; 8 | import 'package:deepfacelab_client/class/workspace.dart'; 9 | import 'package:flutter/cupertino.dart'; 10 | 11 | class ProcessService { 12 | Future getCondaPrefix(Workspace? workspace, 13 | {ValueNotifier>? outputs}) async { 14 | if (Platform.isWindows) { 15 | return _getCondaPrefixWindows(outputs: outputs, workspace: workspace); 16 | } 17 | return _getCondaPrefixLinux(outputs: outputs, workspace: workspace); 18 | } 19 | 20 | static getRandomString() { 21 | const chars = 22 | 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890'; 23 | return List.generate(15, (index) => chars[Random().nextInt(chars.length)]) 24 | .join(); 25 | } 26 | 27 | Future> getCondaEnvironment(Workspace? workspace, 28 | {ValueNotifier>? outputs}) async { 29 | String condaCommand = 30 | (await getCondaPrefix(workspace, outputs: outputs)).trim(); 31 | var filePath = 32 | "${Platform.pathSeparator}ProgramData${Platform.pathSeparator}DeepFaceLabClient${Platform.pathSeparator}${getRandomString()}.bat"; 33 | File file = await File(filePath).create(recursive: true); 34 | await file.writeAsString("""@echo off 35 | $condaCommand"""); 36 | var envVars = (await Process.run(filePath, [], runInShell: true)) 37 | .stdout 38 | .toString() 39 | .split("\r\n") 40 | .map((e) => e.replaceAll(" ", "")) 41 | .where((element) => element != "") 42 | .toList(); 43 | await file.delete(); 44 | Map result = {}; 45 | for (var envVar in envVars) { 46 | var envVarSplit = envVar.split("="); 47 | result[envVarSplit[0]] = envVarSplit[1]; 48 | } 49 | return result; 50 | } 51 | 52 | Future _getCondaPrefixWindows( 53 | {ValueNotifier>? outputs, Workspace? workspace}) async { 54 | var setEnv = File("${store.state.storage?.deepFaceLabFolder}/setenv.bat") 55 | .readAsStringSync() 56 | .replaceAll('SET INTERNAL=%~dp0', 57 | 'SET INTERNAL=${store.state.storage?.deepFaceLabFolder}') 58 | .replaceAll('SET INTERNAL=%INTERNAL:~0,-1%', ''); 59 | if (workspace != null) { 60 | setEnv = setEnv.replaceAll('SET WORKSPACE=%INTERNAL%\\..\\workspace', 61 | 'SET WORKSPACE=${workspace.path}'); 62 | } 63 | var envArr = setEnv 64 | .split("\r\n") 65 | .where((element) => element.trim() != '' && !element.startsWith('rem')) 66 | .toList(); 67 | if (outputs != null) { 68 | outputs.value = [...outputs.value, envArr.join('\n')]; 69 | } 70 | int envArrLength = envArr.length; 71 | for (var i = 0; i < envArrLength; i++) { 72 | String? match = RegExp(r'SET .*=').firstMatch(envArr[i])?.group(0); 73 | if (match != null) { 74 | match = match.replaceAll("SET ", "").replaceAll("=", ""); 75 | envArr.add("echo $match=%$match%"); 76 | } 77 | } 78 | return envArr.join('\n'); 79 | } 80 | 81 | Future _getCondaPrefixLinux( 82 | {ValueNotifier>? outputs, Workspace? workspace}) async { 83 | String condaInit = 84 | (await Process.run('conda', ['init', '--verbose', '-d'])).stdout; 85 | String? match = RegExp(r'initialize[\s\S]*?initialize', multiLine: true) 86 | .firstMatch(condaInit) 87 | ?.group(0); 88 | Iterable? results = match?.split('\n'); 89 | results = results 90 | ?.where((e) => e.startsWith('+')) 91 | .map((e) => e.substring(1)) 92 | .where((e) => e.startsWith('#') == false); 93 | // https://developer.nvidia.com/rdp/cudnn-archive 94 | // https://developer.nvidia.com/cuda-toolkit-archive 95 | // https://www.tensorflow.org/install/source#gpu 96 | // https://repo.anaconda.com/pkgs/main/linux-64/ 97 | String pythonVersion = '3.7'; 98 | String cudnnVersion = '7.6.5'; 99 | String cudatoolkitVersion = '10.1.243'; 100 | String condaEnvName = 101 | 'deepFaceLabClient_python${pythonVersion}_cudnn${cudnnVersion}_cudatoolkit$cudatoolkitVersion'; 102 | CondaEnvList condaEnvList = CondaEnvList.fromJson(jsonDecode( 103 | (await Process.run('conda', ['env', 'list', '--json'])).stdout)); 104 | // https://stackoverflow.com/questions/59343470/type-dynamic-dynamic-is-not-a-subtype-of-type-dynamic-bool-of-tes 105 | // https://stackoverflow.com/questions/52354195/list-firstwhere-bad-state-no-element 106 | if (condaEnvList.envs.firstWhere((env) => env.contains(condaEnvName), 107 | orElse: () => "") == 108 | "") { 109 | if (outputs != null) { 110 | outputs.value = [ 111 | ...outputs.value, 112 | 'conda create -n $condaEnvName -c main python=$pythonVersion cudnn=$cudnnVersion cudatoolkit=$cudatoolkitVersion' 113 | ]; 114 | } 115 | (await Process.run('conda', [ 116 | 'create', 117 | '-n', 118 | condaEnvName, 119 | '-c', 120 | 'main', 121 | 'python=$pythonVersion', 122 | 'cudnn=$cudnnVersion', 123 | 'cudatoolkit=$cudatoolkitVersion' 124 | ])); 125 | } 126 | String result = 127 | "${results?.join("\n") ?? ""}\nconda activate $condaEnvName"; 128 | if (outputs != null) { 129 | outputs.value = [...outputs.value, result]; 130 | } 131 | return result.trim(); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /lib/service/python_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | import 'dart:convert'; 3 | import 'dart:io'; 4 | 5 | import 'package:deepfacelab_client/class/app_state.dart'; 6 | import 'package:deepfacelab_client/class/device.dart'; 7 | import 'package:deepfacelab_client/class/workspace.dart'; 8 | import 'package:deepfacelab_client/service/process_service.dart'; 9 | 10 | class PythonService { 11 | Future _getPythonScript(String filename) async { 12 | return (await (File( 13 | ("${Directory.current.path}${Platform.pathSeparator}script${Platform.pathSeparator}python${Platform.pathSeparator}$filename") 14 | .replaceAll("\n", ""))) 15 | .readAsString()); 16 | } 17 | 18 | String getPythonExec([String? deepFaceLabFolder]) { 19 | if (Platform.isWindows) { 20 | deepFaceLabFolder ??= 21 | store.state.storage?.deepFaceLabFolder ?? Platform.pathSeparator; 22 | return "$deepFaceLabFolder\\python-3.6.8\\python.exe"; 23 | } 24 | return 'python'; 25 | } 26 | 27 | updateDevices(Workspace? workspace) async { 28 | if (store.state.devices != null || 29 | store.state.hasRequirements != true || 30 | store.state.storage?.deepFaceLabFolder == null) { 31 | return; 32 | } 33 | String deepFaceLabFolder = 34 | store.state.storage?.deepFaceLabFolder ?? Platform.pathSeparator; 35 | String pythonScript = ""; 36 | if (Platform.isWindows) { 37 | deepFaceLabFolder = deepFaceLabFolder.replaceAll("\\", "\\\\"); 38 | pythonScript = (await _getPythonScript("getDevices.py")); 39 | pythonScript = pythonScript.replaceAll( 40 | "%deepFaceLabFolder%", "$deepFaceLabFolder\\\\DeepFaceLab"); 41 | } else { 42 | pythonScript = (await _getPythonScript("getDevices.py")) 43 | .replaceAll('%deepFaceLabFolder%', deepFaceLabFolder); 44 | } 45 | ProcessResult result; 46 | var pythonExec = getPythonExec(deepFaceLabFolder); 47 | if (Platform.isWindows) { 48 | // https://stackoverflow.com/a/35651859/6824121 49 | result = 50 | await Process.run(pythonExec, ['-c', 'exec(r"""$pythonScript""")'], 51 | environment: await ProcessService().getCondaEnvironment(workspace)); 52 | } else { 53 | // https://stackoverflow.com/a/2043499/6824121 54 | result = await Process.run("bash", [ 55 | '-c', 56 | """${await ProcessService().getCondaPrefix(workspace)} && \\ 57 | echo -e "$pythonScript" | $pythonExec""" 58 | ]); 59 | } 60 | store.dispatch({ 61 | 'devices': (jsonDecode(result.stdout) as List) 62 | .map((e) => Device.fromJson(e as Map)) 63 | .toList() 64 | }); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /lib/service/workspace_service.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:deepfacelab_client/class/app_state.dart'; 4 | import 'package:deepfacelab_client/class/workspace.dart'; 5 | import 'package:path/path.dart' as p; 6 | import 'package:slugify/slugify.dart'; 7 | 8 | class WorkspaceService { 9 | static List directories = [ 10 | "${Platform.pathSeparator}data_src", 11 | "${Platform.pathSeparator}data_src${Platform.pathSeparator}aligned", 12 | "${Platform.pathSeparator}data_src${Platform.pathSeparator}aligned_debug", 13 | "${Platform.pathSeparator}data_dst", 14 | "${Platform.pathSeparator}data_dst${Platform.pathSeparator}aligned", 15 | "${Platform.pathSeparator}data_dst${Platform.pathSeparator}aligned_debug", 16 | "${Platform.pathSeparator}model", 17 | ]; 18 | 19 | _createWorkspace(Workspace newWorkspace, bool? createFolder) async { 20 | var storage = store.state.storage; 21 | if (createFolder == true) { 22 | storage?.workspaceDefaultPath = newWorkspace.path; 23 | newWorkspace.path = 24 | "${newWorkspace.path}${Platform.pathSeparator}${slugify(newWorkspace.name)}"; 25 | } 26 | reCreateDirectories(workspace: newWorkspace); 27 | storage?.workspaces = [...?storage.workspaces, newWorkspace]; 28 | int newSelectedScreenIndex = 0; 29 | int? workspaceLength = storage?.workspaces?.length; 30 | if (workspaceLength != null) { 31 | newSelectedScreenIndex = workspaceLength + 1; 32 | } 33 | store.dispatch( 34 | {'selectedScreenIndex': newSelectedScreenIndex, 'storage': storage}); 35 | } 36 | 37 | _updateWorkspace(Workspace oldWorkspace, Workspace newWorkspace) async { 38 | if (oldWorkspace.path != newWorkspace.path) { 39 | newWorkspace.path = 40 | "${newWorkspace.path}${Platform.pathSeparator}${slugify(newWorkspace.name)}"; 41 | (await Process.run('mv', [oldWorkspace.path, newWorkspace.path])); 42 | } 43 | var storage = store.state.storage; 44 | int? index = storage?.workspaces 45 | ?.indexWhere((workspace) => workspace.path == oldWorkspace.path); 46 | if (index != null) { 47 | storage?.workspaces![index] = newWorkspace; 48 | } 49 | storage?.workspaces = [...?storage.workspaces]; 50 | store.dispatch({'storage': storage}); 51 | } 52 | 53 | reCreateDirectories({required Workspace? workspace}) async { 54 | if (workspace == null) { 55 | return; 56 | } 57 | for (var directoryPath in directories) { 58 | Directory(workspace.path + directoryPath).createSync(recursive: true); 59 | } 60 | } 61 | 62 | createUpdateWorkspace( 63 | {required Workspace? oldWorkspace, 64 | required Workspace newWorkspace, 65 | bool? createFolder}) async { 66 | if (oldWorkspace == null) { 67 | await _createWorkspace(newWorkspace, createFolder); 68 | } else { 69 | await _updateWorkspace(oldWorkspace, newWorkspace); 70 | } 71 | } 72 | 73 | importWorkspace({required String path}) async { 74 | String folderName = p.basename(path); 75 | await _createWorkspace(Workspace(name: folderName, path: path), false); 76 | } 77 | 78 | deleteWorkspace( 79 | {required Workspace workspace, required bool deleteFolder}) async { 80 | if (deleteFolder) { 81 | await Directory(workspace.path).delete(recursive: true); 82 | } 83 | var storage = store.state.storage; 84 | storage?.workspaces = [ 85 | ...?storage.workspaces?.where((e) => e.path != workspace.path) 86 | ]; 87 | store.dispatch({'storage': storage}); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /lib/widget/common/context_menu_region.dart: -------------------------------------------------------------------------------- 1 | // https://github.com/flutter/samples/blob/main/experimental/context_menus/lib/context_menu_region.dart 2 | // https://stackoverflow.com/questions/74868518/how-to-have-a-custom-context-menu-for-textfields-in-flutter 3 | // https://api.flutter.dev/flutter/widgets/ContextMenuController-class.html 4 | import 'package:flutter/foundation.dart'; 5 | import 'package:flutter/material.dart'; 6 | 7 | typedef ContextMenuBuilder = Widget Function( 8 | BuildContext context, Offset offset); 9 | 10 | /// Shows and hides the context menu based on user gestures. 11 | /// 12 | /// By default, shows the menu on right clicks and long presses. 13 | class ContextMenuRegion extends StatefulWidget { 14 | /// Creates an instance of [ContextMenuRegion]. 15 | const ContextMenuRegion({ 16 | super.key, 17 | required this.child, 18 | required this.contextMenuBuilder, 19 | this.beforeShow, 20 | }); 21 | 22 | /// Builds the context menu. 23 | final ContextMenuBuilder contextMenuBuilder; 24 | 25 | /// The child widget that will be listened to for gestures. 26 | final Widget child; 27 | 28 | final Null Function()? beforeShow; 29 | 30 | @override 31 | State createState() => _ContextMenuRegionState(); 32 | } 33 | 34 | class _ContextMenuRegionState extends State { 35 | Offset? _longPressOffset; 36 | 37 | final ContextMenuController _contextMenuController = ContextMenuController(); 38 | 39 | static bool get _longPressEnabled { 40 | switch (defaultTargetPlatform) { 41 | case TargetPlatform.android: 42 | case TargetPlatform.iOS: 43 | return true; 44 | case TargetPlatform.macOS: 45 | case TargetPlatform.fuchsia: 46 | case TargetPlatform.linux: 47 | case TargetPlatform.windows: 48 | return false; 49 | } 50 | } 51 | 52 | void _onSecondaryTapUp(TapUpDetails details) { 53 | _show(details.globalPosition); 54 | } 55 | 56 | void _onTap() { 57 | if (!_contextMenuController.isShown) { 58 | return; 59 | } 60 | _hide(); 61 | } 62 | 63 | void _onLongPressStart(LongPressStartDetails details) { 64 | _longPressOffset = details.globalPosition; 65 | } 66 | 67 | void _onLongPress() { 68 | assert(_longPressOffset != null); 69 | _show(_longPressOffset!); 70 | _longPressOffset = null; 71 | } 72 | 73 | void _show(Offset position) { 74 | widget.beforeShow!(); 75 | // https://stackoverflow.com/a/18453577/6824121 76 | Future.delayed( 77 | // todo improve by removing Future.delayed, TEST CASE with no selected element, right click on 1 element and the Rename option must appear 78 | const Duration(milliseconds: 50), 79 | () => _contextMenuController.show( 80 | context: context, 81 | contextMenuBuilder: (context) { 82 | return widget.contextMenuBuilder(context, position); 83 | }, 84 | )); 85 | } 86 | 87 | void _hide() { 88 | _contextMenuController.remove(); 89 | } 90 | 91 | @override 92 | void dispose() { 93 | _hide(); 94 | super.dispose(); 95 | } 96 | 97 | @override 98 | Widget build(BuildContext context) { 99 | return GestureDetector( 100 | behavior: HitTestBehavior.opaque, 101 | onSecondaryTapUp: _onSecondaryTapUp, 102 | onTap: _onTap, 103 | onLongPress: _longPressEnabled ? _onLongPress : null, 104 | onLongPressStart: _longPressEnabled ? _onLongPressStart : null, 105 | child: widget.child, 106 | ); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /lib/widget/common/deepfacelab_command_widget.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | 3 | import 'package:collection/collection.dart'; 4 | import 'package:deepfacelab_client/class/app_state.dart'; 5 | import 'package:deepfacelab_client/class/deepfacelab_command_group.dart'; 6 | import 'package:deepfacelab_client/class/locale_storage_question.dart'; 7 | import 'package:deepfacelab_client/class/locale_storage_question_child.dart'; 8 | import 'package:deepfacelab_client/class/source.dart'; 9 | import 'package:deepfacelab_client/class/window_command.dart'; 10 | import 'package:deepfacelab_client/class/workspace.dart'; 11 | import 'package:deepfacelab_client/service/window_command_service.dart'; 12 | import 'package:deepfacelab_client/widget/common/form/deepfacelab_command_form_widget.dart'; 13 | import 'package:desktop_multi_window/desktop_multi_window.dart'; 14 | import 'package:flutter/material.dart'; 15 | import 'package:flutter_hooks/flutter_hooks.dart'; 16 | import 'package:flutter_markdown/flutter_markdown.dart'; 17 | import 'package:flutter_redux_hooks/flutter_redux_hooks.dart'; 18 | import 'package:url_launcher/url_launcher.dart'; 19 | 20 | class _SingleDeepfacelabCommandWidget extends HookWidget { 21 | final Workspace? workspace; 22 | final WindowCommand windowCommand; 23 | final ValueNotifier Function()?> 24 | saveAndGetLocaleStorageQuestion; 25 | final void Function({required String source}) onLaunch; 26 | 27 | const _SingleDeepfacelabCommandWidget( 28 | {Key? key, 29 | required this.workspace, 30 | required this.windowCommand, 31 | required this.saveAndGetLocaleStorageQuestion, 32 | required this.onLaunch}) 33 | : super(key: key); 34 | 35 | @override 36 | Widget build(BuildContext context) { 37 | thisShowDialog({String source = ""}) { 38 | showDialog( 39 | context: context, 40 | builder: (BuildContext context) => AlertDialog( 41 | title: SelectableText( 42 | windowCommand.title.replaceAll(Source.replace, source)), 43 | content: IntrinsicHeight( 44 | child: SingleChildScrollView( 45 | child: Column( 46 | crossAxisAlignment: CrossAxisAlignment.start, 47 | children: [ 48 | MarkdownBody( 49 | selectable: true, 50 | data: 51 | "[Documentation](${windowCommand.documentationLink})", 52 | onTapLink: (text, url, title) { 53 | if (url != null) launchUrl(Uri.parse(url)); 54 | }), 55 | if (workspace != null) 56 | DeepfacelabCommandFormWidget( 57 | workspace: workspace!, 58 | source: source, 59 | saveAndGetLocaleStorageQuestion: 60 | saveAndGetLocaleStorageQuestion, 61 | windowCommand: windowCommand, 62 | onLaunch: onLaunch), 63 | ], 64 | ), 65 | ), 66 | ), 67 | actionsAlignment: MainAxisAlignment.spaceBetween, 68 | actions: [ 69 | TextButton( 70 | onPressed: () => Navigator.pop(context), 71 | child: const Text('Cancel'), 72 | ), 73 | ElevatedButton.icon( 74 | autofocus: true, 75 | onPressed: () => onLaunch(source: source), 76 | icon: const SizedBox.shrink(), 77 | label: const Text("Start"), 78 | ), 79 | ], 80 | ), 81 | ); 82 | } 83 | 84 | return ListTile( 85 | onTap: () => !windowCommand.loading && !windowCommand.multipleSource 86 | ? thisShowDialog() 87 | : null, 88 | title: Column( 89 | crossAxisAlignment: CrossAxisAlignment.start, 90 | children: [ 91 | Text(windowCommand.title.replaceAll(Source.replace, "")), 92 | if (windowCommand.multipleSource) 93 | Row( 94 | mainAxisAlignment: MainAxisAlignment.spaceAround, 95 | children: Source.types 96 | .map((type) => ElevatedButton( 97 | onPressed: !windowCommand.loading 98 | ? () { 99 | thisShowDialog(source: type); 100 | } 101 | : null, 102 | child: Text(type), 103 | )) 104 | .toList(), 105 | ), 106 | ], 107 | ), 108 | trailing: 109 | windowCommand.loading ? const CircularProgressIndicator() : null, 110 | ); 111 | } 112 | } 113 | 114 | class DeepfacelabCommandWidget extends HookWidget { 115 | final Workspace? workspace; 116 | 117 | const DeepfacelabCommandWidget({Key? key, required this.workspace}) 118 | : super(key: key); 119 | 120 | @override 121 | Widget build(BuildContext context) { 122 | final deepFaceLabFolder = useSelector( 123 | (state) => state.storage?.deepFaceLabFolder); 124 | var deepfacelabCommandGroups = useState>( 125 | WindowCommandService().getGroupsDeepfacelabCommand( 126 | deepFaceLabFolder: deepFaceLabFolder, workspace: workspace)); 127 | var saveAndGetLocaleStorageQuestion = 128 | useState Function()?>(null); 129 | 130 | onGroupsDeepfacelabCommandUpdate() async { 131 | bool hasUpdate = false; 132 | for (var deepfacelabCommandGroup in deepfacelabCommandGroups.value) { 133 | for (var windowCommand in deepfacelabCommandGroup.windowCommands) { 134 | if (windowCommand.loading) { 135 | hasUpdate = true; 136 | var originalCommand = windowCommand.command; 137 | windowCommand.command = originalCommand.replaceAll( 138 | Source.replace, windowCommand.source); 139 | var window = await DesktopMultiWindow.createWindow( 140 | jsonEncode(windowCommand.toJson())); 141 | window 142 | ..setFrame(const Offset(0, 0) & const Size(1280, 720)) 143 | ..center() 144 | ..setTitle(windowCommand.windowTitle 145 | .replaceAll(Source.replace, windowCommand.source)) 146 | ..show(); 147 | windowCommand.loading = false; 148 | windowCommand.command = originalCommand; 149 | } 150 | } 151 | } 152 | if (hasUpdate) { 153 | deepfacelabCommandGroups.value = 154 | deepfacelabCommandGroups.value.toList(); 155 | } 156 | } 157 | 158 | onLaunch({required String source}) { 159 | if (saveAndGetLocaleStorageQuestion.value == null) { 160 | return; 161 | } 162 | saveAndGetLocaleStorageQuestion.value!() 163 | .then((LocaleStorageQuestion? localeStorageQuestion) { 164 | if (localeStorageQuestion == null) { 165 | return; 166 | } 167 | for (var deepfacelabCommandGroup in deepfacelabCommandGroups.value) { 168 | for (var windowCommand in deepfacelabCommandGroup.windowCommands) { 169 | if (localeStorageQuestion.key == 170 | windowCommand.key.replaceAll(Source.replace, source)) { 171 | for (var y = 0; y < windowCommand.questions.length; y++) { 172 | var localeStorageQuestionChild = localeStorageQuestion.questions 173 | .firstWhereOrNull((LocaleStorageQuestionChild question) => 174 | question.question == 175 | windowCommand.questions[y].question); 176 | if (localeStorageQuestionChild != null) { 177 | windowCommand.questions[y].answer = 178 | localeStorageQuestionChild.answer; 179 | } 180 | } 181 | windowCommand.source = source; 182 | windowCommand.loading = true; 183 | break; 184 | } 185 | } 186 | } 187 | deepfacelabCommandGroups.value = 188 | deepfacelabCommandGroups.value.toList(); 189 | Navigator.pop(context); 190 | }); 191 | } 192 | 193 | useEffect(() { 194 | deepfacelabCommandGroups.value = WindowCommandService() 195 | .getGroupsDeepfacelabCommand( 196 | deepFaceLabFolder: deepFaceLabFolder, workspace: workspace); 197 | return null; 198 | }, [workspace?.path]); 199 | 200 | useEffect(() { 201 | onGroupsDeepfacelabCommandUpdate(); 202 | return null; 203 | }, [deepfacelabCommandGroups.value]); 204 | 205 | return workspace != null 206 | ? ExpansionTile( 207 | expandedAlignment: Alignment.topLeft, 208 | childrenPadding: const EdgeInsets.symmetric(horizontal: 10), 209 | initiallyExpanded: true, 210 | title: const Text('Commands'), 211 | tilePadding: const EdgeInsets.all(0.0), 212 | children: deepfacelabCommandGroups.value 213 | .map((deepfacelabCommandGroup) => ExpansionTile( 214 | expandedAlignment: Alignment.topLeft, 215 | initiallyExpanded: false, 216 | title: Row( 217 | children: [ 218 | deepfacelabCommandGroup.icon, 219 | Text(deepfacelabCommandGroup.name), 220 | ], 221 | ), 222 | tilePadding: const EdgeInsets.all(0.0), 223 | children: deepfacelabCommandGroup.windowCommands 224 | .map((windowCommand) => 225 | _SingleDeepfacelabCommandWidget( 226 | workspace: workspace, 227 | windowCommand: windowCommand, 228 | onLaunch: onLaunch, 229 | saveAndGetLocaleStorageQuestion: 230 | saveAndGetLocaleStorageQuestion, 231 | )) 232 | .toList(), 233 | )) 234 | .toList(), 235 | ) 236 | : const SizedBox.shrink(); 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /lib/widget/common/devices_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/app_state.dart'; 2 | import 'package:deepfacelab_client/class/device.dart'; 3 | import 'package:deepfacelab_client/class/workspace.dart'; 4 | import 'package:deepfacelab_client/service/python_service.dart'; 5 | import 'package:flutter/material.dart'; 6 | import 'package:flutter_hooks/flutter_hooks.dart'; 7 | import 'package:flutter_markdown/flutter_markdown.dart'; 8 | import 'package:flutter_redux_hooks/flutter_redux_hooks.dart'; 9 | 10 | class DevicesWidget extends HookWidget { 11 | final Workspace? workspace; 12 | 13 | const DevicesWidget({Key? key, required this.workspace}) : super(key: key); 14 | 15 | @override 16 | Widget build(BuildContext context) { 17 | final devices = 18 | useSelector?>((state) => state.devices); 19 | 20 | initWidget() async { 21 | PythonService().updateDevices(workspace); 22 | } 23 | 24 | useEffect(() { 25 | initWidget(); 26 | return null; 27 | }, []); 28 | 29 | return ExpansionTile( 30 | expandedAlignment: Alignment.topLeft, 31 | title: Text( 32 | 'Your GPUs ${(devices != null && devices.isNotEmpty ? "(${devices.length})" : "")}'), 33 | tilePadding: const EdgeInsets.all(0.0), 34 | children: [ 35 | devices == null 36 | ? const CircularProgressIndicator() 37 | : devices.isNotEmpty 38 | ? Table( 39 | border: TableBorder.all(color: Colors.white), 40 | columnWidths: const { 41 | 0: IntrinsicColumnWidth(), 42 | 1: IntrinsicColumnWidth(), 43 | 2: IntrinsicColumnWidth(), 44 | }, 45 | defaultVerticalAlignment: TableCellVerticalAlignment.middle, 46 | children: [ 47 | TableRow( 48 | children: [ 49 | TableCell( 50 | child: Container( 51 | padding: const EdgeInsets.all(10.0), 52 | child: const SelectableText("Index")), 53 | ), 54 | TableCell( 55 | child: Container( 56 | padding: const EdgeInsets.all(10.0), 57 | child: const SelectableText("Name")), 58 | ), 59 | TableCell( 60 | child: Container( 61 | padding: const EdgeInsets.all(10.0), 62 | child: 63 | const SelectableText("Total memory (Gb)")), 64 | ), 65 | ], 66 | ), 67 | ...devices 68 | .map((device) => TableRow( 69 | children: [ 70 | TableCell( 71 | child: Container( 72 | padding: const EdgeInsets.all(10.0), 73 | child: SelectableText( 74 | device.index.toString())), 75 | ), 76 | TableCell( 77 | child: Container( 78 | padding: const EdgeInsets.all(10.0), 79 | child: SelectableText(device.name)), 80 | ), 81 | TableCell( 82 | child: Container( 83 | padding: const EdgeInsets.all(10.0), 84 | child: SelectableText( 85 | device.totalMemGb.toStringAsFixed(2))), 86 | ), 87 | ], 88 | )) 89 | .toList() 90 | ], 91 | ) 92 | : const MarkdownBody( 93 | selectable: true, data: "No GPU detected on your machine"), 94 | ], 95 | ); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /lib/widget/common/divider_with_text_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_hooks/flutter_hooks.dart'; 3 | 4 | class DividerWithTextWidget extends HookWidget { 5 | final String text; 6 | 7 | const DividerWithTextWidget({Key? key, required this.text}) : super(key: key); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Row(children: [ 12 | const Expanded(child: Divider()), 13 | Padding( 14 | padding: const EdgeInsets.symmetric(horizontal: 16.0), 15 | child: Text(text), 16 | ), 17 | const Expanded(child: Divider()), 18 | ]); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/widget/common/form/checkbox_form_fiel_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | // https://stackoverflow.com/questions/53479942/checkbox-form-validation 4 | class CheckboxFormField extends FormField { 5 | CheckboxFormField( 6 | {super.key, 7 | Widget? title, 8 | FormFieldSetter? onSaved, 9 | void Function(bool?)? onChanged, 10 | FormFieldValidator? validator, 11 | EdgeInsetsGeometry? contentPadding, 12 | bool initialValue = false, 13 | bool autovalidate = false}) 14 | : super( 15 | onSaved: onSaved, 16 | validator: validator, 17 | initialValue: initialValue, 18 | builder: (FormFieldState state) { 19 | return CheckboxListTile( 20 | dense: state.hasError, 21 | contentPadding: contentPadding ?? const EdgeInsets.all(0.0), 22 | title: title, 23 | value: state.value, 24 | onChanged: (value) { 25 | state.didChange(value); 26 | onChanged!(value); 27 | }, 28 | subtitle: state.hasError 29 | ? Builder( 30 | builder: (BuildContext context) => Text( 31 | state.errorText ?? "", 32 | style: TextStyle( 33 | color: Theme.of(context).colorScheme.error), 34 | ), 35 | ) 36 | : null, 37 | controlAffinity: ListTileControlAffinity.leading, 38 | ); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /lib/widget/common/form/deepfacelab_command_form_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:collection/collection.dart'; 2 | import 'package:deepfacelab_client/class/locale_storage_question.dart'; 3 | import 'package:deepfacelab_client/class/locale_storage_question_child.dart'; 4 | import 'package:deepfacelab_client/class/question.dart'; 5 | import 'package:deepfacelab_client/class/source.dart'; 6 | import 'package:deepfacelab_client/class/window_command.dart'; 7 | import 'package:deepfacelab_client/class/workspace.dart'; 8 | import 'package:deepfacelab_client/service/window_command_service.dart'; 9 | import 'package:flutter/material.dart'; 10 | import 'package:flutter_hooks/flutter_hooks.dart'; 11 | 12 | class _QuestionController { 13 | TextEditingController? controller; 14 | String? selectValue; 15 | Question question; 16 | 17 | _QuestionController( 18 | {required this.question, this.controller, this.selectValue}); 19 | } 20 | 21 | class DeepfacelabCommandFormWidget extends HookWidget { 22 | final Workspace workspace; 23 | final WindowCommand windowCommand; 24 | final String source; 25 | final ValueNotifier Function()?> 26 | saveAndGetLocaleStorageQuestion; 27 | final void Function({required String source}) onLaunch; 28 | 29 | const DeepfacelabCommandFormWidget( 30 | {Key? key, 31 | required this.workspace, 32 | required this.windowCommand, 33 | required this.source, 34 | required this.saveAndGetLocaleStorageQuestion, 35 | required this.onLaunch}) 36 | : super(key: key); 37 | 38 | @override 39 | Widget build(BuildContext context) { 40 | var formKey = useState>(GlobalKey()); 41 | 42 | List<_QuestionController> getQuestionControllers() { 43 | LocaleStorageQuestion? localeStorageQuestion = workspace 44 | .localeStorageQuestions 45 | ?.firstWhereOrNull((LocaleStorageQuestion localeStorageQuestion) => 46 | localeStorageQuestion.key == 47 | windowCommand.key.replaceAll(Source.replace, source)); 48 | return windowCommand.questions.map((question) { 49 | String? localeStorageAnswer; 50 | if (localeStorageQuestion != null) { 51 | var q = localeStorageQuestion.questions 52 | .firstWhereOrNull((q) => q.question == question.question); 53 | if (q != null) { 54 | localeStorageAnswer = q.answer; 55 | } 56 | } 57 | var thisAnswer = localeStorageAnswer ?? 58 | (question.answer == "" 59 | ? WindowCommandService() 60 | .getDefaultAnswer(question: question, workspace: workspace) 61 | : question.answer); 62 | if (question.options != null) { 63 | return _QuestionController( 64 | selectValue: thisAnswer, question: question); 65 | } 66 | return _QuestionController( 67 | controller: TextEditingController(text: thisAnswer), 68 | question: question); 69 | }).toList(); 70 | } 71 | 72 | var questionControllers = 73 | useState>(getQuestionControllers()); 74 | 75 | Future onSubmit() async { 76 | if (!formKey.value.currentState!.validate()) { 77 | return null; 78 | } 79 | formKey.value.currentState?.save(); 80 | LocaleStorageQuestion localeStorageQuestion = LocaleStorageQuestion( 81 | key: windowCommand.key.replaceAll(Source.replace, source), 82 | questions: []); 83 | for (var questionController in questionControllers.value) { 84 | localeStorageQuestion.questions.add(LocaleStorageQuestionChild( 85 | question: questionController.question.question, 86 | answer: (questionController.controller != null 87 | ? questionController.controller!.value.text 88 | : questionController.selectValue) ?? 89 | "")); 90 | } 91 | return await WindowCommandService().saveAndGetLocaleStorageQuestion( 92 | localeStorageQuestion: localeStorageQuestion, 93 | workspacePath: workspace.path); 94 | } 95 | 96 | bool isNumeric(String s) { 97 | return double.tryParse(s) != null; 98 | } 99 | 100 | num? getNum(String? s) { 101 | if (s == null) { 102 | return null; 103 | } 104 | if (!isNumeric(s)) { 105 | return null; 106 | } 107 | return num.parse(s); 108 | } 109 | 110 | useEffect(() { 111 | questionControllers.value = getQuestionControllers(); 112 | Future.delayed( 113 | // todo improve by removing Future.delayed 114 | const Duration(milliseconds: 50), 115 | () => saveAndGetLocaleStorageQuestion.value = onSubmit); 116 | return null; 117 | }, [windowCommand]); 118 | 119 | return Form( 120 | key: formKey.value, 121 | child: Column( 122 | crossAxisAlignment: CrossAxisAlignment.start, 123 | children: questionControllers.value 124 | .mapIndexed((indexQuestionController, questionController) { 125 | String label = 126 | "${questionController.question.text} [${WindowCommandService().getDefaultAnswer(question: questionController.question, workspace: workspace)}]"; 127 | var inputDecoration = InputDecoration( 128 | hintText: label, 129 | labelText: label, 130 | suffixIcon: Tooltip( 131 | message: questionController.question.help, 132 | child: const Icon(Icons.help), 133 | )); 134 | return (questionController.question.options != null 135 | ? Column( 136 | children: [ 137 | (DropdownButtonFormField( 138 | decoration: inputDecoration, 139 | value: questionController.selectValue, 140 | isExpanded: true, 141 | icon: const Icon(Icons.arrow_downward), 142 | onChanged: (String? value) { 143 | questionControllers 144 | .value[indexQuestionController].selectValue = value; 145 | questionControllers.value = 146 | questionControllers.value.toList(); 147 | }, 148 | items: questionController.question.options 149 | ?.map>((String value) { 150 | return DropdownMenuItem( 151 | value: value, 152 | child: Text(value), 153 | ); 154 | }).toList(), 155 | )), 156 | ], 157 | ) 158 | : TextFormField( 159 | onFieldSubmitted: (value) { 160 | onLaunch(source: source); 161 | }, 162 | decoration: inputDecoration, 163 | controller: questionController.controller, 164 | validator: (value) { 165 | if (questionController.question.validAnswerRegex == null) { 166 | return null; 167 | } 168 | for (var validAnswerRegex 169 | in questionController.question.validAnswerRegex!) { 170 | if (validAnswerRegex.regex != null) { 171 | String regex = validAnswerRegex.regex!; 172 | String? match = RegExp(r'' '$regex' '') 173 | .firstMatch(value!) 174 | ?.group(0); 175 | if (match == null) { 176 | return validAnswerRegex.errorMessage; 177 | } 178 | } else { 179 | var number = getNum(value); 180 | if (number == null || 181 | (validAnswerRegex.min != null && 182 | number < validAnswerRegex.min!) || 183 | (validAnswerRegex.max != null && 184 | number > validAnswerRegex.max!)) { 185 | return validAnswerRegex.errorMessage; 186 | } 187 | } 188 | } 189 | return null; 190 | }, 191 | )); 192 | }).toList(), 193 | ), 194 | ); 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /lib/widget/common/open_issue_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_hooks/flutter_hooks.dart'; 3 | import 'package:flutter_markdown/flutter_markdown.dart'; 4 | import 'package:url_launcher/url_launcher.dart'; 5 | 6 | class OpenIssueWidget extends HookWidget { 7 | const OpenIssueWidget({Key? key}) : super(key: key); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return MarkdownBody( 12 | selectable: true, 13 | data: 14 | "If you encounter a problem please [open an issue](https://github.com/Lenny4/DeepFaceLabClient/issues).", 15 | onTapLink: (text, url, title) { 16 | if (url != null) launchUrl(Uri.parse(url)); 17 | }); 18 | } 19 | } 20 | 21 | class OpenIssue2Widget extends HookWidget { 22 | const OpenIssue2Widget({Key? key}) : super(key: key); 23 | 24 | @override 25 | Widget build(BuildContext context) { 26 | return MarkdownBody( 27 | selectable: true, 28 | data: 29 | "[Open an issue](https://github.com/Lenny4/DeepFaceLabClient/issues).", 30 | onTapLink: (text, url, title) { 31 | if (url != null) launchUrl(Uri.parse(url)); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/widget/common/select_theme_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/action/switch_theme_action.dart'; 2 | import 'package:deepfacelab_client/class/app_state.dart'; 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_hooks/flutter_hooks.dart'; 5 | import 'package:flutter_markdown/flutter_markdown.dart'; 6 | import 'package:flutter_redux_hooks/flutter_redux_hooks.dart'; 7 | 8 | class SelectThemeWidget extends HookWidget { 9 | const SelectThemeWidget({Key? key}) : super(key: key); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | final darkMode = 14 | useSelector((state) => state.storage?.darkMode); 15 | final dispatch = useDispatch(); 16 | 17 | switchTheme() { 18 | dispatch(SwitchThemeAction()); 19 | } 20 | 21 | return Row( 22 | children: [ 23 | const MarkdownBody(selectable: true, data: "## Theme"), 24 | IconButton( 25 | icon: Icon(darkMode != false ? Icons.light_mode : Icons.dark_mode), 26 | splashRadius: 20, 27 | onPressed: switchTheme, 28 | ), 29 | ], 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/widget/common/self_promotion_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_hooks/flutter_hooks.dart'; 3 | import 'package:flutter_markdown/flutter_markdown.dart'; 4 | import 'package:url_launcher/url_launcher.dart'; 5 | 6 | class SelfPromotionWidget extends HookWidget { 7 | const SelfPromotionWidget({Key? key}) : super(key: key); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return MarkdownBody( 12 | selectable: true, 13 | data: """ 14 | If you like DeepFaceLabClient please consider adding a star on the [repository](https://github.com/Lenny4/DeepFaceLabClient). 15 | """, 16 | onTapLink: (text, url, title) { 17 | if (url != null) launchUrl(Uri.parse(url)); 18 | }); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/widget/common/start_process_widget.dart: -------------------------------------------------------------------------------- 1 | import 'dart:convert'; 2 | import 'dart:io'; 3 | 4 | import 'package:deepfacelab_client/class/start_process.dart'; 5 | import 'package:deepfacelab_client/class/workspace.dart'; 6 | import 'package:deepfacelab_client/service/process_service.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:flutter/services.dart'; 9 | import 'package:flutter_hooks/flutter_hooks.dart'; 10 | import 'package:flutter_markdown/flutter_markdown.dart'; 11 | 12 | class StartProcessWidget extends HookWidget { 13 | final String? label; 14 | final bool? autoStart; 15 | final bool? closeIcon; 16 | final double? height; 17 | final bool? usePrototypeItem; 18 | final bool? forceScrollDown; 19 | final List? startProcesses; 20 | final List? startProcessesConda; 21 | final Function? callback; 22 | final ScrollController scrollController = ScrollController(); 23 | final Workspace? workspace; 24 | 25 | StartProcessWidget( 26 | {Key? key, 27 | this.label, 28 | this.autoStart, 29 | this.closeIcon, 30 | this.height, 31 | this.startProcesses, 32 | this.startProcessesConda, 33 | this.usePrototypeItem, 34 | this.forceScrollDown, 35 | required this.workspace, 36 | this.callback}) 37 | : super(key: key); 38 | 39 | @override 40 | Widget build(BuildContext context) { 41 | var loading = useState(false); 42 | var nbPkexec = useState(0); 43 | var outputs = useState>([]); 44 | 45 | addOutput(String output, [List? regex]) { 46 | if (outputs.value.isNotEmpty) { 47 | var lastOutput = outputs.value[outputs.value.length - 1]; 48 | if (regex != null) { 49 | for (var reg in regex) { 50 | String? match = RegExp(r'' '$reg' '').firstMatch(output)?.group(0); 51 | String? match2 = 52 | RegExp(r'' '$reg' '').firstMatch(lastOutput)?.group(0); 53 | if (match != null && match2 != null) { 54 | outputs.value[outputs.value.length - 1] = output; 55 | outputs.value = [...outputs.value]; 56 | return; 57 | } 58 | } 59 | } 60 | } 61 | outputs.value = [...outputs.value, output]; 62 | } 63 | 64 | launchProcesses(int index) async { 65 | if (index == 0) { 66 | outputs.value = []; 67 | } 68 | loading.value = true; 69 | Process process; 70 | if (startProcesses != null) { 71 | process = await Process.start(startProcesses![index].executable, 72 | startProcesses![index].arguments); 73 | } else { 74 | var thisCommand = 75 | startProcessesConda![index].command.replaceAll('\\\n', '').trim(); 76 | if (Platform.isWindows) { 77 | // https://stackoverflow.com/questions/60821479/dartio-process-how-to-run-cmd-start-on-windows 78 | process = await Process.start(thisCommand, [], 79 | environment: await ProcessService() 80 | .getCondaEnvironment(workspace, outputs: outputs)); 81 | } else { 82 | process = await Process.start("bash", [ 83 | '-c', 84 | """${(await ProcessService().getCondaPrefix(workspace, outputs: outputs)).trim()} && \\ 85 | $thisCommand""" 86 | ]); 87 | } 88 | } 89 | if (startProcesses != null) { 90 | addOutput("\$ ${startProcesses![index]}"); 91 | } else { 92 | addOutput("\$ ${startProcessesConda![index]}"); 93 | } 94 | process.stdout.transform(utf8.decoder).forEach((String output) { 95 | List? similarMessageRegex; 96 | if (startProcesses != null) { 97 | similarMessageRegex = startProcesses![index].similarMessageRegex; 98 | } else { 99 | similarMessageRegex = startProcessesConda![index].similarMessageRegex; 100 | } 101 | addOutput(output, similarMessageRegex); 102 | if (startProcessesConda != null && 103 | startProcessesConda![index].getAnswer != null) { 104 | String? answer = startProcessesConda![index].getAnswer!(output); 105 | if (answer != null) { 106 | process.stdin.write("$answer\n"); 107 | } 108 | } 109 | }); 110 | process.stderr.transform(utf8.decoder).forEach((String output) { 111 | List? similarMessageRegex; 112 | if (startProcesses != null) { 113 | similarMessageRegex = startProcesses![index].similarMessageRegex; 114 | } else { 115 | similarMessageRegex = startProcessesConda![index].similarMessageRegex; 116 | } 117 | addOutput(output, similarMessageRegex); 118 | }); 119 | process.exitCode.then((value) { 120 | if ((startProcesses != null && index == startProcesses!.length - 1) || 121 | (startProcessesConda != null && 122 | index == startProcessesConda!.length - 1)) { 123 | if (callback != null) { 124 | callback!(value); 125 | } 126 | loading.value = false; 127 | } else if (value == 0) { 128 | // success exit code 129 | launchProcesses(index + 1); 130 | } 131 | }); 132 | } 133 | 134 | updateNbPkexec() { 135 | if (startProcesses != null) { 136 | nbPkexec.value = startProcesses! 137 | .where((startProcess) => startProcess.executable == 'pkexec') 138 | .length; 139 | } 140 | } 141 | 142 | scrollDown() { 143 | if (scrollController.hasClients) { 144 | double currentPosition = scrollController.position.pixels; 145 | double maxScrollExtent = scrollController.position.maxScrollExtent; 146 | double delta = 100.0; 147 | if (forceScrollDown == true || 148 | currentPosition >= maxScrollExtent - delta) { 149 | scrollController.jumpTo(maxScrollExtent); 150 | } 151 | } 152 | } 153 | 154 | useEffect(() { 155 | updateNbPkexec(); 156 | if (autoStart == true) { 157 | launchProcesses(0); 158 | } 159 | return null; 160 | }, [startProcesses]); 161 | 162 | useEffect(() { 163 | scrollDown(); 164 | return null; 165 | }, [outputs.value]); 166 | 167 | return Column( 168 | crossAxisAlignment: CrossAxisAlignment.start, 169 | children: [ 170 | Container( 171 | margin: const EdgeInsets.only(bottom: 1.0), 172 | child: Row( 173 | children: [ 174 | if (label != null) 175 | ElevatedButton.icon( 176 | onPressed: !loading.value 177 | ? () { 178 | launchProcesses(0); 179 | } 180 | : null, 181 | icon: loading.value 182 | ? const CircularProgressIndicator( 183 | color: Colors.white, 184 | ) 185 | : const SizedBox.shrink(), 186 | label: Text(label ?? ""), 187 | ), 188 | if (nbPkexec.value > 0) 189 | Container( 190 | margin: const EdgeInsets.only(left: 10.0), 191 | child: Text( 192 | 'Your root password will be required ${nbPkexec.value} ${nbPkexec.value > 1 ? "times" : "time"}')), 193 | ], 194 | ), 195 | ), 196 | if (autoStart != true) 197 | ExpansionTile( 198 | title: const Text( 199 | 'If you want to preview what will be run, click here'), 200 | tilePadding: const EdgeInsets.all(0.0), 201 | children: [ 202 | SizedBox( 203 | width: MediaQuery.of(context).size.width, 204 | child: Row( 205 | children: [ 206 | Expanded( 207 | child: MarkdownBody(selectable: true, data: """ 208 | ```shell 209 | ${startProcesses!.map((startProcess) => "\$ $startProcess").join('\n\n')} 210 | ``` 211 | """), 212 | ), 213 | IconButton( 214 | icon: const Icon(Icons.copy), 215 | splashRadius: 20, 216 | tooltip: 'Copy to clipboard', 217 | onPressed: () async { 218 | await Clipboard.setData(ClipboardData( 219 | text: startProcesses! 220 | .map((startProcess) => "$startProcess;") 221 | .join('\n\n'))); 222 | }, 223 | ) 224 | ], 225 | ), 226 | ) 227 | ], 228 | ), 229 | if (outputs.value.isNotEmpty) 230 | Row( 231 | children: [ 232 | Expanded( 233 | child: Container( 234 | height: height, 235 | color: Colors.white10, 236 | child: ListView.builder( 237 | controller: scrollController, 238 | itemCount: outputs.value.length, 239 | shrinkWrap: true, 240 | prototypeItem: usePrototypeItem == false 241 | ? null 242 | : SelectableText(outputs.value.first), 243 | itemBuilder: (context, index) { 244 | return SelectableText(outputs.value[index]); 245 | }, 246 | ), 247 | ), 248 | ), 249 | if (closeIcon == true) 250 | IconButton( 251 | icon: const Icon(Icons.close), 252 | splashRadius: 20, 253 | tooltip: 'Close', 254 | onPressed: () { 255 | outputs.value = []; 256 | }, 257 | ) 258 | ], 259 | ) 260 | ], 261 | ); 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /lib/widget/form/workspace/delete_workspace_form_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/workspace.dart'; 2 | import 'package:deepfacelab_client/service/workspace_service.dart'; 3 | import 'package:deepfacelab_client/widget/common/form/checkbox_form_fiel_widget.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:flutter_hooks/flutter_hooks.dart'; 6 | import 'package:flutter_markdown/flutter_markdown.dart'; 7 | 8 | class DeleteWorkspaceFormWidget extends HookWidget { 9 | final Workspace? workspace; 10 | 11 | const DeleteWorkspaceFormWidget({Key? key, required this.workspace}) 12 | : super(key: key); 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | var loading = useState(false); 17 | var deleteFolder = useState(true); 18 | final formKey = GlobalKey(); 19 | 20 | delete() async { 21 | loading.value = true; 22 | formKey.currentState?.save(); 23 | var thisWorkspace = workspace; 24 | if (thisWorkspace != null) { 25 | WorkspaceService().deleteWorkspace( 26 | workspace: thisWorkspace, deleteFolder: deleteFolder.value); 27 | } 28 | deleteFolder.value = true; 29 | loading.value = false; 30 | } 31 | 32 | return workspace != null 33 | ? Container( 34 | margin: const EdgeInsets.only(top: 10), 35 | child: ElevatedButton( 36 | style: const ButtonStyle( 37 | backgroundColor: MaterialStatePropertyAll(Colors.red)), 38 | onPressed: () => showDialog( 39 | barrierDismissible: !loading.value, 40 | context: context, 41 | builder: (BuildContext context) => AlertDialog( 42 | title: SelectableText('Delete `${workspace?.name}`'), 43 | content: IntrinsicHeight( 44 | child: Form( 45 | key: formKey, 46 | child: Column( 47 | crossAxisAlignment: CrossAxisAlignment.start, 48 | children: [ 49 | SelectableText( 50 | 'Do you really want to delete the workspace `${workspace?.name}` ?'), 51 | CheckboxFormField( 52 | title: const MarkdownBody( 53 | selectable: true, 54 | data: 55 | "Delete the workspace folder on my computer"), 56 | initialValue: deleteFolder.value, 57 | onChanged: (bool? value) => 58 | deleteFolder.value = (value ?? true), 59 | onSaved: (bool? value) => 60 | deleteFolder.value = (value ?? true), 61 | ) 62 | ], 63 | ), 64 | ), 65 | ), 66 | actionsAlignment: MainAxisAlignment.spaceBetween, 67 | actions: [ 68 | TextButton( 69 | onPressed: () => Navigator.pop(context), 70 | child: const Text('No'), 71 | ), 72 | ElevatedButton.icon( 73 | style: const ButtonStyle( 74 | backgroundColor: 75 | MaterialStatePropertyAll(Colors.red)), 76 | onPressed: !loading.value 77 | ? () { 78 | delete().then((value) => Navigator.pop(context)); 79 | } 80 | : null, 81 | icon: loading.value 82 | ? const CircularProgressIndicator( 83 | color: Colors.white, 84 | ) 85 | : const SizedBox.shrink(), 86 | label: const Text("Yes"), 87 | ), 88 | ], 89 | ), 90 | ), 91 | child: const Text("Delete workspace"), 92 | ), 93 | ) 94 | : const SizedBox.shrink(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /lib/widget/installation/has_requirements_widget.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:deepfacelab_client/widget/installation/installation_widget.dart'; 4 | import 'package:deepfacelab_client/widget/installation/requirement_linux_widget.dart'; 5 | import 'package:deepfacelab_client/widget/installation/requirement_windows_widget.dart'; 6 | import 'package:flutter/material.dart'; 7 | import 'package:flutter_hooks/flutter_hooks.dart'; 8 | 9 | class HasRequirementsWidget extends HookWidget { 10 | const HasRequirementsWidget({Key? key}) : super(key: key); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ 15 | if (Platform.isLinux) ...[ 16 | RequirementLinuxWidget(), 17 | ], 18 | if (Platform.isWindows) ...[ 19 | const RequirementWindowsWidget(), 20 | ], 21 | InstallationWidget(), 22 | ]); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/widget/installation/requirement_linux_widget.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:deepfacelab_client/class/app_state.dart'; 4 | import 'package:deepfacelab_client/class/start_process.dart'; 5 | import 'package:deepfacelab_client/service/platform_service.dart'; 6 | import 'package:deepfacelab_client/widget/common/divider_with_text_widget.dart'; 7 | import 'package:deepfacelab_client/widget/common/open_issue_widget.dart'; 8 | import 'package:deepfacelab_client/widget/common/start_process_widget.dart'; 9 | import 'package:filesystem_picker/filesystem_picker.dart'; 10 | import 'package:flutter/gestures.dart'; 11 | import 'package:flutter/material.dart'; 12 | import 'package:flutter_hooks/flutter_hooks.dart'; 13 | import 'package:flutter_markdown/flutter_markdown.dart'; 14 | import 'package:flutter_redux_hooks/flutter_redux_hooks.dart'; 15 | import 'package:url_launcher/url_launcher.dart'; 16 | 17 | class RequirementLinuxWidget extends HookWidget { 18 | RequirementLinuxWidget({Key? key}) : super(key: key); 19 | final String homeDirectory = PlatformService.getHomeDirectory(); 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | final hasRequirements = 24 | useSelector((state) => state.hasRequirements); 25 | final dispatch = useDispatch(); 26 | var requirements = useState?>(null); 27 | var loading = useState(false); 28 | var startProcesses = useState>([]); 29 | var condaInstallFolder = useState(homeDirectory); 30 | var whoami = useState(null); 31 | 32 | updateRequirements() async { 33 | Map newRequirements = { 34 | 'hasWget': (await Process.run('which', ['wget'])).stdout != '', 35 | 'hasBash': (await Process.run('which', ['bash'])).stdout != '', 36 | 'hasGit': (await Process.run('which', ['git'])).stdout != '', 37 | 'hasFfmpeg': (await Process.run('which', ['ffmpeg'])).stdout != '', 38 | 'hasUnzip': (await Process.run('which', ['unzip'])).stdout != '', 39 | 'hasConda': (await Process.run('which', ['conda'])).stdout != '', 40 | }; 41 | requirements.value = newRequirements; 42 | List newStartProcesses = []; 43 | if (newRequirements['hasWget'] == false || 44 | newRequirements['hasBash'] == false || 45 | newRequirements['hasGit'] == false || 46 | newRequirements['hasFfmpeg'] == false || 47 | newRequirements['hasUnzip'] == false) { 48 | newStartProcesses.add(StartProcess(executable: 'pkexec', arguments: [ 49 | 'bash', 50 | '-c', 51 | """ 52 | apt install \\ 53 | ${newRequirements['hasBash'] == false ? "bash \\" : ""} 54 | ${newRequirements['hasWget'] == false ? "wget \\" : ""} 55 | ${newRequirements['hasGit'] == false ? "git \\" : ""} 56 | ${newRequirements['hasFfmpeg'] == false ? "ffmpeg \\" : ""} 57 | ${newRequirements['hasUnzip'] == false ? "unzip \\" : ""} 58 | -y 59 | """ 60 | ])); 61 | } 62 | if (newRequirements['hasConda'] == false) { 63 | String miniCondaFolder = "${condaInstallFolder.value}/miniconda"; 64 | newStartProcesses.add(StartProcess(executable: 'bash', arguments: [ 65 | '-c', 66 | """\\ 67 | rm -f $miniCondaFolder.sh && \\ 68 | rm -rf $miniCondaFolder && \\ 69 | wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O $miniCondaFolder.sh --no-check-certificate && \\ 70 | bash $miniCondaFolder.sh -b -p $miniCondaFolder && \\ 71 | rm $miniCondaFolder.sh 72 | """ 73 | ])); 74 | String binMiniConda = "$miniCondaFolder/bin"; 75 | newStartProcesses.add(StartProcess(executable: 'pkexec', arguments: [ 76 | 'bash', 77 | '-c', 78 | """\n 79 | if ! grep -q '$binMiniConda' /etc/environment; then 80 | sed -i '\$s/.\$/:${binMiniConda.replaceAll('/', '\\/')}"/' /etc/environment 81 | fi 82 | """ 83 | ])); 84 | } 85 | startProcesses.value = newStartProcesses; 86 | whoami.value = (await Process.run('whoami', [])).stdout; 87 | dispatch({ 88 | 'hasRequirements': requirements.value?.entries 89 | .map((e) => e.value) 90 | .reduce((value, element) => value && element) 91 | }); 92 | } 93 | 94 | onUpdateRequirements() async { 95 | loading.value = true; 96 | await updateRequirements(); 97 | loading.value = false; 98 | } 99 | 100 | selectFolder() { 101 | FilesystemPicker.openDialog( 102 | title: 'Save to folder', 103 | context: context, 104 | rootDirectory: Directory(Platform.pathSeparator), 105 | directory: Directory(condaInstallFolder.value), 106 | fsType: FilesystemType.folder, 107 | pickText: 'Validate (use this folder to install conda)', 108 | ).then((value) { 109 | return condaInstallFolder.value = value ?? condaInstallFolder.value; 110 | }); 111 | } 112 | 113 | onInstallationDone(int code) { 114 | if (requirements.value!['hasConda'] == false) { 115 | ScaffoldMessenger.of(context).showSnackBar(SnackBar( 116 | showCloseIcon: false, 117 | backgroundColor: Theme.of(context).colorScheme.background, 118 | content: const SelectableText( 119 | 'Please restart your computer to load conda in your PATH', 120 | style: TextStyle(color: Colors.white), 121 | ), 122 | duration: const Duration(days: 1), 123 | )); 124 | } 125 | onUpdateRequirements(); 126 | } 127 | 128 | useEffect(() { 129 | updateRequirements(); 130 | return null; 131 | }, [condaInstallFolder.value]); 132 | 133 | return Container( 134 | margin: const EdgeInsets.all(10.0), 135 | child: Column( 136 | crossAxisAlignment: CrossAxisAlignment.start, 137 | children: [ 138 | const MarkdownBody( 139 | selectable: true, 140 | data: """# Requirements""", 141 | ), 142 | if (requirements.value != null) ...[ 143 | MarkdownBody( 144 | selectable: true, 145 | data: """ 146 | ${requirements.value!['hasWget'] == true ? "✅ `wget`" : "❌ `wget` was not found by running command `which wget`, just run `sudo apt install wget -y` to install it"} 147 | 148 | ${requirements.value!['hasBash'] == true ? "✅ `bash`" : "❌ `bash` was not found by running command `which bash`, just run `sudo apt install bash -y` to install it"} 149 | 150 | ${requirements.value!['hasGit'] == true ? "✅ `git`" : "❌ `git` was not found by running command `which git`, just run `sudo apt install git -y` to install it"} 151 | 152 | ${requirements.value!['hasFfmpeg'] == true ? "✅ `ffmpeg`" : "❌ `ffmpeg` was not found by running command `which ffmpeg`, just run `sudo apt install ffmpeg -y` to install it"} 153 | 154 | ${requirements.value!['hasUnzip'] == true ? "✅ `unzip`" : "❌ `unzip` was not found by running command `which unzip`, just run `sudo apt install unzip -y` to install it"} 155 | 156 | ${requirements.value!['hasConda'] == true ? "✅ `conda`" : "❌ `conda` was not found by running command which conda, to install conda [follow the tutorial](https://docs.conda.io/projects/conda/en/latest/user-guide/install/)"} 157 | """, 158 | onTapLink: (text, url, title) { 159 | if (url != null) launchUrl(Uri.parse(url)); 160 | }), 161 | hasRequirements != true 162 | ? Column( 163 | crossAxisAlignment: CrossAxisAlignment.start, 164 | children: [ 165 | Container( 166 | margin: const EdgeInsets.only(top: 50.0), 167 | child: const MarkdownBody(selectable: true, data: """ 168 | ## Install by yourself 169 | 170 | You need to install the missing packages, and add it to your `PATH` if necessary 171 | 172 | - You can do it yourself and then click on `Recheck my requirements`. 173 | - Or you can click on `Install for me` and DeepFaceLabClient will try to install all missing packages for you. 174 | """), 175 | ), 176 | Container( 177 | margin: const EdgeInsets.only(top: 30.0, bottom: 30.0), 178 | child: ElevatedButton.icon( 179 | onPressed: 180 | loading.value ? null : onUpdateRequirements, 181 | icon: loading.value 182 | ? const CircularProgressIndicator( 183 | color: Colors.white, 184 | ) 185 | : const SizedBox.shrink(), 186 | label: const Text('Recheck my requirements'), 187 | ), 188 | ), 189 | const DividerWithTextWidget(text: "OR"), 190 | Container( 191 | margin: 192 | const EdgeInsets.only(top: 30.0, bottom: 30.0), 193 | child: Column( 194 | crossAxisAlignment: CrossAxisAlignment.start, 195 | children: [ 196 | const MarkdownBody(selectable: true, data: """ 197 | ## Let DeepFaceLabClient try to install 198 | """), 199 | if (requirements.value!['hasConda'] == false) ...[ 200 | Row( 201 | children: [ 202 | MarkdownBody(selectable: true, data: """ 203 | `conda` will be install in this folder `${condaInstallFolder.value}` 204 | """), 205 | IconButton( 206 | icon: const Icon(Icons.folder), 207 | splashRadius: 20, 208 | onPressed: selectFolder, 209 | ), 210 | ], 211 | ), 212 | MarkdownBody(selectable: true, data: """ 213 | please click on the folder icon to change the location (you must have write permission to this folder as user `${whoami.value}`) 214 | 215 | Note that DeepFaceLabClient will add a path in your `/etc/environment` file to add `conda` in your `PATH`, 216 | when the installation is done you will need to restart your computer. 217 | """), 218 | ], 219 | Container( 220 | margin: const EdgeInsets.only(top: 10.0), 221 | child: StartProcessWidget( 222 | workspace: null, 223 | label: "Install for me", 224 | startProcesses: startProcesses.value, 225 | callback: onInstallationDone, 226 | usePrototypeItem: false, 227 | ), 228 | ), 229 | ], 230 | )), 231 | Container( 232 | margin: const EdgeInsets.only(top: 10.0), 233 | child: const OpenIssueWidget()), 234 | ], 235 | ) 236 | : const SizedBox.shrink() 237 | ] else ...[ 238 | const CircularProgressIndicator() 239 | ], 240 | ], 241 | ), 242 | ); 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /lib/widget/installation/requirement_windows_widget.dart: -------------------------------------------------------------------------------- 1 | import 'package:deepfacelab_client/class/app_state.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_hooks/flutter_hooks.dart'; 4 | import 'package:flutter_redux_hooks/flutter_redux_hooks.dart'; 5 | 6 | class RequirementWindowsWidget extends HookWidget { 7 | const RequirementWindowsWidget({Key? key}) : super(key: key); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | final dispatch = useDispatch(); 12 | 13 | updateRequirements() async { 14 | dispatch({ 15 | 'hasRequirements': true, 16 | }); 17 | } 18 | 19 | useEffect(() { 20 | updateRequirements(); 21 | return null; 22 | }, []); 23 | 24 | return const SizedBox.shrink(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.10) 3 | project(runner LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "DeepFaceLabClient") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.example.deepfacelab_client") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | # Generated plugin build rules, which manage building the plugins and adding 90 | # them to the application. 91 | include(flutter/generated_plugins.cmake) 92 | 93 | 94 | # === Installation === 95 | # By default, "installing" just makes a relocatable bundle in the build 96 | # directory. 97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 100 | endif() 101 | 102 | # Start with a clean build bundle directory every time. 103 | install(CODE " 104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 105 | " COMPONENT Runtime) 106 | 107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 109 | 110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 111 | COMPONENT Runtime) 112 | 113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 114 | COMPONENT Runtime) 115 | 116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 117 | COMPONENT Runtime) 118 | 119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 120 | install(FILES "${bundled_library}" 121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 122 | COMPONENT Runtime) 123 | endforeach(bundled_library) 124 | 125 | # Fully re-copy the assets directory on each build to avoid having stale files 126 | # from a previous install. 127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 128 | install(CODE " 129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 130 | " COMPONENT Runtime) 131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 133 | 134 | # Install the AOT library on non-Debug builds only. 135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 137 | COMPONENT Runtime) 138 | endif() 139 | -------------------------------------------------------------------------------- /linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | void fl_register_plugins(FlPluginRegistry* registry) { 14 | g_autoptr(FlPluginRegistrar) desktop_drop_registrar = 15 | fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopDropPlugin"); 16 | desktop_drop_plugin_register_with_registrar(desktop_drop_registrar); 17 | g_autoptr(FlPluginRegistrar) desktop_multi_window_registrar = 18 | fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopMultiWindowPlugin"); 19 | desktop_multi_window_plugin_register_with_registrar(desktop_multi_window_registrar); 20 | g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = 21 | fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); 22 | url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); 23 | } 24 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | desktop_drop 7 | desktop_multi_window 8 | url_launcher_linux 9 | ) 10 | 11 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 12 | ) 13 | 14 | set(PLUGIN_BUNDLED_LIBRARIES) 15 | 16 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 17 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 18 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 20 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 21 | endforeach(plugin) 22 | 23 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 24 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 25 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 26 | endforeach(ffi_plugin) 27 | -------------------------------------------------------------------------------- /linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "DeepFaceLabClient"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "DeepFaceLabClient"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: deepfacelab_client 2 | description: Just an app to use DeepFaceLab with a user interface. 3 | # The following line prevents the package from being accidentally published to 4 | # pub.dev using `flutter pub publish`. This is preferred for private packages. 5 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 6 | 7 | # The following defines the version and build number for your application. 8 | # A version number is three numbers separated by dots, like 1.2.43 9 | # followed by an optional build number separated by a +. 10 | # Both the version and the builder number may be overridden in flutter 11 | # build by specifying --build-name and --build-number, respectively. 12 | # In Android, build-name is used as versionName while build-number used as versionCode. 13 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 14 | # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. 15 | # Read more about iOS versioning at 16 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 17 | # In Windows, build-name is used as the major, minor, and patch parts 18 | # of the product and file versions while build-number is used as the build suffix. 19 | version: 0.4.4 20 | 21 | environment: 22 | sdk: '>=2.19.4 <3.0.0' 23 | 24 | # Dependencies specify other packages that your package needs in order to work. 25 | # To automatically upgrade your package dependencies to the latest versions 26 | # consider running `flutter pub upgrade --major-versions`. Alternatively, 27 | # dependencies can be manually updated by changing the version numbers below to 28 | # the latest version available on pub.dev. To see which dependencies have newer 29 | # versions available, run `flutter pub outdated`. 30 | dependencies: 31 | flutter: 32 | sdk: flutter 33 | 34 | 35 | # The following adds the Cupertino Icons font to your application. 36 | # Use with the CupertinoIcons class for iOS style icons. 37 | cupertino_icons: ^1.0.2 38 | flutter_hooks: ^0.18.6 39 | path_provider: ^2.0.13 40 | redux: ^5.0.0 41 | flutter_markdown: ^0.7.3+1 42 | url_launcher: ^6.1.10 43 | filesystem_picker: ^4.1.0 44 | json_annotation: ^4.8.0 45 | slugify: ^2.0.0 46 | path: ^1.8.2 47 | package_info_plus: ^8.0.2 48 | flutter_redux_hooks: ^0.2.0 49 | collection: ^1.17.0 50 | desktop_multi_window: ^0.2.0 51 | desktop_drop: ^0.4.1 52 | http: ^1.2.2 53 | file_sizes: ^1.0.6 54 | intl: ^0.19.0 55 | 56 | dev_dependencies: 57 | flutter_test: 58 | sdk: flutter 59 | 60 | # The "flutter_lints" package below contains a set of recommended lints to 61 | # encourage good coding practices. The lint set provided by the package is 62 | # activated in the `analysis_options.yaml` file located at the root of your 63 | # package. See that file for information about deactivating specific lint 64 | # rules and activating additional ones. 65 | flutter_lints: ^4.0.0 66 | build_runner: ^2.3.3 67 | json_serializable: ^6.6.1 68 | 69 | # For information on the generic Dart part of this file, see the 70 | # following page: https://dart.dev/tools/pub/pubspec 71 | 72 | # The following section is specific to Flutter packages. 73 | flutter: 74 | 75 | # The following line ensures that the Material Icons font is 76 | # included with your application, so that you can use the icons in 77 | # the material Icons class. 78 | uses-material-design: true 79 | 80 | # To add assets to your application, add an assets section, like this: 81 | # assets: 82 | # - images/a_dot_burr.jpeg 83 | # - images/a_dot_ham.jpeg 84 | 85 | # An image asset can refer to one or more resolution-specific "variants", see 86 | # https://flutter.dev/assets-and-images/#resolution-aware 87 | 88 | # For details regarding adding assets from package dependencies, see 89 | # https://flutter.dev/assets-and-images/#from-packages 90 | 91 | # To add custom fonts to your application, add a fonts section here, 92 | # in this "flutter" section. Each entry in this list should have a 93 | # "family" key with the font family name, and a "fonts" key with a 94 | # list giving the asset and other descriptors for the font. For 95 | # example: 96 | # fonts: 97 | # - family: Schyler 98 | # fonts: 99 | # - asset: fonts/Schyler-Regular.ttf 100 | # - asset: fonts/Schyler-Italic.ttf 101 | # style: italic 102 | # - family: Trajan Pro 103 | # fonts: 104 | # - asset: fonts/TrajanPro.ttf 105 | # - asset: fonts/TrajanPro_Bold.ttf 106 | # weight: 700 107 | # 108 | # For details regarding fonts from package dependencies, 109 | # see https://flutter.dev/custom-fonts/#from-packages 110 | -------------------------------------------------------------------------------- /requirements/linux/import_lib.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | result=$(ldd DeepFaceLabClient-linux/DeepFaceLabClient) 4 | result=$(echo "$result" | grep --perl-regexp '.*=> /lib.* ' --only-matching) 5 | 6 | readarray -t <<<"$result" 7 | 8 | for (( i=0; i<${#MAPFILE[@]}; i++ )) 9 | do 10 | MAPFILE[$i]=$(echo "${MAPFILE[$i]}" | xargs) 11 | filename=$(echo "${MAPFILE[$i]}" | grep --perl-regexp '.*=>' --only-matching) 12 | filename="${filename/ =>/""}" 13 | filepath=$(echo "${MAPFILE[$i]}" | grep --perl-regexp '=>.*' --only-matching) 14 | filepath="${filepath/=> /""}" 15 | cp "$filepath" DeepFaceLabClient-linux/lib/"$filename" 16 | echo "copied $filepath in DeepFaceLabClient-linux/lib/$filename" 17 | done 18 | -------------------------------------------------------------------------------- /requirements/windows/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lenny4/DeepFaceLabClient/8323c9df12d39624b030572784c977985dd2ee3b/requirements/windows/.gitkeep -------------------------------------------------------------------------------- /requirements/windows/msvcp140.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lenny4/DeepFaceLabClient/8323c9df12d39624b030572784c977985dd2ee3b/requirements/windows/msvcp140.dll -------------------------------------------------------------------------------- /requirements/windows/vcruntime140.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lenny4/DeepFaceLabClient/8323c9df12d39624b030572784c977985dd2ee3b/requirements/windows/vcruntime140.dll -------------------------------------------------------------------------------- /requirements/windows/vcruntime140_1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lenny4/DeepFaceLabClient/8323c9df12d39624b030572784c977985dd2ee3b/requirements/windows/vcruntime140_1.dll -------------------------------------------------------------------------------- /script/linux/install_release.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | folderName=$1 4 | folderPath=$2 5 | downloadFileName=$3 6 | execPath=$4 7 | createdFolder=$5 8 | 9 | #just to be sure that DeepFaceLabClient is closed 10 | sleep 2 11 | 12 | rm -rf $folderPath/$folderName 13 | unzip -o $folderPath/$downloadFileName -d $folderPath 14 | #to preserve shortcut and symbolic link 15 | mv $folderPath/$createdFolder $folderPath/$folderName 16 | rm $folderPath/$downloadFileName 17 | $execPath & rm $folderPath/install_release.sh -------------------------------------------------------------------------------- /script/python/getDevices.py: -------------------------------------------------------------------------------- 1 | # https://stackoverflow.com/questions/4383571/importing-files-from-different-folder#answer-4383597 2 | import json 3 | import sys 4 | 5 | # caution: path[0] is reserved for script path (or '' in REPL) 6 | sys.path.insert(1, '%deepFaceLabFolder%') 7 | 8 | from core.leras.device import Devices 9 | 10 | Devices.initialize_main_env() 11 | all_devices = [] 12 | for device in Devices.getDevices(): 13 | deviceJson = {} 14 | # https://stackoverflow.com/questions/25150955/python-iterating-through-object-attributes#answer-25151000 15 | for attr, value in device.__dict__.items(): 16 | deviceJson[attr] = value 17 | all_devices.append(deviceJson) 18 | # all_devices.append({ 19 | # 'index': 0, 20 | # 'tf_dev_type': 'tf_dev_type', 21 | # 'name': 'name', 22 | # 'total_mem': 3221225472, 23 | # 'total_mem_gb': 3221225472 / 1024 ** 3, 24 | # 'free_mem': 3221225472, 25 | # 'free_mem_gb': 3221225472 / 1024 ** 3, 26 | # }) 27 | # all_devices.append({ 28 | # 'index': 1, 29 | # 'tf_dev_type': 'tf_dev_type', 30 | # 'name': 'name', 31 | # 'total_mem': 3221225472, 32 | # 'total_mem_gb': 3221225472 / 1024 ** 3, 33 | # 'free_mem': 3221225472, 34 | # 'free_mem_gb': 3221225472 / 1024 ** 3, 35 | # }) 36 | print(json.dumps(all_devices), end='') 37 | -------------------------------------------------------------------------------- /script/windows/install_release.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set folderName=%1 4 | set folderPath=%2 5 | set downloadFileName=%3 6 | set execPath=%4 7 | set createdFolder=%5 8 | 9 | powershell -command "Start-Sleep -s 2" 10 | 11 | tar -xf %folderPath%\%downloadFileName% -C %folderPath% 12 | if %createdFolder% neq %folderName% ( 13 | xcopy %folderPath%\%createdFolder% %folderPath%\%folderName% /Y /S 14 | rmdir /s /q %folderPath%\%createdFolder% 15 | ) 16 | del %folderPath%\%downloadFileName% 17 | start /b "" cmd /c %execPath% /b 18 | start /b "" cmd /c del %folderPath%\install_release.bat&exit /b 19 | -------------------------------------------------------------------------------- /windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(deepfacelab_client LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "DeepFaceLabClient") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(SET CMP0063 NEW) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | # Generated plugin build rules, which manage building the plugins and adding 56 | # them to the application. 57 | include(flutter/generated_plugins.cmake) 58 | 59 | 60 | # === Installation === 61 | # Support files are copied into place next to the executable, so that it can 62 | # run in place. This is done instead of making a separate bundle (as on Linux) 63 | # so that building and running from within Visual Studio will work. 64 | set(BUILD_BUNDLE_DIR "$") 65 | # Make the "install" step default, as it's required to run. 66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 69 | endif() 70 | 71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 73 | 74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 75 | COMPONENT Runtime) 76 | 77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 78 | COMPONENT Runtime) 79 | 80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 81 | COMPONENT Runtime) 82 | 83 | if(PLUGIN_BUNDLED_LIBRARIES) 84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 86 | COMPONENT Runtime) 87 | endif() 88 | 89 | # Fully re-copy the assets directory on each build to avoid having stale files 90 | # from a previous install. 91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 92 | install(CODE " 93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 94 | " COMPONENT Runtime) 95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 97 | 98 | # Install the AOT library on non-Debug builds only. 99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 100 | CONFIGURATIONS Profile;Release 101 | COMPONENT Runtime) 102 | -------------------------------------------------------------------------------- /windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # Set fallback configurations for older versions of the flutter tool. 14 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM) 15 | set(FLUTTER_TARGET_PLATFORM "windows-x64") 16 | endif() 17 | 18 | # === Flutter Library === 19 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 20 | 21 | # Published to parent scope for install step. 22 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 23 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 24 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 25 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 26 | 27 | list(APPEND FLUTTER_LIBRARY_HEADERS 28 | "flutter_export.h" 29 | "flutter_windows.h" 30 | "flutter_messenger.h" 31 | "flutter_plugin_registrar.h" 32 | "flutter_texture_registrar.h" 33 | ) 34 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 35 | add_library(flutter INTERFACE) 36 | target_include_directories(flutter INTERFACE 37 | "${EPHEMERAL_DIR}" 38 | ) 39 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 40 | add_dependencies(flutter flutter_assemble) 41 | 42 | # === Wrapper === 43 | list(APPEND CPP_WRAPPER_SOURCES_CORE 44 | "core_implementations.cc" 45 | "standard_codec.cc" 46 | ) 47 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 48 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 49 | "plugin_registrar.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 52 | list(APPEND CPP_WRAPPER_SOURCES_APP 53 | "flutter_engine.cc" 54 | "flutter_view_controller.cc" 55 | ) 56 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 57 | 58 | # Wrapper sources needed for a plugin. 59 | add_library(flutter_wrapper_plugin STATIC 60 | ${CPP_WRAPPER_SOURCES_CORE} 61 | ${CPP_WRAPPER_SOURCES_PLUGIN} 62 | ) 63 | apply_standard_settings(flutter_wrapper_plugin) 64 | set_target_properties(flutter_wrapper_plugin PROPERTIES 65 | POSITION_INDEPENDENT_CODE ON) 66 | set_target_properties(flutter_wrapper_plugin PROPERTIES 67 | CXX_VISIBILITY_PRESET hidden) 68 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 69 | target_include_directories(flutter_wrapper_plugin PUBLIC 70 | "${WRAPPER_ROOT}/include" 71 | ) 72 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 73 | 74 | # Wrapper sources needed for the runner. 75 | add_library(flutter_wrapper_app STATIC 76 | ${CPP_WRAPPER_SOURCES_CORE} 77 | ${CPP_WRAPPER_SOURCES_APP} 78 | ) 79 | apply_standard_settings(flutter_wrapper_app) 80 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 81 | target_include_directories(flutter_wrapper_app PUBLIC 82 | "${WRAPPER_ROOT}/include" 83 | ) 84 | add_dependencies(flutter_wrapper_app flutter_assemble) 85 | 86 | # === Flutter tool backend === 87 | # _phony_ is a non-existent file to force this command to run every time, 88 | # since currently there's no way to get a full input/output list from the 89 | # flutter tool. 90 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 91 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 92 | add_custom_command( 93 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 94 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 95 | ${CPP_WRAPPER_SOURCES_APP} 96 | ${PHONY_OUTPUT} 97 | COMMAND ${CMAKE_COMMAND} -E env 98 | ${FLUTTER_TOOL_ENVIRONMENT} 99 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 100 | ${FLUTTER_TARGET_PLATFORM} $ 101 | VERBATIM 102 | ) 103 | add_custom_target(flutter_assemble DEPENDS 104 | "${FLUTTER_LIBRARY}" 105 | ${FLUTTER_LIBRARY_HEADERS} 106 | ${CPP_WRAPPER_SOURCES_CORE} 107 | ${CPP_WRAPPER_SOURCES_PLUGIN} 108 | ${CPP_WRAPPER_SOURCES_APP} 109 | ) 110 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | void RegisterPlugins(flutter::PluginRegistry* registry) { 14 | DesktopDropPluginRegisterWithRegistrar( 15 | registry->GetRegistrarForPlugin("DesktopDropPlugin")); 16 | DesktopMultiWindowPluginRegisterWithRegistrar( 17 | registry->GetRegistrarForPlugin("DesktopMultiWindowPlugin")); 18 | UrlLauncherWindowsRegisterWithRegistrar( 19 | registry->GetRegistrarForPlugin("UrlLauncherWindows")); 20 | } 21 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | desktop_drop 7 | desktop_multi_window 8 | url_launcher_windows 9 | ) 10 | 11 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 12 | ) 13 | 14 | set(PLUGIN_BUNDLED_LIBRARIES) 15 | 16 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 17 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 18 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 20 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 21 | endforeach(plugin) 22 | 23 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 24 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 25 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 26 | endforeach(ffi_plugin) 27 | -------------------------------------------------------------------------------- /windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") 37 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 38 | 39 | # Run the Flutter tool portions of the build. This must not be removed. 40 | add_dependencies(${BINARY_NAME} flutter_assemble) 41 | -------------------------------------------------------------------------------- /windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.example" "\0" 93 | VALUE "FileDescription", "DeepFaceLabClient" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "DeepFaceLabClient" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2023 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "DeepFaceLabClient.exe" "\0" 98 | VALUE "ProductName", "DeepFaceLabClient" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | 30 | flutter_controller_->engine()->SetNextFrameCallback([&]() { 31 | this->Show(); 32 | }); 33 | 34 | // Flutter can complete the first frame before the "show window" callback is 35 | // registered. The following call ensures a frame is pending to ensure the 36 | // window is shown. It is a no-op if the first frame hasn't completed yet. 37 | // todo commented because of https://github.com/Lenny4/DeepFaceLabClient/actions/runs/5239081494/jobs/9458584452 38 | // flutter_controller_->ForceRedraw(); 39 | 40 | return true; 41 | } 42 | 43 | void FlutterWindow::OnDestroy() { 44 | if (flutter_controller_) { 45 | flutter_controller_ = nullptr; 46 | } 47 | 48 | Win32Window::OnDestroy(); 49 | } 50 | 51 | LRESULT 52 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 53 | WPARAM const wparam, 54 | LPARAM const lparam) noexcept { 55 | // Give Flutter, including plugins, an opportunity to handle window messages. 56 | if (flutter_controller_) { 57 | std::optional result = 58 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 59 | lparam); 60 | if (result) { 61 | return *result; 62 | } 63 | } 64 | 65 | switch (message) { 66 | case WM_FONTCHANGE: 67 | flutter_controller_->engine()->ReloadSystemFonts(); 68 | break; 69 | } 70 | 71 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 72 | } 73 | -------------------------------------------------------------------------------- /windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.Create(L"DeepFaceLabClient", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lenny4/DeepFaceLabClient/8323c9df12d39624b030572784c977985dd2ee3b/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | std::string utf8_string; 52 | if (target_length == 0 || target_length > utf8_string.max_size()) { 53 | return utf8_string; 54 | } 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /windows/runner/win32_window.cpp: -------------------------------------------------------------------------------- 1 | #include "win32_window.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "resource.h" 7 | 8 | namespace { 9 | 10 | /// Window attribute that enables dark mode window decorations. 11 | /// 12 | /// Redefined in case the developer's machine has a Windows SDK older than 13 | /// version 10.0.22000.0. 14 | /// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute 15 | #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE 16 | #define DWMWA_USE_IMMERSIVE_DARK_MODE 20 17 | #endif 18 | 19 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; 20 | 21 | /// Registry key for app theme preference. 22 | /// 23 | /// A value of 0 indicates apps should use dark mode. A non-zero or missing 24 | /// value indicates apps should use light mode. 25 | constexpr const wchar_t kGetPreferredBrightnessRegKey[] = 26 | L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; 27 | constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme"; 28 | 29 | // The number of Win32Window objects that currently exist. 30 | static int g_active_window_count = 0; 31 | 32 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); 33 | 34 | // Scale helper to convert logical scaler values to physical using passed in 35 | // scale factor 36 | int Scale(int source, double scale_factor) { 37 | return static_cast(source * scale_factor); 38 | } 39 | 40 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. 41 | // This API is only needed for PerMonitor V1 awareness mode. 42 | void EnableFullDpiSupportIfAvailable(HWND hwnd) { 43 | HMODULE user32_module = LoadLibraryA("User32.dll"); 44 | if (!user32_module) { 45 | return; 46 | } 47 | auto enable_non_client_dpi_scaling = 48 | reinterpret_cast( 49 | GetProcAddress(user32_module, "EnableNonClientDpiScaling")); 50 | if (enable_non_client_dpi_scaling != nullptr) { 51 | enable_non_client_dpi_scaling(hwnd); 52 | } 53 | FreeLibrary(user32_module); 54 | } 55 | 56 | } // namespace 57 | 58 | // Manages the Win32Window's window class registration. 59 | class WindowClassRegistrar { 60 | public: 61 | ~WindowClassRegistrar() = default; 62 | 63 | // Returns the singleton registar instance. 64 | static WindowClassRegistrar* GetInstance() { 65 | if (!instance_) { 66 | instance_ = new WindowClassRegistrar(); 67 | } 68 | return instance_; 69 | } 70 | 71 | // Returns the name of the window class, registering the class if it hasn't 72 | // previously been registered. 73 | const wchar_t* GetWindowClass(); 74 | 75 | // Unregisters the window class. Should only be called if there are no 76 | // instances of the window. 77 | void UnregisterWindowClass(); 78 | 79 | private: 80 | WindowClassRegistrar() = default; 81 | 82 | static WindowClassRegistrar* instance_; 83 | 84 | bool class_registered_ = false; 85 | }; 86 | 87 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; 88 | 89 | const wchar_t* WindowClassRegistrar::GetWindowClass() { 90 | if (!class_registered_) { 91 | WNDCLASS window_class{}; 92 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); 93 | window_class.lpszClassName = kWindowClassName; 94 | window_class.style = CS_HREDRAW | CS_VREDRAW; 95 | window_class.cbClsExtra = 0; 96 | window_class.cbWndExtra = 0; 97 | window_class.hInstance = GetModuleHandle(nullptr); 98 | window_class.hIcon = 99 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 100 | window_class.hbrBackground = 0; 101 | window_class.lpszMenuName = nullptr; 102 | window_class.lpfnWndProc = Win32Window::WndProc; 103 | RegisterClass(&window_class); 104 | class_registered_ = true; 105 | } 106 | return kWindowClassName; 107 | } 108 | 109 | void WindowClassRegistrar::UnregisterWindowClass() { 110 | UnregisterClass(kWindowClassName, nullptr); 111 | class_registered_ = false; 112 | } 113 | 114 | Win32Window::Win32Window() { 115 | ++g_active_window_count; 116 | } 117 | 118 | Win32Window::~Win32Window() { 119 | --g_active_window_count; 120 | Destroy(); 121 | } 122 | 123 | bool Win32Window::Create(const std::wstring& title, 124 | const Point& origin, 125 | const Size& size) { 126 | Destroy(); 127 | 128 | const wchar_t* window_class = 129 | WindowClassRegistrar::GetInstance()->GetWindowClass(); 130 | 131 | const POINT target_point = {static_cast(origin.x), 132 | static_cast(origin.y)}; 133 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); 134 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); 135 | double scale_factor = dpi / 96.0; 136 | 137 | HWND window = CreateWindow( 138 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW, 139 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), 140 | Scale(size.width, scale_factor), Scale(size.height, scale_factor), 141 | nullptr, nullptr, GetModuleHandle(nullptr), this); 142 | 143 | if (!window) { 144 | return false; 145 | } 146 | 147 | UpdateTheme(window); 148 | 149 | return OnCreate(); 150 | } 151 | 152 | bool Win32Window::Show() { 153 | return ShowWindow(window_handle_, SW_SHOWNORMAL); 154 | } 155 | 156 | // static 157 | LRESULT CALLBACK Win32Window::WndProc(HWND const window, 158 | UINT const message, 159 | WPARAM const wparam, 160 | LPARAM const lparam) noexcept { 161 | if (message == WM_NCCREATE) { 162 | auto window_struct = reinterpret_cast(lparam); 163 | SetWindowLongPtr(window, GWLP_USERDATA, 164 | reinterpret_cast(window_struct->lpCreateParams)); 165 | 166 | auto that = static_cast(window_struct->lpCreateParams); 167 | EnableFullDpiSupportIfAvailable(window); 168 | that->window_handle_ = window; 169 | } else if (Win32Window* that = GetThisFromHandle(window)) { 170 | return that->MessageHandler(window, message, wparam, lparam); 171 | } 172 | 173 | return DefWindowProc(window, message, wparam, lparam); 174 | } 175 | 176 | LRESULT 177 | Win32Window::MessageHandler(HWND hwnd, 178 | UINT const message, 179 | WPARAM const wparam, 180 | LPARAM const lparam) noexcept { 181 | switch (message) { 182 | case WM_DESTROY: 183 | window_handle_ = nullptr; 184 | Destroy(); 185 | if (quit_on_close_) { 186 | PostQuitMessage(0); 187 | } 188 | return 0; 189 | 190 | case WM_DPICHANGED: { 191 | auto newRectSize = reinterpret_cast(lparam); 192 | LONG newWidth = newRectSize->right - newRectSize->left; 193 | LONG newHeight = newRectSize->bottom - newRectSize->top; 194 | 195 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, 196 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE); 197 | 198 | return 0; 199 | } 200 | case WM_SIZE: { 201 | RECT rect = GetClientArea(); 202 | if (child_content_ != nullptr) { 203 | // Size and position the child window. 204 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, 205 | rect.bottom - rect.top, TRUE); 206 | } 207 | return 0; 208 | } 209 | 210 | case WM_ACTIVATE: 211 | if (child_content_ != nullptr) { 212 | SetFocus(child_content_); 213 | } 214 | return 0; 215 | 216 | case WM_DWMCOLORIZATIONCOLORCHANGED: 217 | UpdateTheme(hwnd); 218 | return 0; 219 | } 220 | 221 | return DefWindowProc(window_handle_, message, wparam, lparam); 222 | } 223 | 224 | void Win32Window::Destroy() { 225 | OnDestroy(); 226 | 227 | if (window_handle_) { 228 | DestroyWindow(window_handle_); 229 | window_handle_ = nullptr; 230 | } 231 | if (g_active_window_count == 0) { 232 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); 233 | } 234 | } 235 | 236 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { 237 | return reinterpret_cast( 238 | GetWindowLongPtr(window, GWLP_USERDATA)); 239 | } 240 | 241 | void Win32Window::SetChildContent(HWND content) { 242 | child_content_ = content; 243 | SetParent(content, window_handle_); 244 | RECT frame = GetClientArea(); 245 | 246 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left, 247 | frame.bottom - frame.top, true); 248 | 249 | SetFocus(child_content_); 250 | } 251 | 252 | RECT Win32Window::GetClientArea() { 253 | RECT frame; 254 | GetClientRect(window_handle_, &frame); 255 | return frame; 256 | } 257 | 258 | HWND Win32Window::GetHandle() { 259 | return window_handle_; 260 | } 261 | 262 | void Win32Window::SetQuitOnClose(bool quit_on_close) { 263 | quit_on_close_ = quit_on_close; 264 | } 265 | 266 | bool Win32Window::OnCreate() { 267 | // No-op; provided for subclasses. 268 | return true; 269 | } 270 | 271 | void Win32Window::OnDestroy() { 272 | // No-op; provided for subclasses. 273 | } 274 | 275 | void Win32Window::UpdateTheme(HWND const window) { 276 | DWORD light_mode; 277 | DWORD light_mode_size = sizeof(light_mode); 278 | LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey, 279 | kGetPreferredBrightnessRegValue, 280 | RRF_RT_REG_DWORD, nullptr, &light_mode, 281 | &light_mode_size); 282 | 283 | if (result == ERROR_SUCCESS) { 284 | BOOL enable_dark_mode = light_mode == 0; 285 | DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE, 286 | &enable_dark_mode, sizeof(enable_dark_mode)); 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates a win32 window with |title| that is positioned and sized using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size this function will scale the inputted width and height as 35 | // as appropriate for the default monitor. The window is invisible until 36 | // |Show| is called. Returns true if the window was created successfully. 37 | bool Create(const std::wstring& title, const Point& origin, const Size& size); 38 | 39 | // Show the current window. Returns true if the window was successfully shown. 40 | bool Show(); 41 | 42 | // Release OS resources associated with window. 43 | void Destroy(); 44 | 45 | // Inserts |content| into the window tree. 46 | void SetChildContent(HWND content); 47 | 48 | // Returns the backing Window handle to enable clients to set icon and other 49 | // window properties. Returns nullptr if the window has been destroyed. 50 | HWND GetHandle(); 51 | 52 | // If true, closing this window will quit the application. 53 | void SetQuitOnClose(bool quit_on_close); 54 | 55 | // Return a RECT representing the bounds of the current client area. 56 | RECT GetClientArea(); 57 | 58 | protected: 59 | // Processes and route salient window messages for mouse handling, 60 | // size change and DPI. Delegates handling of these to member overloads that 61 | // inheriting classes can handle. 62 | virtual LRESULT MessageHandler(HWND window, 63 | UINT const message, 64 | WPARAM const wparam, 65 | LPARAM const lparam) noexcept; 66 | 67 | // Called when CreateAndShow is called, allowing subclass window-related 68 | // setup. Subclasses should return false if setup fails. 69 | virtual bool OnCreate(); 70 | 71 | // Called when Destroy is called. 72 | virtual void OnDestroy(); 73 | 74 | private: 75 | friend class WindowClassRegistrar; 76 | 77 | // OS callback called by message pump. Handles the WM_NCCREATE message which 78 | // is passed when the non-client area is being created and enables automatic 79 | // non-client DPI scaling so that the non-client area automatically 80 | // responsponds to changes in DPI. All other messages are handled by 81 | // MessageHandler. 82 | static LRESULT CALLBACK WndProc(HWND const window, 83 | UINT const message, 84 | WPARAM const wparam, 85 | LPARAM const lparam) noexcept; 86 | 87 | // Retrieves a class instance pointer for |window| 88 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 89 | 90 | // Update the window frame's theme to match the system theme. 91 | static void UpdateTheme(HWND const window); 92 | 93 | bool quit_on_close_ = false; 94 | 95 | // window handle for top level window. 96 | HWND window_handle_ = nullptr; 97 | 98 | // window handle for hosted content. 99 | HWND child_content_ = nullptr; 100 | }; 101 | 102 | #endif // RUNNER_WIN32_WINDOW_H_ 103 | --------------------------------------------------------------------------------