Skip to content

Commit

Permalink
refactor: utils.cc translation-unit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed Sep 5, 2023
1 parent 20e924b commit 17b5d71
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
5 changes: 2 additions & 3 deletions lib/windows_taskbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
/// Use of this source code is governed by MIT license that can be found in the LICENSE file.
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:path/path.dart';
import 'package:flutter/services.dart';

/// Sets progress mode.
const String _kSetProgressMode = 'SetProgressMode';
Expand Down Expand Up @@ -342,7 +341,7 @@ class WindowsTaskbar {
);
}

/// Returns `bool` - Whether taskbar is visible (in case of autohiding).
/// Returns whether taskbar is visible (in case of auto-hide).
static Future<bool> isTaskbarVisible() async {
return await _kChannel.invokeMethod(
'IsTaskbarVisible',
Expand Down
1 change: 1 addition & 0 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(PLUGIN_NAME "windows_taskbar_plugin")
add_library(${PLUGIN_NAME} SHARED
"windows_taskbar.cc"
"windows_taskbar_plugin.cc"
"utils.cc"
)
apply_standard_settings(${PLUGIN_NAME})
set_target_properties(${PLUGIN_NAME} PROPERTIES
Expand Down
26 changes: 26 additions & 0 deletions windows/utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// This file is a part of windows_taskbar
/// (https://github.com/alexmercerind/windows_taskbar).
///
/// Copyright (c) 2021 & onwards, Hitesh Kumar Saini <[email protected]>.
/// All rights reserved.
/// Use of this source code is governed by MIT license that can be found in the
/// LICENSE file.

#include "utils.h"

#include <Windows.h>

std::wstring Utf16FromUtf8(std::string string) {
auto size_needed =
::MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1, NULL, 0);
if (size_needed == 0) {
return std::wstring{};
}
auto result = std::wstring(size_needed, 0);
auto converted_length = ::MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1,
&result[0], size_needed);
if (converted_length == 0) {
return std::wstring{};
}
return result;
}
17 changes: 2 additions & 15 deletions windows/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,8 @@
#ifndef UTILS_H_
#define UTILS_H_

#include <strsafe.h>
#include <string>

static inline std::wstring Utf16FromUtf8(std::string string) {
int size_needed =
::MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1, NULL, 0);
if (size_needed == 0) {
return std::wstring();
}
std::wstring result(size_needed, 0);
int converted_length = ::MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1,
&result[0], size_needed);
if (converted_length == 0) {
return std::wstring();
}
return result;
}
std::wstring Utf16FromUtf8(std::string string);

#endif

0 comments on commit 17b5d71

Please sign in to comment.