diff --git a/README.md b/README.md index 658cb95..5e77c6f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ const createWatcher = require("@vscodium/policy-watcher"); createWatcher( - // domain name + // vendor name "VSCodium", // product name "VSCodium", diff --git a/index.d.ts b/index.d.ts index 2429260..44f1949 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,6 +25,7 @@ export type PolicyUpdate = { }; export function createWatcher( + vendorName: string, productName: string, policies: T, onDidChange: (update: PolicyUpdate) => void diff --git a/index.js b/index.js index 3359bab..534aa61 100644 --- a/index.js +++ b/index.js @@ -4,14 +4,3 @@ *--------------------------------------------------------------------------------------------*/ exports.createWatcher = require('bindings')('vscode-policy-watcher'); - -if (require.main === module) { - exports.createWatcher( - 'CodeOSS', - { - UpdateMode: { type: 'string' }, - SCMInputFontSize: { type: 'number' }, - }, - msg => console.log(msg) - ); -} diff --git a/src/PolicyWatcher.hh b/src/PolicyWatcher.hh index 6aa4a7d..36a980c 100644 --- a/src/PolicyWatcher.hh +++ b/src/PolicyWatcher.hh @@ -19,7 +19,7 @@ using namespace Napi; class PolicyWatcher : public AsyncProgressQueueWorker { public: - PolicyWatcher(std::string productName, const Function &okCallback); + PolicyWatcher(std::string vendorName, std::string productName, const Function &okCallback); ~PolicyWatcher(); void AddStringPolicy(const std::string name); @@ -31,6 +31,7 @@ public: void Dispose(); protected: + std::string vendorName; std::string productName; std::vector> policies; diff --git a/src/linux/PolicyWatcher.cc b/src/linux/PolicyWatcher.cc index f7b8a89..0338e99 100644 --- a/src/linux/PolicyWatcher.cc +++ b/src/linux/PolicyWatcher.cc @@ -7,8 +7,9 @@ using namespace Napi; -PolicyWatcher::PolicyWatcher(std::string productName, const Function &okCallback) +PolicyWatcher::PolicyWatcher(std::string vendorName, std::string productName, const Function &okCallback) : AsyncProgressQueueWorker(okCallback), + vendorName(vendorName), productName(productName) { } diff --git a/src/macos/PolicyWatcher.cc b/src/macos/PolicyWatcher.cc index f7b8a89..0338e99 100644 --- a/src/macos/PolicyWatcher.cc +++ b/src/macos/PolicyWatcher.cc @@ -7,8 +7,9 @@ using namespace Napi; -PolicyWatcher::PolicyWatcher(std::string productName, const Function &okCallback) +PolicyWatcher::PolicyWatcher(std::string vendorName, std::string productName, const Function &okCallback) : AsyncProgressQueueWorker(okCallback), + vendorName(vendorName), productName(productName) { } diff --git a/src/main.cc b/src/main.cc index 566e67d..50aa8f2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -26,18 +26,20 @@ Value CreateWatcher(const CallbackInfo &info) throw TypeError::New(env, "Unsupported platform"); #endif - if (info.Length() < 3) + if (info.Length() < 4) throw TypeError::New(env, "Expected 3 arguments"); else if (!info[0].IsString()) throw TypeError::New(env, "Expected first arg to be string"); - else if (!info[1].IsObject()) - throw TypeError::New(env, "Expected second arg to be object"); - else if (!info[2].IsFunction()) - throw TypeError::New(env, "Expected third arg to be function"); + else if (!info[1].IsString()) + throw TypeError::New(env, "Expected second arg to be string"); + else if (!info[2].IsObject()) + throw TypeError::New(env, "Expected third arg to be object"); + else if (!info[3].IsFunction()) + throw TypeError::New(env, "Expected fourth arg to be function"); - auto rawPolicies = info[1].As(); + auto rawPolicies = info[2].As(); auto policies = std::vector>(); - auto watcher = new PolicyWatcher(info[0].As(), info[2].As()); + auto watcher = new PolicyWatcher(info[0].As(), info[1].As(), info[3].As()); for (auto const &item : rawPolicies) { diff --git a/src/windows/NumberPolicy.cc b/src/windows/NumberPolicy.cc index f625387..d8b8f19 100644 --- a/src/windows/NumberPolicy.cc +++ b/src/windows/NumberPolicy.cc @@ -7,8 +7,8 @@ using namespace Napi; -NumberPolicy::NumberPolicy(const std::string name, const std::string &productName) - : RegistryPolicy(name, productName, REG_QWORD) {} +NumberPolicy::NumberPolicy(const std::string name, const std::string &vendorName, const std::string &productName) + : RegistryPolicy(name, vendorName, productName, REG_QWORD) {} long long NumberPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const { diff --git a/src/windows/NumberPolicy.hh b/src/windows/NumberPolicy.hh index 021d381..6ece3ed 100644 --- a/src/windows/NumberPolicy.hh +++ b/src/windows/NumberPolicy.hh @@ -15,7 +15,7 @@ using namespace Napi; class NumberPolicy : public RegistryPolicy { public: - NumberPolicy(const std::string name, const std::string &productName); + NumberPolicy(const std::string name, const std::string &vendorName, const std::string &productName); protected: long long parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const; diff --git a/src/windows/PolicyWatcher.cc b/src/windows/PolicyWatcher.cc index b7107cd..22685d9 100644 --- a/src/windows/PolicyWatcher.cc +++ b/src/windows/PolicyWatcher.cc @@ -11,8 +11,9 @@ using namespace Napi; -PolicyWatcher::PolicyWatcher(std::string productName, const Function &okCallback) +PolicyWatcher::PolicyWatcher(std::string vendorName, std::string productName, const Function &okCallback) : AsyncProgressQueueWorker(okCallback), + vendorName(vendorName), productName(productName) { } @@ -29,12 +30,12 @@ PolicyWatcher::~PolicyWatcher() void PolicyWatcher::AddStringPolicy(const std::string name) { - policies.push_back(std::make_unique(name, productName)); + policies.push_back(std::make_unique(name, vendorName, productName)); } void PolicyWatcher::AddNumberPolicy(const std::string name) { - policies.push_back(std::make_unique(name, productName)); + policies.push_back(std::make_unique(name, vendorName, productName)); } void PolicyWatcher::OnExecute(Napi::Env env) diff --git a/src/windows/RegistryPolicy.hh b/src/windows/RegistryPolicy.hh index 13070b5..bb01a13 100644 --- a/src/windows/RegistryPolicy.hh +++ b/src/windows/RegistryPolicy.hh @@ -17,9 +17,9 @@ template class RegistryPolicy : public Policy { public: - RegistryPolicy(const std::string name, const std::string &productName, const DWORD regType) + RegistryPolicy(const std::string name, const std::string &vendorName, const std::string &productName, const DWORD regType) : Policy(name), - registryKey("Software\\Policies\\Microsoft\\" + productName), + registryKey("Software\\Policies\\" + vendorName + "\\" + productName), regType(regType) {} bool refresh() diff --git a/src/windows/StringPolicy.cc b/src/windows/StringPolicy.cc index 415c83b..aa4e36f 100644 --- a/src/windows/StringPolicy.cc +++ b/src/windows/StringPolicy.cc @@ -7,8 +7,8 @@ using namespace Napi; -StringPolicy::StringPolicy(const std::string name, const std::string &productName) - : RegistryPolicy(name, productName, REG_SZ) {} +StringPolicy::StringPolicy(const std::string name, const std::string &vendorName, const std::string &productName) + : RegistryPolicy(name, vendorName, productName, REG_SZ) {} std::string StringPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const { diff --git a/src/windows/StringPolicy.hh b/src/windows/StringPolicy.hh index 77ecaef..e6af54f 100644 --- a/src/windows/StringPolicy.hh +++ b/src/windows/StringPolicy.hh @@ -15,7 +15,7 @@ using namespace Napi; class StringPolicy : public RegistryPolicy { public: - StringPolicy(const std::string name, const std::string &productName); + StringPolicy(const std::string name, const std::string &vendorName, const std::string &productName); protected: std::string parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const;