mirror of
				https://github.com/velopack/velopack.git
				synced 2025-10-25 15:19:22 +00:00 
			
		
		
		
	| @@ -51,8 +51,14 @@ public: | |||||||
| class MyFrame : public wxFrame | class MyFrame : public wxFrame | ||||||
| { | { | ||||||
| public: | public: | ||||||
|  |     ~MyFrame() | ||||||
|  |     { | ||||||
|  |         vpkc_set_logger(nullptr, nullptr); | ||||||
|  |     } | ||||||
|     MyFrame() : wxFrame(nullptr, wxID_ANY, "VelopackCppWidgetsSample", wxDefaultPosition, wxSize(600, 600)) |     MyFrame() : wxFrame(nullptr, wxID_ANY, "VelopackCppWidgetsSample", wxDefaultPosition, wxSize(600, 600)) | ||||||
|     { |     { | ||||||
|  |         vpkc_set_logger(&MyFrame::HandleVpkcLogStatic, this); | ||||||
|  |  | ||||||
|         // Set background color to white |         // Set background color to white | ||||||
|         // SetBackgroundColour(*wxWHITE); |         // SetBackgroundColour(*wxWHITE); | ||||||
|  |  | ||||||
| @@ -180,6 +186,23 @@ private: | |||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     void HandleVpkcLog(const char* pszLevel, const char* pszMessage) | ||||||
|  |     { | ||||||
|  |         std::string level(pszLevel); | ||||||
|  |         std::string message(pszMessage); | ||||||
|  |         wxTheApp->CallAfter([this, level, message]() { | ||||||
|  |             if (textArea) { // Ensure textArea is valid. | ||||||
|  |                 textArea->AppendText(level + ": " + message + "\n"); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     static void HandleVpkcLogStatic(void* context, const char* pszLevel, const char* pszMessage) | ||||||
|  |     { | ||||||
|  |         MyFrame* instance = static_cast<MyFrame*>(context); | ||||||
|  |         instance->HandleVpkcLog(pszLevel, pszMessage); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     void HandleProgressCallback(size_t progress) |     void HandleProgressCallback(size_t progress) | ||||||
|     { |     { | ||||||
|         wxTheApp->CallAfter([this, progress]() |         wxTheApp->CallAfter([this, progress]() | ||||||
|   | |||||||
| @@ -38,6 +38,11 @@ INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM); | |||||||
| std::wstring        Utf8ToWString(std::string const& str); | std::wstring        Utf8ToWString(std::string const& str); | ||||||
| std::string         WStringToUtf8(std::wstring const& wstr); | std::string         WStringToUtf8(std::wstring const& wstr); | ||||||
|  |  | ||||||
|  | void handle_vpkc_log(void* pUserData, const char* pszLevel, const char* pszMessage) | ||||||
|  | { | ||||||
|  |     std::cout << pszLevel << ": " << pszMessage << std::endl; | ||||||
|  | } | ||||||
|  |  | ||||||
| int APIENTRY wWinMain(_In_ HINSTANCE hInstance, | int APIENTRY wWinMain(_In_ HINSTANCE hInstance, | ||||||
|     _In_opt_ HINSTANCE hPrevInstance, |     _In_opt_ HINSTANCE hPrevInstance, | ||||||
|     _In_ LPWSTR    lpCmdLine, |     _In_ LPWSTR    lpCmdLine, | ||||||
| @@ -52,6 +57,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, | |||||||
|  |  | ||||||
|     // Initialize Velopack log capture |     // Initialize Velopack log capture | ||||||
|     std::cout << "Velopack C++ Sample App" << std::endl; |     std::cout << "Velopack C++ Sample App" << std::endl; | ||||||
|  |     vpkc_set_logger(handle_vpkc_log, 0); | ||||||
|  |  | ||||||
|     // This should run as early as possible in the main method. |     // This should run as early as possible in the main method. | ||||||
|     // Velopack may exit / restart the app at this point.  |     // Velopack may exit / restart the app at this point.  | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| import { app, BrowserWindow } from 'electron'; | import { app, BrowserWindow } from 'electron'; | ||||||
| import { VelopackApp } from "velopack"; | import { VelopackApp, setVelopackLogger } from "velopack"; | ||||||
| import { initializeUpdates } from "./update" | import { initializeUpdates } from "./update" | ||||||
| // This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack | // This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack | ||||||
| // plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on | // plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on | ||||||
| @@ -9,6 +9,7 @@ declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string; | |||||||
|  |  | ||||||
| // VelopackApp should be the first thing to run in startup | // VelopackApp should be the first thing to run in startup | ||||||
| // as it may need to quit / restart the application at certain points | // as it may need to quit / restart the application at certain points | ||||||
|  | setVelopackLogger((lvl, msg) => console.log(`Velopack [${lvl}] ${msg}`)); | ||||||
| VelopackApp.build().run(); | VelopackApp.build().run(); | ||||||
|  |  | ||||||
| // Configure IPC listener for Velopack update messages | // Configure IPC listener for Velopack update messages | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user