Skip to content

Commit

Permalink
neutralinojs#462: Get refactoried codebase working on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
shalithasuranga committed Jun 5, 2021
1 parent 8b55ad5 commit 0703661
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 59 deletions.
3 changes: 0 additions & 3 deletions api/app/app.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef AP_H
#define AP_H

#include <iostream>
#include <map>

using namespace std;

namespace app {
Expand Down
2 changes: 0 additions & 2 deletions api/computer/computer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef COMPUTER_H
#define COMPUTER_H

#include <map>

namespace computer {
string getRamUsage(json input);
}
Expand Down
1 change: 0 additions & 1 deletion api/debug/debug.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <iostream>
#include <fstream>
#include "lib/json.hpp"
#include "settings.h"
#include "lib/easylogging/easylogging++.h"

using namespace std;
Expand Down
2 changes: 1 addition & 1 deletion api/filesystem/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace fs {
string path = input["path"];
#if defined(__linux__) || defined(__APPLE__)
if(mkdir(path.c_str(), 0700) == 0) {
#elif defined(_WIN32
#elif defined(_WIN32)
if(CreateDirectory(path.c_str(), NULL)) {
#endif
output["success"] = true;
Expand Down
1 change: 0 additions & 1 deletion api/filesystem/filesystem.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <map>
#ifndef FILESYSTEM_H
#define FILESYSTEM_H

Expand Down
47 changes: 27 additions & 20 deletions api/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@
#include <string>
#include <array>
#include <map>
#include "platform/platform.h"

#if defined(__APPLE__)
#include <dispatch/dispatch.h>
#include <lib/boxer/boxer.h>
#include <objc/objc-runtime.h>

#elif defined(_WIN32)
#include <windows.h>
#include <shlobj.h>
#include <shobjidl.h>
#include <lib/boxer/boxer.h>

#pragma comment(lib, "Comdlg32.lib")
#pragma comment(lib, "Shell32.lib")
#endif

#include "platform/platform.h"



using namespace std;
Expand Down Expand Up @@ -210,8 +214,8 @@ namespace os {
}

string showMessageBox(json input) {
json output;
#if defined(__linux__)
json output;
map <string, string> messageTypes = {{"INFO", "info"}, {"WARN", "warning"},
{"ERROR", "error"}, {"QUESTION", "question"}};
string messageType;
Expand All @@ -229,31 +233,34 @@ namespace os {
output["success"] = true;

#elif defined(__APPLE__) || defined(_WIN32)

string title = input["title"];
string content = input["content"];
string type = input["type"];

#if defined(__APPLE__)
__block json output;
__block boxer::Selection msgSel;
__block json output;
__block boxer::Selection msgSel;
#elif defined(_WIN32)
json output;
boxer::Selection msgSel;
json output;
boxer::Selection msgSel;
#endif

#if defined(__APPLE__)
dispatch_sync(dispatch_get_main_queue(), ^{
#endif
if(type == "INFO")
msgSel = boxer::show(content.c_str(), title.c_str(), boxer::Style::Info);
else if(type == "WARN")
msgSel = boxer::show(content.c_str(), title.c_str(), boxer::Style::Warning);
else if(type == "ERROR")
msgSel = boxer::show(content.c_str(), title.c_str(), boxer::Style::Error);
else if(type == "QUESTION") {
msgSel = boxer::show(content.c_str(), title.c_str(), boxer::Style::Question,
boxer::Buttons::YesNo);
output["yesButtonClicked"] = msgSel == boxer::Selection::Yes;
}
else
output["error"] = "Invalid message type: '" + type + "' provided";
if(type == "INFO")
msgSel = boxer::show(content.c_str(), title.c_str(), boxer::Style::Info);
else if(type == "WARN")
msgSel = boxer::show(content.c_str(), title.c_str(), boxer::Style::Warning);
else if(type == "ERROR")
msgSel = boxer::show(content.c_str(), title.c_str(), boxer::Style::Error);
else if(type == "QUESTION") {
msgSel = boxer::show(content.c_str(), title.c_str(), boxer::Style::Question,
boxer::Buttons::YesNo);
output["yesButtonClicked"] = msgSel == boxer::Selection::Yes;
}
else
output["error"] = "Invalid message type: '" + type + "' provided";
#if defined(__APPLE__)
});
#endif
Expand Down
2 changes: 0 additions & 2 deletions api/os/os.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef OS_H
#define OS_H

#include <map>

namespace os {
string execCommand(json input);
string getEnvar(json input);
Expand Down
2 changes: 0 additions & 2 deletions api/storage/storage.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef STORAGE_H
#define STORAGE_H

#include <iostream>

using namespace std;

namespace storage {
Expand Down
5 changes: 4 additions & 1 deletion api/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

using namespace std;
using json = nlohmann::json;
#if defined(_WIN32)
using namespace Gdiplus;
#endif

webview::webview *nativeWindow;
#if defined(__linux__)
Expand Down Expand Up @@ -109,7 +112,7 @@ namespace window {
nativeWindow->run();
}
#elif defined(_WIN32)
void __showWindow(int height, int width,
void __createWindow(int height, int width,
bool fullScreen, string title, bool alwaysOnTop, void* icon,
bool enableInspector, bool borderless, bool maximize, bool hidden, string url) {

Expand Down
3 changes: 0 additions & 3 deletions api/window/window.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef WI_H
#define WI_H

#include <iostream>
#include <map>

using namespace std;

namespace window {
Expand Down
Binary file added bin/WebView2Loader.dll
Binary file not shown.
Binary file added bin/neutralino.exe
Binary file not shown.
44 changes: 22 additions & 22 deletions build_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,30 @@ if EXIST bin\neutralino.exe (
)

cl /std:c++17 ^
/I ../core-shared ^
/I src/platform/webview2 ^
/I . ^
/I platform/windows/webview2 ^
/EHsc ^
../core-shared/main.cpp ^
../core-shared/settings.cpp ^
../core-shared/resources.cpp ^
../core-shared/router.cpp ^
../core-shared/auth/authbasic.cpp ^
../core-shared/ping/ping.cpp ^
../core-shared/helpers.cpp ^
../core-shared/permission.cpp ^
../core-shared/server/neuserver.cpp ^
../core-shared/lib/easylogging/easylogging++.cc ^
../core-shared/lib/boxer/boxer_win.cpp ^
src/platform/windows.cpp ^
src/api/computer/computer.cpp ^
src/api/filesystem/filesystem.cpp ^
src/api/os/os.cpp ^
src/api/storage/storage.cpp ^
src/api/debug/debug.cpp ^
src/api/app/app.cpp ^
src/api/window/window.cpp ^
main.cpp ^
settings.cpp ^
resources.cpp ^
server/neuserver.cpp ^
server/router.cpp ^
auth/authbasic.cpp ^
auth/permission.cpp ^
server/ping.cpp ^
helpers.cpp ^
lib/easylogging/easylogging++.cc ^
lib/boxer/boxer_win.cpp ^
platform/windows/platform.cpp ^
api/computer/computer.cpp ^
api/filesystem/filesystem.cpp ^
api/os/os.cpp ^
api/storage/storage.cpp ^
api/debug/debug.cpp ^
api/app/app.cpp ^
api/window/window.cpp ^
/DELPP_NO_DEFAULT_LOG_FILE ^
/link dll/WebView2Loader.dll.lib "/OUT:bin\neutralino.exe"
/link platform/windows/webview2/WebView2Loader.dll.lib "/OUT:bin\neutralino.exe"

if EXIST bin\neutralino.exe (
echo Neutralino binary is compiled in to bin/netralino.exe
Expand Down
Binary file removed platform/windows/dll/WebView2Loader.dll
Binary file not shown.
Binary file removed platform/windows/dll/webview.dll
Binary file not shown.
File renamed without changes.
3 changes: 2 additions & 1 deletion settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#elif defined(__APPLE__)
#define OS_NAME "Darwin"
#endif
#define NL_VERSION "2.2.0"

#define APP_CONFIG_FILE "/neutralino.config.json"

Expand Down Expand Up @@ -66,7 +67,7 @@ namespace settings {

string getGlobalVars(){
string jsSnippet = "var NL_OS='" + std::string(OS_NAME) + "';";
jsSnippet += "var NL_VERSION='2.1.1';";
jsSnippet += "var NL_VERSION='" + std::string(NL_VERSION) + "';";
jsSnippet += "var NL_APPID='" + options["applicationId"].get<std::string>() + "';";
jsSnippet += "var NL_PORT=" + std::to_string(options["port"].get<int>()) + ";";
jsSnippet += "var NL_MODE='" + options["defaultMode"].get<std::string>() + "';";
Expand Down

0 comments on commit 0703661

Please sign in to comment.