Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Binding/JSWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,16 +702,15 @@ bool JSWindow::JS_openURL(JSContext *cx, JS::CallArgs &args)

bool JSWindow::JS_exec(JSContext *cx, JS::CallArgs &args)
{

JS::RootedString url(cx);
if (!JS_ConvertArguments(cx, args, "S", url.address())) {
return false;
}

JSAutoByteString curl(cx, url);
const char *ret = SystemInterface::GetInstance()->execute(curl.ptr());
std::unique_ptr<char> ret(SystemInterface::GetInstance()->execute(curl.ptr());

JS::RootedString retStr(cx, JS_NewStringCopyZ(cx, ret));
JS::RootedString retStr(cx, JS_NewStringCopyZ(cx, ret.get()));
args.rval().setString(retStr);

return true;
Expand Down
38 changes: 17 additions & 21 deletions src/Interface/linux/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ void System::initSystemUI()
}
}


const char *System::cwd()
{
static char dir[MAXPATHLEN];
Expand All @@ -192,14 +191,10 @@ const char *System::cwd()

return dir;
}

const char *System::getLanguage()
{

const char *lang;

lang = setlocale(LC_IDENTIFICATION, NULL);

return lang;
return setlocale(LC_IDENTIFICATION, NULL);
}

void System::sendNotification(const char *title,
Expand All @@ -216,26 +211,27 @@ void System::sendNotification(const char *title,

const char *System::execute(const char *cmd)
{
char buffer[128];
FILE *fp;
// caller must free the allocated string when done.
std::string *result = new std::string();
result.reserve(128);

fp = popen(cmd, "r");
if (fp == nullptr) {
return nullptr;
}
struct pipeDeleter {
void operator()(FILE *ptr) const noexcept {
pclose(ptr);
}
};

while (!feof(fp)) {
if (fgets(buffer, 128, fp) != nullptr) {
result->append(buffer);
std::unique_ptr<FILE, pipeDeleter> pipe(popen(cmd, "r"));

if (pipe) {
while (!feof(pipe.get())) {
if (fgets(const_cast<char*>(result.data()), result.capacity(), pipe.get()) != nullptr) {
result += result.data();
}
}
}

pclose(fp);

// FIXME : Memory leak, caller should have to free the
// memory but osx implementation is different from linux
return result->c_str();
return result.c_str();
}
// }}}

Expand Down
14 changes: 14 additions & 0 deletions src/Interface/windows/System.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "System.h"

System::System(){}

const char* System::getUserDirectory() {
// caller must free memory after receiving result
TCHAR *path = new TCHAR[128];
SHGetSpecialFolderPath(NULL,
path,
CSIDL_PERSONAL,
FALSE);
return path;
}

37 changes: 37 additions & 0 deletions src/Interface/windows/System.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2016 Nidium Inc. All rights reserved.
Use of this source code is governed by a MIT license
that can be found in the LICENSE file.
*/

#ifndef interface_windows_system_h__
#define interface_windows_system_h__


#include "SystemInterface.h"
#include <Windows.h>
#include <Shlobj.h>

namespace Nidium{
namespace Interface{

class System: public SystemInterface
{
public:
System() = default;
~System() = default;
const char* getCacheDirectory();
const char* getEmbedDirectory();
const char* getUserDirectory();
const char* getLanguage();
const char* getCwd();
void sendNotification(const char *title, const char *content, bool sound);
const char *execute(const char *cmd);

private:
bool m_SystemUIReady;
char *m_Emebedpath;
}
} // namepspace Interface
} // namepspace Nidium
#endif