chore: Windows support
Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>krille/remove-custom-fonts
parent
972615f91d
commit
542115a1ee
@ -0,0 +1,116 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'platform_infos.dart';
|
||||
|
||||
/// helper class checking for updates on platforms without store release
|
||||
///
|
||||
/// Currently, this is only Windows
|
||||
class UpdateCheckerNoStore {
|
||||
static const gitLabProjectId = '16112282';
|
||||
static const gitLabHost = 'gitlab.com';
|
||||
|
||||
static Uri get tagsUri => Uri.parse(
|
||||
'https://$gitLabHost/projects/$gitLabProjectId/repository/tags');
|
||||
|
||||
final BuildContext context;
|
||||
|
||||
const UpdateCheckerNoStore(this.context);
|
||||
|
||||
Future<void> checkUpdate() async {
|
||||
// platform-specific implementations
|
||||
try {
|
||||
if (PlatformInfos.isWindows) {
|
||||
final response = await get(tagsUri);
|
||||
if (response.statusCode == 200) {
|
||||
final json = jsonDecode(response.body);
|
||||
var latestTag = json[0]['name'] as String;
|
||||
var currentVersion = await PlatformInfos.getVersion();
|
||||
|
||||
if (latestTag.startsWith('v')) {
|
||||
latestTag = latestTag.substring(1);
|
||||
}
|
||||
if (currentVersion.startsWith('v')) {
|
||||
currentVersion = currentVersion.substring(1);
|
||||
}
|
||||
if (latestTag != currentVersion) {
|
||||
final metadata = UpdateMetadata(latestTag);
|
||||
await showUpdateDialog(metadata);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
throw response;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
Logs().i('Could not look for updates:', e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Uri downloadUri(UpdateMetadata metadata) {
|
||||
// platform specific
|
||||
if (PlatformInfos.isWindows) {
|
||||
return Uri.parse('https://$gitLabHost/famedly/fluffychat/-'
|
||||
'/jobs/artifacts/$metadata/raw/'
|
||||
'build/windows/runner/Release/fluffychat.msix?job=build_windows');
|
||||
} else {
|
||||
throw UnimplementedError('No download URI available for this platform.');
|
||||
}
|
||||
}
|
||||
|
||||
/// launches an app update
|
||||
///
|
||||
/// Either uses the operating systems package or app management to perform
|
||||
/// an update or launches a custom installer
|
||||
Future<void> launchUpdater(UpdateMetadata metadata) async {
|
||||
// platform specific
|
||||
try {
|
||||
if (kIsWeb) return;
|
||||
if (PlatformInfos.isWindows) {
|
||||
final dir = await getTemporaryDirectory();
|
||||
final response = await get(downloadUri(metadata));
|
||||
if (response.statusCode == 200) {
|
||||
final file = File(dir.path + '/fluffychat.msix');
|
||||
await file.writeAsBytes(response.bodyBytes);
|
||||
Process.start(file.path, [], runInShell: true);
|
||||
} else {
|
||||
throw response;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Logs().w('Error launching th update:', e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> showUpdateDialog(UpdateMetadata metadata) async {
|
||||
final result = await showOkCancelAlertDialog(
|
||||
title: L10n.of(context)!.updateAvailable,
|
||||
message: L10n.of(context)!.updateNow,
|
||||
context: context,
|
||||
);
|
||||
if (result == OkCancelResult.ok) {
|
||||
await launchUpdater(metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateMetadata {
|
||||
final String version;
|
||||
|
||||
const UpdateMetadata(this.version);
|
||||
|
||||
@override
|
||||
String toString() => 'v$version';
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
choco install flutter -y
|
||||
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
|
||||
refreshenv
|
||||
refreshenv
|
||||
|
||||
flutter config --no-analytics
|
||||
|
@ -1,18 +1,32 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(runner LANGUAGES CXX)
|
||||
|
||||
# Define the application target. To change its name, change BINARY_NAME in the
|
||||
# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
|
||||
# work.
|
||||
#
|
||||
# Any new source files that you add to the application should be added here.
|
||||
add_executable(${BINARY_NAME} WIN32
|
||||
"flutter_window.cpp"
|
||||
"main.cpp"
|
||||
"run_loop.cpp"
|
||||
"utils.cpp"
|
||||
"win32_window.cpp"
|
||||
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
|
||||
"Runner.rc"
|
||||
"runner.exe.manifest"
|
||||
)
|
||||
|
||||
# Apply the standard set of build settings. This can be removed for applications
|
||||
# that need different build settings.
|
||||
apply_standard_settings(${BINARY_NAME})
|
||||
|
||||
# Disable Windows macros that collide with C++ standard library functions.
|
||||
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
|
||||
|
||||
# Add dependency libraries and include directories. Add any application-specific
|
||||
# dependencies here.
|
||||
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
|
||||
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
|
||||
|
||||
# Run the Flutter tool portions of the build. This must not be removed.
|
||||
add_dependencies(${BINARY_NAME} flutter_assemble)
|
||||
|
@ -1,39 +0,0 @@
|
||||
#include "run_loop.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
RunLoop::RunLoop() {}
|
||||
|
||||
RunLoop::~RunLoop() {}
|
||||
|
||||
void RunLoop::Run() {
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, nullptr, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
void RunLoop::RegisterFlutterInstance(
|
||||
flutter::FlutterEngine* flutter_instance) {
|
||||
flutter_instances_.insert(flutter_instance);
|
||||
}
|
||||
|
||||
void RunLoop::UnregisterFlutterInstance(
|
||||
flutter::FlutterEngine* flutter_instance) {
|
||||
flutter_instances_.erase(flutter_instance);
|
||||
}
|
||||
|
||||
RunLoop::TimePoint RunLoop::ProcessFlutterMessages() {
|
||||
TimePoint next_event_time = TimePoint::max();
|
||||
for (auto instance : flutter_instances_) {
|
||||
std::chrono::nanoseconds wait_duration = instance->ProcessMessages();
|
||||
if (wait_duration != std::chrono::nanoseconds::max()) {
|
||||
next_event_time =
|
||||
std::min(next_event_time, TimePoint::clock::now() + wait_duration);
|
||||
}
|
||||
}
|
||||
return next_event_time;
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
#ifndef RUNNER_RUN_LOOP_H_
|
||||
#define RUNNER_RUN_LOOP_H_
|
||||
|
||||
#include <flutter/flutter_engine.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
|
||||
// A runloop that will service events for Flutter instances as well
|
||||
// as native messages.
|
||||
class RunLoop {
|
||||
public:
|
||||
RunLoop();
|
||||
~RunLoop();
|
||||
|
||||
// Prevent copying
|
||||
RunLoop(RunLoop const&) = delete;
|
||||
RunLoop& operator=(RunLoop const&) = delete;
|
||||
|
||||
// Runs the run loop until the application quits.
|
||||
void Run();
|
||||
|
||||
// Registers the given Flutter instance for event servicing.
|
||||
void RegisterFlutterInstance(
|
||||
flutter::FlutterEngine* flutter_instance);
|
||||
|
||||
// Unregisters the given Flutter instance from event servicing.
|
||||
void UnregisterFlutterInstance(
|
||||
flutter::FlutterEngine* flutter_instance);
|
||||
|
||||
private:
|
||||
using TimePoint = std::chrono::steady_clock::time_point;
|
||||
|
||||
// Processes all currently pending messages for registered Flutter instances.
|
||||
TimePoint ProcessFlutterMessages();
|
||||
|
||||
std::set<flutter::FlutterEngine*> flutter_instances_;
|
||||
};
|
||||
|
||||
#endif // RUNNER_RUN_LOOP_H_
|
@ -1,8 +1,19 @@
|
||||
#ifndef RUNNER_UTILS_H_
|
||||
#define RUNNER_UTILS_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Creates a console for the process, and redirects stdout and stderr to
|
||||
// it for both the runner and the Flutter library.
|
||||
void CreateAndAttachConsole();
|
||||
|
||||
// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
|
||||
// encoded in UTF-8. Returns an empty std::string on failure.
|
||||
std::string Utf8FromUtf16(const wchar_t* utf16_string);
|
||||
|
||||
// Gets the command line arguments passed in as a std::vector<std::string>,
|
||||
// encoded in UTF-8. Returns an empty std::vector<std::string> on failure.
|
||||
std::vector<std::string> GetCommandLineArguments();
|
||||
|
||||
#endif // RUNNER_UTILS_H_
|
||||
|
Loading…
Reference in New Issue