branchseer / DeskGap

A cross-platform desktop app framework based on Node.js and the system webview
https://deskgap.com/
MIT License
1.83k stars 75 forks source link

Inverse slash lose in NAPI cpp #60

Closed ci010 closed 4 years ago

ci010 commented 4 years ago

Currently, I'm ramping up with the project. I'm trying to add showItemInFolder support on Windows (just "copying" electron implementation). I encounter a strange issue that when the path string pass into the NAPI side:

shellObject.Set("showItemInFolder", Napi::Function::New(env, [](const Napi::CallbackInfo& info) {
        std::string pathName = info[0].As<Napi::String>();
        UISync(info.Env(), [&]() {
            Shell::ShowItemInFolder(pathString);
        });
}

The js part pass-in the C:\\Users, but the pathName here is C:User (From debugger view). The inverse slashes are lost. I tried to add more inverse slashes, but none of them shows up here.

I'm a noob in CPP and NAPI. Is this a NAPI issue? I cannot find relative issue around NAPI topic.

The showItemInFolder implantation works... If I hardcode the pathName

shellObject.Set("showItemInFolder", Napi::Function::New(env, [](const Napi::CallbackInfo& info) {
       Napi::Env env = info.Env();
       std::string pathString = Napi::String::New(env, "C:\\Users");
       UISync(info.Env(), [&]() {
            Shell::ShowItemInFolder(pathString);
       });
}

The folder shows up correctly.