Skip to content

Commit

Permalink
Support set icon for CefWing and windows job object
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Jan 23, 2024
1 parent 8581a1f commit 4e2f4d0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dep/*.bz2
.DS_Store
dep/cef_binary_*
.build
include/CefViewWingProcessName.h
5 changes: 5 additions & 0 deletions include/CefViewCoreProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
/// </summary>
#define kCefViewBridgeObjectNameKey "bridge-obj-name"

/// <summary>
///
/// </summary>
#define kCefViewWindowsJobNameKey "windows-job-name"

/// <summary>
///
/// </summary>
Expand Down
12 changes: 0 additions & 12 deletions include/CefViewWingProcessName.h

This file was deleted.

13 changes: 13 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,24 @@ if(OS_WINDOWS)
FILES ${CefViewWing_PLATFORM_SRC_FILES}
)

if(EXISTS ${CEFVIEW_WING_ICON})
# Config resource file
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/CefWing/win/resource.rc.in"
"${CMAKE_CURRENT_BINARY_DIR}/resource.rc"
@ONLY
)
set(CefViewWing_WIN_RESOURCE_FILE "${CMAKE_CURRENT_BINARY_DIR}/resource.rc")
else()
set(CefViewWing_WIN_RESOURCE_FILE "")
endif()

# Create Helper executable target.
add_executable(${CEFVIEW_WING_NAME} WIN32
${CefViewCore_SHARED_SRC_FILES}
${CefViewWing_SRC_FILES}
${CefViewWing_PLATFORM_SRC_FILES}
${CefViewWing_WIN_RESOURCE_FILE}
)

SET_EXECUTABLE_TARGET_PROPERTIES(${CEFVIEW_WING_NAME})
Expand Down
18 changes: 17 additions & 1 deletion src/CefWing/win/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
#pragma endregion win_headers

#pragma region project_heasers
#include <Common/CefViewCoreLog.h>
#include <CefViewCoreProtocol.h>

#include "../CefRenderApp/CefViewAppBase.h"
#include "../CefRenderApp/CefViewOtherApp.h"
#include "../CefRenderApp/CefViewRenderApp.h"
#include <Common/CefViewCoreLog.h>
#pragma endregion project_heasers

int
Expand Down Expand Up @@ -56,6 +58,20 @@ CefViewWingMain(HINSTANCE hInstance)
return 1;
}

// assign current process to window job
if (command_line->HasSwitch(kCefViewWindowsJobNameKey)) {
auto job_name = command_line->GetSwitchValue(kCefViewWindowsJobNameKey);
HANDLE job_handle = ::OpenJobObjectA(JOB_OBJECT_ASSIGN_PROCESS, FALSE, job_name.ToString().c_str());
if (job_handle) {
if (!::AssignProcessToJobObject(job_handle, ::GetCurrentProcess())) {
logE("Failed to assign current process to windows job object: %d", ::GetLastError());
}
::CloseHandle(job_handle);
} else {
logE("Failed to open windows job object: %d", ::GetLastError());
}
}

// Execute the secondary process.
int rt = CefExecuteProcess(main_args, app, sandbox_info);
logI("process returned with code: %d", rt);
Expand Down
3 changes: 3 additions & 0 deletions src/CefWing/win/resource.rc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "winres.h"

IDI_ICON ICON "@CEFVIEW_WING_ICON@"

0 comments on commit 4e2f4d0

Please sign in to comment.