windowpp 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/bin/windowpp.js +86 -0
  2. package/cmake/embed_assets.py +144 -0
  3. package/framework/CMakeLists.txt +176 -0
  4. package/framework/include/windowpp/windowpp.h +704 -0
  5. package/framework/src/AppData/API/AppData.ts +137 -0
  6. package/framework/src/AppData/appdata_bridge.h +138 -0
  7. package/framework/src/AppData/appdata_manager.cpp +126 -0
  8. package/framework/src/AppData/appdata_manager.h +3 -0
  9. package/framework/src/FileSystem/API/FileSystem.ts +389 -0
  10. package/framework/src/FileSystem/Linux/filesearch.cpp +148 -0
  11. package/framework/src/FileSystem/Linux/readfile.cpp +79 -0
  12. package/framework/src/FileSystem/Linux/savefile.cpp +333 -0
  13. package/framework/src/FileSystem/MacOS/filesearch.cpp +149 -0
  14. package/framework/src/FileSystem/MacOS/readfile.cpp +80 -0
  15. package/framework/src/FileSystem/MacOS/savefile.cpp +264 -0
  16. package/framework/src/FileSystem/Windows/filesearch.cpp +195 -0
  17. package/framework/src/FileSystem/Windows/readfile.cpp +122 -0
  18. package/framework/src/FileSystem/Windows/savefile.cpp +290 -0
  19. package/framework/src/FileSystem/file_index_service.cpp +262 -0
  20. package/framework/src/FileSystem/file_index_service.h +55 -0
  21. package/framework/src/FileSystem/filesystem_bridge.h +243 -0
  22. package/framework/src/FileSystem/filesystem_handler.h +93 -0
  23. package/framework/src/FileSystem/filesystem_json.h +241 -0
  24. package/framework/src/FileSystem/filesystem_search_service.cpp +414 -0
  25. package/framework/src/FileSystem/filesystem_search_service.h +94 -0
  26. package/framework/src/Input/API/Input.ts +161 -0
  27. package/framework/src/Input/Linux/linux_key_utils.h +135 -0
  28. package/framework/src/Input/MacOS/macos_key_utils.h +137 -0
  29. package/framework/src/Input/Windows/win32_key_utils.h +199 -0
  30. package/framework/src/Input/input_bridge.h +192 -0
  31. package/framework/src/Input/input_service.cpp +584 -0
  32. package/framework/src/Input/input_service.h +21 -0
  33. package/framework/src/application.cpp +29 -0
  34. package/framework/src/common/hit_test.cpp +40 -0
  35. package/framework/src/common/image_loader.cpp +24 -0
  36. package/framework/src/common/paths.cpp +75 -0
  37. package/framework/src/filedrop/filedrop.cpp +316 -0
  38. package/framework/src/filedrop/filedrop.css +421 -0
  39. package/framework/src/filedrop/filedrop.hpp +92 -0
  40. package/framework/src/filedrop/filedrop.ts +183 -0
  41. package/framework/src/platform/API/App.ts +156 -0
  42. package/framework/src/platform/API/Window.ts +249 -0
  43. package/framework/src/platform/linux/app_linux.cpp +256 -0
  44. package/framework/src/platform/linux/app_linux.h +64 -0
  45. package/framework/src/platform/linux/linux_helpers.cpp +26 -0
  46. package/framework/src/platform/linux/linux_helpers.h +19 -0
  47. package/framework/src/platform/linux/tray_linux.cpp +21 -0
  48. package/framework/src/platform/linux/tray_linux.h +26 -0
  49. package/framework/src/platform/linux/window_linux.cpp +256 -0
  50. package/framework/src/platform/linux/window_linux.h +70 -0
  51. package/framework/src/platform/macos/app_macos.h +59 -0
  52. package/framework/src/platform/macos/app_macos.mm +223 -0
  53. package/framework/src/platform/macos/macos_helpers.h +21 -0
  54. package/framework/src/platform/macos/tray_macos.h +22 -0
  55. package/framework/src/platform/macos/tray_macos.mm +53 -0
  56. package/framework/src/platform/macos/window_macos.h +74 -0
  57. package/framework/src/platform/macos/window_macos.mm +318 -0
  58. package/framework/src/platform/platform_bridge.h +514 -0
  59. package/framework/src/platform/platform_factory.cpp +33 -0
  60. package/framework/src/platform/platform_factory.h +19 -0
  61. package/framework/src/platform/win32/app_win32.cpp +572 -0
  62. package/framework/src/platform/win32/app_win32.h +83 -0
  63. package/framework/src/platform/win32/tray_win32.cpp +57 -0
  64. package/framework/src/platform/win32/tray_win32.h +30 -0
  65. package/framework/src/platform/win32/win32_helpers.h +61 -0
  66. package/framework/src/platform/win32/window_win32.cpp +267 -0
  67. package/framework/src/platform/win32/window_win32.h +79 -0
  68. package/framework/src/renderer/webgpu.h +128 -0
  69. package/framework/src/renderer/webview/include/WebView2.h +48014 -0
  70. package/framework/src/renderer/webview/include/WebView2EnvironmentOptions.h +342 -0
  71. package/framework/src/renderer/webview/webview.h +13 -0
  72. package/framework/src/renderer/webview/webview_linux.cpp +392 -0
  73. package/framework/src/renderer/webview/webview_macos.mm +388 -0
  74. package/framework/src/renderer/webview/webview_win32.cpp +688 -0
  75. package/framework/src/renderer/webview/x64/WebView2Loader.dll +0 -0
  76. package/framework/src/renderer/webview/x64/WebView2Loader.lib +0 -0
  77. package/framework/src/renderer/webview/x64/WebView2LoaderStatic.lib +0 -0
  78. package/lib/build.js +112 -0
  79. package/lib/create.js +283 -0
  80. package/lib/dev.js +155 -0
  81. package/package.json +24 -0
  82. package/scripts/publish.js +67 -0
  83. package/scripts/sync-framework.js +73 -0
  84. package/templates/solid/CMakeLists.txt +56 -0
  85. package/templates/solid/frontend/package.json +22 -0
  86. package/templates/solid/frontend/vite.config.ts +25 -0
  87. package/templates/solid/main.cpp +72 -0
  88. package/templates/solid/package.json +12 -0
