UP 历史命令配置支持
This commit is contained in:
+17
-2
@@ -4,6 +4,7 @@
|
||||
#include "CLIProcess.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <imgui.h>
|
||||
|
||||
class AppState {
|
||||
@@ -15,6 +16,12 @@ public:
|
||||
void SaveSettings();
|
||||
void ApplySettings();
|
||||
|
||||
// 新增:启动命令历史记录管理
|
||||
void AddCommandToHistory(const std::string& command);
|
||||
void RemoveCommandFromHistory(int index);
|
||||
void ClearCommandHistory();
|
||||
const std::vector<std::string>& GetCommandHistory() const { return command_history; }
|
||||
|
||||
bool show_main_window;
|
||||
bool auto_start;
|
||||
CLIProcess cli_process;
|
||||
@@ -33,9 +40,13 @@ public:
|
||||
std::map<std::string, std::string> environment_variables;
|
||||
bool use_custom_environment;
|
||||
|
||||
// 新增:输出编码相关配置
|
||||
// 输出编码相关配置
|
||||
OutputEncoding output_encoding;
|
||||
|
||||
// 新增:启动命令历史记录
|
||||
std::vector<std::string> command_history;
|
||||
int max_command_history;
|
||||
|
||||
bool settings_dirty;
|
||||
|
||||
private:
|
||||
@@ -43,9 +54,13 @@ private:
|
||||
std::string SerializeEnvironmentVariables() const;
|
||||
void DeserializeEnvironmentVariables(const std::string& serialized);
|
||||
|
||||
// 新增:编码序列化辅助函数
|
||||
// 编码序列化辅助函数
|
||||
std::string SerializeOutputEncoding() const;
|
||||
void DeserializeOutputEncoding(const std::string& serialized);
|
||||
|
||||
// 新增:命令历史记录序列化辅助函数
|
||||
std::string SerializeCommandHistory() const;
|
||||
void DeserializeCommandHistory(const std::string& serialized);
|
||||
};
|
||||
|
||||
#endif // APP_STATE_H
|
||||
+40
-10
@@ -6,16 +6,33 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include <windows.h>
|
||||
|
||||
// 新增:输出编码枚举
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
// 输出编码枚举
|
||||
enum class OutputEncoding {
|
||||
AUTO_DETECT =0,
|
||||
AUTO_DETECT = 0,
|
||||
UTF8,
|
||||
#ifdef _WIN32
|
||||
GBK,
|
||||
GB2312,
|
||||
BIG5,
|
||||
SHIFT_JIS,
|
||||
#else
|
||||
// Unix/Linux 常见编码
|
||||
ISO_8859_1,
|
||||
GB18030,
|
||||
BIG5,
|
||||
EUC_JP,
|
||||
#endif
|
||||
};
|
||||
|
||||
class CLIProcess {
|
||||
@@ -26,7 +43,7 @@ public:
|
||||
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 SetOutputEncoding(OutputEncoding encoding);
|
||||
|
||||
void Start(const std::string& command);
|
||||
void Stop();
|
||||
@@ -47,7 +64,7 @@ public:
|
||||
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();
|
||||
@@ -57,9 +74,11 @@ private:
|
||||
void CloseProcessHandles();
|
||||
void CleanupResources();
|
||||
|
||||
// 新增:编码转换相关方法
|
||||
std::string ConvertToUTF8(const std::string& input, OutputEncoding encoding);
|
||||
std::string DetectAndConvertToUTF8(const std::string& input);
|
||||
// 编码转换相关方法
|
||||
static std::string ConvertToUTF8(std::string& input, OutputEncoding encoding);
|
||||
std::string DetectAndConvertToUTF8(std::string& input);
|
||||
|
||||
#ifdef _WIN32
|
||||
static UINT GetCodePageFromEncoding(OutputEncoding encoding);
|
||||
static bool IsValidUTF8(const std::string& str);
|
||||
|
||||
@@ -68,6 +87,17 @@ private:
|
||||
HANDLE hWritePipe_{};
|
||||
HANDLE hReadPipe_stdin_{};
|
||||
HANDLE hWritePipe_stdin_;
|
||||
#else
|
||||
// Unix/Linux 进程管理
|
||||
pid_t process_pid_;
|
||||
int pipe_stdout_[2];
|
||||
int pipe_stdin_[2];
|
||||
bool process_running_;
|
||||
|
||||
// Unix 编码转换辅助函数
|
||||
std::string ConvertUnixEncoding(const std::string& input, const std::string& from_encoding);
|
||||
static std::string GetUnixEncodingName(OutputEncoding encoding);
|
||||
#endif
|
||||
|
||||
mutable std::mutex logs_mutex_;
|
||||
std::vector<std::string> logs_;
|
||||
@@ -76,7 +106,7 @@ private:
|
||||
std::thread output_thread_;
|
||||
|
||||
// 停止命令相关
|
||||
std::mutex stop_mutex_;
|
||||
mutable std::mutex stop_mutex_;
|
||||
std::string stop_command_;
|
||||
int stop_timeout_ms_;
|
||||
|
||||
@@ -84,7 +114,7 @@ private:
|
||||
mutable std::mutex env_mutex_;
|
||||
std::map<std::string, std::string> environment_variables_;
|
||||
|
||||
// 新增:编码相关
|
||||
// 编码相关
|
||||
mutable std::mutex encoding_mutex_;
|
||||
OutputEncoding output_encoding_;
|
||||
};
|
||||
|
||||
+18
-4
@@ -10,12 +10,20 @@
|
||||
#include "imgui_impl_win32.h"
|
||||
#include "imgui_impl_dx11.h"
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GLFW/glfw3native.h>
|
||||
#include <windows.h>
|
||||
#elif __APPLE__
|
||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GLFW/glfw3native.h>
|
||||
#else
|
||||
#include <GLFW/glfw3.h>
|
||||
#endif
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
@@ -33,6 +41,8 @@ public:
|
||||
void OnTrayExit();
|
||||
|
||||
AppState m_app_state;
|
||||
|
||||
|
||||
private:
|
||||
// UI渲染
|
||||
void RenderUI();
|
||||
@@ -41,7 +51,7 @@ private:
|
||||
void RenderSettingsMenu();
|
||||
void RenderStopCommandSettings();
|
||||
void RenderEnvironmentVariablesSettings();
|
||||
void RenderOutputEncodingSettings(); // 新增:输出编码设置UI
|
||||
void RenderOutputEncodingSettings();
|
||||
|
||||
// 事件处理
|
||||
void HandleMessages();
|
||||
@@ -75,10 +85,12 @@ private:
|
||||
// 托盘相关
|
||||
bool InitializeTray();
|
||||
void CleanupTray();
|
||||
#ifdef _WIN32
|
||||
static HWND CreateHiddenWindow();
|
||||
HWND m_tray_hwnd = nullptr;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<TrayIcon> m_tray;
|
||||
HWND m_tray_hwnd = nullptr;
|
||||
|
||||
// 控制标志
|
||||
bool m_should_exit = false;
|
||||
@@ -92,6 +104,8 @@ private:
|
||||
char env_value_input_[512] = {};
|
||||
bool show_env_settings_ = false;
|
||||
|
||||
// 新增:编码设置UI状态
|
||||
// 编码设置UI状态
|
||||
bool show_encoding_settings_ = false;
|
||||
// 历史命令UI状态
|
||||
bool show_command_history_;
|
||||
};
|
||||
+40
-6
@@ -1,6 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
@@ -10,33 +14,63 @@ public:
|
||||
using ShowWindowCallback = std::function<void()>;
|
||||
using ExitCallback = std::function<void()>;
|
||||
|
||||
#ifdef _WIN32
|
||||
TrayIcon(HWND hwnd, HICON icon);
|
||||
void UpdateWebUrl(const std::wstring& url);
|
||||
// 静态窗口过程
|
||||
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
#else
|
||||
TrayIcon(void* app_delegate, void* icon);
|
||||
void UpdateWebUrl(const std::string& url);
|
||||
void OnMacMenuAction(int action);
|
||||
#endif
|
||||
|
||||
~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();
|
||||
|
||||
#ifdef _WIN32
|
||||
void ShowContextMenu() const;
|
||||
|
||||
HWND m_hwnd;
|
||||
HICON m_icon;
|
||||
NOTIFYICONDATA m_nid{};
|
||||
std::wstring m_web_url;
|
||||
bool m_visible;
|
||||
HMENU m_menu;
|
||||
#else
|
||||
void ShowMacTrayIcon();
|
||||
void HideMacTrayIcon();
|
||||
void CreateMacMenu();
|
||||
void DestroyMacMenu();
|
||||
|
||||
void* m_app_delegate;
|
||||
void* m_icon;
|
||||
std::string m_web_url;
|
||||
#endif
|
||||
|
||||
bool m_visible;
|
||||
|
||||
// 回调函数
|
||||
ShowWindowCallback m_show_window_callback;
|
||||
ExitCallback m_exit_callback;
|
||||
};
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// C 接口函数声明,供 Objective-C 调用
|
||||
void TrayIconMenuCallback(void* tray_instance, int action);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user