Skip to content

Commit

Permalink
refactor: Lint Kotlin, C and C++ code (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
luanpotter authored Jan 30, 2024
1 parent 5b78be0 commit 6d3e933
Show file tree
Hide file tree
Showing 26 changed files with 589 additions and 570 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Defines the Chromium style for automatic reformatting.
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
BasedOnStyle: Chromium
Standard: c++17
11 changes: 11 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ jobs:
node-version: 18
- run: npm install -g markdownlint-cli
- run: markdownlint . -p .markdownlintignore -c .markdownlint.yaml

super-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: super-linter/super-linter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: main
VALIDATE_CLANG_FORMAT: true
# END LINTING STAGE

# BEGIN TESTING STAGE
Expand Down
21 changes: 12 additions & 9 deletions packages/gamepads/example/linux/my_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static void my_application_activate(GApplication* application) {
gtk_widget_show(GTK_WIDGET(window));

g_autoptr(FlDartProject) project = fl_dart_project_new();
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
fl_dart_project_set_dart_entrypoint_arguments(
project, self->dart_entrypoint_arguments);

FlView* view = fl_view_new(project);
gtk_widget_show(GTK_WIDGET(view));
Expand All @@ -63,16 +64,18 @@ static void my_application_activate(GApplication* application) {
}

// Implements GApplication::local_command_line.
static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
static gboolean my_application_local_command_line(GApplication* application,
gchar*** arguments,
int* exit_status) {
MyApplication* self = MY_APPLICATION(application);
// Strip out the first argument as it is the binary name.
self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);

g_autoptr(GError) error = nullptr;
if (!g_application_register(application, nullptr, &error)) {
g_warning("Failed to register: %s", error->message);
*exit_status = 1;
return TRUE;
g_warning("Failed to register: %s", error->message);
*exit_status = 1;
return TRUE;
}

g_application_activate(application);
Expand All @@ -90,15 +93,15 @@ static void my_application_dispose(GObject* object) {

static void my_application_class_init(MyApplicationClass* klass) {
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
G_APPLICATION_CLASS(klass)->local_command_line =
my_application_local_command_line;
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
}

static void my_application_init(MyApplication* self) {}

MyApplication* my_application_new() {
return MY_APPLICATION(g_object_new(my_application_get_type(),
"application-id", APPLICATION_ID,
"flags", G_APPLICATION_NON_UNIQUE,
nullptr));
"application-id", APPLICATION_ID, "flags",
G_APPLICATION_NON_UNIQUE, nullptr));
}
5 changes: 4 additions & 1 deletion packages/gamepads/example/linux/my_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

#include <gtk/gtk.h>

G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
G_DECLARE_FINAL_TYPE(MyApplication,
my_application,
MY,
APPLICATION,
GtkApplication)

/**
Expand Down
7 changes: 3 additions & 4 deletions packages/gamepads/example/windows/runner/flutter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ bool FlutterWindow::OnCreate() {
RegisterPlugins(flutter_controller_->engine());
SetChildContent(flutter_controller_->view()->GetNativeWindow());

flutter_controller_->engine()->SetNextFrameCallback([&]() {
this->Show();
});
flutter_controller_->engine()->SetNextFrameCallback([&]() { this->Show(); });

return true;
}
Expand All @@ -43,7 +41,8 @@ void FlutterWindow::OnDestroy() {
}

LRESULT
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
FlutterWindow::MessageHandler(HWND hwnd,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
// Give Flutter, including plugins, an opportunity to handle window messages.
Expand Down
4 changes: 3 additions & 1 deletion packages/gamepads/example/windows/runner/flutter_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class FlutterWindow : public Win32Window {
// Win32Window:
bool OnCreate() override;
void OnDestroy() override;
LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
LRESULT MessageHandler(HWND window,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept override;

private:
Expand Down
9 changes: 5 additions & 4 deletions packages/gamepads/example/windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include "flutter_window.h"
#include "utils.h"

int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
int APIENTRY wWinMain(_In_ HINSTANCE instance,
_In_opt_ HINSTANCE prev,
_In_ wchar_t* command_line,
_In_ int show_command) {
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
Expand All @@ -19,8 +21,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,

flutter::DartProject project(L"data");

std::vector<std::string> command_line_arguments =
GetCommandLineArguments();
std::vector<std::string> command_line_arguments = GetCommandLineArguments();

project.set_dart_entrypoint_arguments(std::move(command_line_arguments));

Expand Down
10 changes: 5 additions & 5 deletions packages/gamepads/example/windows/runner/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Microsoft Visual C++ generated include file.
// Used by Runner.rc
//
#define IDI_APP_ICON 101
#define IDI_APP_ICON 101

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
11 changes: 5 additions & 6 deletions packages/gamepads/example/windows/runner/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

void CreateAndAttachConsole() {
if (::AllocConsole()) {
FILE *unused;
FILE* unused;
if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
_dup2(_fileno(stdout), 1);
}
Expand Down Expand Up @@ -45,17 +45,16 @@ std::string Utf8FromUtf16(const wchar_t* utf16_string) {
if (utf16_string == nullptr) {
return std::string();
}
int target_length = ::WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
-1, nullptr, 0, nullptr, nullptr);
int target_length =
::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, -1,
nullptr, 0, nullptr, nullptr);
std::string utf8_string;
if (target_length == 0 || target_length > utf8_string.max_size()) {
return utf8_string;
}
utf8_string.resize(target_length);
int converted_length = ::WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
-1, utf8_string.data(),
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, -1, utf8_string.data(),
target_length, nullptr, nullptr);
if (converted_length == 0) {
return std::string();
Expand Down
16 changes: 9 additions & 7 deletions packages/gamepads/example/windows/runner/win32_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace {
///
/// Redefined in case the developer's machine has a Windows SDK older than
/// version 10.0.22000.0.
/// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
/// See:
/// https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif
Expand All @@ -23,8 +24,9 @@ constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
/// A value of 0 indicates apps should use dark mode. A non-zero or missing
/// value indicates apps should use light mode.
constexpr const wchar_t kGetPreferredBrightnessRegKey[] =
L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme";
L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
constexpr const wchar_t kGetPreferredBrightnessRegValue[] =
L"AppsUseLightTheme";

// The number of Win32Window objects that currently exist.
static int g_active_window_count = 0;
Expand Down Expand Up @@ -275,10 +277,10 @@ void Win32Window::OnDestroy() {
void Win32Window::UpdateTheme(HWND const window) {
DWORD light_mode;
DWORD light_mode_size = sizeof(light_mode);
LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey,
kGetPreferredBrightnessRegValue,
RRF_RT_REG_DWORD, nullptr, &light_mode,
&light_mode_size);
LSTATUS result =
RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey,
kGetPreferredBrightnessRegValue, RRF_RT_REG_DWORD, nullptr,
&light_mode, &light_mode_size);

if (result == ERROR_SUCCESS) {
BOOL enable_dark_mode = light_mode == 0;
Expand Down
Loading

0 comments on commit 6d3e933

Please sign in to comment.