Skip to content

Commit

Permalink
feat(windows): add windows platform build (#23)
Browse files Browse the repository at this point in the history
* feat(windows): add windows platform build

* feat(msix): add msix config for winwdows installer generation
  • Loading branch information
PiotrFLEURY authored Feb 11, 2022
1 parent 941ecc6 commit 4c754a3
Show file tree
Hide file tree
Showing 24 changed files with 1,080 additions and 48 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
name: CI
on: push
jobs:
build:
windows-build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.10.0'
- name: analyze code
run: |
flutter pub get
flutter format --set-exit-if-changed .
flutter analyze
- name: run automated tests
run: |
flutter test
- name: build windows application
run: |
flutter build windows
flutter pub run msix:create
other-builds:
runs-on: macos-latest
strategy:
matrix:
Expand All @@ -13,7 +35,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v2
with:
flutter-version: '2.8.1'
flutter-version: '2.10.0'
- name: analyze code
run: |
flutter pub get
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ $ cd ..
$ flutter build macos --debug # or flutter run -d macos
```

This commands will build the macOS app for x86_64 architecture and will run the app using Rosetta.
This commands will build the macOS app for x86_64 architecture and will run the app using Rosetta.

## Windows Build

In order to build this app for Windows you must previously install Visual Studio 2022.

More details [here](https://docs.flutter.dev/desktop#additional-windows-requirements)
6 changes: 3 additions & 3 deletions lib/bloc/puzzle_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import 'package:image_picker/image_picker.dart';
import 'package:puzzle/bloc/bloc.dart';
import 'package:puzzle/models/models.dart';
import 'package:puzzle/services/audio_service.dart';
Expand Down Expand Up @@ -92,8 +92,8 @@ class PuzzleCubit extends Cubit<PuzzleState> {
emit(state.copyWith(puzzle: newPuzzle));
}

Future<void> loadUiImage(XFile pickedFile) async {
final bytes = await pickedFile.readAsBytes();
Future<void> loadUiImage(Uint8List? bytes) async {
if (bytes == null) return;
final codec = await ui.instantiateImageCodec(bytes);
final frame = await codec.getNextFrame();
emit(state.copyWith(image: frame.image));
Expand Down
19 changes: 14 additions & 5 deletions lib/view/puzzle_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import 'package:image_picker/image_picker.dart';
import 'package:puzzle/bloc/bloc.dart';
import 'package:puzzle/services/audio_service.dart';
import 'package:puzzle/services/shared.dart';
Expand Down Expand Up @@ -143,10 +146,16 @@ class _PuzzlePageState extends State<PuzzlePage> {
}

Future<void> _pickImage() async {
final picker = ImagePicker();
final pickedFile = await picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
context.read<PuzzleCubit>().loadUiImage(pickedFile);
FilePickerResult? result = await FilePicker.platform.pickFiles();

if (result != null) {
if (kIsWeb) {
context.read<PuzzleCubit>().loadUiImage(result.files.single.bytes);
} else {
final String path = result.files.single.path ?? '';
final bytes = await File(path).readAsBytes();
context.read<PuzzleCubit>().loadUiImage(bytes);
}
}
}

Expand Down
65 changes: 29 additions & 36 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.0"
ansicolor:
dependency: transitive
description:
name: ansicolor
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
archive:
dependency: transitive
description:
Expand Down Expand Up @@ -169,13 +176,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
cross_file:
dependency: transitive
description:
name: cross_file
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.2"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -218,6 +218,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
file_picker:
dependency: "direct main"
description:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.3"
fixnum:
dependency: transitive
description:
Expand Down Expand Up @@ -343,27 +350,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.1"
image_picker:
dependency: "direct main"
description:
name: image_picker
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.4+5"
image_picker_for_web:
dependency: transitive
description:
name: image_picker_for_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
image_picker_platform_interface:
dependency: transitive
description:
name: image_picker_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.3"
intl:
dependency: "direct main"
description:
Expand Down Expand Up @@ -413,6 +399,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
Expand All @@ -434,6 +427,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.17"
msix:
dependency: "direct dev"
description:
name: msix
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.15"
nested:
dependency: transitive
description:
Expand Down Expand Up @@ -504,13 +504,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.1"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -669,7 +662,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.8"
timing:
dependency: transitive
description:
Expand Down
11 changes: 10 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ environment:
dependencies:
audioplayers: ^0.20.1
cupertino_icons: ^1.0.2
file_picker: ^4.3.3
flutter:
sdk: flutter
flutter_bloc: ^8.0.1
flutter_localizations:
sdk: flutter
freezed_annotation: ^1.1.0
get_it: ^7.2.0
image_picker: ^0.8.4+5
intl: ^0.17.0
mockito: ^5.0.17
shake: ^2.0.0
Expand All @@ -49,6 +49,7 @@ dev_dependencies:
sdk: flutter
freezed: ^1.1.1
flutter_launcher_icons: "^0.9.2"
msix: ^2.8.15



Expand Down Expand Up @@ -106,3 +107,11 @@ flutter:
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

msix_config:
display_name: Xpeho mobile Puzzle
publisher_display_name: XpehoMobilePuzzle
identity_name: fr.xpeho.puzzle
msix_version: 1.0.0.0
logo_path: assets\images\icon_batman_pixel_with_background.png
capabilities: "picturesLibrary"
17 changes: 17 additions & 0 deletions windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
flutter/ephemeral/

# Visual Studio user-specific files.
*.suo
*.user
*.userosscache
*.sln.docstates

# Visual Studio build-related files.
x64/
x86/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
95 changes: 95 additions & 0 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
cmake_minimum_required(VERSION 3.14)
project(puzzle LANGUAGES CXX)

set(BINARY_NAME "puzzle")

cmake_policy(SET CMP0063 NEW)

set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")

# Configure build options.
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(IS_MULTICONFIG)
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
CACHE STRING "" FORCE)
else()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Debug" CACHE
STRING "Flutter build mode" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Profile" "Release")
endif()
endif()

set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")

# Use Unicode for all projects.
add_definitions(-DUNICODE -D_UNICODE)

# Compilation settings that should be applied to most targets.
function(APPLY_STANDARD_SETTINGS TARGET)
target_compile_features(${TARGET} PUBLIC cxx_std_17)
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
target_compile_options(${TARGET} PRIVATE /EHsc)
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
endfunction()

set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")

# Flutter library and tool build rules.
add_subdirectory(${FLUTTER_MANAGED_DIR})

# Application build
add_subdirectory("runner")

# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)


# === Installation ===
# Support files are copied into place next to the executable, so that it can
# run in place. This is done instead of making a separate bundle (as on Linux)
# so that building and running from within Visual Studio will work.
set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
# Make the "install" step default, as it's required to run.
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
endif()

set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")

install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
COMPONENT Runtime)

install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
COMPONENT Runtime)

install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)

if(PLUGIN_BUNDLED_LIBRARIES)
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endif()

# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
install(CODE "
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
" COMPONENT Runtime)
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)

# Install the AOT library on non-Debug builds only.
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
CONFIGURATIONS Profile;Release
COMPONENT Runtime)
Loading

0 comments on commit 4c754a3

Please sign in to comment.