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");
|
const createWatcher = require("@vscodium/policy-watcher");
|
||||||
|
|
||||||
createWatcher(
|
createWatcher(
|
||||||
// domain name
|
// vendor name
|
||||||
"VSCodium",
|
"VSCodium",
|
||||||
// product name
|
// product name
|
||||||
"VSCodium",
|
"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>(
|
export function createWatcher<T extends Policies>(
|
||||||
|
vendorName: string,
|
||||||
productName: string,
|
productName: string,
|
||||||
policies: T,
|
policies: T,
|
||||||
onDidChange: (update: PolicyUpdate<T>) => void
|
onDidChange: (update: PolicyUpdate<T>) => void
|
||||||
|
|||||||
11
index.js
11
index.js
@ -4,14 +4,3 @@
|
|||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
exports.createWatcher = require('bindings')('vscode-policy-watcher');
|
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 *>
|
class PolicyWatcher : public AsyncProgressQueueWorker<const Policy *>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PolicyWatcher(std::string productName, const Function &okCallback);
|
PolicyWatcher(std::string vendorName, std::string productName, const Function &okCallback);
|
||||||
~PolicyWatcher();
|
~PolicyWatcher();
|
||||||
|
|
||||||
void AddStringPolicy(const std::string name);
|
void AddStringPolicy(const std::string name);
|
||||||
@ -31,6 +31,7 @@ public:
|
|||||||
void Dispose();
|
void Dispose();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
std::string vendorName;
|
||||||
std::string productName;
|
std::string productName;
|
||||||
std::vector<std::unique_ptr<Policy>> policies;
|
std::vector<std::unique_ptr<Policy>> policies;
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,9 @@
|
|||||||
|
|
||||||
using namespace Napi;
|
using namespace Napi;
|
||||||
|
|
||||||
PolicyWatcher::PolicyWatcher(std::string productName, const Function &okCallback)
|
PolicyWatcher::PolicyWatcher(std::string vendorName, std::string productName, const Function &okCallback)
|
||||||
: AsyncProgressQueueWorker(okCallback),
|
: AsyncProgressQueueWorker(okCallback),
|
||||||
|
vendorName(vendorName),
|
||||||
productName(productName)
|
productName(productName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,9 @@
|
|||||||
|
|
||||||
using namespace Napi;
|
using namespace Napi;
|
||||||
|
|
||||||
PolicyWatcher::PolicyWatcher(std::string productName, const Function &okCallback)
|
PolicyWatcher::PolicyWatcher(std::string vendorName, std::string productName, const Function &okCallback)
|
||||||
: AsyncProgressQueueWorker(okCallback),
|
: AsyncProgressQueueWorker(okCallback),
|
||||||
|
vendorName(vendorName),
|
||||||
productName(productName)
|
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");
|
throw TypeError::New(env, "Unsupported platform");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (info.Length() < 3)
|
if (info.Length() < 4)
|
||||||
throw TypeError::New(env, "Expected 3 arguments");
|
throw TypeError::New(env, "Expected 3 arguments");
|
||||||
else if (!info[0].IsString())
|
else if (!info[0].IsString())
|
||||||
throw TypeError::New(env, "Expected first arg to be string");
|
throw TypeError::New(env, "Expected first arg to be string");
|
||||||
else if (!info[1].IsObject())
|
else if (!info[1].IsString())
|
||||||
throw TypeError::New(env, "Expected second arg to be object");
|
throw TypeError::New(env, "Expected second arg to be string");
|
||||||
else if (!info[2].IsFunction())
|
else if (!info[2].IsObject())
|
||||||
throw TypeError::New(env, "Expected third arg to be function");
|
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 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)
|
for (auto const &item : rawPolicies)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
using namespace Napi;
|
using namespace Napi;
|
||||||
|
|
||||||
NumberPolicy::NumberPolicy(const std::string name, const std::string &productName)
|
NumberPolicy::NumberPolicy(const std::string name, const std::string &vendorName, const std::string &productName)
|
||||||
: RegistryPolicy(name, productName, REG_QWORD) {}
|
: RegistryPolicy(name, vendorName, productName, REG_QWORD) {}
|
||||||
|
|
||||||
long long NumberPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const
|
long long NumberPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -15,7 +15,7 @@ using namespace Napi;
|
|||||||
class NumberPolicy : public RegistryPolicy<long long>
|
class NumberPolicy : public RegistryPolicy<long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NumberPolicy(const std::string name, const std::string &productName);
|
NumberPolicy(const std::string name, const std::string &vendorName, const std::string &productName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
long long parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const;
|
long long parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const;
|
||||||
|
|||||||
@ -11,8 +11,9 @@
|
|||||||
|
|
||||||
using namespace Napi;
|
using namespace Napi;
|
||||||
|
|
||||||
PolicyWatcher::PolicyWatcher(std::string productName, const Function &okCallback)
|
PolicyWatcher::PolicyWatcher(std::string vendorName, std::string productName, const Function &okCallback)
|
||||||
: AsyncProgressQueueWorker(okCallback),
|
: AsyncProgressQueueWorker(okCallback),
|
||||||
|
vendorName(vendorName),
|
||||||
productName(productName)
|
productName(productName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -29,12 +30,12 @@ PolicyWatcher::~PolicyWatcher()
|
|||||||
|
|
||||||
void PolicyWatcher::AddStringPolicy(const std::string name)
|
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)
|
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)
|
void PolicyWatcher::OnExecute(Napi::Env env)
|
||||||
|
|||||||
@ -17,9 +17,9 @@ template <typename T>
|
|||||||
class RegistryPolicy : public Policy
|
class RegistryPolicy : public Policy
|
||||||
{
|
{
|
||||||
public:
|
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),
|
: Policy(name),
|
||||||
registryKey("Software\\Policies\\Microsoft\\" + productName),
|
registryKey("Software\\Policies\\" + vendorName + "\\" + productName),
|
||||||
regType(regType) {}
|
regType(regType) {}
|
||||||
|
|
||||||
bool refresh()
|
bool refresh()
|
||||||
|
|||||||
@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
using namespace Napi;
|
using namespace Napi;
|
||||||
|
|
||||||
StringPolicy::StringPolicy(const std::string name, const std::string &productName)
|
StringPolicy::StringPolicy(const std::string name, const std::string &vendorName, const std::string &productName)
|
||||||
: RegistryPolicy(name, productName, REG_SZ) {}
|
: RegistryPolicy(name, vendorName, productName, REG_SZ) {}
|
||||||
|
|
||||||
std::string StringPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const
|
std::string StringPolicy::parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -15,7 +15,7 @@ using namespace Napi;
|
|||||||
class StringPolicy : public RegistryPolicy<std::string>
|
class StringPolicy : public RegistryPolicy<std::string>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StringPolicy(const std::string name, const std::string &productName);
|
StringPolicy(const std::string name, const std::string &vendorName, const std::string &productName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const;
|
std::string parseRegistryValue(LPBYTE buffer, DWORD bufferSize) const;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user