mirror of
https://github.com/VSCodium/policy-watcher.git
synced 2025-12-10 03:53:55 -06:00
feat: add vendor name
This commit is contained in:
parent
b1ae919794
commit
960cc3ebf4
@ -9,7 +9,7 @@
|
||||
const createWatcher = require("@vscodium/policy-watcher");
|
||||
|
||||
createWatcher(
|
||||
// domain name
|
||||
// vendor name
|
||||
"VSCodium",
|
||||
// product name
|
||||
"VSCodium",
|
||||
|
||||
1
index.d.ts
vendored
1
index.d.ts
vendored
@ -25,6 +25,7 @@ export type PolicyUpdate<T extends Policies> = {
|
||||
};
|
||||
|
||||
export function createWatcher<T extends Policies>(
|
||||
vendorName: string,
|
||||
productName: string,
|
||||
policies: T,
|
||||
onDidChange: (update: PolicyUpdate<T>) => void
|
||||
|
||||
11
index.js
11
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)
|
||||
);
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ using namespace Napi;
|
||||
class PolicyWatcher : public AsyncProgressQueueWorker<const Policy *>
|
||||
{
|
||||
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<std::unique_ptr<Policy>> policies;
|
||||
|
||||
|
||||
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
16
src/main.cc
16
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<Object>();
|
||||
auto rawPolicies = info[2].As<Object>();
|
||||
auto policies = std::vector<std::unique_ptr<Policy>>();
|
||||
auto watcher = new PolicyWatcher(info[0].As<String>(), info[2].As<Function>());
|
||||
auto watcher = new PolicyWatcher(info[0].As<String>(), info[1].As<String>(), info[3].As<Function>());
|
||||
|
||||
for (auto const &item : rawPolicies)
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -15,7 +15,7 @@ using namespace Napi;
|
||||
class NumberPolicy : public RegistryPolicy<long long>
|
||||
{
|
||||
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;
|
||||
|
||||
@ -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<StringPolicy>(name, productName));
|
||||
policies.push_back(std::make_unique<StringPolicy>(name, vendorName, productName));
|
||||
}
|
||||
|
||||
void PolicyWatcher::AddNumberPolicy(const std::string name)
|
||||
{
|
||||
policies.push_back(std::make_unique<NumberPolicy>(name, productName));
|
||||
policies.push_back(std::make_unique<NumberPolicy>(name, vendorName, productName));
|
||||
}
|
||||
|
||||
void PolicyWatcher::OnExecute(Napi::Env env)
|
||||
|
||||
@ -17,9 +17,9 @@ template <typename T>
|
||||
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()
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -15,7 +15,7 @@ using namespace Napi;
|
||||
class StringPolicy : public RegistryPolicy<std::string>
|
||||
{
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user