@@ -0,0 +1,75 @@
1
+ // ============================================================================
2
+ // paths.cpp — Cross-platform app data / user data directory helpers
3
+ // ============================================================================
4
+
5
+ #include <windowpp/windowpp.h>
6
+
7
+ #if defined(_WIN32)
8
+ # include <windows.h>
9
+ # include <shlobj.h> // SHGetKnownFolderPath
10
+ # pragma comment(lib, "shell32.lib")
11
+ #elif defined(__APPLE__)
12
+ # include <sys/types.h>
13
+ # include <pwd.h>
14
+ # include <unistd.h>
15
+ #else // Linux / BSD
16
+ # include <cstdlib>
17
+ # include <sys/types.h>
18
+ # include <pwd.h>
19
+ # include <unistd.h>
20
+ #endif
21
+
22
+ #include <string>
23
+
24
+ namespace wpp {
25
+ namespace paths {
26
+
27
+ std::string app_data_dir(const std::string& app_name) {
28
+ std::string base;
29
+
30
+ #if defined(_WIN32)
31
+ // %APPDATA% → C:\Users\<user>\AppData\Roaming
32
+ PWSTR path_ptr = nullptr;
33
+ if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData,
34
+ KF_FLAG_CREATE, nullptr, &path_ptr))) {
35
+ // Convert wide to UTF-8
36
+ int len = WideCharToMultiByte(CP_UTF8, 0, path_ptr, -1,
37
+ nullptr, 0, nullptr, nullptr);
38
+ base.resize(len > 0 ? len - 1 : 0);
39
+ if (len > 0)
40
+ WideCharToMultiByte(CP_UTF8, 0, path_ptr, -1,
41
+ &base[0], len, nullptr, nullptr);
42
+ CoTaskMemFree(path_ptr);
43
+ }
44
+ return base.empty() ? app_name : base + "\\" + app_name;
45
+
46
+ #elif defined(__APPLE__)
47
+ // ~/Library/Application Support/<AppName>
48
+ const char* home = std::getenv("HOME");
49
+ if (!home) {
50
+ struct passwd* wpp = getpwuid(getuid());
51
+ if (wpp) home = wpp->wpp_dir;
52
+ }
53
+ if (home)
54
+ return std::string(home) + "/Library/Application Support/" + app_name;
55
+ return app_name;
56
+
57
+ #else
58
+ // $XDG_DATA_HOME/<AppName> or ~/.local/share/<AppName>
59
+ const char* xdg = std::getenv("XDG_DATA_HOME");
60
+ if (xdg && *xdg)
61
+ return std::string(xdg) + "/" + app_name;
62
+
63
+ const char* home = std::getenv("HOME");
64
+ if (!home) {
65
+ struct passwd* wpp = getpwuid(getuid());
66
+ if (wpp) home = wpp->wpp_dir;
67
+ }
68
+ if (home)
69
+ return std::string(home) + "/.local/share/" + app_name;
70
+ return app_name;
71
+ #endif
72
+ }
73
+
74
+ } // namespace paths
75
+ } // namespace wpp
@@ -0,0 +1,316 @@
1
+ #include <wpp/filedrop.hpp>
2
+ #include <wpp/window.hpp>
3
+ #include <memory>
4
+ #include <mutex>
5
+ #include <filesystem>
6
+ #include <fstream>
7
+ #include <unordered_map>
8
+ #include <cctype>
9
+ #include <iostream>
10
+
11
+ #ifdef _WIN32
12
+ #define WIN32_LEAN_AND_MEAN
13
+ #include <windows.h>
14
+ #include <shlobj.h>
15
+ #include <objidl.h>
16
+ #include <oleidl.h>
17
+ #include <shellapi.h>
18
+ #elif defined(__APPLE__)
19
+ #include <AppKit/AppKit.h>
20
+ #include <CoreFoundation/CoreFoundation.h>
21
+ #import <WebKit/WebKit.h>
22
+ #else
23
+ // Linux/GTK
24
+ #include <gtk/gtk.h>
25
+ #include <webkit2/webkit2.h>
26
+ #endif
27
+
28
+ namespace wpp {
29
+
30
+ static std::string mimeTypeFromPath(const std::string &path) {
31
+ size_t dot = path.find_last_of(".");
32
+ if (dot == std::string::npos) return "application/octet-stream";
33
+ std::string ext = path.substr(dot + 1);
34
+ for (char &c : ext) c = (char)tolower(c);
35
+ if (ext == "png") return "image/png";
36
+ if (ext == "jpg" || ext == "jpeg") return "image/jpeg";
37
+ if (ext == "gif") return "image/gif";
38
+ if (ext == "html" || ext == "htm") return "text/html";
39
+ if (ext == "js") return "application/javascript";
40
+ if (ext == "json") return "application/json";
41
+ if (ext == "css") return "text/css";
42
+ if (ext == "txt" || ext == "md") return "text/plain";
43
+ if (ext == "svg") return "image/svg+xml";
44
+ if (ext == "pdf") return "application/pdf";
45
+ if (ext == "zip") return "application/zip";
46
+ return "application/octet-stream";
47
+ }
48
+
49
+ struct FileDrop::Impl {
50
+ std::mutex mtx;
51
+ bool enabled = true;
52
+ std::function<void(const std::vector<FileInfo>&)> filesDroppedCallback;
53
+ std::function<void()> dragEnterCallback;
54
+ std::function<void()> dragLeaveCallback;
55
+ void* nativeWindowHandle = nullptr;
56
+ void* nativeWebViewHandle = nullptr;
57
+
58
+ #ifdef _WIN32
59
+ void* dropTarget = nullptr;
60
+ #elif defined(__APPLE__)
61
+ // macOS specific drag context
62
+ #elif defined(__linux__)
63
+ struct DropCtx {
64
+ WebKitWebView *wv;
65
+ bool entered = false;
66
+ gint x = 0, y = 0;
67
+ };
68
+ DropCtx* dc = nullptr;
69
+ #endif
70
+ };
71
+
72
+ FileDrop::FileDrop() : pImpl(new Impl()) {}
73
+
74
+ FileDrop::~FileDrop() {
75
+ #ifdef __linux__
76
+ if (pImpl->dc) delete pImpl->dc;
77
+ #endif
78
+ delete pImpl;
79
+ }
80
+
81
+ #ifdef _WIN32
82
+ class FileDropTarget : public IDropTarget {
83
+ HWND m_hwnd;
84
+ ULONG m_refCount;
85
+ bool m_hasFiles;
86
+ double m_dpiScale;
87
+ std::function<void(const std::vector<FileInfo>&, int, int)> m_onDrop;
88
+ std::function<void(int, int)> m_onDragEnter;
89
+ std::function<void(int, int)> m_onDragOver;
90
+ std::function<void()> m_onDragLeave;
91
+
92
+ public:
93
+ FileDropTarget(HWND hwnd) : m_hwnd(hwnd), m_refCount(1), m_hasFiles(false), m_dpiScale(1.0) {}
94
+
95
+ void setCallbacks(
96
+ std::function<void(const std::vector<FileInfo>&, int, int)> onDrop,
97
+ std::function<void(int, int)> onDragEnter,
98
+ std::function<void(int, int)> onDragOver,
99
+ std::function<void()> onDragLeave
100
+ ) {
101
+ m_onDrop = onDrop;
102
+ m_onDragEnter = onDragEnter;
103
+ m_onDragOver = onDragOver;
104
+ m_onDragLeave = onDragLeave;
105
+ }
106
+
107
+ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override {
108
+ if (riid == IID_IUnknown || riid == IID_IDropTarget) {
109
+ *ppvObject = this;
110
+ AddRef();
111
+ return S_OK;
112
+ }
113
+ *ppvObject = nullptr;
114
+ return E_NOINTERFACE;
115
+ }
116
+ ULONG STDMETHODCALLTYPE AddRef() override { return InterlockedIncrement(&m_refCount); }
117
+ ULONG STDMETHODCALLTYPE Release() override {
118
+ ULONG ref = InterlockedDecrement(&m_refCount);
119
+ if (ref == 0) delete this;
120
+ return ref;
121
+ }
122
+
123
+ void screenToCSS(POINTL pt, int &cssX, int &cssY) {
124
+ POINT ptClient = {pt.x, pt.y};
125
+ ScreenToClient(m_hwnd, &ptClient);
126
+ cssX = static_cast<int>(ptClient.x / m_dpiScale);
127
+ cssY = static_cast<int>(ptClient.y / m_dpiScale);
128
+ }
129
+
130
+ bool hasFiles(IDataObject *pDataObj) {
131
+ if (!pDataObj) return false;
132
+ FORMATETC fmt = {CF_HDROP, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
133
+ return pDataObj->QueryGetData(&fmt) == S_OK;
134
+ }
135
+
136
+ HRESULT STDMETHODCALLTYPE DragEnter(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) override {
137
+ m_hasFiles = hasFiles(pDataObj);
138
+ UINT dpi = GetDpiForWindow(m_hwnd);
139
+ m_dpiScale = (dpi > 0) ? static_cast<double>(dpi) / 96.0 : 1.0;
140
+ if (m_hasFiles) {
141
+ *pdwEffect = DROPEFFECT_COPY;
142
+ if (m_onDragEnter) {
143
+ int cssX, cssY;
144
+ screenToCSS(pt, cssX, cssY);
145
+ m_onDragEnter(cssX, cssY);
146
+ }
147
+ } else {
148
+ *pdwEffect = DROPEFFECT_NONE;
149
+ }
150
+ return S_OK;
151
+ }
152
+
153
+ HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) override {
154
+ if (m_hasFiles) {
155
+ *pdwEffect = DROPEFFECT_COPY;
156
+ if (m_onDragOver) {
157
+ int cssX, cssY;
158
+ screenToCSS(pt, cssX, cssY);
159
+ m_onDragOver(cssX, cssY);
160
+ }
161
+ } else {
162
+ *pdwEffect = DROPEFFECT_NONE;
163
+ }
164
+ return S_OK;
165
+ }
166
+
167
+ HRESULT STDMETHODCALLTYPE DragLeave() override {
168
+ if (m_onDragLeave) {
169
+ m_onDragLeave();
170
+ }
171
+ return S_OK;
172
+ }
173
+
174
+ HRESULT STDMETHODCALLTYPE Drop(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) override {
175
+ if (!pDataObj) return E_FAIL;
176
+
177
+ FORMATETC fmt = {CF_HDROP, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
178
+ STGMEDIUM stg = {};
179
+
180
+ if (pDataObj->GetData(&fmt, &stg) != S_OK) return E_FAIL;
181
+
182
+ HDROP hDrop = static_cast<HDROP>(stg.hGlobal);
183
+ std::vector<FileInfo> files;
184
+ UINT fileCount = DragQueryFileW(hDrop, 0xFFFFFFFF, nullptr, 0);
185
+
186
+ for (UINT i = 0; i < fileCount; ++i) {
187
+ UINT pathLen = DragQueryFileW(hDrop, i, nullptr, 0);
188
+ std::wstring wpath(pathLen + 1, L'\0');
189
+ DragQueryFileW(hDrop, i, &wpath[0], pathLen + 1);
190
+ wpath.resize(pathLen);
191
+
192
+ int utf8Len = WideCharToMultiByte(CP_UTF8, 0, wpath.c_str(), -1, nullptr, 0, nullptr, nullptr);
193
+ std::string path;
194
+ if (utf8Len > 0) {
195
+ path.resize(static_cast<size_t>(utf8Len - 1));
196
+ WideCharToMultiByte(CP_UTF8, 0, wpath.c_str(), -1, &path[0], utf8Len, nullptr, nullptr);
197
+ }
198
+
199
+ std::string name = path;
200
+ size_t lastSlash = path.find_last_of("\\/");
201
+ if (lastSlash != std::string::npos) name = path.substr(lastSlash + 1);
202
+
203
+ unsigned long long sizeBytes = 0;
204
+ WIN32_FILE_ATTRIBUTE_DATA fileAttr;
205
+ if (GetFileAttributesExW(wpath.c_str(), GetFileExInfoStandard, &fileAttr)) {
206
+ ULARGE_INTEGER size;
207
+ size.HighPart = fileAttr.nFileSizeHigh;
208
+ size.LowPart = fileAttr.nFileSizeLow;
209
+ sizeBytes = size.QuadPart;
210
+ }
211
+
212
+ FileInfo fi;
213
+ fi.path = path;
214
+ fi.name = name;
215
+ fi.type = mimeTypeFromPath(path);
216
+ fi.size = sizeBytes;
217
+ files.push_back(fi);
218
+ }
219
+ ReleaseStgMedium(&stg);
220
+
221
+ int cssX, cssY;
222
+ screenToCSS(pt, cssX, cssY);
223
+
224
+ if (m_onDrop) {
225
+ m_onDrop(files, cssX, cssY);
226
+ }
227
+
228
+ *pdwEffect = DROPEFFECT_COPY;
229
+ return S_OK;
230
+ }
231
+ };
232
+ #endif
233
+
234
+ void FileDrop::attach(void* nativeWindowHandle) {
235
+ pImpl->nativeWindowHandle = nativeWindowHandle;
236
+ if (!pImpl->enabled) return;
237
+
238
+ #ifdef _WIN32
239
+ HWND hwnd = static_cast<HWND>(nativeWindowHandle);
240
+ DragAcceptFiles(hwnd, TRUE);
241
+ FileDropTarget* target = new FileDropTarget(hwnd);
242
+
243
+ auto onDrop = [this](const std::vector<FileInfo>& files, int cssX, int cssY) {
244
+ if (pImpl->filesDroppedCallback) {
245
+ pImpl->filesDroppedCallback(files);
246
+ }
247
+ };
248
+
249
+ auto onDragEnter = [this](int cssX, int cssY) {
250
+ if (pImpl->dragEnterCallback) {
251
+ pImpl->dragEnterCallback();
252
+ }
253
+ };
254
+
255
+ auto onDragLeave = [this]() {
256
+ if (pImpl->dragLeaveCallback) {
257
+ pImpl->dragLeaveCallback();
258
+ }
259
+ };
260
+
261
+ target->setCallbacks(onDrop, onDragEnter, {}, onDragLeave);
262
+ pImpl->dropTarget = target;
263
+ RegisterDragDrop(hwnd, target);
264
+
265
+ #elif defined(__APPLE__)
266
+ // We let the objective-c wrapper handle this via PlusUIView
267
+ // No need to redeclare standard drag drops here if it requires subclassing
268
+ #elif defined(__linux__)
269
+ // Linux implementation without WebKit - would need custom IPC
270
+ (void)nativeWindowHandle;
271
+ #endif
272
+ }
273
+
274
+ void FileDrop::setEnabled(bool enabled) {
275
+ std::lock_guard<std::mutex> lock(pImpl->mtx);
276
+ pImpl->enabled = enabled;
277
+ #ifdef _WIN32
278
+ if (pImpl->nativeWindowHandle) {
279
+ DragAcceptFiles(static_cast<HWND>(pImpl->nativeWindowHandle), enabled ? TRUE : FALSE);
280
+ }
281
+ #endif
282
+ }
283
+
284
+ bool FileDrop::isEnabled() const {
285
+ std::lock_guard<std::mutex> lock(pImpl->mtx);
286
+ return pImpl->enabled;
287
+ }
288
+
289
+ void FileDrop::onFilesDropped(std::function<void(const std::vector<FileInfo>&)> callback) {
290
+ std::lock_guard<std::mutex> lock(pImpl->mtx);
291
+ pImpl->filesDroppedCallback = callback;
292
+ }
293
+
294
+ void FileDrop::onDragEnter(std::function<void()> callback) {
295
+ std::lock_guard<std::mutex> lock(pImpl->mtx);
296
+ pImpl->dragEnterCallback = callback;
297
+ }
298
+
299
+ void FileDrop::onDragLeave(std::function<void()> callback) {
300
+ std::lock_guard<std::mutex> lock(pImpl->mtx);
301
+ pImpl->dragLeaveCallback = callback;
302
+ }
303
+
304
+ bool FileDrop::startDrag(const std::vector<std::string>& filePaths) {
305
+ if (filePaths.empty()) return false;
306
+ return false;
307
+ }
308
+
309
+ void FileDrop::clearCallbacks() {
310
+ std::lock_guard<std::mutex> lock(pImpl->mtx);
311
+ pImpl->filesDroppedCallback = nullptr;
312
+ pImpl->dragEnterCallback = nullptr;
313
+ pImpl->dragLeaveCallback = nullptr;
314
+ }
315
+
316
+ } // namespace wpp