Compare commits
20 Commits
207a849f06
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b7596674ab | |||
| ce92b3841f | |||
| 659d1530b0 | |||
| 302753cd3d | |||
| bbba5b2927 | |||
| 29908646ea | |||
| 8cf9b50690 | |||
| d6f15c5dce | |||
| b4d93f24cd | |||
| c514e4faec | |||
| e51594a010 | |||
| 18bc607d93 | |||
| 54216aa133 | |||
| 8eb5c1a3b2 | |||
| 406d73c10f | |||
| 6fac7e320b | |||
| a32940a3f3 | |||
| 10180b7109 | |||
| dd6b3fa70d | |||
| a8786b4c1c |
@@ -0,0 +1,17 @@
|
||||
# clangd configuration for Nebula Browser
|
||||
#
|
||||
# Full diagnostics require:
|
||||
# 1. CEF binary distribution unpacked to thirdparty/cef/
|
||||
# 2. Running: cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
# 3. Symlink or copy: ln -s build/compile_commands.json .
|
||||
#
|
||||
# Without compile_commands.json, clangd uses fallback flags below.
|
||||
|
||||
CompileFlags:
|
||||
Add:
|
||||
- -std=c++20
|
||||
- -xobjective-c++
|
||||
- -Isrc
|
||||
- -Ithirdparty/cef
|
||||
- -Ithirdparty/cef/include
|
||||
- -Wno-c++17-extensions
|
||||
+2
-1
@@ -17,4 +17,5 @@ CMakeFiles/
|
||||
.DS_Store
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
*.log
|
||||
/.cache
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# Nebula Browser Asset License
|
||||
|
||||
The source code of Nebula Browser is licensed under the Mozilla Public License 2.0, as described in the LICENSE file.
|
||||
|
||||
However, the Nebula Browser name, logo, icons, artwork, screenshots, visual identity, branding materials, and other non-code assets are not automatically covered by the MPL-2.0 license.
|
||||
|
||||
Unless otherwise stated, these assets are All Rights Reserved.
|
||||
|
||||
You may not use the Nebula Browser name, logo, or branding in a way that suggests endorsement, official status, or affiliation with the Nebula Project without permission.
|
||||
|
||||
Community forks are welcome, but they should use their own name and branding unless permission is granted.
|
||||
+213
-68
@@ -1,6 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
|
||||
project(NebulaBrowser LANGUAGES CXX)
|
||||
# Enable OBJCXX early on macOS for Cocoa integration
|
||||
if(APPLE)
|
||||
project(NebulaBrowser LANGUAGES CXX OBJCXX)
|
||||
else()
|
||||
project(NebulaBrowser LANGUAGES CXX)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
@@ -16,16 +21,11 @@ if(NOT EXISTS "${CEF_ROOT}/cmake/FindCEF.cmake")
|
||||
"CEF was not found.\n"
|
||||
"Expected CEF here:\n"
|
||||
" ${CEF_ROOT}\n\n"
|
||||
"Make sure the contents of the CEF binary distribution are inside thirdparty/cef."
|
||||
"Unpack the CEF binary distribution for your OS into thirdparty/cef."
|
||||
)
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# CEF setup
|
||||
# ------------------------------------------------------------
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CEF_ROOT}/cmake")
|
||||
|
||||
find_package(CEF REQUIRED)
|
||||
|
||||
add_subdirectory(
|
||||
@@ -33,81 +33,226 @@ add_subdirectory(
|
||||
"${CMAKE_BINARY_DIR}/libcef_dll_wrapper"
|
||||
)
|
||||
|
||||
SET_CEF_TARGET_OUT_DIR()
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Nebula source files
|
||||
# Sources
|
||||
# ------------------------------------------------------------
|
||||
|
||||
set(NEBULA_SOURCES
|
||||
app/main.cpp
|
||||
set(NEBULA_COMMON_SOURCES
|
||||
src/app/first_run_state.cpp
|
||||
src/app/nebula_controller.cpp
|
||||
src/app/run.cpp
|
||||
src/browser/session_state.cpp
|
||||
src/browser/tab.cpp
|
||||
src/browser/tab_manager.cpp
|
||||
src/browser/url_utils.cpp
|
||||
src/cef/browser_client.cpp
|
||||
src/cef/nebula_app.cpp
|
||||
src/ui/paths.cpp
|
||||
)
|
||||
|
||||
add_executable(NebulaBrowser WIN32
|
||||
${NEBULA_SOURCES}
|
||||
)
|
||||
|
||||
SET_EXECUTABLE_TARGET_PROPERTIES(NebulaBrowser)
|
||||
|
||||
if(MSVC)
|
||||
set_property(TARGET NebulaBrowser PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
|
||||
if(OS_WINDOWS)
|
||||
set(NEBULA_PLATFORM_SOURCES
|
||||
src/platform/win/default_browser_win.cpp
|
||||
src/platform/win/paths_win.cpp
|
||||
src/platform/win/startup_win.cpp
|
||||
src/platform/win/browser_host_win.cpp
|
||||
src/platform/win/nebula_window_win.cpp
|
||||
)
|
||||
elseif(OS_MACOSX)
|
||||
set(NEBULA_PLATFORM_SOURCES
|
||||
src/platform/mac/default_browser_mac.mm
|
||||
src/platform/mac/paths_mac.cpp
|
||||
src/platform/mac/startup_mac.mm
|
||||
src/platform/mac/browser_host_mac.mm
|
||||
src/platform/mac/nebula_window_mac.mm
|
||||
)
|
||||
set_source_files_properties(
|
||||
src/platform/mac/startup_mac.mm
|
||||
src/platform/mac/browser_host_mac.mm
|
||||
src/platform/mac/nebula_window_mac.mm
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS "-fobjc-arc"
|
||||
)
|
||||
elseif(OS_LINUX)
|
||||
set(NEBULA_PLATFORM_SOURCES
|
||||
src/platform/linux/default_browser_linux.cpp
|
||||
src/platform/linux/paths_linux.cpp
|
||||
src/platform/linux/startup_linux.cpp
|
||||
src/platform/linux/browser_host_linux.cpp
|
||||
src/platform/linux/nebula_window_linux.cpp
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported platform.")
|
||||
endif()
|
||||
|
||||
target_include_directories(NebulaBrowser PRIVATE
|
||||
"${CEF_ROOT}"
|
||||
"${CEF_ROOT}/include"
|
||||
)
|
||||
|
||||
target_link_libraries(NebulaBrowser PRIVATE
|
||||
libcef_dll_wrapper
|
||||
${CEF_STANDARD_LIBS}
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Platform-specific CEF linking
|
||||
# ------------------------------------------------------------
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(NebulaBrowser PRIVATE
|
||||
"${CEF_ROOT}/Release/libcef.lib"
|
||||
)
|
||||
|
||||
target_compile_definitions(NebulaBrowser PRIVATE
|
||||
NOMINMAX
|
||||
WIN32_LEAN_AND_MEAN
|
||||
)
|
||||
# On macOS, CEF is a framework linked via CEF_STANDARD_LIBS.
|
||||
# On Windows/Linux, we create a logical target for libcef.
|
||||
if(NOT OS_MACOSX)
|
||||
ADD_LOGICAL_TARGET("libcef_lib" "${CEF_LIB_RELEASE}" "${CEF_LIB_DEBUG}")
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Copy CEF runtime files after build
|
||||
# ------------------------------------------------------------
|
||||
if(OS_LINUX)
|
||||
FIND_LINUX_LIBRARIES("X11")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET NebulaBrowser POST_BUILD
|
||||
function(add_nebula_app_target nebula_target entry_source)
|
||||
if(OS_WINDOWS)
|
||||
add_executable(${nebula_target} WIN32
|
||||
${entry_source}
|
||||
${NEBULA_COMMON_SOURCES}
|
||||
${NEBULA_PLATFORM_SOURCES}
|
||||
)
|
||||
elseif(OS_MACOSX)
|
||||
add_executable(${nebula_target} MACOSX_BUNDLE
|
||||
${entry_source}
|
||||
${NEBULA_COMMON_SOURCES}
|
||||
${NEBULA_PLATFORM_SOURCES}
|
||||
)
|
||||
elseif(OS_LINUX)
|
||||
add_executable(${nebula_target}
|
||||
${entry_source}
|
||||
${NEBULA_COMMON_SOURCES}
|
||||
${NEBULA_PLATFORM_SOURCES}
|
||||
)
|
||||
endif()
|
||||
|
||||
SET_EXECUTABLE_TARGET_PROPERTIES(${nebula_target})
|
||||
add_dependencies(${nebula_target} libcef_dll_wrapper)
|
||||
|
||||
target_include_directories(${nebula_target} PRIVATE
|
||||
"${CMAKE_SOURCE_DIR}/src"
|
||||
"${CEF_ROOT}"
|
||||
"${CEF_ROOT}/include"
|
||||
)
|
||||
|
||||
if(OS_MACOSX)
|
||||
# On macOS, CEF is a framework; don't link libcef_lib
|
||||
target_link_libraries(${nebula_target} PRIVATE
|
||||
libcef_dll_wrapper
|
||||
${CEF_STANDARD_LIBS}
|
||||
)
|
||||
else()
|
||||
target_link_libraries(${nebula_target} PRIVATE
|
||||
libcef_lib
|
||||
libcef_dll_wrapper
|
||||
${CEF_STANDARD_LIBS}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
set_property(TARGET ${nebula_target} PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
|
||||
)
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Platform-specific CEF runtime deployment
|
||||
# ------------------------------------------------------------
|
||||
|
||||
if(OS_WINDOWS)
|
||||
target_link_libraries(${nebula_target} PRIVATE dwmapi)
|
||||
target_compile_definitions(${nebula_target} PRIVATE
|
||||
NOMINMAX
|
||||
WIN32_LEAN_AND_MEAN
|
||||
)
|
||||
COPY_FILES("${nebula_target}" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR_RELEASE}" "${CEF_TARGET_OUT_DIR}")
|
||||
COPY_FILES("${nebula_target}" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${CEF_TARGET_OUT_DIR}")
|
||||
elseif(OS_LINUX)
|
||||
COPY_FILES("${nebula_target}" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR_RELEASE}" "${CEF_TARGET_OUT_DIR}")
|
||||
COPY_FILES("${nebula_target}" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${CEF_TARGET_OUT_DIR}")
|
||||
elseif(OS_MACOSX)
|
||||
target_link_libraries(${nebula_target} PRIVATE
|
||||
"-framework Cocoa"
|
||||
"-framework ApplicationServices"
|
||||
)
|
||||
set(NEBULA_APP "${CEF_TARGET_OUT_DIR}/${nebula_target}.app")
|
||||
set(NEBULA_HELPER_TARGET "${nebula_target}_Helper")
|
||||
set(NEBULA_HELPER_OUTPUT_NAME "${nebula_target} Helper")
|
||||
string(TOLOWER "${nebula_target}" NEBULA_HELPER_BUNDLE_NAME)
|
||||
|
||||
COPY_MAC_FRAMEWORK(
|
||||
"${nebula_target}"
|
||||
"${CEF_BINARY_DIR_RELEASE}"
|
||||
"${NEBULA_APP}"
|
||||
)
|
||||
COPY_FILES(
|
||||
"${nebula_target}"
|
||||
"${CEF_BINARY_FILES}"
|
||||
"${CEF_BINARY_DIR_RELEASE}"
|
||||
"${NEBULA_APP}/Contents/Frameworks"
|
||||
)
|
||||
COPY_FILES(
|
||||
"${nebula_target}"
|
||||
"${CEF_RESOURCE_FILES}"
|
||||
"${CEF_RESOURCE_DIR}"
|
||||
"${NEBULA_APP}/Contents/Resources"
|
||||
)
|
||||
|
||||
foreach(_suffix_list ${CEF_HELPER_APP_SUFFIXES})
|
||||
string(REPLACE ":" ";" _suffix_list ${_suffix_list})
|
||||
list(GET _suffix_list 0 _name_suffix)
|
||||
list(GET _suffix_list 1 _target_suffix)
|
||||
list(GET _suffix_list 2 _plist_suffix)
|
||||
|
||||
set(_helper_target "${NEBULA_HELPER_TARGET}${_target_suffix}")
|
||||
set(_helper_output_name "${NEBULA_HELPER_OUTPUT_NAME}${_name_suffix}")
|
||||
set(_helper_info_plist "${CMAKE_CURRENT_BINARY_DIR}/${_helper_target}-Info.plist")
|
||||
|
||||
file(READ "${CMAKE_SOURCE_DIR}/cmake/mac-helper-Info.plist.in" _plist_contents)
|
||||
string(REPLACE "\${EXECUTABLE_NAME}" "${_helper_output_name}" _plist_contents "${_plist_contents}")
|
||||
string(REPLACE "\${PRODUCT_NAME}" "${_helper_output_name}" _plist_contents "${_plist_contents}")
|
||||
string(REPLACE "\${HELPER_BUNDLE_NAME}" "${NEBULA_HELPER_BUNDLE_NAME}" _plist_contents "${_plist_contents}")
|
||||
string(REPLACE "\${BUNDLE_ID_SUFFIX}" "${_plist_suffix}" _plist_contents "${_plist_contents}")
|
||||
file(WRITE "${_helper_info_plist}" "${_plist_contents}")
|
||||
|
||||
add_executable(${_helper_target} MACOSX_BUNDLE
|
||||
app/process_helper_mac.cc
|
||||
src/cef/nebula_app.cpp
|
||||
)
|
||||
SET_EXECUTABLE_TARGET_PROPERTIES(${_helper_target})
|
||||
add_dependencies(${_helper_target} libcef_dll_wrapper)
|
||||
target_include_directories(${_helper_target} PRIVATE
|
||||
"${CMAKE_SOURCE_DIR}/src"
|
||||
"${CEF_ROOT}"
|
||||
"${CEF_ROOT}/include"
|
||||
)
|
||||
target_link_libraries(${_helper_target} PRIVATE
|
||||
libcef_dll_wrapper
|
||||
${CEF_STANDARD_LIBS}
|
||||
)
|
||||
set_target_properties(${_helper_target} PROPERTIES
|
||||
MACOSX_BUNDLE_INFO_PLIST "${_helper_info_plist}"
|
||||
OUTPUT_NAME "${_helper_output_name}"
|
||||
)
|
||||
|
||||
add_dependencies(${nebula_target} "${_helper_target}")
|
||||
add_custom_command(TARGET ${nebula_target} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CEF_TARGET_OUT_DIR}/${_helper_output_name}.app"
|
||||
"${NEBULA_APP}/Contents/Frameworks/${_helper_output_name}.app"
|
||||
VERBATIM
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Copy Nebula UI files after build
|
||||
# ------------------------------------------------------------
|
||||
|
||||
add_custom_command(TARGET ${nebula_target} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CEF_ROOT}/Release"
|
||||
"$<TARGET_FILE_DIR:NebulaBrowser>"
|
||||
"${CMAKE_SOURCE_DIR}/ui"
|
||||
"$<TARGET_FILE_DIR:${nebula_target}>/ui"
|
||||
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CEF_ROOT}/Resources"
|
||||
"$<TARGET_FILE_DIR:NebulaBrowser>"
|
||||
"${CMAKE_SOURCE_DIR}/assets"
|
||||
"$<TARGET_FILE_DIR:${nebula_target}>/ui/assets"
|
||||
|
||||
COMMENT "Copying CEF runtime files..."
|
||||
COMMENT "Copying Nebula UI files and assets for ${nebula_target}..."
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Copy Nebula UI files after build
|
||||
# ------------------------------------------------------------
|
||||
|
||||
add_custom_command(TARGET NebulaBrowser POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CMAKE_SOURCE_DIR}/ui"
|
||||
"$<TARGET_FILE_DIR:NebulaBrowser>/ui"
|
||||
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CMAKE_SOURCE_DIR}/assets"
|
||||
"$<TARGET_FILE_DIR:NebulaBrowser>/ui/assets"
|
||||
|
||||
COMMENT "Copying Nebula UI files and assets..."
|
||||
)
|
||||
add_nebula_app_target(NebulaBrowser app/main.cpp)
|
||||
add_nebula_app_target(NebulaBigPicture app/main_bigpicture.cpp)
|
||||
|
||||
@@ -0,0 +1,373 @@
|
||||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
||||
@@ -0,0 +1,351 @@
|
||||
# Nebula Browser
|
||||
|
||||
A Chromium Embedded Framework (CEF) browser with a custom HTML chrome UI.
|
||||
|
||||
**Nebula Browser** is a controller-first web browser designed for Steam Deck, SteamOS-style systems, handheld PCs, living room setups, and gamepad-driven desktop environments.
|
||||
|
||||
Originally developed as an Electron-based browser for SteamOS users, Nebula Browser is now being rebuilt with **CEF / Chromium Embedded Framework** to provide deeper control over the browser experience, improved native integration, and a cleaner long-term foundation for custom UI, controller navigation, and platform-specific builds.
|
||||
|
||||
Development on Nebula Browser has somewhat resumed, with the project now moving toward a more native custom browser architecture.
|
||||
|
||||
Nebula Browser is intended to remain open source. The browser source code is licensed under MPL-2.0, while Nebula branding and visual assets are protected separately.
|
||||
|
||||
## Documentation
|
||||
|
||||
- **[Cross-platform build & architecture](docs/cross-platform.md)** — how to use one repo for Windows, macOS, and Linux; CEF setup; source layout; porting status.
|
||||
|
||||
---
|
||||
|
||||
## Project Status
|
||||
|
||||
Nebula Browser is currently in early active redevelopment.
|
||||
|
||||
The original Electron version proved the core idea: a browser built around controller use, large-screen navigation, and a UI that does not feel like a standard desktop browser awkwardly placed on a handheld gaming device.
|
||||
|
||||
The new CEF version is the next major step.
|
||||
|
||||
Current focus areas include:
|
||||
|
||||
* Rebuilding the browser around CEF
|
||||
* Creating a fully custom browser interface
|
||||
* Moving away from default Chromium UI elements
|
||||
* Reusing and adapting existing Nebula UI concepts where possible
|
||||
* Supporting controller-first navigation
|
||||
* Preparing for cross-platform builds across Windows, Linux, and macOS
|
||||
* Creating a stronger foundation for future NebulaOS integration
|
||||
|
||||
---
|
||||
|
||||
## Why CEF?
|
||||
|
||||
Nebula Browser originally used Electron because it was fast to prototype, easy to package, and allowed the project to move quickly. However, Electron also comes with limits when building a browser that is meant to feel fully custom and deeply integrated with the operating system.
|
||||
|
||||
The move to **CEF** allows Nebula Browser to become more than a web app wrapped in a browser shell.
|
||||
|
||||
CEF gives the project:
|
||||
|
||||
* More control over the native window and browser lifecycle
|
||||
* Better separation between the browser engine and the custom UI
|
||||
* Greater flexibility for building a non-Chrome-like interface
|
||||
* A more suitable foundation for SteamOS, Linux, and future NebulaOS use
|
||||
* The ability to build a browser that feels purpose-built rather than wrapped
|
||||
|
||||
The goal is not to create another Chromium clone. The goal is to create a browser interface designed around how people actually use handhelds, controllers, TVs, and gaming-first systems.
|
||||
|
||||
---
|
||||
|
||||
## Distribution Direction
|
||||
|
||||
Nebula Browser was originally aimed at Steam. However, after exploring Steam as a release platform, it became clear that Steam may not be the best fit for this kind of application.
|
||||
|
||||
The current distribution direction is:
|
||||
|
||||
### Primary Target
|
||||
|
||||
* **Itch.io**
|
||||
|
||||
Itch.io is currently the most practical and flexible platform for distributing Nebula Browser. It allows the project to be released as a utility-style app without needing to fit into a traditional game store category.
|
||||
|
||||
### Potential Future Targets
|
||||
|
||||
* **Epic Games Store**
|
||||
* **GOG**
|
||||
* **Flatpak / Linux package distribution**
|
||||
* **Direct downloads from the Nebula website**
|
||||
|
||||
Epic Games and GOG are being considered as possible future distribution platforms, especially if Nebula Browser grows into a more polished desktop or gaming utility. These are not confirmed release platforms yet, but they remain possible options.
|
||||
|
||||
---
|
||||
|
||||
## Open Source Direction
|
||||
|
||||
Nebula Browser is intended to remain open source because browsers are privacy-sensitive software. Users should be able to inspect how the browser works, verify that it is not doing anything suspicious, and contribute fixes or improvements when they find problems.
|
||||
|
||||
Open source is especially important for:
|
||||
|
||||
* User trust
|
||||
* Privacy transparency
|
||||
* Linux and Steam Deck community adoption
|
||||
* Cross-platform testing
|
||||
* Community contributions
|
||||
* Long-term sustainability
|
||||
|
||||
The core Nebula Browser project should remain open source, including:
|
||||
|
||||
* Browser shell
|
||||
* CEF integration code
|
||||
* Custom browser UI
|
||||
* Controller navigation systems
|
||||
* Settings and theme systems
|
||||
* Build scripts and documentation
|
||||
|
||||
Not every Nebula-related component has to be open source. Some future or external components may remain private or be licensed separately, such as:
|
||||
|
||||
* NebulaOS-specific services
|
||||
* Account systems
|
||||
* Cloud sync
|
||||
* Hosted backend services
|
||||
* Internal analytics or crash reporting infrastructure
|
||||
* Private distribution tooling
|
||||
* Experimental unreleased features
|
||||
* Protected branding assets
|
||||
|
||||
Suggested openness model:
|
||||
|
||||
```text
|
||||
Nebula Browser: open source
|
||||
Nebula Core: open source or source-available
|
||||
NebulaOS: potentially partially open source
|
||||
Nebula online services/backend: private
|
||||
Branding assets: protected
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Core Vision
|
||||
|
||||
Nebula Browser is built around one simple idea:
|
||||
|
||||
> The web should be comfortable to use from a couch, handheld, controller, or gaming-focused operating system.
|
||||
|
||||
Most browsers are designed around keyboards, mice, and desktop workflows. Nebula Browser is designed around a different experience.
|
||||
|
||||
Nebula Browser aims to support:
|
||||
|
||||
* Controller-first navigation
|
||||
* Large, readable interface elements
|
||||
* Gamepad-friendly menus and shortcuts
|
||||
* Steam Deck and handheld PC usability
|
||||
* Custom home pages and launcher-style navigation
|
||||
* Better integration with gaming-focused environments
|
||||
* A UI that feels closer to a console app than a traditional browser
|
||||
|
||||
---
|
||||
|
||||
## Planned Features
|
||||
|
||||
The CEF rebuild is still early, but the intended feature set includes:
|
||||
|
||||
* Fully custom browser chrome
|
||||
* Custom tab bar
|
||||
* Custom address bar
|
||||
* Controller-friendly navigation system
|
||||
* On-screen keyboard support
|
||||
* Bookmarks and quick access tiles
|
||||
* Custom home page
|
||||
* Desktop mode and controller mode
|
||||
* Fullscreen and couch-friendly browsing
|
||||
* Custom context menus
|
||||
* Download management
|
||||
* Settings system
|
||||
* Theme support
|
||||
* Steam Deck / handheld-focused layout options
|
||||
* Optional integration with NebulaOS
|
||||
|
||||
Some features may be ported or adapted from the earlier Electron version where it makes sense.
|
||||
|
||||
---
|
||||
|
||||
## Nebula Core
|
||||
|
||||
Nebula Browser may also make use of **Nebula Core**, a shared package system for Nebula-related projects.
|
||||
|
||||
Nebula Core is intended to provide reusable systems such as:
|
||||
|
||||
* Controller input handling
|
||||
* Navigation helpers
|
||||
* UI components
|
||||
* Glyphs and button prompts
|
||||
* Theming utilities
|
||||
* On-screen keyboard systems
|
||||
* Shared Nebula project logic
|
||||
|
||||
Because the new browser is CEF-based rather than Electron-based, some Nebula Core modules may need to be adapted for native integration or used through the browser UI layer rather than directly inside the C++ application layer.
|
||||
|
||||
---
|
||||
|
||||
## Relationship to NebulaOS
|
||||
|
||||
Nebula Browser is part of the wider **Nebula Project** ecosystem.
|
||||
|
||||
NebulaOS is a controller-focused operating system / shell concept designed around gaming, handheld PCs, and living room devices. Nebula Browser is intended to become one of the key built-in applications for that ecosystem.
|
||||
|
||||
While Nebula Browser can exist as a standalone app, its long-term role is to provide a web browsing experience that feels native inside NebulaOS.
|
||||
|
||||
---
|
||||
|
||||
## Technology Stack
|
||||
|
||||
The current redevelopment direction uses:
|
||||
|
||||
* **C++** for the native browser shell
|
||||
* **CEF / Chromium Embedded Framework** for web rendering
|
||||
* **HTML, CSS, and JavaScript** for the custom browser UI
|
||||
* **CMake** for project configuration
|
||||
* Platform-specific CEF builds for Windows, Linux, and macOS
|
||||
|
||||
The previous version used Electron, but the current direction is focused on CEF.
|
||||
|
||||
---
|
||||
|
||||
## Repository Structure
|
||||
|
||||
The repository structure may change as the CEF rebuild develops, but the project is expected to follow a layout similar to:
|
||||
|
||||
```text
|
||||
NebulaBrowser/
|
||||
├── app/
|
||||
│ ├── browser/
|
||||
│ ├── ui/
|
||||
│ └── platform/
|
||||
├── cef/
|
||||
│ └── README.md
|
||||
├── resources/
|
||||
│ ├── icons/
|
||||
│ ├── themes/
|
||||
│ └── pages/
|
||||
├── scripts/
|
||||
├── third_party/
|
||||
├── CMakeLists.txt
|
||||
└── README.md
|
||||
```
|
||||
|
||||
CEF itself should generally not be committed directly into the repository. Instead, platform-specific CEF builds should be downloaded separately and placed into the expected local folder during development.
|
||||
|
||||
---
|
||||
|
||||
## Development Notes
|
||||
|
||||
Nebula Browser is still experimental and in transition from the original Electron version to the new CEF version.
|
||||
|
||||
Expect changes in:
|
||||
|
||||
* Build setup
|
||||
* File structure
|
||||
* UI architecture
|
||||
* Controller input systems
|
||||
* Platform support
|
||||
* Packaging and distribution
|
||||
|
||||
The project is not yet considered production-ready.
|
||||
|
||||
---
|
||||
|
||||
## Building
|
||||
|
||||
Build instructions will be expanded as the CEF version becomes more stable.
|
||||
|
||||
At a high level, development requires:
|
||||
|
||||
1. A supported C++ compiler
|
||||
2. CMake
|
||||
3. A downloaded CEF binary distribution for your operating system
|
||||
4. The Nebula Browser source code
|
||||
5. A local build folder
|
||||
|
||||
Example build flow:
|
||||
|
||||
```bash
|
||||
cmake -S . -B build
|
||||
cmake --build build
|
||||
```
|
||||
|
||||
More detailed platform-specific instructions will be added later. For macOS/Linux prerequisites, directory structure, and current port status, see [docs/cross-platform.md](docs/cross-platform.md).
|
||||
|
||||
### Quick start (Windows)
|
||||
|
||||
1. Download the [CEF standard binary distribution](https://cef-builds.spotifycdn.com/index.html) for Windows 64-bit.
|
||||
2. Extract into `thirdparty/cef/` so `thirdparty/cef/cmake/FindCEF.cmake` exists.
|
||||
3. Build:
|
||||
|
||||
```powershell
|
||||
cmake -B build
|
||||
cmake --build build --config Release
|
||||
```
|
||||
|
||||
4. Run `build\Release\NebulaBrowser.exe`.
|
||||
|
||||
---
|
||||
|
||||
## Platform Goals
|
||||
|
||||
Nebula Browser is being designed with cross-platform support in mind.
|
||||
|
||||
Target platforms include:
|
||||
|
||||
* Windows
|
||||
* Linux
|
||||
* SteamOS / Steam Deck
|
||||
* macOS
|
||||
|
||||
Linux and SteamOS are especially important because Nebula Browser was originally created to solve a gap in the handheld and couch-browsing experience.
|
||||
|
||||
---
|
||||
|
||||
## Release Plans
|
||||
|
||||
Nebula Browser does not currently have a fixed release date.
|
||||
|
||||
The current release plan is:
|
||||
|
||||
1. Rebuild the core browser shell in CEF
|
||||
2. Replace default Chromium UI with a custom Nebula interface
|
||||
3. Restore core browser functionality
|
||||
4. Add controller-first navigation
|
||||
5. Prepare an early public build
|
||||
6. Release through Itch.io first
|
||||
7. Explore additional distribution options later
|
||||
|
||||
---
|
||||
|
||||
## Contributing
|
||||
|
||||
Nebula Browser is currently a personal / experimental project and is still finding its new technical direction.
|
||||
|
||||
Contributions, ideas, testing, and feedback may become more open once the CEF rebuild has a more stable foundation.
|
||||
|
||||
---
|
||||
|
||||
## Licensing
|
||||
|
||||
Nebula Browser separates source code licensing from branding and visual assets.
|
||||
|
||||
The preferred licensing direction is:
|
||||
|
||||
* **Source code:** Mozilla Public License 2.0
|
||||
* **Documentation:** CC BY 4.0, unless otherwise specified
|
||||
* **Branding, logos, icons, names, and visual identity:** All Rights Reserved, unless explicitly stated otherwise
|
||||
|
||||
MPL-2.0 is being used because it is a practical open-source license for a browser-style project. It allows people to use, modify, and contribute to the code while requiring changes to MPL-licensed files to remain open under the same license.
|
||||
|
||||
The Nebula name, logo, and brand identity are not automatically granted for reuse just because the code is open source. See [ASSETS-LICENSE.md](ASSETS-LICENSE.md) for the separate asset and branding terms.
|
||||
|
||||
See the CEF distribution and Chromium license terms for third-party runtime components.
|
||||
|
||||
---
|
||||
|
||||
## About
|
||||
|
||||
Nebula Browser is created as part of the wider Nebula Project, a collection of software experiments focused on controller-first computing, gaming-focused interfaces, and custom desktop experiences.
|
||||
|
||||
The project began as a browser for SteamOS and Steam Deck users, but is now evolving into a more flexible, native, and custom browser experience built around CEF.
|
||||
+25
-333
@@ -1,341 +1,33 @@
|
||||
#include "app/run.h"
|
||||
#include "platform/types.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include "include/wrapper/cef_library_loader.h"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include "include/cef_app.h"
|
||||
#include "include/cef_browser.h"
|
||||
#include "include/cef_client.h"
|
||||
#include "include/cef_command_line.h"
|
||||
#include "include/cef_request.h"
|
||||
#include "include/cef_request_handler.h"
|
||||
#include "include/wrapper/cef_helpers.h"
|
||||
|
||||
namespace {
|
||||
|
||||
std::string WideToUtf8(const std::wstring& value) {
|
||||
if (value.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const int size = WideCharToMultiByte(
|
||||
CP_UTF8, 0, value.data(), static_cast<int>(value.size()),
|
||||
nullptr, 0, nullptr, nullptr);
|
||||
std::string result(size, '\0');
|
||||
WideCharToMultiByte(
|
||||
CP_UTF8, 0, value.data(), static_cast<int>(value.size()),
|
||||
result.data(), size, nullptr, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string FilePathToUrl(std::filesystem::path path) {
|
||||
std::string value = WideToUtf8(path.wstring());
|
||||
for (char& ch : value) {
|
||||
if (ch == '\\') {
|
||||
ch = '/';
|
||||
}
|
||||
}
|
||||
|
||||
std::string encoded;
|
||||
encoded.reserve(value.size());
|
||||
for (char ch : value) {
|
||||
encoded += ch == ' ' ? "%20" : std::string(1, ch);
|
||||
}
|
||||
return "file:///" + encoded;
|
||||
}
|
||||
|
||||
std::filesystem::path GetHomePath() {
|
||||
wchar_t exe_path[MAX_PATH] = {};
|
||||
const DWORD length = GetModuleFileNameW(nullptr, exe_path, MAX_PATH);
|
||||
if (length == 0 || length == MAX_PATH) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::filesystem::path(exe_path).parent_path() /
|
||||
"ui" / "pages" / "home.html";
|
||||
}
|
||||
|
||||
std::string GetHomeUrl() {
|
||||
const auto home_path = GetHomePath();
|
||||
if (home_path.empty()) {
|
||||
return "https://www.google.com";
|
||||
}
|
||||
|
||||
return FilePathToUrl(home_path);
|
||||
}
|
||||
|
||||
std::string GetUrlWithoutDecoration(std::string url) {
|
||||
const size_t split = url.find_first_of("?#");
|
||||
if (split != std::string::npos) {
|
||||
url.resize(split);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
std::string ToLowerAscii(std::string value) {
|
||||
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char ch) {
|
||||
return static_cast<char>(std::tolower(ch));
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
bool IsInternalHomeUrl(const std::string& url) {
|
||||
return GetUrlWithoutDecoration(url) == GetHomeUrl();
|
||||
}
|
||||
|
||||
bool IsChromiumNewTabUrl(const std::string& url) {
|
||||
const std::string target = ToLowerAscii(GetUrlWithoutDecoration(url));
|
||||
return target == "about:blank" ||
|
||||
target == "chrome://newtab" ||
|
||||
target == "chrome://newtab/" ||
|
||||
target == "chrome://new-tab-page" ||
|
||||
target == "chrome://new-tab-page/" ||
|
||||
target == "chrome-search://local-ntp/local-ntp.html";
|
||||
}
|
||||
|
||||
bool IsEmptyOrChromiumNewTabUrl(const std::string& url) {
|
||||
return url.empty() || IsChromiumNewTabUrl(url);
|
||||
}
|
||||
|
||||
class NebulaClient final : public CefClient,
|
||||
public CefDisplayHandler,
|
||||
public CefKeyboardHandler,
|
||||
public CefLifeSpanHandler,
|
||||
public CefPermissionHandler,
|
||||
public CefRequestHandler {
|
||||
public:
|
||||
CefRefPtr<CefDisplayHandler> GetDisplayHandler() override {
|
||||
return this;
|
||||
}
|
||||
|
||||
CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() override {
|
||||
return this;
|
||||
}
|
||||
|
||||
CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override {
|
||||
return this;
|
||||
}
|
||||
|
||||
CefRefPtr<CefPermissionHandler> GetPermissionHandler() override {
|
||||
return this;
|
||||
}
|
||||
|
||||
CefRefPtr<CefRequestHandler> GetRequestHandler() override {
|
||||
return this;
|
||||
}
|
||||
|
||||
void OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url) override {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
if (browser && frame && frame->IsMain() &&
|
||||
IsChromiumNewTabUrl(url)) {
|
||||
browser->GetMainFrame()->LoadURL(GetHomeUrl());
|
||||
}
|
||||
}
|
||||
|
||||
void OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) override {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
CefWindowHandle window = browser->GetHost()->GetWindowHandle();
|
||||
if (window) {
|
||||
SetWindowText(window, std::wstring(title).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
const CefKeyEvent& event,
|
||||
CefEventHandle os_event,
|
||||
bool* is_keyboard_shortcut) override {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
UNREFERENCED_PARAMETER(os_event);
|
||||
|
||||
if (event.type == KEYEVENT_RAWKEYDOWN &&
|
||||
(event.modifiers & EVENTFLAG_CONTROL_DOWN) != 0 &&
|
||||
event.windows_key_code == 'T') {
|
||||
if (is_keyboard_shortcut) {
|
||||
*is_keyboard_shortcut = true;
|
||||
}
|
||||
browser->GetMainFrame()->LoadURL(GetHomeUrl());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int popup_id,
|
||||
const CefString& target_url,
|
||||
const CefString& target_frame_name,
|
||||
CefLifeSpanHandler::WindowOpenDisposition target_disposition,
|
||||
bool user_gesture,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefWindowInfo& windowInfo,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue>& extra_info,
|
||||
bool* no_javascript_access) override {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
UNREFERENCED_PARAMETER(frame);
|
||||
UNREFERENCED_PARAMETER(popup_id);
|
||||
UNREFERENCED_PARAMETER(target_frame_name);
|
||||
UNREFERENCED_PARAMETER(user_gesture);
|
||||
UNREFERENCED_PARAMETER(popupFeatures);
|
||||
UNREFERENCED_PARAMETER(windowInfo);
|
||||
UNREFERENCED_PARAMETER(settings);
|
||||
UNREFERENCED_PARAMETER(extra_info);
|
||||
UNREFERENCED_PARAMETER(no_javascript_access);
|
||||
|
||||
if (target_disposition == CEF_WOD_NEW_WINDOW &&
|
||||
IsEmptyOrChromiumNewTabUrl(target_url)) {
|
||||
client = this;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsChromiumNewTabUrl(target_url)) {
|
||||
browser->GetMainFrame()->LoadURL(GetHomeUrl());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool user_gesture,
|
||||
bool is_redirect) override {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
UNREFERENCED_PARAMETER(browser);
|
||||
UNREFERENCED_PARAMETER(user_gesture);
|
||||
UNREFERENCED_PARAMETER(is_redirect);
|
||||
|
||||
if (frame && frame->IsMain() && request &&
|
||||
IsChromiumNewTabUrl(request->GetURL())) {
|
||||
frame->LoadURL(GetHomeUrl());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
++browser_count_;
|
||||
|
||||
if (browser_count_ > 1 && browser &&
|
||||
IsEmptyOrChromiumNewTabUrl(browser->GetMainFrame()->GetURL())) {
|
||||
browser->GetMainFrame()->LoadURL(GetHomeUrl());
|
||||
}
|
||||
}
|
||||
|
||||
void OnBeforeClose(CefRefPtr<CefBrowser> browser) override {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
--browser_count_;
|
||||
if (browser_count_ == 0) {
|
||||
CefQuitMessageLoop();
|
||||
}
|
||||
}
|
||||
|
||||
bool OnShowPermissionPrompt(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
uint64_t prompt_id,
|
||||
const CefString& requesting_origin,
|
||||
uint32_t requested_permissions,
|
||||
CefRefPtr<CefPermissionPromptCallback> callback) override {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
UNREFERENCED_PARAMETER(prompt_id);
|
||||
UNREFERENCED_PARAMETER(requesting_origin);
|
||||
|
||||
if ((requested_permissions & CEF_PERMISSION_TYPE_GEOLOCATION) != 0 &&
|
||||
browser && callback &&
|
||||
IsInternalHomeUrl(browser->GetMainFrame()->GetURL())) {
|
||||
callback->Continue(CEF_PERMISSION_RESULT_ACCEPT);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
int browser_count_ = 0;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(NebulaClient);
|
||||
};
|
||||
|
||||
class NebulaApp final : public CefApp {
|
||||
public:
|
||||
void OnBeforeCommandLineProcessing(
|
||||
const CefString& process_type,
|
||||
CefRefPtr<CefCommandLine> command_line) override {
|
||||
UNREFERENCED_PARAMETER(process_type);
|
||||
|
||||
// The bundled UI is loaded from file:// and uses ES modules.
|
||||
command_line->AppendSwitch("allow-file-access-from-files");
|
||||
}
|
||||
|
||||
private:
|
||||
IMPLEMENT_REFCOUNTING(NebulaApp);
|
||||
};
|
||||
|
||||
int RunNebula(HINSTANCE instance) {
|
||||
CefMainArgs main_args(instance);
|
||||
CefRefPtr<NebulaApp> app(new NebulaApp);
|
||||
|
||||
const int subprocess_exit_code =
|
||||
CefExecuteProcess(main_args, app, nullptr);
|
||||
if (subprocess_exit_code >= 0) {
|
||||
return subprocess_exit_code;
|
||||
}
|
||||
|
||||
CefSettings settings;
|
||||
settings.no_sandbox = true;
|
||||
|
||||
if (!CefInitialize(main_args, settings, app, nullptr)) {
|
||||
return CefGetExitCode();
|
||||
}
|
||||
|
||||
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
||||
command_line->InitFromString(GetCommandLineW());
|
||||
|
||||
std::string url = command_line->GetSwitchValue("url");
|
||||
if (url.empty()) {
|
||||
url = GetHomeUrl();
|
||||
}
|
||||
|
||||
CefWindowInfo window_info;
|
||||
window_info.SetAsPopup(nullptr, "Nebula Browser");
|
||||
|
||||
CefBrowserSettings browser_settings;
|
||||
CefRefPtr<NebulaClient> client(new NebulaClient);
|
||||
|
||||
if (!CefBrowserHost::CreateBrowser(
|
||||
window_info, client, url, browser_settings, nullptr, nullptr)) {
|
||||
CefShutdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
CefRunMessageLoop();
|
||||
CefShutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#if defined(_WIN32)
|
||||
int APIENTRY wWinMain(HINSTANCE instance,
|
||||
HINSTANCE previous_instance,
|
||||
LPWSTR command_line,
|
||||
int show_command) {
|
||||
UNREFERENCED_PARAMETER(previous_instance);
|
||||
UNREFERENCED_PARAMETER(command_line);
|
||||
UNREFERENCED_PARAMETER(show_command);
|
||||
NEBULA_UNUSED(previous_instance);
|
||||
NEBULA_UNUSED(command_line);
|
||||
|
||||
return RunNebula(instance);
|
||||
const nebula::platform::AppStartup startup{instance, show_command};
|
||||
return nebula::app::RunNebula(startup, {nebula::app::AppMode::Desktop});
|
||||
}
|
||||
#else
|
||||
int main(int argc, char* argv[]) {
|
||||
#if defined(__APPLE__)
|
||||
CefScopedLibraryLoader library_loader;
|
||||
if (!library_loader.LoadInMain()) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
const nebula::platform::AppStartup startup{argc, argv};
|
||||
return nebula::app::RunNebula(startup, {nebula::app::AppMode::Desktop});
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "app/run.h"
|
||||
#include "platform/types.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include "include/wrapper/cef_library_loader.h"
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
int APIENTRY wWinMain(HINSTANCE instance,
|
||||
HINSTANCE previous_instance,
|
||||
LPWSTR command_line,
|
||||
int show_command) {
|
||||
NEBULA_UNUSED(previous_instance);
|
||||
NEBULA_UNUSED(command_line);
|
||||
|
||||
const nebula::platform::AppStartup startup{instance, show_command};
|
||||
return nebula::app::RunNebula(startup, {nebula::app::AppMode::BigPicture});
|
||||
}
|
||||
#else
|
||||
int main(int argc, char* argv[]) {
|
||||
#if defined(__APPLE__)
|
||||
CefScopedLibraryLoader library_loader;
|
||||
if (!library_loader.LoadInMain()) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
const nebula::platform::AppStartup startup{argc, argv};
|
||||
return nebula::app::RunNebula(startup, {nebula::app::AppMode::BigPicture});
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "cef/nebula_app.h"
|
||||
#include "include/cef_app.h"
|
||||
#include "include/wrapper/cef_library_loader.h"
|
||||
|
||||
#if defined(CEF_USE_SANDBOX)
|
||||
#include "include/cef_sandbox_mac.h"
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
#if defined(CEF_USE_SANDBOX)
|
||||
CefScopedSandboxContext sandbox_context;
|
||||
if (!sandbox_context.Initialize(argc, argv)) {
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
CefScopedLibraryLoader library_loader;
|
||||
if (!library_loader.LoadInHelper()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const CefMainArgs main_args(argc, argv);
|
||||
CefRefPtr<nebula::cef::NebulaApp> app(new nebula::cef::NebulaApp);
|
||||
return CefExecuteProcess(main_args, app, nullptr);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.nebula.browser.${HELPER_BUNDLE_NAME}.helper${BUNDLE_ID_SUFFIX}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>LSEnvironment</key>
|
||||
<dict>
|
||||
<key>MallocNanoZone</key>
|
||||
<string>0</string>
|
||||
</dict>
|
||||
<key>LSFileQuarantineEnabled</key>
|
||||
<true/>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>12.0</string>
|
||||
<key>LSUIElement</key>
|
||||
<string>1</string>
|
||||
<key>NSSupportsAutomaticGraphicsSwitching</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
build/compile_commands.json
|
||||
@@ -0,0 +1,215 @@
|
||||
# Cross-platform build guide
|
||||
|
||||
Nebula Browser uses a **single codebase** and **one git branch** for Windows, macOS, and Linux. You do not maintain separate platform branches. Instead, each machine unpacks the correct [CEF](https://bitbucket.org/chromiumembedded/cef) binary distribution into `thirdparty/cef/` and builds with CMake.
|
||||
|
||||
## Overview
|
||||
|
||||
| Layer | Location | Platform-specific? |
|
||||
|-------|----------|-------------------|
|
||||
| CEF binaries | `thirdparty/cef/` (gitignored) | Yes — one distribution per OS |
|
||||
| CMake / deploy | `CMakeLists.txt` | Yes — uses CEF’s `COPY_FILES`, `COPY_MAC_FRAMEWORK`, etc. |
|
||||
| App entry & CEF init | `src/app/run.cpp`, `src/platform/*/startup_*.cpp` | Partly |
|
||||
| Native window shell | `src/platform/win\|mac\|linux/` | Yes |
|
||||
| Browser embedding | `src/platform/*/browser_host_*.cpp` | Partly |
|
||||
| Tabs, URLs, UI routing | `src/browser/`, `src/ui/`, `src/cef/` | No (shared) |
|
||||
|
||||
**Windows** has a full native shell (custom frame, DWM, embedded CEF views).
|
||||
|
||||
**macOS** has a Cocoa native shell (`NSWindow` / `NSView`) with CEF child-view embedding.
|
||||
|
||||
**Linux** compiles and links today, but `NebulaWindow::Create()` is still a stub that returns `false` until a real X11 (or GTK) host is implemented.
|
||||
|
||||
## Directory layout
|
||||
|
||||
```
|
||||
thirdparty/cef/ # CEF standard distribution for your OS (not in git)
|
||||
|
||||
src/platform/
|
||||
types.h # Rect, BrowserLayout, NativeWindow, AppStartup
|
||||
startup.h # PrepareApp, single-instance, CefMainArgs, CefSettings paths
|
||||
browser_host.h # CefWindowInfo helpers, resize/show/destroy browser HWNDs
|
||||
paths_platform.h # ExecutableDirectory, DefaultUserDataRoot, PathToUtf8
|
||||
|
||||
win/ # Windows implementation
|
||||
mac/ # macOS Cocoa implementation
|
||||
linux/ # Linux stubs + partial CEF glue
|
||||
|
||||
src/window/
|
||||
nebula_window.h # Platform-agnostic window API (PIMPL)
|
||||
|
||||
src/app/ # Shared controller and run loop
|
||||
src/browser/ # Shared tab/session logic
|
||||
src/cef/ # Shared CEF app and browser client
|
||||
src/ui/ # Shared nebula:// URLs and path helpers
|
||||
ui/ # HTML/JS UI (copied next to the binary at build time)
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- **CMake** 3.21+
|
||||
- **C++20** compiler
|
||||
- Windows: Visual Studio 2022
|
||||
- macOS: Xcode 16+ (Clang)
|
||||
- Linux: GCC 10+ or Clang, plus development packages for X11 (CEF’s CMake runs `pkg-config` for X11 on Linux)
|
||||
- **CEF standard binary distribution** for your OS and CPU architecture from the [CEF builds](https://cef-builds.spotifycdn.com/index.html) page (or your usual CEF source)
|
||||
|
||||
## CEF setup
|
||||
|
||||
1. Download the **standard distribution** for your platform (e.g. `cef_binary_*_windows64`, `*_macos*`, `*_linux64`).
|
||||
2. Extract so that this path exists:
|
||||
|
||||
```
|
||||
thirdparty/cef/cmake/FindCEF.cmake
|
||||
```
|
||||
|
||||
3. The rest of the distribution (`Release/`, `Resources/`, `libcef_dll/`, etc.) should sit directly under `thirdparty/cef/` as shipped by CEF.
|
||||
|
||||
`thirdparty/cef/` is listed in `.gitignore` so binaries are never committed. Each developer and CI machine supplies its own copy.
|
||||
|
||||
## IDE / clangd setup
|
||||
|
||||
Without CEF headers, clangd will show many errors (unknown types like `CefWindowInfo`, `CefMainArgs`, etc.). To get full IDE support:
|
||||
|
||||
1. Unpack CEF into `thirdparty/cef/` as described above
|
||||
2. Generate `compile_commands.json`:
|
||||
```bash
|
||||
cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
```
|
||||
3. Symlink it to the project root:
|
||||
```bash
|
||||
ln -s build/compile_commands.json .
|
||||
```
|
||||
|
||||
The included `.clangd` file provides fallback flags, but full diagnostics require the compile database.
|
||||
|
||||
Optional: override the location at configure time:
|
||||
|
||||
```bash
|
||||
cmake -B build -DCEF_ROOT=/path/to/cef_binary
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
### Windows
|
||||
|
||||
```powershell
|
||||
cmake -B build
|
||||
cmake --build build --config Release
|
||||
```
|
||||
|
||||
Output: `build/Release/NebulaBrowser.exe` (plus CEF DLLs and `ui/` copied beside it).
|
||||
|
||||
### macOS
|
||||
|
||||
```bash
|
||||
cmake -B build -DPROJECT_ARCH=x86_64 # or arm64 on Apple Silicon
|
||||
cmake --build build --config Release
|
||||
```
|
||||
|
||||
CMake builds a `NebulaBrowser.app` bundle and copies the Chromium Embedded Framework into `Contents/Frameworks`. The macOS port includes a Cocoa `NSWindow` / `NSView` host and child-view embedding for CEF browsers.
|
||||
|
||||
CEF **helper app** subprocess targets may still need to be added if the selected CEF distribution does not provide a compatible default subprocess layout. Use CEF’s `cefsimple` sample as the reference for the complete Mac bundle layout.
|
||||
|
||||
### Linux
|
||||
|
||||
```bash
|
||||
cmake -B build
|
||||
cmake --build build
|
||||
```
|
||||
|
||||
Output: `build/NebulaBrowser` (or `build/<Config>/NebulaBrowser` depending on generator). CEF `.so` files and resources are copied next to the executable.
|
||||
|
||||
You may need to set **SUID** on `chrome-sandbox` as printed by CMake post-build (CEF documents this in its Linux README).
|
||||
|
||||
Until a Linux host window exists, the binary will not show a UI for the same reason as macOS.
|
||||
|
||||
## How CMake picks a platform
|
||||
|
||||
`find_package(CEF)` loads CEF’s `cef_variables.cmake`, which sets:
|
||||
|
||||
- `OS_WINDOWS`
|
||||
- `OS_MACOSX`
|
||||
- `OS_LINUX`
|
||||
|
||||
`CMakeLists.txt` then:
|
||||
|
||||
1. Adds the matching `src/platform/{win,mac,linux}/*.cpp` sources
|
||||
2. Sets the executable type (`WIN32`, `MACOSX_BUNDLE`, or plain executable)
|
||||
3. Links `libcef_dll_wrapper`, `libcef_lib`, and `${CEF_STANDARD_LIBS}`
|
||||
4. Runs CEF’s copy macros so runtime files land beside the app
|
||||
|
||||
Shared sources are always compiled; only the `src/platform/...` tree changes per OS.
|
||||
|
||||
## Application flow
|
||||
|
||||
```
|
||||
main (app/main.cpp)
|
||||
└─ RunNebula(AppStartup) src/app/run.cpp
|
||||
├─ platform::PrepareApp()
|
||||
├─ CefExecuteProcess() (subprocesses)
|
||||
├─ platform::TryAcquireSingleInstance()
|
||||
├─ CefInitialize()
|
||||
├─ NebulaController::Create()
|
||||
│ └─ NebulaWindow::Create() platform-specific
|
||||
└─ CefRunMessageLoop()
|
||||
```
|
||||
|
||||
`AppStartup` carries platform entry data:
|
||||
|
||||
- **Windows:** `HINSTANCE` + show command (`wWinMain`)
|
||||
- **macOS / Linux:** `argc` / `argv` (`main`)
|
||||
|
||||
## User data and profile paths
|
||||
|
||||
Shared logic in `src/ui/paths.cpp` writes under:
|
||||
|
||||
| OS | Default root |
|
||||
|----|----------------|
|
||||
| Windows | `%LOCALAPPDATA%\Nebula\User Data` (falls back to exe directory) |
|
||||
| macOS | `~/Library/Application Support/Nebula/User Data` |
|
||||
| Linux | `$XDG_DATA_HOME/Nebula/User Data` or `~/.local/share/Nebula/User Data` |
|
||||
|
||||
Platform-specific discovery lives in `src/platform/*/paths_*.cpp`.
|
||||
|
||||
## GPU / Chromium flags
|
||||
|
||||
`src/cef/nebula_app.cpp` applies shared switches (`no-sandbox`, `ignore-gpu-blocklist`, etc.) and platform graphics backends:
|
||||
|
||||
| OS | Backend |
|
||||
|----|---------|
|
||||
| Windows | ANGLE + D3D11 |
|
||||
| macOS | ANGLE + Metal |
|
||||
| Linux | EGL |
|
||||
|
||||
## Adding or changing platform code
|
||||
|
||||
1. **Shared behavior** (tabs, `nebula://` URLs, CEF clients) → edit under `src/browser/`, `src/ui/`, `src/cef/`, `src/app/` only if it is truly cross-platform.
|
||||
2. **Native window or OS API** → edit `src/platform/<os>/` and keep `src/window/nebula_window.h` free of `#include <windows.h>` (or Cocoa/X11 headers).
|
||||
3. **CEF child window embedding** → `src/platform/<os>/browser_host_*.cpp` (`MakeChildWindowInfo`, resize, visibility).
|
||||
4. **Startup / paths** → `startup_*.cpp` and `paths_*.cpp` in the same folder.
|
||||
5. **New OS** → add `src/platform/<os>/`, extend the `if(OS_...)` blocks in `CMakeLists.txt`, and document CEF distribution layout here.
|
||||
|
||||
## Porting checklist (macOS / Linux)
|
||||
|
||||
- [x] macOS: implement `NebulaWindow` in `nebula_window_mac.mm`
|
||||
- [x] macOS: wire `browser_host_mac.mm` resize/show/raise to Cocoa views
|
||||
- [ ] Linux: implement `NebulaWindow` in `nebula_window_linux.cpp`
|
||||
- [ ] Linux: wire `browser_host_linux.cpp` resize/show/raise to the real toolkit
|
||||
- [ ] macOS: add CEF helper app targets and bundle layout (copy from `cefsimple`)
|
||||
- [ ] Linux: confirm X11 (or chosen toolkit) parent handle for `CefWindowInfo::SetAsChild`
|
||||
- [ ] Test GPU diagnostics page and hardware acceleration on target hardware
|
||||
- [ ] Package or script runtime layout (`ui/`, CEF frameworks/libs, ICU locales, etc.)
|
||||
|
||||
## FAQ
|
||||
|
||||
**Do I need a separate git branch per OS?**
|
||||
No. Use one branch; swap `thirdparty/cef` and rebuild on each machine.
|
||||
|
||||
**Can I commit CEF into the repo?**
|
||||
Not recommended (size, licensing, per-arch binaries). Keeping `thirdparty/cef/` gitignored is intentional.
|
||||
|
||||
**Why does Linux build but not run?**
|
||||
The Linux window stub intentionally returns `false` from `Create()` until a native shell exists. Shared CEF and browser code are ready; the missing piece is the host window.
|
||||
|
||||
**Where is the Windows UI code?**
|
||||
`src/platform/win/nebula_window_win.cpp` — custom chrome, hit-testing, fullscreen, and child browser placement.
|
||||
@@ -0,0 +1,96 @@
|
||||
#include "app/first_run_state.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <system_error>
|
||||
|
||||
#include "ui/paths.h"
|
||||
|
||||
namespace nebula::app {
|
||||
namespace {
|
||||
|
||||
std::string ReadFile(const std::filesystem::path& path) {
|
||||
std::ifstream input(path, std::ios::binary);
|
||||
if (!input) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::ostringstream buffer;
|
||||
buffer << input.rdbuf();
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
bool ReadFirstStartValue(const std::string& json, bool& first_start) {
|
||||
constexpr std::string_view key = "\"first-start\"";
|
||||
const size_t key_pos = json.find(key);
|
||||
if (key_pos == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t colon = json.find(':', key_pos + key.size());
|
||||
if (colon == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
++colon;
|
||||
while (colon < json.size() && std::isspace(static_cast<unsigned char>(json[colon]))) {
|
||||
++colon;
|
||||
}
|
||||
|
||||
if (json.compare(colon, 4, "true") == 0) {
|
||||
first_start = true;
|
||||
return true;
|
||||
}
|
||||
if (json.compare(colon, 5, "false") == 0) {
|
||||
first_start = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool ShouldShowFirstRunSetup() {
|
||||
const auto path = nebula::ui::GetFirstRunStatePath();
|
||||
if (path.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string json = ReadFile(path);
|
||||
if (json.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool first_start = true;
|
||||
return ReadFirstStartValue(json, first_start) ? first_start : true;
|
||||
}
|
||||
|
||||
bool WriteFirstRunState(bool first_start) {
|
||||
const auto path = nebula::ui::GetFirstRunStatePath();
|
||||
if (path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::filesystem::path temp_path = path;
|
||||
temp_path += L".tmp";
|
||||
{
|
||||
std::ofstream output(temp_path, std::ios::binary | std::ios::trunc);
|
||||
if (!output) {
|
||||
return false;
|
||||
}
|
||||
output << "{\n \"first-start\": " << (first_start ? "true" : "false") << "\n}\n";
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(path, ec);
|
||||
ec.clear();
|
||||
std::filesystem::rename(temp_path, path, ec);
|
||||
return !ec;
|
||||
}
|
||||
|
||||
} // namespace nebula::app
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
namespace nebula::app {
|
||||
|
||||
bool ShouldShowFirstRunSetup();
|
||||
bool WriteFirstRunState(bool first_start);
|
||||
|
||||
} // namespace nebula::app
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,117 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#include "app/run.h"
|
||||
#include "browser/tab_manager.h"
|
||||
#include "cef/browser_client.h"
|
||||
#include "platform/types.h"
|
||||
#include "window/nebula_window.h"
|
||||
|
||||
namespace nebula::app {
|
||||
|
||||
class NebulaController final : public nebula::window::WindowDelegate,
|
||||
public nebula::browser::TabObserver,
|
||||
public nebula::cef::BrowserClientDelegate {
|
||||
public:
|
||||
NebulaController(nebula::platform::AppStartup startup,
|
||||
std::string initial_url,
|
||||
LaunchOptions launch_options = {});
|
||||
~NebulaController() override;
|
||||
|
||||
bool Create();
|
||||
|
||||
void OnWindowCreated() override;
|
||||
void OnWindowResized(const nebula::window::BrowserLayout& layout) override;
|
||||
void OnWindowCloseRequested() override;
|
||||
void OnExternalOpenRequested(const std::string& target) override;
|
||||
|
||||
void OnActiveTabChanged(const nebula::browser::NebulaTab& tab) override;
|
||||
|
||||
void OnBrowserCreated(nebula::cef::BrowserRole role, CefRefPtr<CefBrowser> browser) override;
|
||||
void OnBrowserClosing(nebula::cef::BrowserRole role, CefRefPtr<CefBrowser> browser) override;
|
||||
void OnChromeCommand(const std::string& command, const std::string& payload) override;
|
||||
void OnContentAddressChanged(CefRefPtr<CefBrowser> browser, const std::string& url) override;
|
||||
void OnContentTitleChanged(CefRefPtr<CefBrowser> browser, const std::string& title) override;
|
||||
void OnContentLoadingStateChanged(CefRefPtr<CefBrowser> browser, bool is_loading) override;
|
||||
void OnContentLoadProgressChanged(CefRefPtr<CefBrowser> browser, double progress) override;
|
||||
void OnContentLoadFinished(CefRefPtr<CefBrowser> browser, const std::string& url) override;
|
||||
void OnContentFaviconChanged(CefRefPtr<CefBrowser> browser, const std::vector<std::string>& urls) override;
|
||||
void OnContentFullscreenChanged(CefRefPtr<CefBrowser> browser, bool fullscreen) override;
|
||||
void OnPopupRequested(CefRefPtr<CefBrowser> browser, const std::string& target_url) override;
|
||||
bool ShouldBypassInsecureWarning(CefRefPtr<CefBrowser> browser, const std::string& target_url) override;
|
||||
|
||||
private:
|
||||
void CreateNewTab(std::string url = {});
|
||||
void ActivateTab(int tab_id);
|
||||
void CloseTab(int tab_id);
|
||||
void CreateChromeBrowser();
|
||||
void CreateBigPictureBrowser();
|
||||
void CreateContentBrowser();
|
||||
void EnterBigPictureMode();
|
||||
void ExitBigPictureMode();
|
||||
nebula::window::BrowserLayout CurrentBrowserLayout() const;
|
||||
void ToggleMenuPopup();
|
||||
void CloseMenuPopup();
|
||||
void CreateMenuPopupBrowser();
|
||||
void PositionMenuPopup();
|
||||
void SendMenuPopupZoom();
|
||||
void SendThemeToChromeSurfaces(const std::string& theme_json);
|
||||
void ToggleDevTools();
|
||||
void AdjustZoom(double delta);
|
||||
void FreshReload();
|
||||
void SendBigPictureMouseMove(const std::string& payload);
|
||||
void SendBigPictureMouseClick(const std::string& payload, bool right_click);
|
||||
void SendBigPictureMouseWheel(const std::string& payload);
|
||||
void SendBigPictureText(const std::string& payload);
|
||||
void SetBigPictureBrowseVisible(bool visible);
|
||||
void SetContentFullscreen(bool fullscreen);
|
||||
void CompleteFirstRunSetup();
|
||||
void SendDefaultBrowserResult(const std::string& request_id,
|
||||
bool success,
|
||||
bool needs_user_action,
|
||||
const std::string& error = {});
|
||||
void ResizeBrowsers();
|
||||
void SendChromeState(const nebula::browser::NebulaTab& tab);
|
||||
void SendBigPictureState(const nebula::browser::NebulaTab& tab);
|
||||
void RecordSiteHistory(const std::string& url);
|
||||
void InjectSettingsHistory(CefRefPtr<CefBrowser> browser);
|
||||
void InjectBigPictureCursor(CefRefPtr<CefBrowser> browser);
|
||||
void RemoveBigPictureCursor(CefRefPtr<CefBrowser> browser);
|
||||
void PersistSession() const;
|
||||
void BeginShutdown();
|
||||
void MaybeFinishShutdown();
|
||||
bool ForgetClosingTabBrowser(CefRefPtr<CefBrowser> browser);
|
||||
void LoadPendingNavigationDelayed();
|
||||
|
||||
nebula::platform::AppStartup startup_;
|
||||
std::string initial_url_;
|
||||
std::string pending_initial_navigation_;
|
||||
LaunchOptions launch_options_;
|
||||
bool closing_ = false;
|
||||
bool chrome_ready_ = false;
|
||||
bool big_picture_ready_ = false;
|
||||
bool big_picture_mode_ = false;
|
||||
bool big_picture_browse_visible_ = false;
|
||||
bool content_fullscreen_ = false;
|
||||
bool first_run_setup_active_ = false;
|
||||
bool menu_popup_visible_ = false;
|
||||
|
||||
std::unique_ptr<nebula::window::NebulaWindow> window_;
|
||||
nebula::browser::TabManager tabs_;
|
||||
CefRefPtr<CefBrowser> chrome_browser_;
|
||||
CefRefPtr<CefBrowser> big_picture_browser_;
|
||||
CefRefPtr<CefBrowser> menu_popup_browser_;
|
||||
CefRefPtr<nebula::cef::NebulaBrowserClient> chrome_client_;
|
||||
CefRefPtr<nebula::cef::NebulaBrowserClient> big_picture_client_;
|
||||
CefRefPtr<nebula::cef::NebulaBrowserClient> content_client_;
|
||||
CefRefPtr<nebula::cef::NebulaBrowserClient> menu_popup_client_;
|
||||
std::vector<CefRefPtr<CefBrowser>> closing_tab_browsers_;
|
||||
std::unordered_set<std::string> insecure_warning_bypasses_;
|
||||
std::vector<std::string> site_history_;
|
||||
};
|
||||
|
||||
} // namespace nebula::app
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
#include "app/run.h"
|
||||
|
||||
#include "app/nebula_controller.h"
|
||||
#include "browser/url_utils.h"
|
||||
#include "cef/nebula_app.h"
|
||||
#include "include/cef_app.h"
|
||||
#include "include/cef_command_line.h"
|
||||
#include "platform/default_browser.h"
|
||||
#include "platform/startup.h"
|
||||
#include "ui/paths.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <filesystem>
|
||||
#include <system_error>
|
||||
#include <vector>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace nebula::app {
|
||||
namespace {
|
||||
|
||||
std::string Trim(std::string value) {
|
||||
while (!value.empty() && std::isspace(static_cast<unsigned char>(value.front()))) {
|
||||
value.erase(value.begin());
|
||||
}
|
||||
while (!value.empty() && std::isspace(static_cast<unsigned char>(value.back()))) {
|
||||
value.pop_back();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string ToLowerAscii(std::string value) {
|
||||
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char ch) {
|
||||
return static_cast<char>(std::tolower(ch));
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
bool StartsWithKnownScheme(const std::string& value) {
|
||||
const std::string lower = ToLowerAscii(value);
|
||||
return lower.starts_with("http://") ||
|
||||
lower.starts_with("https://") ||
|
||||
lower.starts_with("file:") ||
|
||||
lower.starts_with("data:") ||
|
||||
lower.starts_with("blob:") ||
|
||||
lower.starts_with("chrome:") ||
|
||||
lower.starts_with("nebula://");
|
||||
}
|
||||
|
||||
std::filesystem::path PathFromUtf8(const std::string& value) {
|
||||
#if defined(_WIN32)
|
||||
const int size = MultiByteToWideChar(
|
||||
CP_UTF8, 0, value.data(), static_cast<int>(value.size()), nullptr, 0);
|
||||
if (size <= 0) {
|
||||
return std::filesystem::path(value);
|
||||
}
|
||||
|
||||
std::wstring wide(size, L'\0');
|
||||
MultiByteToWideChar(
|
||||
CP_UTF8, 0, value.data(), static_cast<int>(value.size()), wide.data(), size);
|
||||
return std::filesystem::path(wide);
|
||||
#else
|
||||
return std::filesystem::path(value);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string NormalizeLaunchTarget(std::string target) {
|
||||
target = Trim(std::move(target));
|
||||
if (target.empty() || nebula::ui::IsChromiumNewTabUrl(target)) {
|
||||
return target.empty() ? std::string{} : nebula::ui::GetHomeUrl();
|
||||
}
|
||||
|
||||
if (StartsWithKnownScheme(target)) {
|
||||
return target;
|
||||
}
|
||||
|
||||
const std::filesystem::path path = PathFromUtf8(target);
|
||||
std::error_code ec;
|
||||
if (!path.empty() && std::filesystem::exists(path, ec) && !ec) {
|
||||
const std::filesystem::path absolute_path = std::filesystem::absolute(path, ec);
|
||||
return nebula::ui::FilePathToUrl(ec ? path : absolute_path);
|
||||
}
|
||||
|
||||
return nebula::browser::NormalizeNavigationInput(target);
|
||||
}
|
||||
|
||||
std::string GetLaunchTarget(CefRefPtr<CefCommandLine> command_line) {
|
||||
if (!command_line) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string target = command_line->GetSwitchValue("url");
|
||||
if (!target.empty()) {
|
||||
return NormalizeLaunchTarget(std::move(target));
|
||||
}
|
||||
|
||||
std::vector<CefString> arguments;
|
||||
command_line->GetArguments(arguments);
|
||||
for (const auto& argument : arguments) {
|
||||
target = argument.ToString();
|
||||
if (!Trim(target).empty()) {
|
||||
return NormalizeLaunchTarget(std::move(target));
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int RunNebula(const nebula::platform::AppStartup& startup, LaunchOptions options) {
|
||||
nebula::platform::PrepareApp();
|
||||
|
||||
const CefMainArgs main_args = nebula::platform::MakeMainArgs(startup);
|
||||
CefRefPtr<nebula::cef::NebulaApp> app(new nebula::cef::NebulaApp);
|
||||
|
||||
const int subprocess_exit_code = CefExecuteProcess(main_args, app, nullptr);
|
||||
if (subprocess_exit_code >= 0) {
|
||||
return subprocess_exit_code;
|
||||
}
|
||||
|
||||
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
||||
nebula::platform::InitCommandLine(command_line, startup);
|
||||
std::string initial_url = GetLaunchTarget(command_line);
|
||||
|
||||
if (!nebula::platform::TryAcquireSingleInstance(initial_url)) {
|
||||
return 0;
|
||||
}
|
||||
nebula::platform::EnsureDefaultBrowserRegistration();
|
||||
|
||||
CefSettings settings;
|
||||
settings.no_sandbox = true;
|
||||
settings.persist_session_cookies = true;
|
||||
nebula::platform::ConfigureCefSettings(settings);
|
||||
|
||||
if (!CefInitialize(main_args, settings, app, nullptr)) {
|
||||
return CefGetExitCode();
|
||||
}
|
||||
|
||||
NebulaController controller(startup, std::move(initial_url), options);
|
||||
const bool created = controller.Create();
|
||||
if (created) {
|
||||
CefRunMessageLoop();
|
||||
}
|
||||
|
||||
CefShutdown();
|
||||
return created ? 0 : 1;
|
||||
}
|
||||
|
||||
} // namespace nebula::app
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "platform/types.h"
|
||||
|
||||
namespace nebula::app {
|
||||
|
||||
enum class AppMode {
|
||||
Desktop,
|
||||
BigPicture,
|
||||
};
|
||||
|
||||
struct LaunchOptions {
|
||||
AppMode mode = AppMode::Desktop;
|
||||
};
|
||||
|
||||
int RunNebula(const nebula::platform::AppStartup& startup, LaunchOptions options = {});
|
||||
|
||||
} // namespace nebula::app
|
||||
@@ -0,0 +1,229 @@
|
||||
#include "browser/session_state.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <charconv>
|
||||
#include <cctype>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <system_error>
|
||||
|
||||
#include "browser/url_utils.h"
|
||||
#include "ui/paths.h"
|
||||
|
||||
namespace nebula::browser {
|
||||
namespace {
|
||||
|
||||
constexpr size_t kMaxRestoredTabs = 50;
|
||||
|
||||
std::string ReadFile(const std::filesystem::path& path) {
|
||||
std::ifstream input(path, std::ios::binary);
|
||||
if (!input) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::ostringstream buffer;
|
||||
buffer << input.rdbuf();
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
std::optional<size_t> ReadUnsignedValue(const std::string& json, std::string_view key) {
|
||||
const size_t key_pos = json.find(key);
|
||||
if (key_pos == std::string::npos) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
size_t colon = json.find(':', key_pos + key.size());
|
||||
if (colon == std::string::npos) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
++colon;
|
||||
while (colon < json.size() && std::isspace(static_cast<unsigned char>(json[colon]))) {
|
||||
++colon;
|
||||
}
|
||||
|
||||
size_t end = colon;
|
||||
while (end < json.size() && std::isdigit(static_cast<unsigned char>(json[end]))) {
|
||||
++end;
|
||||
}
|
||||
|
||||
size_t value = 0;
|
||||
const auto result = std::from_chars(json.data() + colon, json.data() + end, value);
|
||||
if (result.ec != std::errc{} || result.ptr != json.data() + end) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
std::optional<std::string> ReadStringValue(const std::string& object, std::string_view key) {
|
||||
const size_t key_pos = object.find(key);
|
||||
if (key_pos == std::string::npos) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
size_t colon = object.find(':', key_pos + key.size());
|
||||
if (colon == std::string::npos) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
size_t quote = object.find('"', colon + 1);
|
||||
if (quote == std::string::npos) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string value;
|
||||
for (size_t i = quote + 1; i < object.size(); ++i) {
|
||||
const char ch = object[i];
|
||||
if (ch == '"') {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (ch != '\\') {
|
||||
value += ch;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (++i >= object.size()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
switch (object[i]) {
|
||||
case '"':
|
||||
case '\\':
|
||||
case '/':
|
||||
value += object[i];
|
||||
break;
|
||||
case 'b':
|
||||
value += '\b';
|
||||
break;
|
||||
case 'f':
|
||||
value += '\f';
|
||||
break;
|
||||
case 'n':
|
||||
value += '\n';
|
||||
break;
|
||||
case 'r':
|
||||
value += '\r';
|
||||
break;
|
||||
case 't':
|
||||
value += '\t';
|
||||
break;
|
||||
default:
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::vector<PersistedTab> ReadTabs(const std::string& json) {
|
||||
std::vector<PersistedTab> tabs;
|
||||
const size_t tabs_pos = json.find("\"tabs\"");
|
||||
if (tabs_pos == std::string::npos) {
|
||||
return tabs;
|
||||
}
|
||||
|
||||
const size_t array_start = json.find('[', tabs_pos);
|
||||
const size_t array_end = json.find(']', array_start == std::string::npos ? tabs_pos : array_start);
|
||||
if (array_start == std::string::npos || array_end == std::string::npos) {
|
||||
return tabs;
|
||||
}
|
||||
|
||||
size_t cursor = array_start + 1;
|
||||
while (cursor < array_end && tabs.size() < kMaxRestoredTabs) {
|
||||
const size_t object_start = json.find('{', cursor);
|
||||
if (object_start == std::string::npos || object_start >= array_end) {
|
||||
break;
|
||||
}
|
||||
|
||||
const size_t object_end = json.find('}', object_start + 1);
|
||||
if (object_end == std::string::npos || object_end > array_end) {
|
||||
break;
|
||||
}
|
||||
|
||||
const std::string object = json.substr(object_start, object_end - object_start + 1);
|
||||
const auto url = ReadStringValue(object, "\"url\"");
|
||||
if (url && !url->empty()) {
|
||||
PersistedTab tab;
|
||||
tab.url = *url;
|
||||
if (const auto title = ReadStringValue(object, "\"title\""); title && !title->empty()) {
|
||||
tab.title = *title;
|
||||
}
|
||||
tabs.push_back(std::move(tab));
|
||||
}
|
||||
|
||||
cursor = object_end + 1;
|
||||
}
|
||||
|
||||
return tabs;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
SessionState LoadSessionState() {
|
||||
SessionState state;
|
||||
const std::string json = ReadFile(nebula::ui::GetSessionStatePath());
|
||||
if (json.empty()) {
|
||||
return state;
|
||||
}
|
||||
|
||||
state.tabs = ReadTabs(json);
|
||||
if (const auto active_index = ReadUnsignedValue(json, "\"activeTabIndex\"")) {
|
||||
state.active_tab_index = *active_index;
|
||||
}
|
||||
|
||||
if (!state.tabs.empty()) {
|
||||
state.active_tab_index = std::min(state.active_tab_index, state.tabs.size() - 1);
|
||||
} else {
|
||||
state.active_tab_index = 0;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void SaveSessionState(const std::vector<NebulaTab>& tabs, size_t active_tab_index) {
|
||||
const auto path = nebula::ui::GetSessionStatePath();
|
||||
if (path.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostringstream json;
|
||||
json << "{\n \"activeTabIndex\": " << active_tab_index << ",\n \"tabs\": [\n";
|
||||
|
||||
bool wrote_tab = false;
|
||||
for (const auto& tab : tabs) {
|
||||
if (tab.url.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (wrote_tab) {
|
||||
json << ",\n";
|
||||
}
|
||||
|
||||
json << " {\"url\": \"" << JsonEscape(tab.url)
|
||||
<< "\", \"title\": \"" << JsonEscape(tab.title) << "\"}";
|
||||
wrote_tab = true;
|
||||
}
|
||||
|
||||
json << "\n ]\n}\n";
|
||||
|
||||
std::filesystem::path temp_path = path;
|
||||
temp_path += L".tmp";
|
||||
{
|
||||
std::ofstream output(temp_path, std::ios::binary | std::ios::trunc);
|
||||
if (!output) {
|
||||
return;
|
||||
}
|
||||
output << json.str();
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(path, ec);
|
||||
ec.clear();
|
||||
std::filesystem::rename(temp_path, path, ec);
|
||||
}
|
||||
|
||||
} // namespace nebula::browser
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "browser/tab.h"
|
||||
|
||||
namespace nebula::browser {
|
||||
|
||||
struct PersistedTab {
|
||||
std::string url;
|
||||
std::string title = "New Tab";
|
||||
};
|
||||
|
||||
struct SessionState {
|
||||
std::vector<PersistedTab> tabs;
|
||||
size_t active_tab_index = 0;
|
||||
};
|
||||
|
||||
SessionState LoadSessionState();
|
||||
void SaveSessionState(const std::vector<NebulaTab>& tabs, size_t active_tab_index);
|
||||
|
||||
} // namespace nebula::browser
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "browser/tab.h"
|
||||
|
||||
namespace nebula::browser {
|
||||
|
||||
bool NebulaTab::CanGoBack() const {
|
||||
return browser && browser->CanGoBack();
|
||||
}
|
||||
|
||||
bool NebulaTab::CanGoForward() const {
|
||||
return browser && browser->CanGoForward();
|
||||
}
|
||||
|
||||
} // namespace nebula::browser
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "include/cef_browser.h"
|
||||
|
||||
namespace nebula::browser {
|
||||
|
||||
struct NebulaTab {
|
||||
int id = 1;
|
||||
std::string url;
|
||||
std::string title = "New Tab";
|
||||
bool is_loading = false;
|
||||
double load_progress = 0.0;
|
||||
std::string favicon_url;
|
||||
CefRefPtr<CefBrowser> browser;
|
||||
|
||||
bool CanGoBack() const;
|
||||
bool CanGoForward() const;
|
||||
};
|
||||
|
||||
} // namespace nebula::browser
|
||||
@@ -0,0 +1,273 @@
|
||||
#include "browser/tab_manager.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "browser/url_utils.h"
|
||||
#include "ui/paths.h"
|
||||
|
||||
namespace nebula::browser {
|
||||
|
||||
TabManager::TabManager(TabObserver* observer) : observer_(observer) {}
|
||||
|
||||
NebulaTab& TabManager::CreateInitialTab(std::string initial_url) {
|
||||
tabs_.clear();
|
||||
NebulaTab tab;
|
||||
tab.id = next_tab_id_++;
|
||||
tab.url = std::move(initial_url);
|
||||
tabs_.push_back(std::move(tab));
|
||||
active_tab_id_ = tabs_.front().id;
|
||||
Notify();
|
||||
return tabs_.front();
|
||||
}
|
||||
|
||||
NebulaTab& TabManager::CreateTab(std::string url) {
|
||||
NebulaTab tab;
|
||||
tab.id = next_tab_id_++;
|
||||
tab.url = std::move(url);
|
||||
tabs_.push_back(std::move(tab));
|
||||
active_tab_id_ = tabs_.back().id;
|
||||
Notify();
|
||||
return tabs_.back();
|
||||
}
|
||||
|
||||
void TabManager::RestoreTabs(const std::vector<PersistedTab>& tabs, size_t active_tab_index) {
|
||||
tabs_.clear();
|
||||
active_tab_id_ = 0;
|
||||
|
||||
for (const auto& restored_tab : tabs) {
|
||||
NebulaTab tab;
|
||||
tab.id = next_tab_id_++;
|
||||
tab.url = restored_tab.url.empty() ? nebula::ui::GetHomeUrl() : restored_tab.url;
|
||||
tab.title = restored_tab.title.empty() ? "New Tab" : restored_tab.title;
|
||||
tabs_.push_back(std::move(tab));
|
||||
}
|
||||
|
||||
if (tabs_.empty()) {
|
||||
CreateInitialTab(nebula::ui::GetHomeUrl());
|
||||
return;
|
||||
}
|
||||
|
||||
active_tab_index = std::min(active_tab_index, tabs_.size() - 1);
|
||||
active_tab_id_ = tabs_[active_tab_index].id;
|
||||
Notify();
|
||||
}
|
||||
|
||||
NebulaTab* TabManager::ActiveTab() {
|
||||
for (auto& tab : tabs_) {
|
||||
if (tab.id == active_tab_id_) {
|
||||
return &tab;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const NebulaTab* TabManager::ActiveTab() const {
|
||||
for (const auto& tab : tabs_) {
|
||||
if (tab.id == active_tab_id_) {
|
||||
return &tab;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const std::vector<NebulaTab>& TabManager::Tabs() const {
|
||||
return tabs_;
|
||||
}
|
||||
|
||||
size_t TabManager::ActiveTabIndex() const {
|
||||
for (size_t i = 0; i < tabs_.size(); ++i) {
|
||||
if (tabs_[i].id == active_tab_id_) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool TabManager::ActivateTab(int tab_id) {
|
||||
if (!FindTab(tab_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
active_tab_id_ = tab_id;
|
||||
Notify();
|
||||
return true;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> TabManager::CloseTab(int tab_id) {
|
||||
for (auto it = tabs_.begin(); it != tabs_.end(); ++it) {
|
||||
if (it->id != tab_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> browser = it->browser;
|
||||
const bool was_active = it->id == active_tab_id_;
|
||||
const auto next_it = tabs_.erase(it);
|
||||
|
||||
if (tabs_.empty()) {
|
||||
active_tab_id_ = 0;
|
||||
} else if (was_active) {
|
||||
active_tab_id_ = next_it != tabs_.end() ? next_it->id : tabs_.back().id;
|
||||
}
|
||||
|
||||
Notify();
|
||||
return browser;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TabManager::SetActiveBrowser(CefRefPtr<CefBrowser> browser) {
|
||||
if (NebulaTab* tab = ActiveTab()) {
|
||||
tab->browser = browser;
|
||||
if (browser && tab->url.empty()) {
|
||||
tab->url = browser->GetMainFrame()->GetURL();
|
||||
}
|
||||
Notify();
|
||||
}
|
||||
}
|
||||
|
||||
bool TabManager::OwnsBrowser(CefRefPtr<CefBrowser> browser) const {
|
||||
if (!browser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& tab : tabs_) {
|
||||
if (tab.browser && tab.browser->IsSame(browser)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TabManager::HasOpenBrowsers() const {
|
||||
for (const auto& tab : tabs_) {
|
||||
if (tab.browser) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TabManager::ClearBrowser(CefRefPtr<CefBrowser> browser) {
|
||||
if (NebulaTab* tab = FindTab(browser)) {
|
||||
tab->browser = nullptr;
|
||||
Notify();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::LoadURL(const std::string& input) {
|
||||
NebulaTab* tab = ActiveTab();
|
||||
if (!tab || !tab->browser) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string target = NormalizeNavigationInput(input);
|
||||
if (target.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
tab->url = target;
|
||||
tab->favicon_url.clear();
|
||||
tab->browser->GetMainFrame()->LoadURL(nebula::ui::ResolveInternalUrl(target));
|
||||
Notify();
|
||||
}
|
||||
|
||||
void TabManager::GoBack() {
|
||||
NebulaTab* tab = ActiveTab();
|
||||
if (tab && tab->browser && tab->browser->CanGoBack()) {
|
||||
tab->browser->GoBack();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::GoForward() {
|
||||
NebulaTab* tab = ActiveTab();
|
||||
if (tab && tab->browser && tab->browser->CanGoForward()) {
|
||||
tab->browser->GoForward();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::Reload() {
|
||||
NebulaTab* tab = ActiveTab();
|
||||
if (tab && tab->browser) {
|
||||
tab->browser->Reload();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::StopLoad() {
|
||||
NebulaTab* tab = ActiveTab();
|
||||
if (tab && tab->browser) {
|
||||
tab->browser->StopLoad();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::UpdateURL(CefRefPtr<CefBrowser> browser, std::string url) {
|
||||
if (NebulaTab* tab = FindTab(browser)) {
|
||||
tab->url = std::move(url);
|
||||
Notify();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::UpdateTitle(CefRefPtr<CefBrowser> browser, std::string title) {
|
||||
if (NebulaTab* tab = FindTab(browser)) {
|
||||
tab->title = title.empty() ? "New Tab" : std::move(title);
|
||||
Notify();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::UpdateLoadingState(CefRefPtr<CefBrowser> browser, bool is_loading) {
|
||||
if (NebulaTab* tab = FindTab(browser)) {
|
||||
tab->is_loading = is_loading;
|
||||
if (is_loading) {
|
||||
tab->favicon_url.clear();
|
||||
}
|
||||
if (!is_loading) {
|
||||
tab->load_progress = 1.0;
|
||||
}
|
||||
Notify();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::UpdateLoadProgress(CefRefPtr<CefBrowser> browser, double progress) {
|
||||
if (NebulaTab* tab = FindTab(browser)) {
|
||||
tab->load_progress = progress;
|
||||
Notify();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::UpdateFavicon(CefRefPtr<CefBrowser> browser, const std::vector<std::string>& urls) {
|
||||
if (NebulaTab* tab = FindTab(browser)) {
|
||||
tab->favicon_url = urls.empty() ? std::string{} : urls.front();
|
||||
Notify();
|
||||
}
|
||||
}
|
||||
|
||||
void TabManager::Notify() {
|
||||
const NebulaTab* tab = ActiveTab();
|
||||
if (observer_ && tab) {
|
||||
observer_->OnActiveTabChanged(*tab);
|
||||
}
|
||||
}
|
||||
|
||||
NebulaTab* TabManager::FindTab(int tab_id) {
|
||||
for (auto& tab : tabs_) {
|
||||
if (tab.id == tab_id) {
|
||||
return &tab;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NebulaTab* TabManager::FindTab(CefRefPtr<CefBrowser> browser) {
|
||||
if (!browser) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (auto& tab : tabs_) {
|
||||
if (tab.browser && tab.browser->IsSame(browser)) {
|
||||
return &tab;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace nebula::browser
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "browser/tab.h"
|
||||
#include "browser/session_state.h"
|
||||
|
||||
namespace nebula::browser {
|
||||
|
||||
class TabObserver {
|
||||
public:
|
||||
virtual ~TabObserver() = default;
|
||||
virtual void OnActiveTabChanged(const NebulaTab& tab) = 0;
|
||||
};
|
||||
|
||||
class TabManager {
|
||||
public:
|
||||
explicit TabManager(TabObserver* observer);
|
||||
|
||||
NebulaTab& CreateInitialTab(std::string initial_url);
|
||||
NebulaTab& CreateTab(std::string url);
|
||||
void RestoreTabs(const std::vector<PersistedTab>& tabs, size_t active_tab_index);
|
||||
NebulaTab* ActiveTab();
|
||||
const NebulaTab* ActiveTab() const;
|
||||
const std::vector<NebulaTab>& Tabs() const;
|
||||
size_t ActiveTabIndex() const;
|
||||
|
||||
bool ActivateTab(int tab_id);
|
||||
CefRefPtr<CefBrowser> CloseTab(int tab_id);
|
||||
void SetActiveBrowser(CefRefPtr<CefBrowser> browser);
|
||||
bool OwnsBrowser(CefRefPtr<CefBrowser> browser) const;
|
||||
void ClearBrowser(CefRefPtr<CefBrowser> browser);
|
||||
bool HasOpenBrowsers() const;
|
||||
|
||||
void LoadURL(const std::string& input);
|
||||
void GoBack();
|
||||
void GoForward();
|
||||
void Reload();
|
||||
void StopLoad();
|
||||
|
||||
void UpdateURL(CefRefPtr<CefBrowser> browser, std::string url);
|
||||
void UpdateTitle(CefRefPtr<CefBrowser> browser, std::string title);
|
||||
void UpdateLoadingState(CefRefPtr<CefBrowser> browser, bool is_loading);
|
||||
void UpdateLoadProgress(CefRefPtr<CefBrowser> browser, double progress);
|
||||
void UpdateFavicon(CefRefPtr<CefBrowser> browser, const std::vector<std::string>& urls);
|
||||
|
||||
private:
|
||||
void Notify();
|
||||
NebulaTab* FindTab(int tab_id);
|
||||
NebulaTab* FindTab(CefRefPtr<CefBrowser> browser);
|
||||
|
||||
TabObserver* observer_ = nullptr;
|
||||
std::vector<NebulaTab> tabs_;
|
||||
int active_tab_id_ = 0;
|
||||
int next_tab_id_ = 1;
|
||||
};
|
||||
|
||||
} // namespace nebula::browser
|
||||
@@ -0,0 +1,115 @@
|
||||
#include "browser/url_utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
namespace nebula::browser {
|
||||
namespace {
|
||||
|
||||
constexpr char kSearchUrl[] = "https://www.google.com/search?q=";
|
||||
|
||||
std::string Trim(std::string value) {
|
||||
while (!value.empty() && std::isspace(static_cast<unsigned char>(value.front()))) {
|
||||
value.erase(value.begin());
|
||||
}
|
||||
while (!value.empty() && std::isspace(static_cast<unsigned char>(value.back()))) {
|
||||
value.pop_back();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
bool StartsWithScheme(std::string value) {
|
||||
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char ch) {
|
||||
return static_cast<char>(std::tolower(ch));
|
||||
});
|
||||
return value.starts_with("http://") ||
|
||||
value.starts_with("https://") ||
|
||||
value.starts_with("file:") ||
|
||||
value.starts_with("data:") ||
|
||||
value.starts_with("blob:") ||
|
||||
value.starts_with("chrome:") ||
|
||||
value.starts_with("nebula://");
|
||||
}
|
||||
|
||||
bool LooksLikeHostName(const std::string& value) {
|
||||
return value.find('.') != std::string::npos &&
|
||||
value.find_first_of(" \t\r\n") == std::string::npos;
|
||||
}
|
||||
|
||||
std::string UrlEncodeSearch(const std::string& value) {
|
||||
std::ostringstream encoded;
|
||||
encoded << std::hex << std::uppercase;
|
||||
|
||||
for (unsigned char ch : value) {
|
||||
if (std::isalnum(ch) || ch == '-' || ch == '_' || ch == '.' || ch == '~') {
|
||||
encoded << static_cast<char>(ch);
|
||||
} else if (ch == ' ') {
|
||||
encoded << '+';
|
||||
} else {
|
||||
encoded << '%' << std::setw(2) << std::setfill('0') << static_cast<int>(ch);
|
||||
}
|
||||
}
|
||||
|
||||
return encoded.str();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string NormalizeNavigationInput(const std::string& input) {
|
||||
const std::string value = Trim(input);
|
||||
if (value.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (StartsWithScheme(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (LooksLikeHostName(value)) {
|
||||
return "https://" + value;
|
||||
}
|
||||
|
||||
return std::string(kSearchUrl) + UrlEncodeSearch(value);
|
||||
}
|
||||
|
||||
std::string JsonEscape(const std::string& value) {
|
||||
std::ostringstream escaped;
|
||||
for (unsigned char ch : value) {
|
||||
switch (ch) {
|
||||
case '\\':
|
||||
escaped << "\\\\";
|
||||
break;
|
||||
case '"':
|
||||
escaped << "\\\"";
|
||||
break;
|
||||
case '\b':
|
||||
escaped << "\\b";
|
||||
break;
|
||||
case '\f':
|
||||
escaped << "\\f";
|
||||
break;
|
||||
case '\n':
|
||||
escaped << "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
escaped << "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
escaped << "\\t";
|
||||
break;
|
||||
default:
|
||||
if (ch < 0x20) {
|
||||
escaped << "\\u" << std::hex << std::uppercase << std::setw(4)
|
||||
<< std::setfill('0') << static_cast<int>(ch);
|
||||
} else {
|
||||
escaped << static_cast<char>(ch);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return escaped.str();
|
||||
}
|
||||
|
||||
} // namespace nebula::browser
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace nebula::browser {
|
||||
|
||||
std::string NormalizeNavigationInput(const std::string& input);
|
||||
std::string JsonEscape(const std::string& value);
|
||||
|
||||
} // namespace nebula::browser
|
||||
@@ -0,0 +1,340 @@
|
||||
#include "cef/browser_client.h"
|
||||
|
||||
#include "include/cef_request.h"
|
||||
#include "platform/types.h"
|
||||
#include "include/wrapper/cef_helpers.h"
|
||||
#include "ui/paths.h"
|
||||
|
||||
namespace nebula::cef {
|
||||
namespace {
|
||||
|
||||
constexpr char kChromeCommandMessage[] = "NebulaChromeCommand";
|
||||
|
||||
bool IsInsecureInterstitialFrame(CefRefPtr<CefFrame> frame) {
|
||||
if (!frame) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return nebula::ui::ToInternalUrl(frame->GetURL().ToString()).starts_with("nebula://insecure");
|
||||
}
|
||||
|
||||
bool IsSettingsFrame(CefRefPtr<CefFrame> frame) {
|
||||
if (!frame) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return nebula::ui::ToInternalUrl(frame->GetURL().ToString()).starts_with("nebula://settings");
|
||||
}
|
||||
|
||||
bool IsSetupFrame(CefRefPtr<CefFrame> frame) {
|
||||
if (!frame) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return nebula::ui::ToInternalUrl(frame->GetURL().ToString()).starts_with("nebula://setup");
|
||||
}
|
||||
|
||||
bool IsBigPictureFrame(CefRefPtr<CefFrame> frame) {
|
||||
if (!frame) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string url = nebula::ui::ToInternalUrl(frame->GetURL().ToString());
|
||||
return url.starts_with("nebula://bigpicture") ||
|
||||
url.starts_with("nebula://big-picture");
|
||||
}
|
||||
|
||||
bool IsBigPictureCommand(const std::string& command) {
|
||||
return command == "navigate" ||
|
||||
command == "new-tab" ||
|
||||
command == "activate-tab" ||
|
||||
command == "close-tab" ||
|
||||
command == "back" ||
|
||||
command == "forward" ||
|
||||
command == "reload" ||
|
||||
command == "stop" ||
|
||||
command == "home" ||
|
||||
command == "settings" ||
|
||||
command == "open-settings" ||
|
||||
command == "big-picture" ||
|
||||
command == "exit-bigpicture" ||
|
||||
command == "gpu-diagnostics" ||
|
||||
command == "zoom-out" ||
|
||||
command == "zoom-in" ||
|
||||
command == "clear-site-history" ||
|
||||
command == "clear-search-history" ||
|
||||
command == "bigpicture-mouse-move" ||
|
||||
command == "bigpicture-click" ||
|
||||
command == "bigpicture-right-click" ||
|
||||
command == "bigpicture-scroll" ||
|
||||
command == "bigpicture-text" ||
|
||||
command == "bigpicture-browse-visible";
|
||||
}
|
||||
|
||||
std::vector<std::string> ToStringVector(const std::vector<CefString>& values) {
|
||||
std::vector<std::string> result;
|
||||
result.reserve(values.size());
|
||||
for (const auto& value : values) {
|
||||
result.push_back(value.ToString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NebulaBrowserClient::NebulaBrowserClient(BrowserRole role, BrowserClientDelegate* delegate)
|
||||
: role_(role), delegate_(delegate) {}
|
||||
|
||||
bool NebulaBrowserClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NEBULA_UNUSED(browser);
|
||||
NEBULA_UNUSED(source_process);
|
||||
|
||||
if (!message || message->GetName().ToString() != kChromeCommandMessage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (role_ != BrowserRole::Chrome && role_ != BrowserRole::Content &&
|
||||
role_ != BrowserRole::BigPicture && role_ != BrowserRole::MenuPopup) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
const std::string command = args && args->GetSize() > 0 ? args->GetString(0).ToString() : "";
|
||||
const std::string payload = args && args->GetSize() > 1 ? args->GetString(1).ToString() : "";
|
||||
if (role_ == BrowserRole::Content) {
|
||||
const bool allowed_insecure_command =
|
||||
command == "navigate-insecure" && IsInsecureInterstitialFrame(frame);
|
||||
const bool allowed_settings_command =
|
||||
IsSettingsFrame(frame) && (command == "navigate" ||
|
||||
command == "new-tab" ||
|
||||
command == "check-default-browser" ||
|
||||
command == "set-default-browser" ||
|
||||
command == "clear-site-history" ||
|
||||
command == "clear-search-history");
|
||||
const bool allowed_setup_command =
|
||||
IsSetupFrame(frame) && (command == "complete-first-run" ||
|
||||
command == "check-default-browser" ||
|
||||
command == "set-default-browser");
|
||||
const bool allowed_big_picture_command =
|
||||
IsBigPictureFrame(frame) && command == "exit-bigpicture";
|
||||
if (!allowed_insecure_command && !allowed_settings_command &&
|
||||
!allowed_setup_command && !allowed_big_picture_command) {
|
||||
return false;
|
||||
}
|
||||
} else if (role_ == BrowserRole::BigPicture) {
|
||||
if (!IsBigPictureFrame(frame) || !IsBigPictureCommand(command)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (delegate_ && !command.empty()) {
|
||||
delegate_->OnChromeCommand(command, payload);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void NebulaBrowserClient::OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
if (role_ == BrowserRole::Content && delegate_ && frame && frame->IsMain()) {
|
||||
delegate_->OnContentAddressChanged(browser, url.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaBrowserClient::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
if (role_ == BrowserRole::Content && delegate_) {
|
||||
delegate_->OnContentTitleChanged(browser, title.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaBrowserClient::OnFaviconURLChange(CefRefPtr<CefBrowser> browser,
|
||||
const std::vector<CefString>& icon_urls) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
if (role_ == BrowserRole::Content && delegate_) {
|
||||
delegate_->OnContentFaviconChanged(browser, ToStringVector(icon_urls));
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaBrowserClient::OnFullscreenModeChange(CefRefPtr<CefBrowser> browser, bool fullscreen) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
if (role_ == BrowserRole::Content && delegate_) {
|
||||
delegate_->OnContentFullscreenChanged(browser, fullscreen);
|
||||
}
|
||||
}
|
||||
|
||||
bool NebulaBrowserClient::OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
const CefKeyEvent& event,
|
||||
CefEventHandle os_event,
|
||||
bool* is_keyboard_shortcut) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NEBULA_UNUSED(os_event);
|
||||
|
||||
if (role_ == BrowserRole::Content &&
|
||||
event.type == KEYEVENT_RAWKEYDOWN &&
|
||||
(event.modifiers & EVENTFLAG_CONTROL_DOWN) != 0 &&
|
||||
event.windows_key_code == 'T') {
|
||||
if (is_keyboard_shortcut) {
|
||||
*is_keyboard_shortcut = true;
|
||||
}
|
||||
if (delegate_) {
|
||||
delegate_->OnPopupRequested(browser, nebula::ui::GetHomeUrl());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NebulaBrowserClient::OnBeforePopup(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int popup_id,
|
||||
const CefString& target_url,
|
||||
const CefString& target_frame_name,
|
||||
CefLifeSpanHandler::WindowOpenDisposition target_disposition,
|
||||
bool user_gesture,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefWindowInfo& windowInfo,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue>& extra_info,
|
||||
bool* no_javascript_access) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NEBULA_UNUSED(frame);
|
||||
NEBULA_UNUSED(popup_id);
|
||||
NEBULA_UNUSED(target_frame_name);
|
||||
NEBULA_UNUSED(target_disposition);
|
||||
NEBULA_UNUSED(user_gesture);
|
||||
NEBULA_UNUSED(popupFeatures);
|
||||
NEBULA_UNUSED(windowInfo);
|
||||
NEBULA_UNUSED(client);
|
||||
NEBULA_UNUSED(settings);
|
||||
NEBULA_UNUSED(extra_info);
|
||||
NEBULA_UNUSED(no_javascript_access);
|
||||
|
||||
if (role_ == BrowserRole::Content && delegate_) {
|
||||
delegate_->OnPopupRequested(browser, target_url.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void NebulaBrowserClient::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
if (delegate_) {
|
||||
delegate_->OnBrowserCreated(role_, browser);
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaBrowserClient::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
if (delegate_) {
|
||||
delegate_->OnBrowserClosing(role_, browser);
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaBrowserClient::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool isLoading,
|
||||
bool canGoBack,
|
||||
bool canGoForward) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NEBULA_UNUSED(canGoBack);
|
||||
NEBULA_UNUSED(canGoForward);
|
||||
|
||||
if (role_ == BrowserRole::Content && delegate_) {
|
||||
delegate_->OnContentLoadingStateChanged(browser, isLoading);
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaBrowserClient::OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
TransitionType transition_type) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NEBULA_UNUSED(transition_type);
|
||||
|
||||
if (role_ == BrowserRole::Content && delegate_ && frame && frame->IsMain()) {
|
||||
delegate_->OnContentLoadProgressChanged(browser, 0.12);
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaBrowserClient::OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
if (role_ == BrowserRole::Content && delegate_ && frame && frame->IsMain()) {
|
||||
if (httpStatusCode == 404) {
|
||||
frame->LoadURL(nebula::ui::ResolveInternalUrl(
|
||||
nebula::ui::GetNotFoundUrl(frame->GetURL().ToString())));
|
||||
return;
|
||||
}
|
||||
|
||||
delegate_->OnContentLoadProgressChanged(browser, 1.0);
|
||||
delegate_->OnContentLoadFinished(browser, frame->GetURL().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
bool NebulaBrowserClient::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool user_gesture,
|
||||
bool is_redirect) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NEBULA_UNUSED(browser);
|
||||
NEBULA_UNUSED(user_gesture);
|
||||
NEBULA_UNUSED(is_redirect);
|
||||
|
||||
if (role_ == BrowserRole::Content && frame && frame->IsMain() && request) {
|
||||
const std::string url = request->GetURL().ToString();
|
||||
if (nebula::ui::IsChromiumNewTabUrl(url)) {
|
||||
frame->LoadURL(nebula::ui::ResolveInternalUrl(nebula::ui::GetHomeUrl()));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nebula::ui::IsNebulaInternalUrl(url)) {
|
||||
frame->LoadURL(nebula::ui::ResolveInternalUrl(url));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nebula::ui::IsHttpUrl(url) &&
|
||||
(!delegate_ || !delegate_->ShouldBypassInsecureWarning(browser, url))) {
|
||||
frame->LoadURL(nebula::ui::ResolveInternalUrl(
|
||||
nebula::ui::GetInsecureWarningUrl(url)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NebulaBrowserClient::OnShowPermissionPrompt(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
uint64_t prompt_id,
|
||||
const CefString& requesting_origin,
|
||||
uint32_t requested_permissions,
|
||||
CefRefPtr<CefPermissionPromptCallback> callback) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NEBULA_UNUSED(prompt_id);
|
||||
NEBULA_UNUSED(requesting_origin);
|
||||
|
||||
if (role_ == BrowserRole::Content &&
|
||||
(requested_permissions & CEF_PERMISSION_TYPE_GEOLOCATION) != 0 &&
|
||||
browser && callback &&
|
||||
nebula::ui::IsInternalHomeUrl(browser->GetMainFrame()->GetURL().ToString())) {
|
||||
callback->Continue(CEF_PERMISSION_RESULT_ACCEPT);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace nebula::cef
|
||||
@@ -0,0 +1,123 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "include/cef_client.h"
|
||||
#include "include/cef_display_handler.h"
|
||||
#include "include/cef_keyboard_handler.h"
|
||||
#include "include/cef_life_span_handler.h"
|
||||
#include "include/cef_load_handler.h"
|
||||
#include "include/cef_permission_handler.h"
|
||||
#include "include/cef_request_handler.h"
|
||||
|
||||
namespace nebula::cef {
|
||||
|
||||
enum class BrowserRole {
|
||||
Chrome,
|
||||
Content,
|
||||
BigPicture,
|
||||
MenuPopup,
|
||||
};
|
||||
|
||||
class BrowserClientDelegate {
|
||||
public:
|
||||
virtual ~BrowserClientDelegate() = default;
|
||||
virtual void OnBrowserCreated(BrowserRole role, CefRefPtr<CefBrowser> browser) = 0;
|
||||
virtual void OnBrowserClosing(BrowserRole role, CefRefPtr<CefBrowser> browser) = 0;
|
||||
virtual void OnChromeCommand(const std::string& command, const std::string& payload) = 0;
|
||||
virtual void OnContentAddressChanged(CefRefPtr<CefBrowser> browser, const std::string& url) = 0;
|
||||
virtual void OnContentTitleChanged(CefRefPtr<CefBrowser> browser, const std::string& title) = 0;
|
||||
virtual void OnContentLoadingStateChanged(CefRefPtr<CefBrowser> browser, bool is_loading) = 0;
|
||||
virtual void OnContentLoadProgressChanged(CefRefPtr<CefBrowser> browser, double progress) = 0;
|
||||
virtual void OnContentLoadFinished(CefRefPtr<CefBrowser> browser, const std::string& url) = 0;
|
||||
virtual void OnContentFaviconChanged(CefRefPtr<CefBrowser> browser, const std::vector<std::string>& urls) = 0;
|
||||
virtual void OnContentFullscreenChanged(CefRefPtr<CefBrowser> browser, bool fullscreen) = 0;
|
||||
virtual void OnPopupRequested(CefRefPtr<CefBrowser> browser, const std::string& target_url) = 0;
|
||||
virtual bool ShouldBypassInsecureWarning(CefRefPtr<CefBrowser> browser, const std::string& target_url) = 0;
|
||||
};
|
||||
|
||||
class NebulaBrowserClient final : public CefClient,
|
||||
public CefDisplayHandler,
|
||||
public CefKeyboardHandler,
|
||||
public CefLifeSpanHandler,
|
||||
public CefLoadHandler,
|
||||
public CefPermissionHandler,
|
||||
public CefRequestHandler {
|
||||
public:
|
||||
NebulaBrowserClient(BrowserRole role, BrowserClientDelegate* delegate);
|
||||
|
||||
CefRefPtr<CefDisplayHandler> GetDisplayHandler() override { return this; }
|
||||
CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() override { return this; }
|
||||
CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override { return this; }
|
||||
CefRefPtr<CefLoadHandler> GetLoadHandler() override { return this; }
|
||||
CefRefPtr<CefPermissionHandler> GetPermissionHandler() override { return this; }
|
||||
CefRefPtr<CefRequestHandler> GetRequestHandler() override { return this; }
|
||||
|
||||
bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefProcessId source_process,
|
||||
CefRefPtr<CefProcessMessage> message) override;
|
||||
|
||||
void OnAddressChange(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
const CefString& url) override;
|
||||
void OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) override;
|
||||
void OnFaviconURLChange(CefRefPtr<CefBrowser> browser,
|
||||
const std::vector<CefString>& icon_urls) override;
|
||||
void OnFullscreenModeChange(CefRefPtr<CefBrowser> browser, bool fullscreen) override;
|
||||
|
||||
bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
|
||||
const CefKeyEvent& event,
|
||||
CefEventHandle os_event,
|
||||
bool* is_keyboard_shortcut) override;
|
||||
|
||||
bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int popup_id,
|
||||
const CefString& target_url,
|
||||
const CefString& target_frame_name,
|
||||
CefLifeSpanHandler::WindowOpenDisposition target_disposition,
|
||||
bool user_gesture,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefWindowInfo& windowInfo,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings,
|
||||
CefRefPtr<CefDictionaryValue>& extra_info,
|
||||
bool* no_javascript_access) override;
|
||||
|
||||
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;
|
||||
void OnBeforeClose(CefRefPtr<CefBrowser> browser) override;
|
||||
|
||||
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool isLoading,
|
||||
bool canGoBack,
|
||||
bool canGoForward) override;
|
||||
void OnLoadStart(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
TransitionType transition_type) override;
|
||||
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
int httpStatusCode) override;
|
||||
|
||||
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool user_gesture,
|
||||
bool is_redirect) override;
|
||||
|
||||
bool OnShowPermissionPrompt(CefRefPtr<CefBrowser> browser,
|
||||
uint64_t prompt_id,
|
||||
const CefString& requesting_origin,
|
||||
uint32_t requested_permissions,
|
||||
CefRefPtr<CefPermissionPromptCallback> callback) override;
|
||||
|
||||
private:
|
||||
BrowserRole role_;
|
||||
BrowserClientDelegate* delegate_ = nullptr;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(NebulaBrowserClient);
|
||||
};
|
||||
|
||||
} // namespace nebula::cef
|
||||
@@ -0,0 +1,119 @@
|
||||
#include "cef/nebula_app.h"
|
||||
|
||||
#include "include/cef_process_message.h"
|
||||
#include "platform/types.h"
|
||||
#include "include/wrapper/cef_helpers.h"
|
||||
|
||||
namespace nebula::cef {
|
||||
namespace {
|
||||
|
||||
constexpr char kChromeCommandMessage[] = "NebulaChromeCommand";
|
||||
|
||||
class NativeBridgeHandler final : public CefV8Handler {
|
||||
public:
|
||||
bool Execute(const CefString& name,
|
||||
CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) override {
|
||||
NEBULA_UNUSED(object);
|
||||
NEBULA_UNUSED(retval);
|
||||
|
||||
if (name != "postMessage" && name != "sendToHost" && name != "send") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arguments.empty() || !arguments[0]->IsString()) {
|
||||
exception = "nebulaNative.postMessage requires a command string.";
|
||||
return true;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
|
||||
CefRefPtr<CefBrowser> browser = context ? context->GetBrowser() : nullptr;
|
||||
CefRefPtr<CefFrame> frame = context ? context->GetFrame() : nullptr;
|
||||
if (!browser || !frame) {
|
||||
exception = "No CEF frame is available for native messaging.";
|
||||
return true;
|
||||
}
|
||||
|
||||
CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create(kChromeCommandMessage);
|
||||
CefRefPtr<CefListValue> args = message->GetArgumentList();
|
||||
args->SetString(0, arguments[0]->GetStringValue());
|
||||
args->SetString(1, arguments.size() > 1 && arguments[1]->IsString()
|
||||
? arguments[1]->GetStringValue()
|
||||
: CefString());
|
||||
|
||||
frame->SendProcessMessage(PID_BROWSER, message);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
IMPLEMENT_REFCOUNTING(NativeBridgeHandler);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void NebulaApp::OnBeforeCommandLineProcessing(const CefString& process_type,
|
||||
CefRefPtr<CefCommandLine> command_line) {
|
||||
NEBULA_UNUSED(process_type);
|
||||
|
||||
// The bundled UI is loaded from file:// and uses ES modules.
|
||||
command_line->AppendSwitch("allow-file-access-from-files");
|
||||
|
||||
// CefSettings.no_sandbox disables the browser-level sandbox, but Chromium
|
||||
// still attempts to bring up a separate GPU sandbox inside the GPU process.
|
||||
// Without the host-side sandbox plumbing this fails with STATUS_BREAKPOINT
|
||||
// (-2147483645) immediately on startup, which is exactly what the GPU
|
||||
// diagnostics page was showing - the GPU process crashed three times and
|
||||
// Chromium then fell back to software rendering. Disabling the GPU sandbox
|
||||
// matches the rest of our no_sandbox configuration and lets the GPU
|
||||
// process initialize.
|
||||
command_line->AppendSwitch("no-sandbox");
|
||||
command_line->AppendSwitch("disable-gpu-sandbox");
|
||||
command_line->AppendSwitch("in-process-gpu");
|
||||
|
||||
// Avoid Chromium's conservative GPU blocklist, but let Chromium choose the
|
||||
// safest graphics backend for this machine. Forcing raster/zero-copy paths
|
||||
// can prevent WebGL shared contexts from initializing on some drivers.
|
||||
command_line->AppendSwitch("ignore-gpu-blocklist");
|
||||
command_line->AppendSwitch("enable-accelerated-video-decode");
|
||||
|
||||
#if defined(_WIN32)
|
||||
command_line->AppendSwitchWithValue("use-gl", "angle");
|
||||
command_line->AppendSwitchWithValue("use-angle", "d3d11");
|
||||
#elif defined(__APPLE__)
|
||||
command_line->AppendSwitchWithValue("use-angle", "metal");
|
||||
#else
|
||||
command_line->AppendSwitchWithValue("use-gl", "egl");
|
||||
#endif
|
||||
}
|
||||
|
||||
void NebulaApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) {
|
||||
CEF_REQUIRE_RENDERER_THREAD();
|
||||
NEBULA_UNUSED(browser);
|
||||
NEBULA_UNUSED(frame);
|
||||
|
||||
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||
CefRefPtr<NativeBridgeHandler> handler = new NativeBridgeHandler();
|
||||
CefRefPtr<CefV8Value> native = CefV8Value::CreateObject(nullptr, nullptr);
|
||||
native->SetValue(
|
||||
"postMessage",
|
||||
CefV8Value::CreateFunction("postMessage", handler),
|
||||
V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
global->SetValue("nebulaNative", native, V8_PROPERTY_ATTRIBUTE_READONLY);
|
||||
|
||||
CefRefPtr<CefV8Value> electron_api = CefV8Value::CreateObject(nullptr, nullptr);
|
||||
electron_api->SetValue(
|
||||
"sendToHost",
|
||||
CefV8Value::CreateFunction("sendToHost", handler),
|
||||
V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
electron_api->SetValue(
|
||||
"send",
|
||||
CefV8Value::CreateFunction("send", handler),
|
||||
V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
global->SetValue("electronAPI", electron_api, V8_PROPERTY_ATTRIBUTE_READONLY);
|
||||
}
|
||||
|
||||
} // namespace nebula::cef
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_app.h"
|
||||
#include "include/cef_render_process_handler.h"
|
||||
#include "include/cef_v8.h"
|
||||
|
||||
namespace nebula::cef {
|
||||
|
||||
class NebulaApp final : public CefApp,
|
||||
public CefRenderProcessHandler {
|
||||
public:
|
||||
CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override { return this; }
|
||||
|
||||
void OnBeforeCommandLineProcessing(const CefString& process_type,
|
||||
CefRefPtr<CefCommandLine> command_line) override;
|
||||
|
||||
void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefV8Context> context) override;
|
||||
|
||||
private:
|
||||
IMPLEMENT_REFCOUNTING(NebulaApp);
|
||||
};
|
||||
|
||||
} // namespace nebula::cef
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "include/cef_browser.h"
|
||||
#include "platform/types.h"
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
CefWindowInfo MakeChildWindowInfo(NativeWindow parent, const Rect& rect);
|
||||
CefWindowInfo MakeDevToolsPopup(NativeWindow parent, const char* title);
|
||||
void ResizeBrowserWindow(NativeWindow browser_window, const Rect& rect);
|
||||
void SetBrowserVisible(NativeWindow browser_window, bool visible);
|
||||
void RaiseBrowserWindow(NativeWindow browser_window);
|
||||
void MoveCursorToBrowserPoint(NativeWindow browser_window, int x, int y);
|
||||
Rect MenuPopupRect(NativeWindow parent, const BrowserLayout& layout);
|
||||
std::string CacheBusterToken();
|
||||
void DestroyTopLevelWindow(NativeWindow window);
|
||||
int ScaleForParentWindow(NativeWindow parent, int value);
|
||||
std::pair<int, int> ParentClientSize(NativeWindow parent);
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
bool IsDefaultBrowser();
|
||||
bool EnsureDefaultBrowserRegistration();
|
||||
bool RequestDefaultBrowser();
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "platform/browser_host.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
CefWindowInfo MakeChildWindowInfo(NativeWindow parent, const Rect& rect) {
|
||||
CefWindowInfo info;
|
||||
info.SetAsChild(
|
||||
reinterpret_cast<CefWindowHandle>(parent),
|
||||
CefRect(rect.x, rect.y, rect.width, rect.height));
|
||||
info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
|
||||
return info;
|
||||
}
|
||||
|
||||
CefWindowInfo MakeDevToolsPopup(NativeWindow parent, const char* title) {
|
||||
CefWindowInfo info;
|
||||
info.SetAsPopup(reinterpret_cast<CefWindowHandle>(parent), title);
|
||||
info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
|
||||
return info;
|
||||
}
|
||||
|
||||
void ResizeBrowserWindow(NativeWindow browser_window, const Rect& rect) {
|
||||
NEBULA_UNUSED(browser_window);
|
||||
NEBULA_UNUSED(rect);
|
||||
}
|
||||
|
||||
void SetBrowserVisible(NativeWindow browser_window, bool visible) {
|
||||
NEBULA_UNUSED(browser_window);
|
||||
NEBULA_UNUSED(visible);
|
||||
}
|
||||
|
||||
void RaiseBrowserWindow(NativeWindow browser_window) {
|
||||
NEBULA_UNUSED(browser_window);
|
||||
}
|
||||
|
||||
void MoveCursorToBrowserPoint(NativeWindow browser_window, int x, int y) {
|
||||
NEBULA_UNUSED(browser_window);
|
||||
NEBULA_UNUSED(x);
|
||||
NEBULA_UNUSED(y);
|
||||
}
|
||||
|
||||
int ScaleForParentWindow(NativeWindow parent, int value) {
|
||||
NEBULA_UNUSED(parent);
|
||||
return value;
|
||||
}
|
||||
|
||||
std::pair<int, int> ParentClientSize(NativeWindow parent) {
|
||||
NEBULA_UNUSED(parent);
|
||||
return {1280, 720};
|
||||
}
|
||||
|
||||
Rect MenuPopupRect(NativeWindow parent, const BrowserLayout& layout) {
|
||||
const auto client_size = ParentClientSize(parent);
|
||||
const int width = 260;
|
||||
const int height = 258;
|
||||
const int margin = 12;
|
||||
const int overlap = 2;
|
||||
const int x = std::max(0, client_size.first - width - margin);
|
||||
const int y = std::max(0, layout.chrome.y + layout.chrome.height - overlap);
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
std::min(client_size.first, x + width) - x,
|
||||
std::min(client_size.second, y + height) - y,
|
||||
};
|
||||
}
|
||||
|
||||
std::string CacheBusterToken() {
|
||||
return "0";
|
||||
}
|
||||
|
||||
void DestroyTopLevelWindow(NativeWindow window) {
|
||||
NEBULA_UNUSED(window);
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "platform/default_browser.h"
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
bool IsDefaultBrowser() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EnsureDefaultBrowserRegistration() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RequestDefaultBrowser() {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "window/nebula_window.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace nebula::window {
|
||||
|
||||
struct nebula::window::NebulaWindowImpl {
|
||||
WindowDelegate* delegate = nullptr;
|
||||
};
|
||||
|
||||
NebulaWindow::NebulaWindow(WindowDelegate* delegate)
|
||||
: impl_(std::make_unique<NebulaWindowImpl>()) {
|
||||
impl_->delegate = delegate;
|
||||
}
|
||||
|
||||
NebulaWindow::~NebulaWindow() = default;
|
||||
|
||||
bool NebulaWindow::Create(const platform::AppStartup& startup) {
|
||||
NEBULA_UNUSED(startup);
|
||||
return false;
|
||||
}
|
||||
|
||||
platform::NativeWindow NebulaWindow::native_handle() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BrowserLayout NebulaWindow::CurrentLayout(bool show_chrome) const {
|
||||
NEBULA_UNUSED(show_chrome);
|
||||
return {};
|
||||
}
|
||||
|
||||
void NebulaWindow::ResizeChild(platform::NativeWindow child, const platform::Rect& rect) const {
|
||||
NEBULA_UNUSED(child);
|
||||
NEBULA_UNUSED(rect);
|
||||
}
|
||||
|
||||
void NebulaWindow::Minimize() {}
|
||||
void NebulaWindow::ToggleMaximize() {}
|
||||
void NebulaWindow::SetFullscreen(bool fullscreen) { NEBULA_UNUSED(fullscreen); }
|
||||
void NebulaWindow::Close() {}
|
||||
void NebulaWindow::BeginDrag() {}
|
||||
void NebulaWindow::SetTitle(const std::string& title) { NEBULA_UNUSED(title); }
|
||||
void NebulaWindow::EnableFrameHitTest(platform::NativeWindow child) const { NEBULA_UNUSED(child); }
|
||||
|
||||
} // namespace nebula::window
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "platform/paths_platform.h"
|
||||
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
std::filesystem::path ExecutableDirectory() {
|
||||
char buffer[4096] = {};
|
||||
const ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
|
||||
if (length <= 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
buffer[length] = '\0';
|
||||
return std::filesystem::path(buffer).parent_path();
|
||||
}
|
||||
|
||||
std::filesystem::path DefaultUserDataRoot() {
|
||||
if (const char* xdg_data = std::getenv("XDG_DATA_HOME"); xdg_data && *xdg_data) {
|
||||
return std::filesystem::path(xdg_data);
|
||||
}
|
||||
|
||||
if (const char* home = std::getenv("HOME")) {
|
||||
return std::filesystem::path(home) / ".local" / "share";
|
||||
}
|
||||
|
||||
if (passwd* pw = getpwuid(getuid())) {
|
||||
return std::filesystem::path(pw->pw_dir) / ".local" / "share";
|
||||
}
|
||||
|
||||
return ExecutableDirectory();
|
||||
}
|
||||
|
||||
std::string PathToUtf8(const std::filesystem::path& path) {
|
||||
return path.string();
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "platform/startup.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
#include <system_error>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "include/cef_command_line.h"
|
||||
#include "ui/paths.h"
|
||||
|
||||
namespace nebula::platform {
|
||||
namespace {
|
||||
|
||||
int g_single_instance_lock = -1;
|
||||
|
||||
} // namespace
|
||||
|
||||
void PrepareApp() {}
|
||||
|
||||
bool TryAcquireSingleInstance(const std::string& launch_target) {
|
||||
NEBULA_UNUSED(launch_target);
|
||||
|
||||
const auto lock_path = nebula::ui::GetUserDataDirectory() / ".nebula_instance.lock";
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(lock_path.parent_path(), ec);
|
||||
|
||||
g_single_instance_lock = open(lock_path.c_str(), O_CREAT | O_RDWR, 0644);
|
||||
if (g_single_instance_lock < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return flock(g_single_instance_lock, LOCK_EX | LOCK_NB) == 0;
|
||||
}
|
||||
|
||||
CefMainArgs MakeMainArgs(const AppStartup& startup) {
|
||||
return CefMainArgs(startup.argc, startup.argv);
|
||||
}
|
||||
|
||||
void InitCommandLine(CefRefPtr<CefCommandLine> command_line, const AppStartup& startup) {
|
||||
command_line->InitFromArgv(startup.argc, startup.argv);
|
||||
}
|
||||
|
||||
void ConfigureCefSettings(CefSettings& settings) {
|
||||
const std::string user_data_dir = nebula::ui::GetUserDataDirectory().string();
|
||||
const std::string cache_dir = nebula::ui::GetCacheDirectory().string();
|
||||
if (!user_data_dir.empty()) {
|
||||
CefString(&settings.root_cache_path).FromString(user_data_dir);
|
||||
}
|
||||
if (!cache_dir.empty()) {
|
||||
CefString(&settings.cache_path).FromString(cache_dir);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,134 @@
|
||||
#include "platform/browser_host.h"
|
||||
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
|
||||
namespace nebula::platform {
|
||||
namespace {
|
||||
|
||||
NSView* AsView(NativeWindow window) {
|
||||
return (__bridge NSView*)window;
|
||||
}
|
||||
|
||||
NSRect ToNativeRect(const Rect& rect) {
|
||||
return NSMakeRect(rect.x, rect.y, std::max(0, rect.width), std::max(0, rect.height));
|
||||
}
|
||||
|
||||
Rect ToPlatformRect(NSRect rect) {
|
||||
return {
|
||||
static_cast<int>(std::round(NSMinX(rect))),
|
||||
static_cast<int>(std::round(NSMinY(rect))),
|
||||
std::max(0, static_cast<int>(std::round(NSWidth(rect)))),
|
||||
std::max(0, static_cast<int>(std::round(NSHeight(rect)))),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefWindowInfo MakeChildWindowInfo(NativeWindow parent, const Rect& rect) {
|
||||
CefWindowInfo info;
|
||||
info.SetAsChild((__bridge CefWindowHandle)AsView(parent),
|
||||
CefRect(rect.x, rect.y, rect.width, rect.height));
|
||||
info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
|
||||
return info;
|
||||
}
|
||||
|
||||
CefWindowInfo MakeDevToolsPopup(NativeWindow parent, const char* title) {
|
||||
(void)title;
|
||||
CefWindowInfo info;
|
||||
info.SetAsChild((__bridge CefWindowHandle)AsView(parent), CefRect(0, 0, 800, 600));
|
||||
info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
|
||||
return info;
|
||||
}
|
||||
|
||||
void ResizeBrowserWindow(NativeWindow browser_window, const Rect& rect) {
|
||||
NSView* view = AsView(browser_window);
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
|
||||
[view setFrame:ToNativeRect(rect)];
|
||||
}
|
||||
|
||||
void SetBrowserVisible(NativeWindow browser_window, bool visible) {
|
||||
NSView* view = AsView(browser_window);
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
|
||||
[view setHidden:!visible];
|
||||
if (visible && [view superview]) {
|
||||
[[view superview] addSubview:view positioned:NSWindowAbove relativeTo:nil];
|
||||
}
|
||||
}
|
||||
|
||||
void RaiseBrowserWindow(NativeWindow browser_window) {
|
||||
NSView* view = AsView(browser_window);
|
||||
if (view && [view superview]) {
|
||||
[[view superview] addSubview:view positioned:NSWindowAbove relativeTo:nil];
|
||||
}
|
||||
}
|
||||
|
||||
void MoveCursorToBrowserPoint(NativeWindow browser_window, int x, int y) {
|
||||
NSView* view = AsView(browser_window);
|
||||
if (!view || ![view window]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const NSPoint window_point = [view convertPoint:NSMakePoint(x, y) toView:nil];
|
||||
const NSPoint screen_point = [[view window] convertPointToScreen:window_point];
|
||||
const CGFloat screen_height = NSMaxY([[NSScreen mainScreen] frame]);
|
||||
CGWarpMouseCursorPosition(CGPointMake(screen_point.x, screen_height - screen_point.y));
|
||||
}
|
||||
|
||||
int ScaleForParentWindow(NativeWindow parent, int value) {
|
||||
(void)parent;
|
||||
return value;
|
||||
}
|
||||
|
||||
std::pair<int, int> ParentClientSize(NativeWindow parent) {
|
||||
NSView* view = AsView(parent);
|
||||
if (!view) {
|
||||
return {0, 0};
|
||||
}
|
||||
|
||||
const Rect rect = ToPlatformRect([view bounds]);
|
||||
return {rect.width, rect.height};
|
||||
}
|
||||
|
||||
Rect MenuPopupRect(NativeWindow parent, const BrowserLayout& layout) {
|
||||
const auto client_size = ParentClientSize(parent);
|
||||
const int width = 260;
|
||||
const int height = 258;
|
||||
const int margin = 12;
|
||||
const int overlap = 2;
|
||||
const int x = std::max(0, client_size.first - width - margin);
|
||||
const int y = std::max(0, layout.chrome.y + layout.chrome.height - overlap);
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
std::min(client_size.first, x + width) - x,
|
||||
std::min(client_size.second, y + height) - y,
|
||||
};
|
||||
}
|
||||
|
||||
std::string CacheBusterToken() {
|
||||
const auto now = std::chrono::system_clock::now().time_since_epoch();
|
||||
const auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(now).count();
|
||||
return std::to_string(millis);
|
||||
}
|
||||
|
||||
void DestroyTopLevelWindow(NativeWindow window) {
|
||||
NSView* view = AsView(window);
|
||||
NSWindow* native_window = [view window];
|
||||
if (native_window) {
|
||||
[native_window setDelegate:nil];
|
||||
[native_window close];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "platform/default_browser.h"
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
bool IsDefaultBrowser() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EnsureDefaultBrowserRegistration() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RequestDefaultBrowser() {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,222 @@
|
||||
#include "window/nebula_window.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
namespace nebula::window {
|
||||
struct NebulaWindowImpl;
|
||||
} // namespace nebula::window
|
||||
|
||||
@interface NebulaContentView : NSView
|
||||
@end
|
||||
|
||||
@implementation NebulaContentView
|
||||
- (BOOL)isFlipped {
|
||||
return YES;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NebulaWindowDelegate : NSObject <NSWindowDelegate> {
|
||||
@private
|
||||
nebula::window::NebulaWindowImpl* owner_;
|
||||
}
|
||||
- (instancetype)initWithOwner:(nebula::window::NebulaWindowImpl*)owner;
|
||||
@end
|
||||
|
||||
namespace nebula::window {
|
||||
namespace {
|
||||
|
||||
constexpr CGFloat kChromeHeight = 104.0;
|
||||
|
||||
NSRect ToNativeRect(const platform::Rect& rect) {
|
||||
return NSMakeRect(rect.x, rect.y, std::max(0, rect.width), std::max(0, rect.height));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
struct NebulaWindowImpl {
|
||||
WindowDelegate* delegate = nullptr;
|
||||
NSWindow* window = nil;
|
||||
NebulaContentView* content_view = nil;
|
||||
NebulaWindowDelegate* window_delegate = nil;
|
||||
bool fullscreen = false;
|
||||
|
||||
BrowserLayout CurrentLayout(bool show_chrome) const {
|
||||
const NSRect bounds = content_view ? [content_view bounds] : NSZeroRect;
|
||||
const int width = std::max(0, static_cast<int>(std::round(NSWidth(bounds))));
|
||||
const int height = std::max(0, static_cast<int>(std::round(NSHeight(bounds))));
|
||||
const int chrome_height = show_chrome ? std::min(height, static_cast<int>(kChromeHeight)) : 0;
|
||||
|
||||
BrowserLayout layout;
|
||||
layout.chrome = show_chrome ? platform::Rect{0, 0, width, chrome_height} : platform::Rect{};
|
||||
layout.content = {0, chrome_height, width, std::max(0, height - chrome_height)};
|
||||
return layout;
|
||||
}
|
||||
|
||||
void NotifyCreated() const {
|
||||
if (delegate) {
|
||||
delegate->OnWindowCreated();
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyResized() const {
|
||||
if (delegate) {
|
||||
delegate->OnWindowResized(CurrentLayout(true));
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyCloseRequested() const {
|
||||
if (delegate) {
|
||||
delegate->OnWindowCloseRequested();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace nebula::window
|
||||
|
||||
@implementation NebulaWindowDelegate
|
||||
- (instancetype)initWithOwner:(nebula::window::NebulaWindowImpl*)owner {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
owner_ = owner;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)windowDidResize:(NSNotification*)notification {
|
||||
(void)notification;
|
||||
if (owner_) {
|
||||
owner_->NotifyResized();
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)windowShouldClose:(id)sender {
|
||||
(void)sender;
|
||||
if (owner_) {
|
||||
owner_->NotifyCloseRequested();
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
@end
|
||||
|
||||
namespace nebula::window {
|
||||
|
||||
NebulaWindow::NebulaWindow(WindowDelegate* delegate)
|
||||
: impl_(std::make_unique<NebulaWindowImpl>()) {
|
||||
impl_->delegate = delegate;
|
||||
}
|
||||
|
||||
NebulaWindow::~NebulaWindow() = default;
|
||||
|
||||
bool NebulaWindow::Create(const platform::AppStartup& startup) {
|
||||
(void)startup;
|
||||
|
||||
@autoreleasepool {
|
||||
[NSApplication sharedApplication];
|
||||
|
||||
const NSRect visible_frame = [[NSScreen mainScreen] visibleFrame];
|
||||
const CGFloat width = std::min<CGFloat>(1400.0, NSWidth(visible_frame));
|
||||
const CGFloat height = std::min<CGFloat>(900.0, NSHeight(visible_frame));
|
||||
const CGFloat x = NSMinX(visible_frame) + (NSWidth(visible_frame) - width) / 2.0;
|
||||
const CGFloat y = NSMinY(visible_frame) + (NSHeight(visible_frame) - height) / 2.0;
|
||||
|
||||
impl_->content_view = [[NebulaContentView alloc] initWithFrame:NSMakeRect(0, 0, width, height)];
|
||||
impl_->window_delegate = [[NebulaWindowDelegate alloc] initWithOwner:impl_.get()];
|
||||
impl_->window = [[NSWindow alloc] initWithContentRect:NSMakeRect(x, y, width, height)
|
||||
styleMask:NSWindowStyleMaskTitled |
|
||||
NSWindowStyleMaskClosable |
|
||||
NSWindowStyleMaskMiniaturizable |
|
||||
NSWindowStyleMaskResizable |
|
||||
NSWindowStyleMaskFullSizeContentView
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
if (!impl_->window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
[impl_->window setTitle:@"Nebula Browser"];
|
||||
[impl_->window setTitleVisibility:NSWindowTitleHidden];
|
||||
[impl_->window setTitlebarAppearsTransparent:YES];
|
||||
[impl_->window setContentView:impl_->content_view];
|
||||
[impl_->window setDelegate:impl_->window_delegate];
|
||||
[impl_->window center];
|
||||
[impl_->window makeKeyAndOrderFront:nil];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
|
||||
impl_->NotifyCreated();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
platform::NativeWindow NebulaWindow::native_handle() const {
|
||||
return (__bridge void*)impl_->content_view;
|
||||
}
|
||||
|
||||
BrowserLayout NebulaWindow::CurrentLayout(bool show_chrome) const {
|
||||
return impl_->CurrentLayout(show_chrome);
|
||||
}
|
||||
|
||||
void NebulaWindow::ResizeChild(platform::NativeWindow child, const platform::Rect& rect) const {
|
||||
NSView* view = (__bridge NSView*)child;
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
|
||||
[view setFrame:ToNativeRect(rect)];
|
||||
}
|
||||
|
||||
void NebulaWindow::Minimize() {
|
||||
[impl_->window miniaturize:nil];
|
||||
}
|
||||
|
||||
void NebulaWindow::ToggleMaximize() {
|
||||
if (impl_->window && !impl_->fullscreen) {
|
||||
[impl_->window zoom:nil];
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaWindow::SetFullscreen(bool fullscreen) {
|
||||
if (!impl_->window || impl_->fullscreen == fullscreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
impl_->fullscreen = fullscreen;
|
||||
[impl_->window toggleFullScreen:nil];
|
||||
}
|
||||
|
||||
void NebulaWindow::Close() {
|
||||
if (impl_->delegate) {
|
||||
impl_->delegate->OnWindowCloseRequested();
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaWindow::BeginDrag() {
|
||||
if (!impl_->window) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSEvent* event = [NSApp currentEvent];
|
||||
if (event) {
|
||||
[impl_->window performWindowDragWithEvent:event];
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaWindow::SetTitle(const std::string& title) {
|
||||
if (!impl_->window) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSString* native_title = title.empty()
|
||||
? @"Nebula Browser"
|
||||
: [[NSString alloc] initWithUTF8String:title.c_str()];
|
||||
[impl_->window setTitle:native_title ?: @"Nebula Browser"];
|
||||
}
|
||||
|
||||
void NebulaWindow::EnableFrameHitTest(platform::NativeWindow child) const {
|
||||
(void)child;
|
||||
}
|
||||
|
||||
} // namespace nebula::window
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "platform/paths_platform.h"
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
std::filesystem::path ExecutableDirectory() {
|
||||
char buffer[4096] = {};
|
||||
uint32_t size = sizeof(buffer);
|
||||
if (_NSGetExecutablePath(buffer, &size) != 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::filesystem::path(buffer).parent_path();
|
||||
}
|
||||
|
||||
std::filesystem::path DefaultUserDataRoot() {
|
||||
if (const char* home = std::getenv("HOME")) {
|
||||
return std::filesystem::path(home) / "Library" / "Application Support";
|
||||
}
|
||||
|
||||
if (passwd* pw = getpwuid(getuid())) {
|
||||
return std::filesystem::path(pw->pw_dir) / "Library" / "Application Support";
|
||||
}
|
||||
|
||||
return ExecutableDirectory();
|
||||
}
|
||||
|
||||
std::string PathToUtf8(const std::filesystem::path& path) {
|
||||
return path.string();
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "platform/startup.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <filesystem>
|
||||
#include <system_error>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "include/cef_command_line.h"
|
||||
#include "ui/paths.h"
|
||||
|
||||
namespace nebula::platform {
|
||||
namespace {
|
||||
|
||||
int g_single_instance_lock = -1;
|
||||
|
||||
} // namespace
|
||||
|
||||
void PrepareApp() {
|
||||
@autoreleasepool {
|
||||
[NSApplication sharedApplication];
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
[NSApp finishLaunching];
|
||||
}
|
||||
}
|
||||
|
||||
bool TryAcquireSingleInstance(const std::string& launch_target) {
|
||||
NEBULA_UNUSED(launch_target);
|
||||
|
||||
const auto lock_path = nebula::ui::GetUserDataDirectory() / ".nebula_instance.lock";
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(lock_path.parent_path(), ec);
|
||||
|
||||
g_single_instance_lock = open(lock_path.c_str(), O_CREAT | O_RDWR, 0644);
|
||||
if (g_single_instance_lock < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return flock(g_single_instance_lock, LOCK_EX | LOCK_NB) == 0;
|
||||
}
|
||||
|
||||
CefMainArgs MakeMainArgs(const AppStartup& startup) {
|
||||
return CefMainArgs(startup.argc, startup.argv);
|
||||
}
|
||||
|
||||
void InitCommandLine(CefRefPtr<CefCommandLine> command_line, const AppStartup& startup) {
|
||||
command_line->InitFromArgv(startup.argc, startup.argv);
|
||||
}
|
||||
|
||||
void ConfigureCefSettings(CefSettings& settings) {
|
||||
const std::string user_data_dir = nebula::ui::GetUserDataDirectory().string();
|
||||
const std::string cache_dir = nebula::ui::GetCacheDirectory().string();
|
||||
if (!user_data_dir.empty()) {
|
||||
CefString(&settings.root_cache_path).FromString(user_data_dir);
|
||||
}
|
||||
if (!cache_dir.empty()) {
|
||||
CefString(&settings.cache_path).FromString(cache_dir);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
std::filesystem::path ExecutableDirectory();
|
||||
std::filesystem::path DefaultUserDataRoot();
|
||||
std::string PathToUtf8(const std::filesystem::path& path);
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_app.h"
|
||||
#include "platform/types.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
void PrepareApp();
|
||||
bool TryAcquireSingleInstance(const std::string& launch_target = {});
|
||||
CefMainArgs MakeMainArgs(const AppStartup& startup);
|
||||
void InitCommandLine(CefRefPtr<CefCommandLine> command_line, const AppStartup& startup);
|
||||
void ConfigureCefSettings(CefSettings& settings);
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NEBULA_UNUSED
|
||||
#define NEBULA_UNUSED(P) (void)(P)
|
||||
#endif
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
struct Rect {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
};
|
||||
|
||||
struct BrowserLayout {
|
||||
Rect chrome;
|
||||
Rect content;
|
||||
};
|
||||
|
||||
using NativeWindow = void*;
|
||||
|
||||
#if defined(_WIN32)
|
||||
struct AppStartup {
|
||||
void* instance = nullptr;
|
||||
int show_command = 0;
|
||||
};
|
||||
#else
|
||||
struct AppStartup {
|
||||
int argc = 0;
|
||||
char** argv = nullptr;
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,139 @@
|
||||
#include "platform/browser_host.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace nebula::platform {
|
||||
namespace {
|
||||
|
||||
HWND AsHwnd(NativeWindow window) {
|
||||
return static_cast<HWND>(window);
|
||||
}
|
||||
|
||||
RECT ToRect(const Rect& rect) {
|
||||
return {
|
||||
rect.x,
|
||||
rect.y,
|
||||
rect.x + rect.width,
|
||||
rect.y + rect.height,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefWindowInfo MakeChildWindowInfo(NativeWindow parent, const Rect& rect) {
|
||||
CefWindowInfo info;
|
||||
info.SetAsChild(
|
||||
AsHwnd(parent),
|
||||
CefRect(rect.x, rect.y, rect.width, rect.height));
|
||||
info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
|
||||
return info;
|
||||
}
|
||||
|
||||
CefWindowInfo MakeDevToolsPopup(NativeWindow parent, const char* title) {
|
||||
CefWindowInfo info;
|
||||
info.SetAsPopup(AsHwnd(parent), title);
|
||||
info.runtime_style = CEF_RUNTIME_STYLE_ALLOY;
|
||||
return info;
|
||||
}
|
||||
|
||||
void ResizeBrowserWindow(NativeWindow browser_window, const Rect& rect) {
|
||||
const HWND hwnd = AsHwnd(browser_window);
|
||||
if (!hwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetWindowPos(
|
||||
hwnd,
|
||||
nullptr,
|
||||
rect.x,
|
||||
rect.y,
|
||||
std::max(0, rect.width),
|
||||
std::max(0, rect.height),
|
||||
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
|
||||
}
|
||||
|
||||
void SetBrowserVisible(NativeWindow browser_window, bool visible) {
|
||||
const HWND hwnd = AsHwnd(browser_window);
|
||||
if (!hwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShowWindow(hwnd, visible ? SW_SHOW : SW_HIDE);
|
||||
if (visible) {
|
||||
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
}
|
||||
}
|
||||
|
||||
void RaiseBrowserWindow(NativeWindow browser_window) {
|
||||
const HWND hwnd = AsHwnd(browser_window);
|
||||
if (!hwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
}
|
||||
|
||||
void MoveCursorToBrowserPoint(NativeWindow browser_window, int x, int y) {
|
||||
const HWND hwnd = AsHwnd(browser_window);
|
||||
if (!hwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
POINT point = {x, y};
|
||||
if (!ClientToScreen(hwnd, &point)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetCursorPos(point.x, point.y);
|
||||
}
|
||||
|
||||
int ScaleForParentWindow(NativeWindow parent, int value) {
|
||||
const HWND hwnd = AsHwnd(parent);
|
||||
if (!hwnd) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return MulDiv(value, static_cast<int>(GetDpiForWindow(hwnd)), 96);
|
||||
}
|
||||
|
||||
std::pair<int, int> ParentClientSize(NativeWindow parent) {
|
||||
RECT client = {};
|
||||
const HWND hwnd = AsHwnd(parent);
|
||||
if (hwnd) {
|
||||
GetClientRect(hwnd, &client);
|
||||
}
|
||||
|
||||
return {static_cast<int>(client.right), static_cast<int>(client.bottom)};
|
||||
}
|
||||
|
||||
Rect MenuPopupRect(NativeWindow parent, const BrowserLayout& layout) {
|
||||
const auto client_size = ParentClientSize(parent);
|
||||
const int width = ScaleForParentWindow(parent, 260);
|
||||
const int height = ScaleForParentWindow(parent, 258);
|
||||
const int margin = ScaleForParentWindow(parent, 12);
|
||||
const int overlap = ScaleForParentWindow(parent, 2);
|
||||
|
||||
const int x = std::max(0, client_size.first - width - margin);
|
||||
const int y = std::max(0, layout.chrome.y + layout.chrome.height - overlap);
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
std::min(client_size.first, x + width) - x,
|
||||
std::min(client_size.second, y + height) - y,
|
||||
};
|
||||
}
|
||||
|
||||
std::string CacheBusterToken() {
|
||||
return std::to_string(GetTickCount64());
|
||||
}
|
||||
|
||||
void DestroyTopLevelWindow(NativeWindow window) {
|
||||
const HWND hwnd = AsHwnd(window);
|
||||
if (hwnd) {
|
||||
DestroyWindow(hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,176 @@
|
||||
#include "platform/default_browser.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace nebula::platform {
|
||||
namespace {
|
||||
|
||||
constexpr wchar_t kAppName[] = L"Nebula Browser";
|
||||
constexpr wchar_t kClientKeyName[] = L"NebulaBrowser";
|
||||
constexpr wchar_t kRegisteredApplicationsKey[] = L"Software\\RegisteredApplications";
|
||||
constexpr wchar_t kClientRootKey[] = L"Software\\Clients\\StartMenuInternet\\NebulaBrowser";
|
||||
constexpr wchar_t kFileAssociationsKey[] =
|
||||
L"Software\\Clients\\StartMenuInternet\\NebulaBrowser\\Capabilities\\FileAssociations";
|
||||
constexpr wchar_t kUrlAssociationsKey[] =
|
||||
L"Software\\Clients\\StartMenuInternet\\NebulaBrowser\\Capabilities\\URLAssociations";
|
||||
constexpr wchar_t kHttpUserChoiceKey[] =
|
||||
L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice";
|
||||
constexpr wchar_t kHttpsUserChoiceKey[] =
|
||||
L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\https\\UserChoice";
|
||||
constexpr std::wstring_view kWebFileExtensions[] = {
|
||||
L".htm",
|
||||
L".html",
|
||||
L".shtml",
|
||||
L".xht",
|
||||
L".xhtml",
|
||||
L".svg",
|
||||
L".webp",
|
||||
};
|
||||
|
||||
std::wstring CurrentExecutablePath() {
|
||||
std::wstring path(MAX_PATH, L'\0');
|
||||
DWORD length = 0;
|
||||
while (true) {
|
||||
length = GetModuleFileNameW(nullptr, path.data(), static_cast<DWORD>(path.size()));
|
||||
if (length == 0) {
|
||||
return {};
|
||||
}
|
||||
if (length < path.size() - 1) {
|
||||
path.resize(length);
|
||||
return path;
|
||||
}
|
||||
path.resize(path.size() * 2);
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring Quote(std::wstring_view value) {
|
||||
std::wstring quoted = L"\"";
|
||||
quoted += value;
|
||||
quoted += L"\"";
|
||||
return quoted;
|
||||
}
|
||||
|
||||
bool SetStringValue(HKEY root,
|
||||
const std::wstring& subkey,
|
||||
const wchar_t* value_name,
|
||||
const std::wstring& value) {
|
||||
HKEY key = nullptr;
|
||||
const LSTATUS status = RegCreateKeyExW(
|
||||
root, subkey.c_str(), 0, nullptr, 0, KEY_SET_VALUE, nullptr, &key, nullptr);
|
||||
if (status != ERROR_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const DWORD byte_size = static_cast<DWORD>((value.size() + 1) * sizeof(wchar_t));
|
||||
const LSTATUS set_status = RegSetValueExW(
|
||||
key,
|
||||
value_name,
|
||||
0,
|
||||
REG_SZ,
|
||||
reinterpret_cast<const BYTE*>(value.c_str()),
|
||||
byte_size);
|
||||
RegCloseKey(key);
|
||||
return set_status == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
std::wstring ReadStringValue(HKEY root, const wchar_t* subkey, const wchar_t* value_name) {
|
||||
HKEY key = nullptr;
|
||||
if (RegOpenKeyExW(root, subkey, 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS) {
|
||||
return {};
|
||||
}
|
||||
|
||||
DWORD type = 0;
|
||||
DWORD byte_size = 0;
|
||||
if (RegQueryValueExW(key, value_name, nullptr, &type, nullptr, &byte_size) != ERROR_SUCCESS ||
|
||||
type != REG_SZ || byte_size == 0) {
|
||||
RegCloseKey(key);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::wstring value(byte_size / sizeof(wchar_t), L'\0');
|
||||
const LSTATUS status = RegQueryValueExW(
|
||||
key, value_name, nullptr, nullptr, reinterpret_cast<BYTE*>(value.data()), &byte_size);
|
||||
RegCloseKey(key);
|
||||
if (status != ERROR_SUCCESS) {
|
||||
return {};
|
||||
}
|
||||
|
||||
while (!value.empty() && value.back() == L'\0') {
|
||||
value.pop_back();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
bool RegisterDefaultBrowserCapabilities() {
|
||||
const std::wstring exe_path = CurrentExecutablePath();
|
||||
if (exe_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::wstring exe_name = std::filesystem::path(exe_path).filename().wstring();
|
||||
const std::wstring command = Quote(exe_path) + L" --url=" + Quote(L"%1");
|
||||
bool ok = true;
|
||||
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, kRegisteredApplicationsKey, kAppName,
|
||||
std::wstring(kClientRootKey) + L"\\Capabilities");
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, kClientRootKey, nullptr, kAppName);
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, std::wstring(kClientRootKey) + L"\\DefaultIcon",
|
||||
nullptr, exe_path + L",0");
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, std::wstring(kClientRootKey) + L"\\shell\\open\\command",
|
||||
nullptr, Quote(exe_path));
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, std::wstring(kClientRootKey) + L"\\Capabilities",
|
||||
L"ApplicationName", kAppName);
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, std::wstring(kClientRootKey) + L"\\Capabilities",
|
||||
L"ApplicationDescription", L"Nebula Browser");
|
||||
for (std::wstring_view extension : kWebFileExtensions) {
|
||||
const std::wstring extension_name(extension);
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, kFileAssociationsKey, extension_name.c_str(),
|
||||
kClientKeyName);
|
||||
}
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, kUrlAssociationsKey, L"http", kClientKeyName);
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, kUrlAssociationsKey, L"https", kClientKeyName);
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, L"Software\\Classes\\NebulaBrowser", nullptr,
|
||||
L"Nebula Browser HTML Document");
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, L"Software\\Classes\\NebulaBrowser", L"URL Protocol",
|
||||
L"");
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, L"Software\\Classes\\NebulaBrowser\\DefaultIcon",
|
||||
nullptr, exe_path + L",0");
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, L"Software\\Classes\\NebulaBrowser\\shell\\open\\command",
|
||||
nullptr, command);
|
||||
const std::wstring application_key = std::wstring(L"Software\\Classes\\Applications\\") + exe_name;
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER, application_key,
|
||||
L"ApplicationName", kAppName);
|
||||
ok &= SetStringValue(HKEY_CURRENT_USER,
|
||||
application_key + L"\\shell\\open\\command",
|
||||
nullptr, command);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
void OpenDefaultAppsSettings() {
|
||||
ShellExecuteW(nullptr, L"open", L"ms-settings:defaultapps", nullptr, nullptr, SW_SHOWNORMAL);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool IsDefaultBrowser() {
|
||||
return ReadStringValue(HKEY_CURRENT_USER, kHttpUserChoiceKey, L"ProgId") == kClientKeyName &&
|
||||
ReadStringValue(HKEY_CURRENT_USER, kHttpsUserChoiceKey, L"ProgId") == kClientKeyName;
|
||||
}
|
||||
|
||||
bool EnsureDefaultBrowserRegistration() {
|
||||
return RegisterDefaultBrowserCapabilities();
|
||||
}
|
||||
|
||||
bool RequestDefaultBrowser() {
|
||||
const bool registered = RegisterDefaultBrowserCapabilities();
|
||||
OpenDefaultAppsSettings();
|
||||
return registered;
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,673 @@
|
||||
#include "window/nebula_window.h"
|
||||
|
||||
#include <dwmapi.h>
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
namespace nebula::window {
|
||||
namespace {
|
||||
|
||||
constexpr wchar_t kWindowClassName[] = L"NebulaBrowserWindow";
|
||||
constexpr wchar_t kWindowTitle[] = L"Nebula Browser";
|
||||
constexpr wchar_t kChildFrameHitTestOldProcProp[] = L"NebulaChildFrameHitTestOldProc";
|
||||
constexpr wchar_t kChildFrameHitTestParentProp[] = L"NebulaChildFrameHitTestParent";
|
||||
constexpr ULONG_PTR kOpenTargetCopyDataId = 0x4E42554CUL;
|
||||
constexpr int kTitleRowHeightDip = 42;
|
||||
constexpr int kWindowControlWidthDip = 46;
|
||||
constexpr int kWindowControlCount = 3;
|
||||
constexpr COLORREF kNoWindowBorderColor = 0xFFFFFFFE;
|
||||
|
||||
RECT GetWorkArea() {
|
||||
RECT work_area = {};
|
||||
SystemParametersInfoW(SPI_GETWORKAREA, 0, &work_area, 0);
|
||||
return work_area;
|
||||
}
|
||||
|
||||
RECT GetMonitorWorkArea(HWND hwnd) {
|
||||
MONITORINFO monitor_info = {};
|
||||
monitor_info.cbSize = sizeof(monitor_info);
|
||||
|
||||
const HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
if (monitor && GetMonitorInfoW(monitor, &monitor_info)) {
|
||||
return monitor_info.rcWork;
|
||||
}
|
||||
|
||||
return GetWorkArea();
|
||||
}
|
||||
|
||||
RECT GetMonitorArea(HWND hwnd) {
|
||||
MONITORINFO monitor_info = {};
|
||||
monitor_info.cbSize = sizeof(monitor_info);
|
||||
|
||||
const HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
if (monitor && GetMonitorInfoW(monitor, &monitor_info)) {
|
||||
return monitor_info.rcMonitor;
|
||||
}
|
||||
|
||||
return GetWorkArea();
|
||||
}
|
||||
|
||||
bool IsResizeHit(LRESULT hit) {
|
||||
return hit == HTLEFT || hit == HTRIGHT || hit == HTTOP || hit == HTBOTTOM ||
|
||||
hit == HTTOPLEFT || hit == HTTOPRIGHT || hit == HTBOTTOMLEFT || hit == HTBOTTOMRIGHT;
|
||||
}
|
||||
|
||||
HCURSOR CursorForResizeHit(LRESULT hit) {
|
||||
switch (hit) {
|
||||
case HTLEFT:
|
||||
case HTRIGHT:
|
||||
return LoadCursor(nullptr, IDC_SIZEWE);
|
||||
case HTTOP:
|
||||
case HTBOTTOM:
|
||||
return LoadCursor(nullptr, IDC_SIZENS);
|
||||
case HTTOPLEFT:
|
||||
case HTBOTTOMRIGHT:
|
||||
return LoadCursor(nullptr, IDC_SIZENWSE);
|
||||
case HTTOPRIGHT:
|
||||
case HTBOTTOMLEFT:
|
||||
return LoadCursor(nullptr, IDC_SIZENESW);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool SetResizeCursor(LRESULT hit) {
|
||||
HCURSOR cursor = CursorForResizeHit(hit);
|
||||
if (!cursor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SetCursor(cursor);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ApplyWindowFrameStyle(HWND hwnd) {
|
||||
const BOOL dark_mode = TRUE;
|
||||
const DWM_WINDOW_CORNER_PREFERENCE corner_preference = DWMWCP_ROUND;
|
||||
DwmSetWindowAttribute(
|
||||
hwnd,
|
||||
DWMWA_USE_IMMERSIVE_DARK_MODE,
|
||||
&dark_mode,
|
||||
sizeof(dark_mode));
|
||||
|
||||
DwmSetWindowAttribute(
|
||||
hwnd,
|
||||
DWMWA_WINDOW_CORNER_PREFERENCE,
|
||||
&corner_preference,
|
||||
sizeof(corner_preference));
|
||||
|
||||
DwmSetWindowAttribute(
|
||||
hwnd,
|
||||
DWMWA_BORDER_COLOR,
|
||||
&kNoWindowBorderColor,
|
||||
sizeof(kNoWindowBorderColor));
|
||||
}
|
||||
|
||||
platform::Rect ToPlatformRect(const RECT& rect) {
|
||||
return {
|
||||
rect.left,
|
||||
rect.top,
|
||||
std::max(0L, rect.right - rect.left),
|
||||
std::max(0L, rect.bottom - rect.top),
|
||||
};
|
||||
}
|
||||
|
||||
RECT ToNativeRect(const platform::Rect& rect) {
|
||||
return {
|
||||
rect.x,
|
||||
rect.y,
|
||||
rect.x + rect.width,
|
||||
rect.y + rect.height,
|
||||
};
|
||||
}
|
||||
|
||||
std::string WideToUtf8(std::wstring_view value) {
|
||||
if (value.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const int size = WideCharToMultiByte(
|
||||
CP_UTF8,
|
||||
0,
|
||||
value.data(),
|
||||
static_cast<int>(value.size()),
|
||||
nullptr,
|
||||
0,
|
||||
nullptr,
|
||||
nullptr);
|
||||
if (size <= 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string result(size, '\0');
|
||||
WideCharToMultiByte(
|
||||
CP_UTF8,
|
||||
0,
|
||||
value.data(),
|
||||
static_cast<int>(value.size()),
|
||||
result.data(),
|
||||
size,
|
||||
nullptr,
|
||||
nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
struct nebula::window::NebulaWindowImpl {
|
||||
WindowDelegate* delegate = nullptr;
|
||||
HINSTANCE instance = nullptr;
|
||||
HWND hwnd = nullptr;
|
||||
bool fullscreen = false;
|
||||
LONG_PTR restore_style = 0;
|
||||
LONG_PTR restore_ex_style = 0;
|
||||
WINDOWPLACEMENT restore_placement = {sizeof(WINDOWPLACEMENT)};
|
||||
UINT dpi = 96;
|
||||
int resize_border_dip = 8;
|
||||
int chrome_height_dip = 104;
|
||||
|
||||
int ScaleForDpi(int value) const {
|
||||
return MulDiv(value, static_cast<int>(dpi), 96);
|
||||
}
|
||||
|
||||
void UpdateDpi() {
|
||||
if (hwnd) {
|
||||
dpi = GetDpiForWindow(hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyResize() {
|
||||
if (delegate) {
|
||||
delegate->OnWindowResized(CurrentLayout(true));
|
||||
}
|
||||
}
|
||||
|
||||
BrowserLayout CurrentLayout(bool show_chrome) const {
|
||||
RECT client = {};
|
||||
if (hwnd) {
|
||||
GetClientRect(hwnd, &client);
|
||||
}
|
||||
|
||||
BrowserLayout layout;
|
||||
layout.chrome = show_chrome
|
||||
? ToPlatformRect(RECT{
|
||||
0,
|
||||
0,
|
||||
client.right,
|
||||
std::min<LONG>(ScaleForDpi(chrome_height_dip), client.bottom)})
|
||||
: platform::Rect{};
|
||||
layout.content = ToPlatformRect(
|
||||
RECT{0, layout.chrome.y + layout.chrome.height, client.right, client.bottom});
|
||||
return layout;
|
||||
}
|
||||
|
||||
void EnableFrameHitTestForWindow(HWND child) const;
|
||||
LRESULT HitTest(LPARAM lparam) const;
|
||||
LRESULT HitTestPoint(POINT point) const;
|
||||
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam);
|
||||
void RegisterClass(HINSTANCE instance_handle);
|
||||
|
||||
static LRESULT CALLBACK StaticWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
|
||||
static LRESULT CALLBACK ChildFrameWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
|
||||
static BOOL CALLBACK EnableFrameHitTestForDescendant(HWND hwnd, LPARAM lparam);
|
||||
};
|
||||
|
||||
LRESULT CALLBACK nebula::window::NebulaWindowImpl::StaticWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
|
||||
NebulaWindowImpl* self = nullptr;
|
||||
|
||||
if (message == WM_NCCREATE) {
|
||||
auto* create = reinterpret_cast<CREATESTRUCTW*>(lparam);
|
||||
self = static_cast<NebulaWindowImpl*>(create->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(self));
|
||||
self->hwnd = hwnd;
|
||||
} else {
|
||||
self = reinterpret_cast<NebulaWindowImpl*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
}
|
||||
|
||||
return self ? self->WndProc(message, wparam, lparam)
|
||||
: DefWindowProcW(hwnd, message, wparam, lparam);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK nebula::window::NebulaWindowImpl::ChildFrameWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
|
||||
auto old_proc = reinterpret_cast<WNDPROC>(GetPropW(hwnd, kChildFrameHitTestOldProcProp));
|
||||
|
||||
if (message == WM_NCHITTEST) {
|
||||
const auto parent = reinterpret_cast<HWND>(GetPropW(hwnd, kChildFrameHitTestParentProp));
|
||||
auto* self = parent ? reinterpret_cast<NebulaWindowImpl*>(GetWindowLongPtrW(parent, GWLP_USERDATA)) : nullptr;
|
||||
if (self) {
|
||||
const LRESULT hit = self->HitTest(lparam);
|
||||
if (IsResizeHit(hit)) {
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (message == WM_SETCURSOR) {
|
||||
const auto parent = reinterpret_cast<HWND>(GetPropW(hwnd, kChildFrameHitTestParentProp));
|
||||
auto* self = parent ? reinterpret_cast<NebulaWindowImpl*>(GetWindowLongPtrW(parent, GWLP_USERDATA)) : nullptr;
|
||||
POINT point = {};
|
||||
if (self && GetCursorPos(&point) && SetResizeCursor(self->HitTestPoint(point))) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (message == WM_MOUSEMOVE || message == WM_NCMOUSEMOVE) {
|
||||
const auto parent = reinterpret_cast<HWND>(GetPropW(hwnd, kChildFrameHitTestParentProp));
|
||||
auto* self = parent ? reinterpret_cast<NebulaWindowImpl*>(GetWindowLongPtrW(parent, GWLP_USERDATA)) : nullptr;
|
||||
POINT point = {};
|
||||
if (self && GetCursorPos(&point) && SetResizeCursor(self->HitTestPoint(point))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (message == WM_NCLBUTTONDOWN && IsResizeHit(static_cast<LRESULT>(wparam))) {
|
||||
const auto parent = reinterpret_cast<HWND>(GetPropW(hwnd, kChildFrameHitTestParentProp));
|
||||
if (parent) {
|
||||
ReleaseCapture();
|
||||
SendMessageW(parent, WM_NCLBUTTONDOWN, wparam, lparam);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (message == WM_NCDESTROY) {
|
||||
RemovePropW(hwnd, kChildFrameHitTestParentProp);
|
||||
RemovePropW(hwnd, kChildFrameHitTestOldProcProp);
|
||||
if (old_proc) {
|
||||
SetWindowLongPtrW(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(old_proc));
|
||||
}
|
||||
}
|
||||
|
||||
return old_proc ? CallWindowProcW(old_proc, hwnd, message, wparam, lparam)
|
||||
: DefWindowProcW(hwnd, message, wparam, lparam);
|
||||
}
|
||||
|
||||
BOOL CALLBACK nebula::window::NebulaWindowImpl::EnableFrameHitTestForDescendant(HWND hwnd, LPARAM lparam) {
|
||||
const auto* self = reinterpret_cast<const NebulaWindowImpl*>(lparam);
|
||||
if (self) {
|
||||
self->EnableFrameHitTestForWindow(hwnd);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void nebula::window::NebulaWindowImpl::EnableFrameHitTestForWindow(HWND child) const {
|
||||
if (!child || GetPropW(child, kChildFrameHitTestOldProcProp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetPropW(child, kChildFrameHitTestParentProp, hwnd);
|
||||
const auto old_proc = reinterpret_cast<WNDPROC>(
|
||||
SetWindowLongPtrW(child, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&NebulaWindowImpl::ChildFrameWndProc)));
|
||||
if (old_proc) {
|
||||
SetPropW(child, kChildFrameHitTestOldProcProp, reinterpret_cast<HANDLE>(old_proc));
|
||||
} else {
|
||||
RemovePropW(child, kChildFrameHitTestParentProp);
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT nebula::window::NebulaWindowImpl::WndProc(UINT message, WPARAM wparam, LPARAM lparam) {
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
UpdateDpi();
|
||||
if (delegate) {
|
||||
delegate->OnWindowCreated();
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_NCCALCSIZE:
|
||||
if (wparam == TRUE) {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_NCACTIVATE:
|
||||
ApplyWindowFrameStyle(hwnd);
|
||||
return TRUE;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
|
||||
case WM_NCHITTEST:
|
||||
return HitTest(lparam);
|
||||
|
||||
case WM_SETCURSOR: {
|
||||
POINT point = {};
|
||||
if (GetCursorPos(&point) && SetResizeCursor(HitTestPoint(point))) {
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
case WM_NCMOUSEMOVE: {
|
||||
POINT point = {};
|
||||
if (GetCursorPos(&point) && SetResizeCursor(HitTestPoint(point))) {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_SIZE:
|
||||
NotifyResize();
|
||||
return 0;
|
||||
|
||||
case WM_DPICHANGED: {
|
||||
dpi = HIWORD(wparam);
|
||||
const auto* suggested_rect = reinterpret_cast<RECT*>(lparam);
|
||||
SetWindowPos(
|
||||
hwnd,
|
||||
nullptr,
|
||||
suggested_rect->left,
|
||||
suggested_rect->top,
|
||||
suggested_rect->right - suggested_rect->left,
|
||||
suggested_rect->bottom - suggested_rect->top,
|
||||
SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
NotifyResize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_GETMINMAXINFO: {
|
||||
const RECT work_area = GetMonitorWorkArea(hwnd);
|
||||
const RECT monitor_area = GetMonitorArea(hwnd);
|
||||
|
||||
auto* minmax = reinterpret_cast<MINMAXINFO*>(lparam);
|
||||
minmax->ptMaxPosition.x = work_area.left - monitor_area.left;
|
||||
minmax->ptMaxPosition.y = work_area.top - monitor_area.top;
|
||||
minmax->ptMaxSize.x = work_area.right - work_area.left;
|
||||
minmax->ptMaxSize.y = work_area.bottom - work_area.top;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_CLOSE:
|
||||
if (delegate) {
|
||||
delegate->OnWindowCloseRequested();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_COPYDATA: {
|
||||
const auto* copy_data = reinterpret_cast<const COPYDATASTRUCT*>(lparam);
|
||||
if (copy_data && copy_data->dwData == kOpenTargetCopyDataId &&
|
||||
copy_data->lpData && copy_data->cbData >= sizeof(wchar_t)) {
|
||||
const auto* text = static_cast<const wchar_t*>(copy_data->lpData);
|
||||
const size_t char_count = (copy_data->cbData / sizeof(wchar_t)) - 1;
|
||||
if (delegate) {
|
||||
delegate->OnExternalOpenRequested(WideToUtf8(std::wstring_view(text, char_count)));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_DESTROY:
|
||||
hwnd = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wparam, lparam);
|
||||
}
|
||||
|
||||
void nebula::window::NebulaWindowImpl::RegisterClass(HINSTANCE instance_handle) {
|
||||
WNDCLASSEXW window_class = {};
|
||||
window_class.cbSize = sizeof(window_class);
|
||||
window_class.lpfnWndProc = StaticWndProc;
|
||||
window_class.hInstance = instance_handle;
|
||||
window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
window_class.lpszClassName = kWindowClassName;
|
||||
|
||||
RegisterClassExW(&window_class);
|
||||
}
|
||||
|
||||
LRESULT nebula::window::NebulaWindowImpl::HitTest(LPARAM lparam) const {
|
||||
if (!hwnd) {
|
||||
return HTNOWHERE;
|
||||
}
|
||||
|
||||
POINT point = {GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)};
|
||||
return HitTestPoint(point);
|
||||
}
|
||||
|
||||
LRESULT nebula::window::NebulaWindowImpl::HitTestPoint(POINT point) const {
|
||||
if (!hwnd) {
|
||||
return HTNOWHERE;
|
||||
}
|
||||
|
||||
RECT window = {};
|
||||
GetWindowRect(hwnd, &window);
|
||||
|
||||
if (fullscreen || IsZoomed(hwnd)) {
|
||||
return HTCLIENT;
|
||||
}
|
||||
|
||||
const int resize_border = ScaleForDpi(resize_border_dip);
|
||||
const bool left = point.x >= window.left && point.x < window.left + resize_border;
|
||||
const bool right = point.x < window.right && point.x >= window.right - resize_border;
|
||||
const bool top = point.y >= window.top && point.y < window.top + resize_border;
|
||||
const bool bottom = point.y < window.bottom && point.y >= window.bottom - resize_border;
|
||||
|
||||
if (top && left) {
|
||||
return HTTOPLEFT;
|
||||
}
|
||||
if (top && right) {
|
||||
return HTTOPRIGHT;
|
||||
}
|
||||
if (bottom && left) {
|
||||
return HTBOTTOMLEFT;
|
||||
}
|
||||
if (bottom && right) {
|
||||
return HTBOTTOMRIGHT;
|
||||
}
|
||||
if (left) {
|
||||
return HTLEFT;
|
||||
}
|
||||
if (right) {
|
||||
return HTRIGHT;
|
||||
}
|
||||
if (top) {
|
||||
return HTTOP;
|
||||
}
|
||||
if (bottom) {
|
||||
return HTBOTTOM;
|
||||
}
|
||||
|
||||
const int controls_width = ScaleForDpi(kWindowControlWidthDip * kWindowControlCount);
|
||||
const int controls_height = ScaleForDpi(kTitleRowHeightDip);
|
||||
const bool window_controls = point.x >= window.right - controls_width && point.x < window.right &&
|
||||
point.y >= window.top && point.y < window.top + controls_height;
|
||||
if (window_controls) {
|
||||
return HTCLIENT;
|
||||
}
|
||||
|
||||
return HTCLIENT;
|
||||
}
|
||||
|
||||
std::wstring Utf8ToWide(const std::string& value) {
|
||||
if (value.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const int size = MultiByteToWideChar(
|
||||
CP_UTF8, 0, value.data(), static_cast<int>(value.size()), nullptr, 0);
|
||||
std::wstring result(size, L'\0');
|
||||
MultiByteToWideChar(
|
||||
CP_UTF8, 0, value.data(), static_cast<int>(value.size()), result.data(), size);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace nebula::window {
|
||||
|
||||
NebulaWindow::NebulaWindow(WindowDelegate* delegate)
|
||||
: impl_(std::make_unique<NebulaWindowImpl>()) {
|
||||
impl_->delegate = delegate;
|
||||
}
|
||||
|
||||
NebulaWindow::~NebulaWindow() = default;
|
||||
|
||||
bool NebulaWindow::Create(const platform::AppStartup& startup) {
|
||||
impl_->instance = static_cast<HINSTANCE>(startup.instance);
|
||||
impl_->RegisterClass(impl_->instance);
|
||||
|
||||
const RECT work_area = GetWorkArea();
|
||||
impl_->dpi = GetDpiForSystem();
|
||||
const int width =
|
||||
std::min<LONG>(impl_->ScaleForDpi(1400), work_area.right - work_area.left);
|
||||
const int height =
|
||||
std::min<LONG>(impl_->ScaleForDpi(900), work_area.bottom - work_area.top);
|
||||
const int x = work_area.left + ((work_area.right - work_area.left) - width) / 2;
|
||||
const int y = work_area.top + ((work_area.bottom - work_area.top) - height) / 2;
|
||||
|
||||
impl_->hwnd = CreateWindowExW(
|
||||
0,
|
||||
kWindowClassName,
|
||||
kWindowTitle,
|
||||
WS_POPUP | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CLIPCHILDREN,
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
nullptr,
|
||||
nullptr,
|
||||
impl_->instance,
|
||||
impl_.get());
|
||||
|
||||
if (!impl_->hwnd) {
|
||||
return false;
|
||||
}
|
||||
|
||||
impl_->UpdateDpi();
|
||||
ApplyWindowFrameStyle(impl_->hwnd);
|
||||
|
||||
const MARGINS margins = {0, 0, 0, 0};
|
||||
DwmExtendFrameIntoClientArea(impl_->hwnd, &margins);
|
||||
|
||||
ShowWindow(impl_->hwnd, startup.show_command);
|
||||
UpdateWindow(impl_->hwnd);
|
||||
return true;
|
||||
}
|
||||
|
||||
platform::NativeWindow NebulaWindow::native_handle() const {
|
||||
return impl_->hwnd;
|
||||
}
|
||||
|
||||
BrowserLayout NebulaWindow::CurrentLayout(bool show_chrome) const {
|
||||
return impl_->CurrentLayout(show_chrome);
|
||||
}
|
||||
|
||||
void NebulaWindow::ResizeChild(platform::NativeWindow child, const platform::Rect& rect) const {
|
||||
const HWND hwnd = static_cast<HWND>(child);
|
||||
if (!hwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
EnableFrameHitTest(child);
|
||||
const RECT native_rect = ToNativeRect(rect);
|
||||
SetWindowPos(
|
||||
hwnd,
|
||||
nullptr,
|
||||
native_rect.left,
|
||||
native_rect.top,
|
||||
std::max(0L, native_rect.right - native_rect.left),
|
||||
std::max(0L, native_rect.bottom - native_rect.top),
|
||||
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
|
||||
}
|
||||
|
||||
void NebulaWindow::Minimize() {
|
||||
if (impl_->hwnd) {
|
||||
ShowWindow(impl_->hwnd, SW_MINIMIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaWindow::ToggleMaximize() {
|
||||
if (!impl_->hwnd || impl_->fullscreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShowWindow(impl_->hwnd, IsZoomed(impl_->hwnd) ? SW_RESTORE : SW_MAXIMIZE);
|
||||
}
|
||||
|
||||
void NebulaWindow::SetFullscreen(bool fullscreen) {
|
||||
if (!impl_->hwnd || impl_->fullscreen == fullscreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fullscreen) {
|
||||
impl_->restore_style = GetWindowLongPtrW(impl_->hwnd, GWL_STYLE);
|
||||
impl_->restore_ex_style = GetWindowLongPtrW(impl_->hwnd, GWL_EXSTYLE);
|
||||
impl_->restore_placement.length = sizeof(impl_->restore_placement);
|
||||
GetWindowPlacement(impl_->hwnd, &impl_->restore_placement);
|
||||
|
||||
impl_->fullscreen = true;
|
||||
const RECT monitor = GetMonitorArea(impl_->hwnd);
|
||||
SetWindowLongPtrW(
|
||||
impl_->hwnd,
|
||||
GWL_STYLE,
|
||||
impl_->restore_style & ~(WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
|
||||
SetWindowLongPtrW(impl_->hwnd, GWL_EXSTYLE, impl_->restore_ex_style);
|
||||
SetWindowPos(
|
||||
impl_->hwnd,
|
||||
HWND_TOPMOST,
|
||||
monitor.left,
|
||||
monitor.top,
|
||||
monitor.right - monitor.left,
|
||||
monitor.bottom - monitor.top,
|
||||
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||
} else {
|
||||
impl_->fullscreen = false;
|
||||
SetWindowLongPtrW(impl_->hwnd, GWL_STYLE, impl_->restore_style);
|
||||
SetWindowLongPtrW(impl_->hwnd, GWL_EXSTYLE, impl_->restore_ex_style);
|
||||
SetWindowPlacement(impl_->hwnd, &impl_->restore_placement);
|
||||
SetWindowPos(
|
||||
impl_->hwnd,
|
||||
HWND_NOTOPMOST,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||
ApplyWindowFrameStyle(impl_->hwnd);
|
||||
}
|
||||
|
||||
impl_->NotifyResize();
|
||||
}
|
||||
|
||||
void NebulaWindow::Close() {
|
||||
if (impl_->hwnd) {
|
||||
SendMessageW(impl_->hwnd, WM_CLOSE, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void NebulaWindow::BeginDrag() {
|
||||
if (!impl_->hwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReleaseCapture();
|
||||
SendMessageW(impl_->hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
|
||||
}
|
||||
|
||||
void NebulaWindow::SetTitle(const std::string& title) {
|
||||
if (!impl_->hwnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::wstring wide = title.empty() ? kWindowTitle : Utf8ToWide(title);
|
||||
SetWindowTextW(impl_->hwnd, wide.c_str());
|
||||
}
|
||||
|
||||
void NebulaWindow::EnableFrameHitTest(platform::NativeWindow child) const {
|
||||
if (!impl_->hwnd || !child) {
|
||||
return;
|
||||
}
|
||||
|
||||
impl_->EnableFrameHitTestForWindow(static_cast<HWND>(child));
|
||||
EnumChildWindows(
|
||||
static_cast<HWND>(child),
|
||||
&NebulaWindowImpl::EnableFrameHitTestForDescendant,
|
||||
reinterpret_cast<LPARAM>(impl_.get()));
|
||||
}
|
||||
|
||||
} // namespace nebula::window
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "platform/paths_platform.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace nebula::platform {
|
||||
|
||||
std::filesystem::path ExecutableDirectory() {
|
||||
wchar_t exe_path[MAX_PATH] = {};
|
||||
const DWORD length = GetModuleFileNameW(nullptr, exe_path, MAX_PATH);
|
||||
if (length == 0 || length == MAX_PATH) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::filesystem::path(exe_path).parent_path();
|
||||
}
|
||||
|
||||
std::filesystem::path DefaultUserDataRoot() {
|
||||
wchar_t buffer[MAX_PATH] = {};
|
||||
const DWORD length = GetEnvironmentVariableW(L"LOCALAPPDATA", buffer, MAX_PATH);
|
||||
if (length > 0 && length < MAX_PATH) {
|
||||
return std::filesystem::path(buffer);
|
||||
}
|
||||
|
||||
return ExecutableDirectory();
|
||||
}
|
||||
|
||||
std::string PathToUtf8(const std::filesystem::path& path) {
|
||||
const std::wstring wide = path.wstring();
|
||||
if (wide.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const int size = WideCharToMultiByte(
|
||||
CP_UTF8, 0, wide.data(), static_cast<int>(wide.size()), nullptr, 0, nullptr, nullptr);
|
||||
std::string result(size, '\0');
|
||||
WideCharToMultiByte(
|
||||
CP_UTF8, 0, wide.data(), static_cast<int>(wide.size()), result.data(), size, nullptr, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,112 @@
|
||||
#include "platform/startup.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "include/cef_command_line.h"
|
||||
#include "ui/paths.h"
|
||||
|
||||
namespace nebula::platform {
|
||||
namespace {
|
||||
|
||||
constexpr wchar_t kMainInstanceMutexName[] = L"Local\\NebulaBrowserMainInstance";
|
||||
constexpr wchar_t kWindowClassName[] = L"NebulaBrowserWindow";
|
||||
constexpr ULONG_PTR kOpenTargetCopyDataId = 0x4E42554CUL;
|
||||
|
||||
class ScopedHandle {
|
||||
public:
|
||||
explicit ScopedHandle(HANDLE handle) : handle_(handle) {}
|
||||
~ScopedHandle() {
|
||||
if (handle_) {
|
||||
CloseHandle(handle_);
|
||||
}
|
||||
}
|
||||
|
||||
ScopedHandle(const ScopedHandle&) = delete;
|
||||
ScopedHandle& operator=(const ScopedHandle&) = delete;
|
||||
|
||||
bool valid() const { return handle_ != nullptr; }
|
||||
|
||||
private:
|
||||
HANDLE handle_ = nullptr;
|
||||
};
|
||||
|
||||
std::wstring Utf8ToWide(const std::string& value) {
|
||||
if (value.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const int size = MultiByteToWideChar(
|
||||
CP_UTF8, 0, value.data(), static_cast<int>(value.size()), nullptr, 0);
|
||||
if (size <= 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::wstring result(size, L'\0');
|
||||
MultiByteToWideChar(
|
||||
CP_UTF8, 0, value.data(), static_cast<int>(value.size()), result.data(), size);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ForwardLaunchTargetToExistingWindow(const std::string& launch_target) {
|
||||
if (launch_target.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
HWND existing_window = FindWindowW(kWindowClassName, nullptr);
|
||||
if (!existing_window) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::wstring target = Utf8ToWide(launch_target);
|
||||
if (target.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
COPYDATASTRUCT data = {};
|
||||
data.dwData = kOpenTargetCopyDataId;
|
||||
data.cbData = static_cast<DWORD>((target.size() + 1) * sizeof(wchar_t));
|
||||
data.lpData = const_cast<wchar_t*>(target.c_str());
|
||||
SendMessageW(existing_window, WM_COPYDATA, 0, reinterpret_cast<LPARAM>(&data));
|
||||
|
||||
ShowWindow(existing_window, SW_SHOWNORMAL);
|
||||
SetForegroundWindow(existing_window);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void PrepareApp() {
|
||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
}
|
||||
|
||||
bool TryAcquireSingleInstance(const std::string& launch_target) {
|
||||
static ScopedHandle mutex(CreateMutexW(nullptr, TRUE, kMainInstanceMutexName));
|
||||
const bool already_running = mutex.valid() && GetLastError() == ERROR_ALREADY_EXISTS;
|
||||
if (already_running) {
|
||||
ForwardLaunchTargetToExistingWindow(launch_target);
|
||||
}
|
||||
return !already_running;
|
||||
}
|
||||
|
||||
CefMainArgs MakeMainArgs(const AppStartup& startup) {
|
||||
return CefMainArgs(static_cast<HINSTANCE>(startup.instance));
|
||||
}
|
||||
|
||||
void InitCommandLine(CefRefPtr<CefCommandLine> command_line, const AppStartup& startup) {
|
||||
NEBULA_UNUSED(startup);
|
||||
command_line->InitFromString(::GetCommandLineW());
|
||||
}
|
||||
|
||||
void ConfigureCefSettings(CefSettings& settings) {
|
||||
const std::wstring user_data_dir = nebula::ui::GetUserDataDirectory().wstring();
|
||||
const std::wstring cache_dir = nebula::ui::GetCacheDirectory().wstring();
|
||||
if (!user_data_dir.empty()) {
|
||||
CefString(&settings.root_cache_path).FromWString(user_data_dir);
|
||||
}
|
||||
if (!cache_dir.empty()) {
|
||||
CefString(&settings.cache_path).FromWString(cache_dir);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nebula::platform
|
||||
@@ -0,0 +1,281 @@
|
||||
#include "ui/paths.h"
|
||||
|
||||
#include "platform/paths_platform.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <string_view>
|
||||
|
||||
namespace nebula::ui {
|
||||
namespace {
|
||||
|
||||
constexpr std::string_view kNebulaScheme = "nebula://";
|
||||
constexpr std::string_view kInternalFallbackPage = "404.html";
|
||||
|
||||
struct InternalPage {
|
||||
std::string_view slug;
|
||||
std::string_view file_name;
|
||||
};
|
||||
|
||||
constexpr InternalPage kInternalPages[] = {
|
||||
{"home", "home.html"},
|
||||
{"settings", "settings.html"},
|
||||
{"downloads", "downloads.html"},
|
||||
{"bigpicture", "bigpicture.html"},
|
||||
{"big-picture", "bigpicture.html"},
|
||||
{"gpu-diagnostics", "gpu-diagnostics.html"},
|
||||
{"setup", "setup.html"},
|
||||
{"404", "404.html"},
|
||||
{"insecure", "insecure.html"},
|
||||
};
|
||||
|
||||
std::string GetUrlWithoutDecoration(std::string url) {
|
||||
const size_t split = url.find_first_of("?#");
|
||||
if (split != std::string::npos) {
|
||||
url.resize(split);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
std::string GetUrlDecoration(const std::string& url) {
|
||||
const size_t split = url.find_first_of("?#");
|
||||
return split == std::string::npos ? std::string{} : url.substr(split);
|
||||
}
|
||||
|
||||
std::string ToLowerAscii(std::string value) {
|
||||
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char ch) {
|
||||
return static_cast<char>(std::tolower(ch));
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
std::string PageFileUrl(std::string_view page_name) {
|
||||
const auto path = GetUiPagePath(std::string(page_name));
|
||||
return path.empty() ? std::string{} : FilePathToUrl(path);
|
||||
}
|
||||
|
||||
std::string PercentEncode(const std::string& value) {
|
||||
constexpr char kHex[] = "0123456789ABCDEF";
|
||||
std::string encoded;
|
||||
encoded.reserve(value.size());
|
||||
for (unsigned char ch : value) {
|
||||
if (std::isalnum(ch) || ch == '-' || ch == '_' || ch == '.' || ch == '~') {
|
||||
encoded += static_cast<char>(ch);
|
||||
} else {
|
||||
encoded += '%';
|
||||
encoded += kHex[ch >> 4];
|
||||
encoded += kHex[ch & 0x0F];
|
||||
}
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
std::string InternalPageName(const std::string& url) {
|
||||
std::string target = ToLowerAscii(GetUrlWithoutDecoration(url));
|
||||
if (!target.starts_with(kNebulaScheme)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
target.erase(0, kNebulaScheme.size());
|
||||
while (!target.empty() && target.front() == '/') {
|
||||
target.erase(target.begin());
|
||||
}
|
||||
while (!target.empty() && target.back() == '/') {
|
||||
target.pop_back();
|
||||
}
|
||||
return target.empty() ? "home" : target;
|
||||
}
|
||||
|
||||
std::string InternalUrlForSlug(std::string_view slug) {
|
||||
return std::string(kNebulaScheme) + std::string(slug);
|
||||
}
|
||||
|
||||
const InternalPage* FindInternalPageBySlug(std::string_view slug) {
|
||||
for (const auto& page : kInternalPages) {
|
||||
if (page.slug == slug) {
|
||||
return &page;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const InternalPage* FindInternalPageByFileUrl(const std::string& url) {
|
||||
const std::string base_url = GetUrlWithoutDecoration(url);
|
||||
for (const auto& page : kInternalPages) {
|
||||
if (PageFileUrl(page.file_name) == base_url) {
|
||||
return &page;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::filesystem::path GetExecutableDirectory() {
|
||||
return nebula::platform::ExecutableDirectory();
|
||||
}
|
||||
|
||||
std::filesystem::path GetUserDataDirectory() {
|
||||
auto root = nebula::platform::DefaultUserDataRoot();
|
||||
if (root.empty()) {
|
||||
root = GetExecutableDirectory();
|
||||
}
|
||||
if (root.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::filesystem::path user_data = root / "Nebula" / "User Data";
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(user_data, ec);
|
||||
return user_data;
|
||||
}
|
||||
|
||||
std::filesystem::path GetCacheDirectory() {
|
||||
auto user_data = GetUserDataDirectory();
|
||||
if (user_data.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::filesystem::path cache = user_data / "Cache";
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(cache, ec);
|
||||
return cache;
|
||||
}
|
||||
|
||||
std::filesystem::path GetSessionStatePath() {
|
||||
auto user_data = GetUserDataDirectory();
|
||||
return user_data.empty() ? std::filesystem::path{} : user_data / "session_state.json";
|
||||
}
|
||||
|
||||
std::filesystem::path GetFirstRunStatePath() {
|
||||
auto user_data = GetUserDataDirectory();
|
||||
return user_data.empty() ? std::filesystem::path{} : user_data / "first_run_state.json";
|
||||
}
|
||||
|
||||
std::filesystem::path GetUiPagePath(const std::string& page_name) {
|
||||
const auto exe_dir = GetExecutableDirectory();
|
||||
if (exe_dir.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return exe_dir / "ui" / "pages" / page_name;
|
||||
}
|
||||
|
||||
std::string FilePathToUrl(std::filesystem::path path) {
|
||||
std::string value = nebula::platform::PathToUtf8(path);
|
||||
for (char& ch : value) {
|
||||
if (ch == '\\') {
|
||||
ch = '/';
|
||||
}
|
||||
}
|
||||
|
||||
std::string encoded;
|
||||
encoded.reserve(value.size());
|
||||
for (char ch : value) {
|
||||
encoded += ch == ' ' ? "%20" : std::string(1, ch);
|
||||
}
|
||||
return encoded.starts_with('/') ? "file://" + encoded : "file:///" + encoded;
|
||||
}
|
||||
|
||||
std::string GetChromeUrl() {
|
||||
const auto path = GetUiPagePath("chrome.html");
|
||||
const std::string fallback = PageFileUrl("home.html");
|
||||
return path.empty() ? (fallback.empty() ? "https://www.google.com" : fallback) : FilePathToUrl(path);
|
||||
}
|
||||
|
||||
std::string GetHomeUrl() {
|
||||
return InternalUrlForSlug("home");
|
||||
}
|
||||
|
||||
std::string GetSetupUrl() {
|
||||
return InternalUrlForSlug("setup");
|
||||
}
|
||||
|
||||
std::string GetSettingsUrl() {
|
||||
return InternalUrlForSlug("settings");
|
||||
}
|
||||
|
||||
std::string GetDownloadsUrl() {
|
||||
return InternalUrlForSlug("downloads");
|
||||
}
|
||||
|
||||
std::string GetBigPictureUrl() {
|
||||
return InternalUrlForSlug("bigpicture");
|
||||
}
|
||||
|
||||
std::string GetGpuDiagnosticsUrl() {
|
||||
return InternalUrlForSlug("gpu-diagnostics");
|
||||
}
|
||||
|
||||
std::string GetMenuPopupUrl() {
|
||||
const auto path = GetUiPagePath("menu-popup.html");
|
||||
const std::string fallback = PageFileUrl("home.html");
|
||||
return path.empty() ? (fallback.empty() ? "https://www.google.com" : fallback) : FilePathToUrl(path);
|
||||
}
|
||||
|
||||
std::string GetInsecureWarningUrl(const std::string& target_url) {
|
||||
return InternalUrlForSlug("insecure") + "?target=" + PercentEncode(target_url);
|
||||
}
|
||||
|
||||
std::string GetNotFoundUrl(const std::string& target_url) {
|
||||
return InternalUrlForSlug("404") + "?url=" + PercentEncode(target_url);
|
||||
}
|
||||
|
||||
std::string ResolveInternalUrl(const std::string& url) {
|
||||
const std::string page_name = InternalPageName(url);
|
||||
if (page_name.empty()) {
|
||||
return url;
|
||||
}
|
||||
|
||||
if (const auto* page = FindInternalPageBySlug(page_name)) {
|
||||
const std::string file_url = PageFileUrl(page->file_name);
|
||||
return file_url.empty() ? url : file_url + GetUrlDecoration(url);
|
||||
}
|
||||
|
||||
const std::string fallback_url = PageFileUrl(kInternalFallbackPage);
|
||||
return fallback_url.empty() ? url : fallback_url + "?url=" + PercentEncode(url);
|
||||
}
|
||||
|
||||
std::string ToInternalUrl(const std::string& url) {
|
||||
const std::string page_name = InternalPageName(url);
|
||||
if (!page_name.empty()) {
|
||||
if (const auto* page = FindInternalPageBySlug(page_name)) {
|
||||
return InternalUrlForSlug(page->slug) + GetUrlDecoration(url);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
if (const auto* page = FindInternalPageByFileUrl(url)) {
|
||||
return InternalUrlForSlug(page->slug) + GetUrlDecoration(url);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
bool IsInternalHomeUrl(const std::string& url) {
|
||||
return GetUrlWithoutDecoration(ToInternalUrl(url)) == GetHomeUrl();
|
||||
}
|
||||
|
||||
bool IsNebulaInternalUrl(const std::string& url) {
|
||||
return ToLowerAscii(url).starts_with(kNebulaScheme);
|
||||
}
|
||||
|
||||
bool IsHttpUrl(const std::string& url) {
|
||||
return ToLowerAscii(url).starts_with("http://");
|
||||
}
|
||||
|
||||
bool IsChromiumNewTabUrl(const std::string& url) {
|
||||
const std::string target = ToLowerAscii(GetUrlWithoutDecoration(url));
|
||||
return target == "about:blank" ||
|
||||
target == "chrome://newtab" ||
|
||||
target == "chrome://newtab/" ||
|
||||
target == "chrome://new-tab-page" ||
|
||||
target == "chrome://new-tab-page/" ||
|
||||
target == "chrome-search://local-ntp/local-ntp.html";
|
||||
}
|
||||
|
||||
bool IsEmptyOrChromiumNewTabUrl(const std::string& url) {
|
||||
return url.empty() || IsChromiumNewTabUrl(url);
|
||||
}
|
||||
|
||||
} // namespace nebula::ui
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace nebula::ui {
|
||||
|
||||
std::filesystem::path GetExecutableDirectory();
|
||||
std::filesystem::path GetUserDataDirectory();
|
||||
std::filesystem::path GetCacheDirectory();
|
||||
std::filesystem::path GetSessionStatePath();
|
||||
std::filesystem::path GetFirstRunStatePath();
|
||||
std::filesystem::path GetUiPagePath(const std::string& page_name);
|
||||
std::string FilePathToUrl(std::filesystem::path path);
|
||||
std::string GetChromeUrl();
|
||||
std::string GetHomeUrl();
|
||||
std::string GetSetupUrl();
|
||||
std::string GetSettingsUrl();
|
||||
std::string GetDownloadsUrl();
|
||||
std::string GetBigPictureUrl();
|
||||
std::string GetGpuDiagnosticsUrl();
|
||||
std::string GetMenuPopupUrl();
|
||||
std::string GetInsecureWarningUrl(const std::string& target_url);
|
||||
std::string GetNotFoundUrl(const std::string& target_url);
|
||||
std::string ResolveInternalUrl(const std::string& url);
|
||||
std::string ToInternalUrl(const std::string& url);
|
||||
|
||||
bool IsInternalHomeUrl(const std::string& url);
|
||||
bool IsNebulaInternalUrl(const std::string& url);
|
||||
bool IsHttpUrl(const std::string& url);
|
||||
bool IsChromiumNewTabUrl(const std::string& url);
|
||||
bool IsEmptyOrChromiumNewTabUrl(const std::string& url);
|
||||
|
||||
} // namespace nebula::ui
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "platform/types.h"
|
||||
|
||||
namespace nebula::window {
|
||||
|
||||
struct NebulaWindowImpl;
|
||||
|
||||
using BrowserLayout = nebula::platform::BrowserLayout;
|
||||
|
||||
class WindowDelegate {
|
||||
public:
|
||||
virtual ~WindowDelegate() = default;
|
||||
virtual void OnWindowCreated() = 0;
|
||||
virtual void OnWindowResized(const BrowserLayout& layout) = 0;
|
||||
virtual void OnWindowCloseRequested() = 0;
|
||||
virtual void OnExternalOpenRequested(const std::string& target) = 0;
|
||||
};
|
||||
|
||||
class NebulaWindow {
|
||||
public:
|
||||
explicit NebulaWindow(WindowDelegate* delegate);
|
||||
~NebulaWindow();
|
||||
|
||||
bool Create(const nebula::platform::AppStartup& startup);
|
||||
nebula::platform::NativeWindow native_handle() const;
|
||||
BrowserLayout CurrentLayout(bool show_chrome = true) const;
|
||||
|
||||
void ResizeChild(nebula::platform::NativeWindow child, const nebula::platform::Rect& rect) const;
|
||||
void Minimize();
|
||||
void ToggleMaximize();
|
||||
void SetFullscreen(bool fullscreen);
|
||||
void Close();
|
||||
void BeginDrag();
|
||||
void SetTitle(const std::string& title);
|
||||
void EnableFrameHitTest(nebula::platform::NativeWindow child) const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<NebulaWindowImpl> impl_;
|
||||
};
|
||||
|
||||
} // namespace nebula::window
|
||||
+237
-1
@@ -132,6 +132,83 @@ body.mouse-active {
|
||||
left: -100px;
|
||||
}
|
||||
|
||||
.browser-stage-frame {
|
||||
position: fixed;
|
||||
left: var(--browser-stage-x, 20%);
|
||||
top: var(--browser-stage-y, 10%);
|
||||
width: var(--browser-stage-width, 60%);
|
||||
height: var(--browser-stage-height, 80%);
|
||||
z-index: 3;
|
||||
pointer-events: none;
|
||||
border-radius: var(--bp-radius-xl);
|
||||
box-shadow:
|
||||
0 0 0 2px rgba(255, 255, 255, 0.08),
|
||||
0 0 0 6px rgba(123, 46, 255, 0.18),
|
||||
0 24px 80px rgba(0, 0, 0, 0.55),
|
||||
0 0 80px var(--bp-primary-glow);
|
||||
opacity: 1;
|
||||
transition: opacity var(--bp-transition-normal), box-shadow var(--bp-transition-normal);
|
||||
}
|
||||
|
||||
.browser-stage-frame.hidden {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.virtual-cursor {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 250;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
pointer-events: none;
|
||||
transform: translate3d(var(--virtual-cursor-x, 50vw), var(--virtual-cursor-y, 50vh), 0);
|
||||
transition: opacity var(--bp-transition-fast);
|
||||
filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.55));
|
||||
}
|
||||
|
||||
.virtual-cursor.hidden {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.virtual-cursor::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 4px;
|
||||
top: 3px;
|
||||
width: 18px;
|
||||
height: 24px;
|
||||
background: linear-gradient(135deg, var(--bp-text), var(--bp-accent));
|
||||
clip-path: polygon(0 0, 0 100%, 38% 76%, 60% 100%, 84% 86%, 62% 62%, 100% 62%);
|
||||
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.45), 0 0 20px var(--bp-accent-glow);
|
||||
}
|
||||
|
||||
.virtual-cursor-dot {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
top: 10px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 999px;
|
||||
background: var(--bp-primary);
|
||||
opacity: 0;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
.virtual-cursor.clicking .virtual-cursor-dot {
|
||||
animation: virtual-cursor-click 180ms ease-out;
|
||||
}
|
||||
|
||||
.virtual-cursor.right-clicking .virtual-cursor-dot {
|
||||
background: var(--bp-warning);
|
||||
animation: virtual-cursor-click 180ms ease-out;
|
||||
}
|
||||
|
||||
@keyframes virtual-cursor-click {
|
||||
0% { opacity: 0.95; transform: scale(0.8); }
|
||||
100% { opacity: 0; transform: scale(4.4); }
|
||||
}
|
||||
|
||||
@keyframes glow-pulse {
|
||||
0% { transform: scale(1); opacity: 0.3; }
|
||||
100% { transform: scale(1.2); opacity: 0.5; }
|
||||
@@ -220,6 +297,15 @@ body.mouse-active {
|
||||
color: var(--bp-text-muted);
|
||||
}
|
||||
|
||||
.status-icon.controller-status.connected {
|
||||
color: var(--bp-success);
|
||||
box-shadow: 0 0 20px rgba(74, 222, 128, 0.25);
|
||||
}
|
||||
|
||||
.status-icon.controller-status.disconnected {
|
||||
color: var(--bp-text-dim);
|
||||
}
|
||||
|
||||
.status-icon .material-symbols-outlined {
|
||||
font-size: 20px;
|
||||
}
|
||||
@@ -338,8 +424,9 @@ body.mouse-active {
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: var(--bp-bg);
|
||||
background: transparent;
|
||||
z-index: 2;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.webview-container.hidden {
|
||||
@@ -353,6 +440,155 @@ body.mouse-active {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.native-browser-panel {
|
||||
position: absolute;
|
||||
top: var(--bp-spacing-md);
|
||||
right: var(--bp-spacing-md);
|
||||
bottom: var(--bp-spacing-md);
|
||||
width: clamp(168px, 18vw, 260px);
|
||||
overflow-y: auto;
|
||||
padding: var(--bp-spacing-sm);
|
||||
background: linear-gradient(180deg, rgba(10,10,15,0.88) 0%, rgba(20,20,31,0.82) 100%);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
border-radius: var(--bp-radius-lg);
|
||||
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
|
||||
backdrop-filter: blur(20px);
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.native-page-card {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: var(--bp-spacing-sm);
|
||||
padding: var(--bp-spacing-sm);
|
||||
margin-bottom: var(--bp-spacing-md);
|
||||
background: rgba(20, 20, 31, 0.78);
|
||||
border: 2px solid var(--bp-border);
|
||||
border-radius: var(--bp-radius-lg);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.native-page-card:focus,
|
||||
.native-page-card.focused {
|
||||
outline: none;
|
||||
border-color: var(--bp-accent);
|
||||
box-shadow: var(--bp-focus-ring-accent);
|
||||
}
|
||||
|
||||
.native-page-card .material-symbols-outlined {
|
||||
font-size: 28px;
|
||||
color: var(--bp-accent);
|
||||
}
|
||||
|
||||
.native-page-card h2 {
|
||||
font-size: 0.95rem;
|
||||
color: var(--bp-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.native-page-card p {
|
||||
font-size: 0.72rem;
|
||||
color: var(--bp-text-muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.native-page-card .controller-note {
|
||||
grid-column: 1 / -1;
|
||||
margin-top: 4px;
|
||||
color: var(--bp-accent);
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.browser-actions {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: var(--bp-spacing-xs);
|
||||
margin-bottom: var(--bp-spacing-lg);
|
||||
}
|
||||
|
||||
.action-button:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.tab-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--bp-spacing-xs);
|
||||
}
|
||||
|
||||
.bp-tab {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr) auto;
|
||||
grid-template-areas:
|
||||
"dot title close"
|
||||
"dot url close";
|
||||
align-items: center;
|
||||
column-gap: var(--bp-spacing-sm);
|
||||
padding: var(--bp-spacing-sm);
|
||||
background: var(--bp-surface);
|
||||
border: 2px solid var(--bp-border);
|
||||
border-radius: var(--bp-radius-md);
|
||||
color: var(--bp-text);
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.bp-tab.active {
|
||||
border-color: var(--bp-primary);
|
||||
background: var(--bp-surface-active);
|
||||
}
|
||||
|
||||
.bp-tab:focus,
|
||||
.bp-tab.focused {
|
||||
outline: none;
|
||||
border-color: var(--bp-accent);
|
||||
box-shadow: var(--bp-focus-ring-accent);
|
||||
}
|
||||
|
||||
.tab-dot {
|
||||
grid-area: dot;
|
||||
color: var(--bp-accent);
|
||||
}
|
||||
|
||||
.tab-text {
|
||||
grid-area: title;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.tab-url {
|
||||
grid-area: url;
|
||||
color: var(--bp-text-muted);
|
||||
font-size: 0.8rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.tab-close-inline {
|
||||
grid-area: close;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: var(--bp-radius-sm);
|
||||
color: var(--bp-text-muted);
|
||||
}
|
||||
|
||||
.tab-close-inline:hover {
|
||||
background: var(--bp-danger);
|
||||
color: var(--bp-text);
|
||||
}
|
||||
|
||||
/* Content area */
|
||||
.bp-content {
|
||||
flex: 1;
|
||||
|
||||
@@ -0,0 +1,384 @@
|
||||
:root {
|
||||
--bg: #080a0f;
|
||||
--surface: #0e1119;
|
||||
--surface-raised: #141824;
|
||||
--surface-hover: rgba(255, 255, 255, 0.06);
|
||||
--text: #e8e8f0;
|
||||
--muted: #7a7e90;
|
||||
--accent: #7b2eff;
|
||||
--primary: #7b2eff;
|
||||
--accent-2: #00c6ff;
|
||||
--outline: #1f2533;
|
||||
--outline-soft: rgba(255, 255, 255, 0.06);
|
||||
--danger: #e0445c;
|
||||
--url-bar-bg: #1c2030;
|
||||
--url-bar-text: #e0e0e0;
|
||||
--url-bar-border: #3e4652;
|
||||
--tab-bg: #161925;
|
||||
--tab-text: #a4a7b3;
|
||||
--tab-active: #1c2030;
|
||||
--tab-active-text: #e0e0e0;
|
||||
--tab-border: #2b3040;
|
||||
--chrome-hover: color-mix(in srgb, var(--text) 10%, transparent);
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "InterVariable";
|
||||
src: url("../assets/fonts/InterVariable.ttf") format("truetype");
|
||||
font-weight: 100 900;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: "InterVariable", "Segoe UI", system-ui, sans-serif;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
button,
|
||||
input {
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
button {
|
||||
border: 0;
|
||||
color: var(--text);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
cursor: default;
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
/* ── Chrome shell ───────────────────────────────────────────── */
|
||||
|
||||
.nebula-chrome {
|
||||
display: grid;
|
||||
grid-template-rows: 42px 52px 1fr;
|
||||
height: 100%;
|
||||
border-bottom: 1px solid var(--outline);
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
/* ── Title row ──────────────────────────────────────────────── */
|
||||
|
||||
.title-row,
|
||||
.toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.title-row {
|
||||
gap: 10px;
|
||||
padding: 0 0 0 12px;
|
||||
background: var(--bg);
|
||||
}
|
||||
|
||||
.platform-macos .title-row {
|
||||
padding: 0 12px 0 78px;
|
||||
}
|
||||
|
||||
/* ── Tabs ───────────────────────────────────────────────────── */
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
min-width: 0;
|
||||
width: min(260px, 38vw);
|
||||
height: 33px;
|
||||
padding: 0 14px;
|
||||
border-radius: 10px 10px 0 0;
|
||||
border: 1px solid transparent;
|
||||
border-bottom: none;
|
||||
background: transparent;
|
||||
color: var(--tab-text);
|
||||
cursor: pointer;
|
||||
font-size: 0.82rem;
|
||||
transition: background 120ms, color 120ms;
|
||||
}
|
||||
|
||||
.tab:hover:not(.active) {
|
||||
background: var(--tab-bg);
|
||||
color: var(--tab-active-text);
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
background: var(--tab-active);
|
||||
border-color: var(--tab-border);
|
||||
color: var(--tab-active-text);
|
||||
}
|
||||
|
||||
.tab-title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.tab-favicon,
|
||||
.tab-loading {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
flex: 0 0 auto;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.tab-favicon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--primary);
|
||||
opacity: 0.85;
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tab-favicon.has-favicon {
|
||||
background: transparent;
|
||||
border-radius: 3px;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.tab-favicon.empty {
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
}
|
||||
|
||||
.tab-favicon img {
|
||||
display: block;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.tab-loading {
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
border: 2px solid color-mix(in srgb, var(--accent) 20%, transparent);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 999px;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
.tab-close {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
padding: 0;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: var(--tab-text);
|
||||
opacity: 0;
|
||||
transition: background 120ms, color 120ms, opacity 120ms;
|
||||
}
|
||||
|
||||
.tab:hover .tab-close,
|
||||
.tab.active .tab-close,
|
||||
.tab-close:focus-visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.tab-close:hover {
|
||||
background: var(--chrome-hover);
|
||||
color: var(--tab-active-text);
|
||||
}
|
||||
|
||||
.tab-add {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
margin-bottom: 2px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
background: transparent;
|
||||
color: var(--tab-text);
|
||||
transition: background 120ms, color 120ms, border-color 120ms;
|
||||
}
|
||||
|
||||
.tab-add:hover {
|
||||
background: var(--chrome-hover);
|
||||
border-color: var(--tab-border);
|
||||
color: var(--tab-active-text);
|
||||
}
|
||||
|
||||
/* ── Window controls ────────────────────────────────────────── */
|
||||
|
||||
.window-controls {
|
||||
display: flex;
|
||||
align-self: stretch;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
|
||||
.window-controls button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 46px;
|
||||
background: transparent;
|
||||
color: var(--tab-text);
|
||||
transition: background 100ms, color 100ms;
|
||||
}
|
||||
|
||||
.window-controls button:hover {
|
||||
background: var(--chrome-hover);
|
||||
color: var(--tab-active-text);
|
||||
}
|
||||
|
||||
.window-controls .close:hover {
|
||||
background: var(--danger);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.platform-macos .window-controls {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ── Toolbar ────────────────────────────────────────────────── */
|
||||
|
||||
.toolbar {
|
||||
gap: 4px;
|
||||
padding: 0 12px;
|
||||
background: var(--tab-active);
|
||||
border-top: 1px solid var(--tab-border);
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
/* ── Lucide icon sizing ─────────────────────────────────────── */
|
||||
|
||||
/* Lucide replaces <i data-lucide> with <svg>; enforce consistent size */
|
||||
.icon-button svg,
|
||||
.tab-close svg,
|
||||
.tab-add svg,
|
||||
.window-controls svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
display: block;
|
||||
stroke-width: 1.75;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* ── Icon buttons ───────────────────────────────────────────── */
|
||||
|
||||
.icon-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
padding: 0;
|
||||
border-radius: 9px;
|
||||
background: transparent;
|
||||
border: 1px solid transparent;
|
||||
color: var(--tab-text);
|
||||
flex-shrink: 0;
|
||||
transition: background 120ms, color 120ms, border-color 120ms;
|
||||
}
|
||||
|
||||
.icon-button:hover:not(:disabled) {
|
||||
background: var(--chrome-hover);
|
||||
border-color: var(--tab-border);
|
||||
color: var(--tab-active-text);
|
||||
}
|
||||
|
||||
/* ── Address bar ────────────────────────────────────────────── */
|
||||
|
||||
.address-shell {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 160px;
|
||||
height: 36px;
|
||||
flex: 1;
|
||||
margin: 0 4px;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--url-bar-border);
|
||||
border-radius: 10px;
|
||||
background: var(--url-bar-bg);
|
||||
transition: border-color 140ms, box-shadow 140ms;
|
||||
}
|
||||
|
||||
.address-shell:focus-within {
|
||||
border-color: color-mix(in srgb, var(--primary) 70%, var(--url-bar-border));
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
|
||||
}
|
||||
|
||||
.address-shell input {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
padding: 0 16px;
|
||||
background: transparent;
|
||||
color: var(--url-bar-text);
|
||||
font-size: 0.84rem;
|
||||
}
|
||||
|
||||
.address-shell input::placeholder {
|
||||
color: color-mix(in srgb, var(--url-bar-text) 55%, transparent);
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
height: 2px;
|
||||
width: 0%;
|
||||
pointer-events: none;
|
||||
background: var(--accent);
|
||||
border-radius: 0 2px 2px 0;
|
||||
opacity: 0.7;
|
||||
transition: width 120ms ease, opacity 160ms ease;
|
||||
}
|
||||
|
||||
/* ── Utilities ──────────────────────────────────────────────── */
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
+31
-21
@@ -1,34 +1,40 @@
|
||||
:root {
|
||||
--bg: #0b0d10;
|
||||
--primary: #7b2eff;
|
||||
--accent: #00c6ff;
|
||||
--text: #e0e0e0;
|
||||
--url-bar-bg: #1c2030;
|
||||
--url-bar-border: #3e4652;
|
||||
--shadow-1: 0 12px 30px rgba(0, 0, 0, 0.35);
|
||||
--blur: 12px;
|
||||
--surface-raised: #141824;
|
||||
--surface-hover: rgba(255, 255, 255, 0.06);
|
||||
--text: #e8e8f0;
|
||||
--muted: #7a7e90;
|
||||
--outline: #1f2533;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "InterVariable";
|
||||
src: url("../assets/fonts/InterVariable.ttf") format("truetype");
|
||||
font-weight: 100 900;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: transparent;
|
||||
background: var(--surface-raised);
|
||||
color: var(--text);
|
||||
font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
|
||||
font-family: "InterVariable", "Segoe UI", system-ui, sans-serif;
|
||||
overflow: hidden;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#menu-popup {
|
||||
background: color-mix(in srgb, var(--url-bar-bg) 92%, var(--text) 8%);
|
||||
border: 1px solid color-mix(in srgb, var(--primary) 25%, color-mix(in srgb, var(--accent) 18%, transparent));
|
||||
border-radius: 14px;
|
||||
padding: 8px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: var(--surface-raised);
|
||||
border: 1px solid var(--outline);
|
||||
border-radius: 12px;
|
||||
padding: 6px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 220px;
|
||||
box-shadow: var(--shadow-1);
|
||||
-webkit-backdrop-filter: blur(var(--blur));
|
||||
backdrop-filter: blur(var(--blur));
|
||||
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
|
||||
#menu-popup button {
|
||||
@@ -37,13 +43,15 @@ body {
|
||||
color: var(--text);
|
||||
text-align: left;
|
||||
padding: 8px 10px;
|
||||
border-radius: 10px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: background 120ms ease, filter 120ms ease;
|
||||
font: inherit;
|
||||
font-size: 0.84rem;
|
||||
transition: background 120ms ease;
|
||||
}
|
||||
|
||||
#menu-popup button:hover {
|
||||
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||
background: var(--surface-hover);
|
||||
}
|
||||
|
||||
.zoom-controls {
|
||||
@@ -63,4 +71,6 @@ body {
|
||||
#zoom-percent {
|
||||
min-width: 54px;
|
||||
text-align: center;
|
||||
color: var(--muted);
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
+817
-2821
File diff suppressed because it is too large
Load Diff
+301
@@ -0,0 +1,301 @@
|
||||
const SEARCH_URL = 'https://www.google.com/search?q=';
|
||||
|
||||
const DEFAULT_THEME = {
|
||||
colors: {
|
||||
bg: '#080a0f',
|
||||
darkBlue: '#0e1119',
|
||||
darkPurple: '#141824',
|
||||
primary: '#7b2eff',
|
||||
accent: '#00c6ff',
|
||||
text: '#e8e8f0',
|
||||
urlBarBg: '#1c2030',
|
||||
urlBarText: '#e0e0e0',
|
||||
urlBarBorder: '#3e4652',
|
||||
tabBg: '#161925',
|
||||
tabText: '#a4a7b3',
|
||||
tabActive: '#1c2030',
|
||||
tabActiveText: '#e0e0e0',
|
||||
tabBorder: '#2b3040'
|
||||
}
|
||||
};
|
||||
|
||||
const state = {
|
||||
id: 1,
|
||||
url: '',
|
||||
title: 'New Tab',
|
||||
isLoading: false,
|
||||
progress: 0,
|
||||
canGoBack: false,
|
||||
canGoForward: false,
|
||||
favicon: '',
|
||||
platform: detectHostPlatform(),
|
||||
tabs: []
|
||||
};
|
||||
|
||||
function detectHostPlatform() {
|
||||
const platform = `${navigator.userAgentData?.platform || ''} ${navigator.platform || ''} ${navigator.userAgent || ''}`.toLowerCase();
|
||||
if (platform.includes('mac')) return 'macos';
|
||||
if (platform.includes('win')) return 'windows';
|
||||
if (platform.includes('linux')) return 'linux';
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
function applyPlatform(platform) {
|
||||
const normalized = ['macos', 'windows', 'linux'].includes(platform) ? platform : 'unknown';
|
||||
document.body.classList.remove('platform-macos', 'platform-windows', 'platform-linux', 'platform-unknown');
|
||||
document.body.classList.add(`platform-${normalized}`);
|
||||
}
|
||||
|
||||
function hexToRgb(hex) {
|
||||
if (!hex || typeof hex !== 'string') return null;
|
||||
let normalized = hex.trim().replace(/^#/, '');
|
||||
if (normalized.length === 3) {
|
||||
normalized = normalized.split('').map(char => char + char).join('');
|
||||
}
|
||||
if (!/^[a-fA-F\d]{6}$/.test(normalized)) return null;
|
||||
|
||||
const value = parseInt(normalized, 16);
|
||||
return {
|
||||
r: (value >> 16) & 255,
|
||||
g: (value >> 8) & 255,
|
||||
b: value & 255
|
||||
};
|
||||
}
|
||||
|
||||
function isDarkColor(hex) {
|
||||
const rgb = hexToRgb(hex);
|
||||
if (!rgb) return true;
|
||||
const luminance = (0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b) / 255;
|
||||
return luminance < 0.5;
|
||||
}
|
||||
|
||||
function setCssVar(name, value, fallback) {
|
||||
document.documentElement.style.setProperty(name, value || fallback);
|
||||
}
|
||||
|
||||
function normalizeTheme(theme) {
|
||||
const colors = theme?.colors || {};
|
||||
return {
|
||||
...DEFAULT_THEME,
|
||||
...(theme || {}),
|
||||
colors: {
|
||||
...DEFAULT_THEME.colors,
|
||||
...colors
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function applyTheme(theme) {
|
||||
const normalized = normalizeTheme(theme);
|
||||
const colors = normalized.colors;
|
||||
|
||||
setCssVar('--bg', colors.bg, DEFAULT_THEME.colors.bg);
|
||||
setCssVar('--surface', colors.darkBlue, DEFAULT_THEME.colors.darkBlue);
|
||||
setCssVar('--surface-raised', colors.darkPurple, DEFAULT_THEME.colors.darkPurple);
|
||||
setCssVar('--text', colors.text, DEFAULT_THEME.colors.text);
|
||||
setCssVar('--muted', colors.tabText, DEFAULT_THEME.colors.tabText);
|
||||
setCssVar('--primary', colors.primary, DEFAULT_THEME.colors.primary);
|
||||
setCssVar('--accent', colors.accent, DEFAULT_THEME.colors.accent);
|
||||
setCssVar('--accent-2', colors.accent, DEFAULT_THEME.colors.accent);
|
||||
setCssVar('--outline', colors.tabBorder, DEFAULT_THEME.colors.tabBorder);
|
||||
setCssVar('--url-bar-bg', colors.urlBarBg, colors.darkBlue);
|
||||
setCssVar('--url-bar-text', colors.urlBarText, colors.text);
|
||||
setCssVar('--url-bar-border', colors.urlBarBorder, colors.primary);
|
||||
setCssVar('--tab-bg', colors.tabBg, colors.darkBlue);
|
||||
setCssVar('--tab-text', colors.tabText, colors.text);
|
||||
setCssVar('--tab-active', colors.tabActive, colors.darkPurple);
|
||||
setCssVar('--tab-active-text', colors.tabActiveText, colors.text);
|
||||
setCssVar('--tab-border', colors.tabBorder, colors.darkBlue);
|
||||
|
||||
document.documentElement.style.colorScheme = isDarkColor(colors.bg) ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
function applySavedTheme() {
|
||||
try {
|
||||
const savedTheme = localStorage.getItem('currentTheme');
|
||||
if (savedTheme) applyTheme(JSON.parse(savedTheme));
|
||||
} catch (error) {
|
||||
console.warn('[Chrome] Failed to apply saved theme:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function toNavigationUrl(input) {
|
||||
const value = (input || '').trim();
|
||||
if (!value) return null;
|
||||
if (/^(https?:|file:|data:|blob:|chrome:|nebula:\/\/)/i.test(value)) return value;
|
||||
if (value.includes('.') && !/\s/.test(value)) return `https://${value}`;
|
||||
return `${SEARCH_URL}${encodeURIComponent(value)}`;
|
||||
}
|
||||
|
||||
function postCommand(command, payload = '') {
|
||||
if (window.nebulaNative && typeof window.nebulaNative.postMessage === 'function') {
|
||||
window.nebulaNative.postMessage(command, String(payload));
|
||||
}
|
||||
}
|
||||
|
||||
function renderFavicon(favicon, tab) {
|
||||
const url = (tab.favicon || '').trim();
|
||||
favicon.className = 'tab-favicon';
|
||||
favicon.textContent = '';
|
||||
|
||||
if (!url) {
|
||||
favicon.classList.add('empty');
|
||||
return;
|
||||
}
|
||||
|
||||
const image = document.createElement('img');
|
||||
image.alt = '';
|
||||
image.decoding = 'async';
|
||||
image.draggable = false;
|
||||
image.addEventListener('load', () => {
|
||||
favicon.classList.add('has-favicon');
|
||||
});
|
||||
image.addEventListener('error', () => {
|
||||
image.remove();
|
||||
favicon.classList.remove('has-favicon');
|
||||
favicon.classList.add('empty');
|
||||
});
|
||||
|
||||
favicon.append(image);
|
||||
image.src = url;
|
||||
}
|
||||
|
||||
function renderTabs() {
|
||||
const tabsElement = document.querySelector('.tabs');
|
||||
const addButton = tabsElement.querySelector('.tab-add');
|
||||
const tabs = state.tabs.length
|
||||
? state.tabs
|
||||
: [{ id: state.id, title: state.title, isLoading: state.isLoading, favicon: state.favicon }];
|
||||
|
||||
tabsElement.querySelectorAll('.tab').forEach(tab => tab.remove());
|
||||
|
||||
tabs.forEach(tab => {
|
||||
const button = document.createElement('div');
|
||||
const isActive = tab.id === state.id;
|
||||
button.className = `tab${isActive ? ' active' : ''}`;
|
||||
button.setAttribute('role', 'tab');
|
||||
button.setAttribute('aria-selected', String(isActive));
|
||||
button.tabIndex = 0;
|
||||
button.dataset.tabId = String(tab.id);
|
||||
|
||||
const favicon = document.createElement('span');
|
||||
renderFavicon(favicon, tab);
|
||||
|
||||
const title = document.createElement('span');
|
||||
title.className = 'tab-title';
|
||||
title.textContent = tab.title || 'New Tab';
|
||||
|
||||
const loading = document.createElement('span');
|
||||
loading.className = 'tab-loading';
|
||||
loading.hidden = !tab.isLoading;
|
||||
|
||||
const close = document.createElement('button');
|
||||
close.className = 'tab-close';
|
||||
close.type = 'button';
|
||||
close.title = 'Close tab';
|
||||
close.setAttribute('aria-label', `Close ${tab.title || 'New Tab'}`);
|
||||
close.dataset.tabId = String(tab.id);
|
||||
close.innerHTML = '<i data-lucide="x"></i>';
|
||||
|
||||
button.append(favicon, title, loading, close);
|
||||
tabsElement.insertBefore(button, addButton);
|
||||
});
|
||||
|
||||
if (window.lucide) lucide.createIcons({ nodes: [tabsElement] });
|
||||
}
|
||||
|
||||
function applyState(nextState) {
|
||||
Object.assign(state, nextState || {});
|
||||
applyPlatform(state.platform);
|
||||
|
||||
const title = state.title || 'New Tab';
|
||||
const url = state.url || '';
|
||||
const addressInput = document.getElementById('address-input');
|
||||
const backButton = document.getElementById('back-button');
|
||||
const forwardButton = document.getElementById('forward-button');
|
||||
const reloadButton = document.getElementById('reload-button');
|
||||
const progressBar = document.getElementById('progress-bar');
|
||||
|
||||
document.title = `${title} - Nebula`;
|
||||
renderTabs();
|
||||
backButton.disabled = !state.canGoBack;
|
||||
forwardButton.disabled = !state.canGoForward;
|
||||
const reloadIcon = state.isLoading ? 'x' : 'rotate-cw';
|
||||
reloadButton.dataset.command = state.isLoading ? 'stop' : 'reload';
|
||||
reloadButton.innerHTML = `<i data-lucide="${reloadIcon}"></i>`;
|
||||
if (window.lucide) lucide.createIcons({ nodes: [reloadButton] });
|
||||
|
||||
if (document.activeElement !== addressInput) {
|
||||
addressInput.value = url;
|
||||
}
|
||||
|
||||
progressBar.style.width = `${Math.max(0, Math.min(1, state.progress || 0)) * 100}%`;
|
||||
progressBar.style.opacity = state.isLoading ? '1' : '0';
|
||||
|
||||
}
|
||||
|
||||
function wireCommands() {
|
||||
document.querySelector('.tabs').addEventListener('click', event => {
|
||||
const close = event.target.closest('.tab-close[data-tab-id]');
|
||||
if (close) {
|
||||
postCommand('close-tab', close.dataset.tabId);
|
||||
return;
|
||||
}
|
||||
|
||||
const tab = event.target.closest('.tab[data-tab-id]');
|
||||
if (tab && !tab.classList.contains('active')) {
|
||||
postCommand('activate-tab', tab.dataset.tabId);
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector('.tabs').addEventListener('auxclick', event => {
|
||||
if (event.button !== 1) return;
|
||||
|
||||
const tab = event.target.closest('.tab[data-tab-id]');
|
||||
if (tab) {
|
||||
postCommand('close-tab', tab.dataset.tabId);
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-command]').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
postCommand(button.dataset.command);
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-drag-region]').forEach(region => {
|
||||
region.addEventListener('pointerdown', event => {
|
||||
const interactive = event.target.closest('button, input, .tab, .address-shell');
|
||||
if (event.button === 0 && !interactive) {
|
||||
postCommand('drag');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('address-form').addEventListener('submit', event => {
|
||||
event.preventDefault();
|
||||
const input = document.getElementById('address-input');
|
||||
const target = toNavigationUrl(input.value);
|
||||
if (target) {
|
||||
postCommand('navigate', target);
|
||||
input.blur();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.NebulaChrome = { applyState, applyTheme, postCommand, toNavigationUrl };
|
||||
|
||||
window.addEventListener('storage', event => {
|
||||
if (event.key !== 'currentTheme' || !event.newValue) return;
|
||||
try {
|
||||
applyTheme(JSON.parse(event.newValue));
|
||||
} catch (error) {
|
||||
console.warn('[Chrome] Failed to apply updated theme:', error);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
applySavedTheme();
|
||||
wireCommands();
|
||||
applyState(state);
|
||||
});
|
||||
+12
-4
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
class BrowserCustomizer {
|
||||
constructor() {
|
||||
constructor(options = {}) {
|
||||
this.defaultTheme = {
|
||||
name: 'Default',
|
||||
colors: {
|
||||
@@ -286,6 +286,10 @@ class BrowserCustomizer {
|
||||
}
|
||||
};
|
||||
|
||||
if (options.skipInit) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.currentTheme = this.loadTheme();
|
||||
this.activeThemeName = this.loadActiveThemeName();
|
||||
this.init();
|
||||
@@ -584,9 +588,13 @@ class BrowserCustomizer {
|
||||
// This will be called to apply theme to home.html and other pages
|
||||
this.saveTheme();
|
||||
|
||||
// Send theme update to host (for settings webview)
|
||||
if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
window.electronAPI.sendToHost('theme-update', this.currentTheme);
|
||||
const themePayload = JSON.stringify(this.currentTheme);
|
||||
|
||||
// Send theme update to host so the separate chrome browser can update live.
|
||||
if (window.nebulaNative && typeof window.nebulaNative.postMessage === 'function') {
|
||||
window.nebulaNative.postMessage('theme-update', themePayload);
|
||||
} else if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
window.electronAPI.sendToHost('theme-update', themePayload);
|
||||
}
|
||||
// Fallback: send via postMessage (for iframe embedding)
|
||||
try {
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ function applySelectedSearchEngine(engine) {
|
||||
function normalizeNavigationUrl(input) {
|
||||
const value = (input || '').trim();
|
||||
if (!value) return null;
|
||||
if (/^(https?:|file:|data:|blob:)/i.test(value)) return value;
|
||||
if (/^(https?:|file:|data:|blob:|nebula:\/\/)/i.test(value)) return value;
|
||||
if (value.includes('.') && !/\s/.test(value)) return `https://${value}`;
|
||||
return `${searchEngines[selectedSearchEngine]}${encodeURIComponent(value)}`;
|
||||
}
|
||||
|
||||
Vendored
+12
File diff suppressed because one or more lines are too long
+19
-16
@@ -17,33 +17,36 @@ function applyTheme(theme) {
|
||||
setCssVar('--url-bar-border', colors.urlBarBorder, '#3e4652');
|
||||
}
|
||||
|
||||
async function refreshZoom() {
|
||||
if (!window.electronAPI?.invoke || !zoomPercentEl) return;
|
||||
try {
|
||||
const z = await window.electronAPI.invoke('get-zoom-factor');
|
||||
zoomPercentEl.textContent = `${Math.round(z * 100)}%`;
|
||||
} catch {}
|
||||
function sendMenuCommand(cmd) {
|
||||
if (window.nebulaNative?.postMessage) {
|
||||
window.nebulaNative.postMessage(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
window.electronAPI?.on?.('menu-popup-init', (payload) => {
|
||||
applyTheme(payload?.theme);
|
||||
refreshZoom();
|
||||
});
|
||||
function formatZoomPercent(zoomLevel) {
|
||||
const level = Number.isFinite(zoomLevel) ? zoomLevel : 0;
|
||||
return `${Math.round(Math.pow(1.2, level) * 100)}%`;
|
||||
}
|
||||
|
||||
function setZoomLevel(zoomLevel) {
|
||||
if (zoomPercentEl) {
|
||||
zoomPercentEl.textContent = formatZoomPercent(zoomLevel);
|
||||
}
|
||||
}
|
||||
|
||||
window.NebulaMenuPopup = { applyTheme, setZoomLevel };
|
||||
|
||||
window.addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('button[data-cmd]');
|
||||
if (!btn) return;
|
||||
const cmd = btn.getAttribute('data-cmd');
|
||||
window.electronAPI?.send?.('menu-popup-command', { cmd });
|
||||
if (cmd === 'zoom-in' || cmd === 'zoom-out') {
|
||||
setTimeout(refreshZoom, 50);
|
||||
}
|
||||
sendMenuCommand(cmd);
|
||||
});
|
||||
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') {
|
||||
window.electronAPI?.send?.('menu-popup-command', { cmd: 'close' });
|
||||
sendMenuCommand('close-menu-popup');
|
||||
}
|
||||
});
|
||||
|
||||
refreshZoom();
|
||||
setZoomLevel(0);
|
||||
|
||||
+112
-3
@@ -12,6 +12,109 @@ const HOME_SEARCH_Y_KEY = 'nebula-home-search-y'; // number (vh)
|
||||
const HOME_BOOKMARKS_Y_KEY = 'nebula-home-bookmarks-y'; // number (vh)
|
||||
const HOME_GLANCE_CORNER_KEY = 'nebula-home-glance-corner'; // 'br'|'bl'|'tr'|'tl'
|
||||
const DISPLAY_SCALE_KEY = 'nebula-display-scale'; // number (50-300)
|
||||
const defaultBrowserRequests = new Map();
|
||||
let defaultBrowserRequestId = 0;
|
||||
|
||||
function hasNebulaNativeBridge() {
|
||||
return !!(window.nebulaNative && typeof window.nebulaNative.postMessage === 'function');
|
||||
}
|
||||
|
||||
window.addEventListener('nebula-default-browser-result', (event) => {
|
||||
const detail = event.detail || {};
|
||||
const pending = defaultBrowserRequests.get(detail.requestId);
|
||||
if (!pending) return;
|
||||
|
||||
defaultBrowserRequests.delete(detail.requestId);
|
||||
pending.resolve(detail);
|
||||
});
|
||||
|
||||
function sendDefaultBrowserRequest(command) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!hasNebulaNativeBridge()) {
|
||||
reject(new Error('Native browser integration is unavailable.'));
|
||||
return;
|
||||
}
|
||||
|
||||
const requestId = `settings-default-browser-${Date.now()}-${++defaultBrowserRequestId}`;
|
||||
const timeout = setTimeout(() => {
|
||||
defaultBrowserRequests.delete(requestId);
|
||||
reject(new Error('Timed out waiting for default browser status.'));
|
||||
}, 10000);
|
||||
|
||||
defaultBrowserRequests.set(requestId, {
|
||||
resolve: (value) => {
|
||||
clearTimeout(timeout);
|
||||
resolve(value);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
window.nebulaNative.postMessage(command, requestId);
|
||||
} catch (error) {
|
||||
defaultBrowserRequests.delete(requestId);
|
||||
clearTimeout(timeout);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function refreshDefaultBrowserStatus() {
|
||||
const btn = document.getElementById('set-default-browser-btn');
|
||||
const status = document.getElementById('default-browser-status');
|
||||
if (!btn || !status) return;
|
||||
|
||||
if (!hasNebulaNativeBridge()) {
|
||||
btn.disabled = true;
|
||||
status.textContent = 'Default browser setup is only available in the native app.';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await sendDefaultBrowserRequest('check-default-browser');
|
||||
btn.disabled = !!result.isDefault;
|
||||
btn.textContent = result.isDefault ? 'Already Default' : 'Make Default Browser';
|
||||
status.textContent = result.isDefault
|
||||
? 'Nebula is your default browser.'
|
||||
: 'Nebula is not your default browser.';
|
||||
} catch (error) {
|
||||
console.error('Default browser status error:', error);
|
||||
status.textContent = 'Unable to check default browser status.';
|
||||
}
|
||||
}
|
||||
|
||||
function attachDefaultBrowserHandler() {
|
||||
const btn = document.getElementById('set-default-browser-btn');
|
||||
const status = document.getElementById('default-browser-status');
|
||||
if (!btn || !status) return;
|
||||
|
||||
btn.addEventListener('click', async () => {
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Opening Settings...';
|
||||
status.textContent = 'Opening Windows default apps settings...';
|
||||
|
||||
try {
|
||||
const result = await sendDefaultBrowserRequest('set-default-browser');
|
||||
if (result.isDefault) {
|
||||
btn.textContent = 'Already Default';
|
||||
status.textContent = 'Nebula is your default browser.';
|
||||
return;
|
||||
}
|
||||
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Check Again';
|
||||
status.textContent = result.success
|
||||
? 'Choose Nebula in Windows default apps settings, then check again.'
|
||||
: (result.error || 'Unable to open default browser settings.');
|
||||
} catch (error) {
|
||||
console.error('Default browser setup error:', error);
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Try Again';
|
||||
status.textContent = 'Unable to open default browser settings.';
|
||||
}
|
||||
});
|
||||
|
||||
refreshDefaultBrowserStatus();
|
||||
}
|
||||
|
||||
function showStatus(message) {
|
||||
if (statusText && statusDiv) {
|
||||
@@ -65,7 +168,7 @@ function attachClearHandler(btn) {
|
||||
} finally {
|
||||
const currentTheme = window.browserCustomizer ? window.browserCustomizer.currentTheme : null;
|
||||
if (currentTheme && window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
window.electronAPI.sendToHost('theme-update', currentTheme);
|
||||
window.electronAPI.sendToHost('theme-update', JSON.stringify(currentTheme));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -74,6 +177,8 @@ function attachClearHandler(btn) {
|
||||
// Try attaching immediately, and again on DOMContentLoaded
|
||||
attachClearHandler(clearBtn);
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
attachDefaultBrowserHandler();
|
||||
|
||||
if (!clearBtn) {
|
||||
clearBtn = document.getElementById('clear-data-btn');
|
||||
attachClearHandler(clearBtn);
|
||||
@@ -773,7 +878,9 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
try {
|
||||
e.preventDefault();
|
||||
const url = gh.getAttribute('href');
|
||||
if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
if (window.nebulaNative && typeof window.nebulaNative.postMessage === 'function') {
|
||||
window.nebulaNative.postMessage('new-tab', url);
|
||||
} else if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
window.electronAPI.sendToHost('navigate', url, { newTab: true });
|
||||
} else if (window.parent && window.parent !== window) {
|
||||
window.parent.postMessage({ type: 'navigate', url, newTab: true }, '*');
|
||||
@@ -792,7 +899,9 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||
try {
|
||||
e.preventDefault();
|
||||
const url = help.getAttribute('href');
|
||||
if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
if (window.nebulaNative && typeof window.nebulaNative.postMessage === 'function') {
|
||||
window.nebulaNative.postMessage('new-tab', url);
|
||||
} else if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
window.electronAPI.sendToHost('navigate', url, { newTab: true });
|
||||
} else if (window.parent && window.parent !== window) {
|
||||
window.parent.postMessage({ type: 'navigate', url, newTab: true }, '*');
|
||||
|
||||
+146
-21
@@ -12,17 +12,130 @@ const setupState = {
|
||||
themes: []
|
||||
};
|
||||
|
||||
const nativeApi = window.api || {
|
||||
async getAllThemes() {
|
||||
return {
|
||||
default: {
|
||||
default: {
|
||||
name: 'Default',
|
||||
description: 'Classic Nebula theme',
|
||||
colors: { bg: '#121418', primary: '#7B2EFF', accent: '#00C6FF', text: '#E0E0E0' }
|
||||
}
|
||||
function hasNebulaNativeBridge() {
|
||||
return !!(window.nebulaNative && typeof window.nebulaNative.postMessage === 'function');
|
||||
}
|
||||
|
||||
const defaultBrowserRequests = new Map();
|
||||
let defaultBrowserRequestId = 0;
|
||||
|
||||
window.addEventListener('nebula-default-browser-result', (event) => {
|
||||
const detail = event.detail || {};
|
||||
const pending = defaultBrowserRequests.get(detail.requestId);
|
||||
if (!pending) return;
|
||||
|
||||
defaultBrowserRequests.delete(detail.requestId);
|
||||
pending.resolve(detail);
|
||||
});
|
||||
|
||||
function sendDefaultBrowserRequest(command) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!hasNebulaNativeBridge()) {
|
||||
reject(new Error('Native browser integration is unavailable.'));
|
||||
return;
|
||||
}
|
||||
|
||||
const requestId = `default-browser-${Date.now()}-${++defaultBrowserRequestId}`;
|
||||
const timeout = setTimeout(() => {
|
||||
defaultBrowserRequests.delete(requestId);
|
||||
reject(new Error('Timed out waiting for default browser status.'));
|
||||
}, 10000);
|
||||
|
||||
defaultBrowserRequests.set(requestId, {
|
||||
resolve: (value) => {
|
||||
clearTimeout(timeout);
|
||||
resolve(value);
|
||||
},
|
||||
reject: (error) => {
|
||||
clearTimeout(timeout);
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
try {
|
||||
window.nebulaNative.postMessage(command, requestId);
|
||||
} catch (error) {
|
||||
defaultBrowserRequests.delete(requestId);
|
||||
clearTimeout(timeout);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createNebulaNativeApi() {
|
||||
return {
|
||||
async getAllThemes() {
|
||||
return { default: getPresetThemes() };
|
||||
},
|
||||
async isDefaultBrowser() {
|
||||
const result = await sendDefaultBrowserRequest('check-default-browser');
|
||||
return !!result.isDefault;
|
||||
},
|
||||
async setAsDefaultBrowser() {
|
||||
return sendDefaultBrowserRequest('set-default-browser');
|
||||
},
|
||||
async applyTheme(themeId) {
|
||||
const theme = getThemeById(themeId);
|
||||
if (theme) {
|
||||
localStorage.setItem('currentTheme', JSON.stringify(normalizeTheme(theme)));
|
||||
}
|
||||
localStorage.setItem('activeThemeName', themeId);
|
||||
},
|
||||
async completeFirstRun(data) {
|
||||
localStorage.setItem('nebula-first-run-complete', JSON.stringify(data));
|
||||
window.nebulaNative.postMessage('complete-first-run', JSON.stringify(data));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getPresetThemes() {
|
||||
if (typeof BrowserCustomizer === 'function') {
|
||||
const customizer = new BrowserCustomizer({ skipInit: true });
|
||||
return customizer.predefinedThemes || { default: customizer.defaultTheme };
|
||||
}
|
||||
|
||||
return {
|
||||
default: {
|
||||
name: 'Default',
|
||||
colors: {
|
||||
bg: '#121418',
|
||||
darkBlue: '#0B1C2B',
|
||||
darkPurple: '#1B1035',
|
||||
primary: '#7B2EFF',
|
||||
accent: '#00C6FF',
|
||||
text: '#E0E0E0',
|
||||
urlBarBg: '#1C2030',
|
||||
urlBarText: '#E0E0E0',
|
||||
urlBarBorder: '#3E4652',
|
||||
tabBg: '#161925',
|
||||
tabText: '#A4A7B3',
|
||||
tabActive: '#1C2030',
|
||||
tabActiveText: '#E0E0E0',
|
||||
tabBorder: '#2B3040'
|
||||
},
|
||||
layout: 'centered',
|
||||
showLogo: true,
|
||||
customTitle: 'Nebula Browser',
|
||||
gradient: 'linear-gradient(145deg, #121418 0%, #1B1035 100%)'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeTheme(theme) {
|
||||
const fallback = getPresetThemes().default;
|
||||
return {
|
||||
...fallback,
|
||||
...(theme || {}),
|
||||
colors: {
|
||||
...fallback.colors,
|
||||
...((theme && theme.colors) || {})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const fallbackApi = {
|
||||
async getAllThemes() {
|
||||
return { default: getPresetThemes() };
|
||||
},
|
||||
async isDefaultBrowser() {
|
||||
return false;
|
||||
@@ -31,13 +144,22 @@ const nativeApi = window.api || {
|
||||
return { success: false, error: 'Default browser setup is handled by the native CEF app.' };
|
||||
},
|
||||
async applyTheme(themeId) {
|
||||
const theme = getThemeById(themeId);
|
||||
if (theme) {
|
||||
localStorage.setItem('currentTheme', JSON.stringify(normalizeTheme(theme)));
|
||||
}
|
||||
localStorage.setItem('activeThemeName', themeId);
|
||||
},
|
||||
async completeFirstRun(data) {
|
||||
localStorage.setItem('nebula-first-run-complete', JSON.stringify(data));
|
||||
if (hasNebulaNativeBridge()) {
|
||||
window.nebulaNative.postMessage('complete-first-run', JSON.stringify(data));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const nativeApi = window.api || (hasNebulaNativeBridge() ? createNebulaNativeApi() : fallbackApi);
|
||||
|
||||
// Initialize setup when DOM is ready
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
console.log('[Setup] Initializing first-time setup...');
|
||||
@@ -67,9 +189,7 @@ async function loadThemes() {
|
||||
console.error('[Setup] Error loading themes:', error);
|
||||
// Fallback to a default theme
|
||||
setupState.themes = {
|
||||
default: {
|
||||
default: { name: 'Default', description: 'Classic Nebula theme', colors: { bg: '#121418', primary: '#7B2EFF', accent: '#00C6FF' } }
|
||||
}
|
||||
default: getPresetThemes()
|
||||
};
|
||||
renderThemeGrid(setupState.themes);
|
||||
}
|
||||
@@ -167,8 +287,9 @@ function hexToRgb(hex) {
|
||||
* Apply theme to the setup page UI and persist selection
|
||||
*/
|
||||
function applyThemeToSetupPage(theme, themeId = null) {
|
||||
if (!theme || !theme.colors) return;
|
||||
const colors = theme.colors;
|
||||
const completeTheme = normalizeTheme(theme);
|
||||
if (!completeTheme || !completeTheme.colors) return;
|
||||
const colors = completeTheme.colors;
|
||||
const root = document.documentElement;
|
||||
|
||||
const setVar = (cssVar, value, fallback) => {
|
||||
@@ -202,15 +323,15 @@ function applyThemeToSetupPage(theme, themeId = null) {
|
||||
setVar('--warning-rgb', `${warningRgb.r}, ${warningRgb.g}, ${warningRgb.b}`);
|
||||
}
|
||||
|
||||
if (theme.gradient) {
|
||||
document.body.style.background = theme.gradient;
|
||||
if (completeTheme.gradient) {
|
||||
document.body.style.background = completeTheme.gradient;
|
||||
} else if (colors.bg) {
|
||||
document.body.style.background = colors.bg;
|
||||
}
|
||||
|
||||
// Persist for main UI to pick up on first load
|
||||
try {
|
||||
localStorage.setItem('currentTheme', JSON.stringify(theme));
|
||||
localStorage.setItem('currentTheme', JSON.stringify(completeTheme));
|
||||
if (themeId) localStorage.setItem('activeThemeName', themeId);
|
||||
} catch (err) {
|
||||
console.warn('[Setup] Failed to persist theme:', err);
|
||||
@@ -355,7 +476,7 @@ async function setDefaultBrowser() {
|
||||
const result = await nativeApi.setAsDefaultBrowser();
|
||||
|
||||
if (result.success) {
|
||||
const isDefault = await window.api.isDefaultBrowser();
|
||||
const isDefault = !!result.isDefault || await nativeApi.isDefaultBrowser();
|
||||
if (isDefault) {
|
||||
setupState.defaultBrowserSet = true;
|
||||
|
||||
@@ -499,7 +620,9 @@ async function completeSetup() {
|
||||
|
||||
console.log('[Setup] First-time setup completed successfully');
|
||||
|
||||
window.location.href = 'home.html';
|
||||
if (!hasNebulaNativeBridge()) {
|
||||
window.location.href = 'home.html';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[Setup] Error completing setup:', error);
|
||||
alert('There was an error saving your preferences. Please try again.');
|
||||
@@ -522,7 +645,9 @@ async function skipSetup() {
|
||||
|
||||
console.log('[Setup] Setup skipped, using defaults');
|
||||
|
||||
window.location.href = 'home.html';
|
||||
if (!hasNebulaNativeBridge()) {
|
||||
window.location.href = 'home.html';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[Setup] Error skipping setup:', error);
|
||||
window.location.href = 'home.html';
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@
|
||||
const attemptedUrl = params.get('url');
|
||||
const box = document.getElementById('targetBox');
|
||||
if (attemptedUrl) {
|
||||
box.textContent = decodeURIComponent(attemptedUrl);
|
||||
box.textContent = attemptedUrl;
|
||||
} else {
|
||||
box.textContent = 'Unknown URL';
|
||||
}
|
||||
|
||||
+21
-22
@@ -26,6 +26,10 @@
|
||||
<div class="bg-particles"></div>
|
||||
<div class="bg-glow"></div>
|
||||
</div>
|
||||
<div id="browser-stage-frame" class="browser-stage-frame hidden" aria-hidden="true"></div>
|
||||
<div id="virtual-cursor" class="virtual-cursor hidden" aria-hidden="true">
|
||||
<div class="virtual-cursor-dot"></div>
|
||||
</div>
|
||||
|
||||
<!-- Top header bar -->
|
||||
<header class="bp-header">
|
||||
@@ -41,6 +45,9 @@
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<div class="status-icons">
|
||||
<span id="bp-controller-status" class="status-icon controller-status disconnected" title="Controller disconnected">
|
||||
<span class="material-symbols-outlined">sports_esports</span>
|
||||
</span>
|
||||
<span id="bp-wifi" class="status-icon" title="Connected">
|
||||
<span class="material-symbols-outlined">wifi</span>
|
||||
</span>
|
||||
@@ -123,13 +130,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Recent sites -->
|
||||
<div class="recent-sites">
|
||||
<h2 class="subsection-title">Continue Browsing</h2>
|
||||
<div class="horizontal-scroll" id="recentSitesScroll">
|
||||
<!-- Recent sites will be populated dynamically -->
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Browse section (for webview) -->
|
||||
@@ -162,20 +162,19 @@
|
||||
<section id="section-history" class="bp-section">
|
||||
<div class="section-header">
|
||||
<h1 class="section-title">History</h1>
|
||||
<p class="section-subtitle">Recently visited sites</p>
|
||||
<p class="section-subtitle">Recently visited sites from this profile</p>
|
||||
</div>
|
||||
<div class="section-actions">
|
||||
<button class="action-btn" id="clearHistoryBtn" data-focusable tabindex="0">
|
||||
<span class="material-symbols-outlined">delete_sweep</span>
|
||||
<button class="action-btn danger" id="bp-clear-history" data-focusable tabindex="0">
|
||||
<span class="material-symbols-outlined">delete</span>
|
||||
<span>Clear History</span>
|
||||
</button>
|
||||
<button class="action-btn" id="refreshHistoryBtn" data-focusable tabindex="0">
|
||||
<span class="material-symbols-outlined">refresh</span>
|
||||
<span>Refresh</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="list-container" id="historyList">
|
||||
<!-- History will be populated dynamically -->
|
||||
<div class="empty-state">
|
||||
<span class="material-symbols-outlined">history</span>
|
||||
<p>No browsing history</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -364,7 +363,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="option-control">
|
||||
<button class="action-button" id="bp-clear-history" data-focusable tabindex="0">
|
||||
<button class="action-button" id="bp-clear-history-settings" data-focusable tabindex="0">
|
||||
<span class="material-symbols-outlined">delete</span>
|
||||
<span>Clear</span>
|
||||
</button>
|
||||
@@ -435,28 +434,28 @@
|
||||
|
||||
<!-- Bottom controller hints -->
|
||||
<footer class="bp-footer">
|
||||
<div class="controller-hints">
|
||||
<div class="controller-hints" id="controller-hints">
|
||||
<div class="hint">
|
||||
<span class="controller-btn dpad">
|
||||
<span class="material-symbols-outlined">gamepad</span>
|
||||
</span>
|
||||
<span>Navigate</span>
|
||||
<span id="hint-navigate">Navigate</span>
|
||||
</div>
|
||||
<div class="hint">
|
||||
<span class="controller-btn a-btn">A</span>
|
||||
<span>Select</span>
|
||||
<span id="hint-a">Select</span>
|
||||
</div>
|
||||
<div class="hint">
|
||||
<span class="controller-btn b-btn">B</span>
|
||||
<span>Back</span>
|
||||
<span id="hint-b">Back</span>
|
||||
</div>
|
||||
<div class="hint">
|
||||
<span class="controller-btn y-btn">Y</span>
|
||||
<span>Search</span>
|
||||
<span id="hint-y">Search</span>
|
||||
</div>
|
||||
<div class="hint">
|
||||
<span class="controller-btn menu-btn">☰</span>
|
||||
<span>Menu</span>
|
||||
<span id="hint-menu">Menu</span>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Nebula Chrome</title>
|
||||
<link rel="stylesheet" href="../css/chrome.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="nebula-chrome" data-drag-region>
|
||||
<div class="title-row" data-drag-region>
|
||||
<div class="tabs" role="tablist" aria-label="Nebula tabs">
|
||||
<button id="active-tab" class="tab active" type="button" role="tab" aria-selected="true">
|
||||
<span id="tab-favicon" class="tab-favicon"></span>
|
||||
<span id="tab-title" class="tab-title">New Tab</span>
|
||||
<span id="tab-loading" class="tab-loading" hidden></span>
|
||||
</button>
|
||||
<button class="tab-add" type="button" data-command="new-tab" title="New tab" aria-label="New tab">
|
||||
<i data-lucide="plus"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="window-controls" aria-label="Window controls">
|
||||
<button type="button" data-command="minimize" aria-label="Minimize">
|
||||
<i data-lucide="minus"></i>
|
||||
</button>
|
||||
<button type="button" data-command="maximize" aria-label="Maximize">
|
||||
<i data-lucide="square"></i>
|
||||
</button>
|
||||
<button type="button" data-command="close" class="close" aria-label="Close">
|
||||
<i data-lucide="x"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toolbar">
|
||||
<button id="back-button" class="icon-button" type="button" data-command="back" aria-label="Back" disabled>
|
||||
<i data-lucide="chevron-left"></i>
|
||||
</button>
|
||||
<button id="forward-button" class="icon-button" type="button" data-command="forward" aria-label="Forward" disabled>
|
||||
<i data-lucide="chevron-right"></i>
|
||||
</button>
|
||||
<button id="reload-button" class="icon-button" type="button" data-command="reload" aria-label="Reload">
|
||||
<i data-lucide="rotate-cw"></i>
|
||||
</button>
|
||||
<button class="icon-button" type="button" data-command="home" aria-label="Home">
|
||||
<i data-lucide="home"></i>
|
||||
</button>
|
||||
|
||||
<form id="address-form" class="address-shell" autocomplete="off">
|
||||
<div id="progress-bar" class="progress-bar"></div>
|
||||
<label class="sr-only" for="address-input">Search or enter address</label>
|
||||
<input id="address-input" type="text" spellcheck="false" placeholder="Search or enter address">
|
||||
</form>
|
||||
|
||||
<button class="icon-button" type="button" data-command="settings" aria-label="Settings">
|
||||
<i data-lucide="settings"></i>
|
||||
</button>
|
||||
<button class="icon-button menu-button" type="button" data-command="menu-popup" aria-label="Open menu" title="Open menu">
|
||||
<i data-lucide="menu"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../js/lucide.min.js"></script>
|
||||
<script>lucide.createIcons();</script>
|
||||
<script src="../js/chrome.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+935
-201
File diff suppressed because it is too large
Load Diff
@@ -62,6 +62,10 @@
|
||||
const box = document.getElementById('targetBox');
|
||||
if (target) box.textContent = target;
|
||||
function sendNavigate(url, opts){
|
||||
if (opts && opts.insecureBypass && window.nebulaNative && window.nebulaNative.postMessage){
|
||||
window.nebulaNative.postMessage('navigate-insecure', url);
|
||||
return;
|
||||
}
|
||||
if (window.electronAPI && window.electronAPI.sendToHost){
|
||||
window.electronAPI.sendToHost('navigate', url, opts||{});
|
||||
} else if (window.parent && window.parent !== window) {
|
||||
|
||||
+19
-14
@@ -1,23 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Menu</title>
|
||||
<link rel="stylesheet" href="../css/menu-popup.css" />
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Nebula Menu</title>
|
||||
<link rel="stylesheet" href="../css/menu-popup.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="menu-popup" role="menu">
|
||||
<button data-cmd="open-settings" role="menuitem">Settings</button>
|
||||
<button data-cmd="big-picture" role="menuitem">🎮 Big Picture Mode</button>
|
||||
<button data-cmd="toggle-devtools" role="menuitem">Toggle Developer Tools</button>
|
||||
<div class="zoom-controls" role="group" aria-label="Zoom controls">
|
||||
<button data-cmd="zoom-out" aria-label="Zoom out">-</button>
|
||||
<main id="menu-popup" role="menu" aria-label="Nebula browser menu">
|
||||
<button type="button" role="menuitem" data-cmd="open-settings">Settings</button>
|
||||
<button type="button" role="menuitem" data-cmd="gpu-diagnostics">GPU diagnostics</button>
|
||||
<button type="button" role="menuitem" data-cmd="big-picture">Big Picture mode</button>
|
||||
<button type="button" role="menuitem" data-cmd="toggle-devtools">Developer tools</button>
|
||||
|
||||
<div class="zoom-controls" aria-label="Page zoom">
|
||||
<button type="button" data-cmd="zoom-out" aria-label="Zoom out">-</button>
|
||||
<span id="zoom-percent">100%</span>
|
||||
<button data-cmd="zoom-in" aria-label="Zoom in">+</button>
|
||||
<button type="button" data-cmd="zoom-in" aria-label="Zoom in">+</button>
|
||||
</div>
|
||||
<button data-cmd="hard-reload" role="menuitem">Hard Reload (Ignore Cache)</button>
|
||||
<button data-cmd="fresh-reload" role="menuitem">Reload Fresh (Add Cache-Buster)</button>
|
||||
</div>
|
||||
|
||||
<button type="button" role="menuitem" data-cmd="hard-reload">Hard reload</button>
|
||||
<button type="button" role="menuitem" data-cmd="fresh-reload">Fresh reload</button>
|
||||
</main>
|
||||
|
||||
<script src="../js/menu-popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Nebot</title>
|
||||
<link rel="stylesheet" href="../plugins/nebot/page.css" onerror="this.remove()"/>
|
||||
<style>
|
||||
body { margin:0; font-family: system-ui,-apple-system,Segoe UI,Roboto,sans-serif; background:#12141c; color:#e6e8ef; }
|
||||
.fallback { max-width:620px; margin:60px auto; padding:32px 36px; background:#1d222e; border:1px solid rgba(255,255,255,0.08); border-radius:18px; }
|
||||
.fallback h1 { margin:0 0 12px; font-size:28px; background:linear-gradient(90deg,#a48bff,#6cb6ff); -webkit-background-clip:text; color:transparent; }
|
||||
.fallback p { line-height:1.55; }
|
||||
.tip { background:#232b38; padding:10px 14px; border-radius:10px; font-size:13px; margin-top:18px; border:1px solid rgba(255,255,255,0.08); }
|
||||
.err { color:#ff6d7d; font-weight:600; }
|
||||
#mount { min-height:400px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="mount"></div>
|
||||
<script>
|
||||
(async function(){
|
||||
// Wait a tick so plugin preload (renderer-preload) runs and exposes window.ollamaChat
|
||||
const mount = document.getElementById('mount');
|
||||
function showFallback(reason){
|
||||
mount.innerHTML = `<div class="fallback">`+
|
||||
`<h1>Nebot</h1>`+
|
||||
`<p>The Nebot plugin page could not load automatically.</p>`+
|
||||
(reason?`<p class='err'>${reason}</p>`:'')+
|
||||
`<div class="tip"><strong>How to fix</strong><br/>1. Ensure the Nebot plugin folder exists at plugins/nebot.<br/>2. Confirm plugin is enabled (manifest enabled: true).<br/>3. Restart the app so the plugin manager registers pages.</div>`+
|
||||
`</div>`;
|
||||
}
|
||||
try {
|
||||
// Try to fetch plugin page HTML directly
|
||||
const res = await fetch('../plugins/nebot/page.html');
|
||||
if(!res.ok){ showFallback('Missing page.html (status '+res.status+').'); return; }
|
||||
const html = await res.text();
|
||||
// Simple sandboxed injection
|
||||
mount.innerHTML = html;
|
||||
// The injected page expects its CSS & JS relative to itself; adjust asset paths
|
||||
const fixLinks = mount.querySelectorAll('link[rel="stylesheet"], script[src]');
|
||||
fixLinks.forEach(el=>{
|
||||
const attr = el.tagName==='SCRIPT'?'src':'href';
|
||||
if(el.getAttribute(attr) && !/plugins\/nebot\//.test(el.getAttribute(attr))){
|
||||
el.setAttribute(attr,'../plugins/nebot/'+el.getAttribute(attr));
|
||||
}
|
||||
});
|
||||
// Inject JS if not already present
|
||||
if(!mount.querySelector('script[data-nebot-page]')){
|
||||
const s=document.createElement('script'); s.dataset.nebotPage='1';
|
||||
// Pass the current URL hash to the page script for debug mode
|
||||
s.src='../plugins/nebot/page.js' + window.location.hash;
|
||||
mount.appendChild(s);
|
||||
}
|
||||
} catch(e){
|
||||
showFallback(e.message||'Unknown error');
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+21
-4
@@ -45,6 +45,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-group">
|
||||
<h3>Default Browser</h3>
|
||||
<p class="note">Use Nebula Browser for web links opened from other apps.</p>
|
||||
<div class="setting-row">
|
||||
<button id="set-default-browser-btn" class="primary-btn">Make Default Browser</button>
|
||||
<span id="default-browser-status" class="note">Checking status...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-group">
|
||||
<h3>Weather Display</h3>
|
||||
<p class="note">Choose how temperature is displayed on the Home page weather card.</p>
|
||||
@@ -293,12 +302,12 @@
|
||||
|
||||
<div class="customization-group about-actions">
|
||||
<button id="copy-about-btn">Copy diagnostics</button>
|
||||
<a id="github-link" href="https://github.com/Bobbybear007/NebulaBrowser" class="github-btn" rel="noopener noreferrer">
|
||||
<a id="github-link" href="https://gitpub.zambazosmedia.group/#repo/nebula-project/NebulaBrowser" class="github-btn" rel="noopener noreferrer">
|
||||
<!-- GitHub mark (Octicons) MIT License -->
|
||||
<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false" role="img">
|
||||
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.01.08-2.11 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.91.08 2.11.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/>
|
||||
</svg>
|
||||
<span>GitHub</span>
|
||||
<span>Gitpub</span>
|
||||
</a>
|
||||
<a id="help-link" href="https://nebula.zambazosmedia.group" class="help-btn" rel="noopener noreferrer">
|
||||
<!-- Help icon -->
|
||||
@@ -489,8 +498,10 @@
|
||||
a.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
// Ask the host to open this URL in a new tab to keep Settings open
|
||||
if (window.nebulaNative && typeof window.nebulaNative.postMessage === 'function') {
|
||||
// Ask the CEF host to open this URL in a new tab to keep Settings open.
|
||||
window.nebulaNative.postMessage('new-tab', item);
|
||||
} else if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
window.electronAPI.sendToHost('navigate', item, { newTab: true });
|
||||
} else if (window.parent && window.parent !== window) {
|
||||
// Fallback: postMessage to parent if available
|
||||
@@ -534,6 +545,12 @@
|
||||
|
||||
async function clearSiteHistory() {
|
||||
try {
|
||||
if (window.electronAPI && typeof window.electronAPI.sendToHost === 'function') {
|
||||
window.electronAPI.sendToHost('clear-site-history');
|
||||
} else if (window.nebulaNative && typeof window.nebulaNative.postMessage === 'function') {
|
||||
window.nebulaNative.postMessage('clear-site-history');
|
||||
}
|
||||
|
||||
// Clear from localStorage
|
||||
localStorage.removeItem('siteHistory');
|
||||
console.log('[SETTINGS DEBUG] Cleared site history from localStorage');
|
||||
|
||||
@@ -129,6 +129,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../js/customization.js"></script>
|
||||
<script src="../js/setup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user