UP
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#ifndef APP_STATE_H
|
||||
#define APP_STATE_H
|
||||
|
||||
#include "CLIProcess.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <imgui.h>
|
||||
|
||||
class AppState {
|
||||
public:
|
||||
AppState();
|
||||
~AppState() = default;
|
||||
|
||||
void LoadSettings();
|
||||
void SaveSettings();
|
||||
void ApplySettings();
|
||||
|
||||
bool show_main_window;
|
||||
bool auto_start;
|
||||
CLIProcess cli_process;
|
||||
char command_input[256]{};
|
||||
char send_command[256]{};
|
||||
bool auto_scroll_logs;
|
||||
int max_log_lines;
|
||||
char web_url[256]{};
|
||||
|
||||
// 停止命令相关配置
|
||||
char stop_command[256]{};
|
||||
int stop_timeout_ms;
|
||||
bool use_stop_command;
|
||||
|
||||
// 环境变量相关配置
|
||||
std::map<std::string, std::string> environment_variables;
|
||||
bool use_custom_environment;
|
||||
|
||||
// 新增:输出编码相关配置
|
||||
OutputEncoding output_encoding;
|
||||
|
||||
bool settings_dirty;
|
||||
|
||||
private:
|
||||
// 环境变量序列化辅助函数
|
||||
std::string SerializeEnvironmentVariables() const;
|
||||
void DeserializeEnvironmentVariables(const std::string& serialized);
|
||||
|
||||
// 新增:编码序列化辅助函数
|
||||
std::string SerializeOutputEncoding() const;
|
||||
void DeserializeOutputEncoding(const std::string& serialized);
|
||||
};
|
||||
|
||||
#endif // APP_STATE_H
|
||||
@@ -0,0 +1,92 @@
|
||||
#ifndef CLIPROCESS_H
|
||||
#define CLIPROCESS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include <windows.h>
|
||||
|
||||
// 新增:输出编码枚举
|
||||
enum class OutputEncoding {
|
||||
UTF8 = 0,
|
||||
GBK,
|
||||
GB2312,
|
||||
BIG5,
|
||||
SHIFT_JIS,
|
||||
AUTO_DETECT
|
||||
};
|
||||
|
||||
class CLIProcess {
|
||||
public:
|
||||
CLIProcess();
|
||||
~CLIProcess();
|
||||
|
||||
void SetMaxLogLines(int max_lines);
|
||||
void SetStopCommand(const std::string& command, int timeout_ms = 5000);
|
||||
void SetEnvironmentVariables(const std::map<std::string, std::string>& env_vars);
|
||||
void SetOutputEncoding(OutputEncoding encoding); // 新增:设置输出编码
|
||||
|
||||
void Start(const std::string& command);
|
||||
void Stop();
|
||||
void Restart(const std::string& command);
|
||||
|
||||
void ClearLogs();
|
||||
void AddLog(const std::string& log);
|
||||
const std::vector<std::string>& GetLogs() const;
|
||||
|
||||
bool SendCommand(const std::string& command);
|
||||
void CopyLogsToClipboard() const;
|
||||
|
||||
bool IsRunning() const;
|
||||
|
||||
// 环境变量管理接口
|
||||
const std::map<std::string, std::string>& GetEnvironmentVariables() const;
|
||||
void AddEnvironmentVariable(const std::string& key, const std::string& value);
|
||||
void RemoveEnvironmentVariable(const std::string& key);
|
||||
void ClearEnvironmentVariables();
|
||||
|
||||
// 新增:编码相关接口
|
||||
OutputEncoding GetOutputEncoding() const;
|
||||
static std::string GetEncodingName(OutputEncoding encoding);
|
||||
static std::vector<std::pair<OutputEncoding, std::string>> GetSupportedEncodings();
|
||||
|
||||
private:
|
||||
void ReadOutput();
|
||||
void CloseProcessHandles();
|
||||
void CleanupResources();
|
||||
|
||||
// 新增:编码转换相关方法
|
||||
std::string ConvertToUTF8(const std::string& input, OutputEncoding encoding);
|
||||
std::string DetectAndConvertToUTF8(const std::string& input);
|
||||
UINT GetCodePageFromEncoding(OutputEncoding encoding);
|
||||
bool IsValidUTF8(const std::string& str);
|
||||
|
||||
PROCESS_INFORMATION pi_{};
|
||||
HANDLE hReadPipe_{};
|
||||
HANDLE hWritePipe_{};
|
||||
HANDLE hReadPipe_stdin_{};
|
||||
HANDLE hWritePipe_stdin_;
|
||||
|
||||
mutable std::mutex logs_mutex_;
|
||||
std::vector<std::string> logs_;
|
||||
int max_log_lines_;
|
||||
|
||||
std::thread output_thread_;
|
||||
|
||||
// 停止命令相关
|
||||
std::mutex stop_mutex_;
|
||||
std::string stop_command_;
|
||||
int stop_timeout_ms_;
|
||||
|
||||
// 环境变量相关
|
||||
mutable std::mutex env_mutex_;
|
||||
std::map<std::string, std::string> environment_variables_;
|
||||
|
||||
// 新增:编码相关
|
||||
mutable std::mutex encoding_mutex_;
|
||||
OutputEncoding output_encoding_;
|
||||
};
|
||||
|
||||
#endif // CLIPROCESS_H
|
||||
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include "imgui.h"
|
||||
#include "AppState.h"
|
||||
#include "TrayIcon.h"
|
||||
|
||||
#ifdef USE_WIN32_BACKEND
|
||||
#include <d3d11.h>
|
||||
#include <windows.h>
|
||||
#include "imgui_impl_win32.h"
|
||||
#include "imgui_impl_dx11.h"
|
||||
#else
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GLFW/glfw3native.h>
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Manager {
|
||||
public:
|
||||
Manager();
|
||||
~Manager();
|
||||
|
||||
bool Initialize();
|
||||
void Run();
|
||||
void Shutdown();
|
||||
|
||||
void OnTrayShowWindow();
|
||||
void OnTrayExit();
|
||||
|
||||
AppState m_app_state;
|
||||
private:
|
||||
// UI渲染
|
||||
void RenderUI();
|
||||
void RenderMenuBar();
|
||||
void RenderMainContent();
|
||||
void RenderSettingsMenu();
|
||||
void RenderStopCommandSettings();
|
||||
void RenderEnvironmentVariablesSettings();
|
||||
void RenderOutputEncodingSettings(); // 新增:输出编码设置UI
|
||||
|
||||
// 事件处理
|
||||
void HandleMessages();
|
||||
bool ShouldExit() const;
|
||||
void ShowMainWindow();
|
||||
void HideMainWindow();
|
||||
|
||||
// 平台相关初始化
|
||||
#ifdef USE_WIN32_BACKEND
|
||||
bool InitializeWin32();
|
||||
bool InitializeDirectX11();
|
||||
void CleanupWin32();
|
||||
void CleanupDirectX11();
|
||||
static LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
WNDCLASSEX m_wc = {};
|
||||
ID3D11Device* m_pd3dDevice = nullptr;
|
||||
ID3D11DeviceContext* m_pd3dDeviceContext = nullptr;
|
||||
IDXGISwapChain* m_pSwapChain = nullptr;
|
||||
ID3D11RenderTargetView* m_mainRenderTargetView = nullptr;
|
||||
#else
|
||||
bool InitializeGLFW();
|
||||
void CleanupGLFW();
|
||||
static void GlfwErrorCallback(int error, const char* description);
|
||||
|
||||
GLFWwindow* m_window = nullptr;
|
||||
const char* m_glsl_version = nullptr;
|
||||
#endif
|
||||
|
||||
// 托盘相关
|
||||
bool InitializeTray();
|
||||
void CleanupTray();
|
||||
static HWND CreateHiddenWindow();
|
||||
|
||||
std::unique_ptr<TrayIcon> m_tray;
|
||||
HWND m_tray_hwnd = nullptr;
|
||||
|
||||
// 控制标志
|
||||
bool m_should_exit = false;
|
||||
bool m_initialized = false;
|
||||
|
||||
// DPI缩放因子
|
||||
float m_dpi_scale = 1.0f;
|
||||
|
||||
// 环境变量UI状态
|
||||
char env_key_input_[256] = {};
|
||||
char env_value_input_[512] = {};
|
||||
bool show_env_settings_ = false;
|
||||
|
||||
// 新增:编码设置UI状态
|
||||
bool show_encoding_settings_ = false;
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
class TrayIcon {
|
||||
public:
|
||||
// 回调函数类型定义
|
||||
using ShowWindowCallback = std::function<void()>;
|
||||
using ExitCallback = std::function<void()>;
|
||||
|
||||
TrayIcon(HWND hwnd, HICON icon);
|
||||
~TrayIcon();
|
||||
|
||||
void Show();
|
||||
void Hide();
|
||||
void UpdateWebUrl(const std::wstring& url);
|
||||
|
||||
// 设置回调函数
|
||||
void SetShowWindowCallback(const ShowWindowCallback &callback);
|
||||
void SetExitCallback(const ExitCallback &callback);
|
||||
|
||||
// 静态窗口过程
|
||||
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
private:
|
||||
void CreateMenu();
|
||||
void DestroyMenu();
|
||||
void ShowContextMenu() const;
|
||||
|
||||
HWND m_hwnd;
|
||||
HICON m_icon;
|
||||
NOTIFYICONDATA m_nid{};
|
||||
std::wstring m_web_url;
|
||||
bool m_visible;
|
||||
HMENU m_menu;
|
||||
|
||||
// 回调函数
|
||||
ShowWindowCallback m_show_window_callback;
|
||||
ExitCallback m_exit_callback;
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef UNITS_H
|
||||
#define UNITS_H
|
||||
#include <string>
|
||||
|
||||
std::wstring StringToWide(const std::string& str);
|
||||
std::string WideToString(const std::wstring& wstr);
|
||||
void SetAutoStart(bool enable);
|
||||
bool IsAutoStartEnabled();
|
||||
|
||||
|
||||
#endif //UNITS_H
|
||||
Reference in New Issue
Block a user