18#ifdef PHOTON_END_OF_BUFFER
19#undef PHOTON_END_OF_BUFFER
22#define PHOTON_END_OF_BUFFER '\0'
24#define PHOTON_EMPTY_HTML "<html>\r\n<head>\r\n</head>\r\n<body>\r\n</body>\r\n</html>\r\n"
34 namespace FS = std::filesystem;
39 template <
typename CharType>
using BasicString = std::basic_string<CharType>;
59 auto err_pos =
output.find(
"{{ " +
fmt +
" }}");
61 if (err_pos != String::npos)
63 output.replace(err_pos, (
"{{ " +
fmt +
" }}").size(), with);
82 NSWindow* window{
nullptr};
83 NSScroller* scroller{
nullptr};
90 double val = [scroller doubleValue];
91 CGFloat contentHeight = NSHeight([window.contentView
frame]);
92 CGFloat maxOffset = contentHeight;
94 NSRect f = [window.contentView
frame];
95 f.origin.y = -val * maxOffset;
96 [window.contentView
frame] = f;
100 static constexpr const auto kWidth = 1280;
101 static constexpr const auto kHeight = 720;
108 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, kWidth, kHeight)
109 styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable)
110 backing:NSBackingStoreBuffered
113 [window setTitle:[NSString stringWithUTF8String:((!text.empty()) ? text.c_str() :
"Untitled - Photon")]];
116 [window setBackgroundColor:[NSColor whiteColor]];
118 [window makeKeyAndOrderFront:nil];
119 [window setLevel:NSStatusWindowLevel];
126 NSAlert* alert = [[NSAlert alloc] init];
128 [alert setMessageText:[NSString stringWithUTF8String:((!
title.empty()) ?
title.c_str() :
"Photon")]];
129 [alert setInformativeText:[NSString stringWithUTF8String:text.c_str()]];
130 [alert addButtonWithTitle:
@"Ok"];
131 [alert addButtonWithTitle:
@"Cancel"];
132 [alert setAlertStyle:NSAlertStyleInformational];
134 NSModalResponse response = [alert runModal];
136 return response == NSAlertFirstButtonReturn ?
"YES" :
"NO";
141 if (std::find(kPermsList.cbegin(), kPermsList.cend(), permission_name) != kPermsList.end())
144 if (this->prompt(
"Photon - Security",
"The page is asking for: " + permission_name +
"\nAccept?") ==
"NO")
147 kPermsList.push_back(permission_name);
159 return std::system(cmd.c_str());
164#define PHOTON_CRITICAL(...) spdlog::critical(__VA_ARGS__)
165#define PHOTON_ERROR(...) spdlog::error(__VA_ARGS__)
166#define PHOTON_INFO(...) spdlog::info(__VA_ARGS__)
167#define PHOTON_WARN(...) spdlog::warn(__VA_ARGS__)
PHOTON_API FILE * photon_get_logger()
PHOTON_API size_t photon_strlen(const char *str)
Definition Core.mm:16
PHOTON_API void photon_log(const char *str)
PHOTON_API time_t photon_get_epoch()
PHOTON_API bool photon_open_logger()
BrowserError(const BrowserError &)=default
BrowserError(const char *error="ERROR_UNKNOWN")
Definition Core.hpp:48
BrowserError & operator=(const BrowserError &)=default
static std::vector< String > kPermsList
Definition Core.hpp:79
bool grant_or_fail(const String permission_name)
Definition Core.hpp:139
void scroller_moved_(NSScroller *sender)
Definition Core.hpp:86
WindowHelper & operator=(const WindowHelper &)=default
WindowHelper(const WindowHelper &)=default
int open(const char *app_name)
Definition Core.hpp:151
NSWindow * tab(const String text)
Definition Core.hpp:103
String prompt(const String title, const String text="")
Definition Core.hpp:124
#define PHOTON_API
Definition Config.hpp:64
This file is also about defining core js concepts.
Definition BasePhotonWindow.hpp:22
std::thread Thread
Definition Core.hpp:36
String photon_replace_format(String fmt, String output, String with)
Definition Core.hpp:57
std::basic_string< CharType > BasicString
Definition Core.hpp:39
std::string String
Definition Core.hpp:37
BasicString< PChar > PString
Definition Core.hpp:43
wchar_t PChar
Definition Core.hpp:41
Definition bin_to_hex.h:111
title
Definition tag_strings.h:6
annotation output
Definition tag_strings.h:122
annotation center
Definition tag_strings.h:147
annotation frame
Definition tag_strings.h:133