office-addin-dev-settings
Version:
Configure developer settings for Office Add-ins.
420 lines • 19.6 kB
JavaScript
;
// copyright (c) Microsoft Corporation. All rights reserved.
// licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutlookSideloadManifestPath = void 0;
exports.clearDevSettings = clearDevSettings;
exports.deleteDeveloperSettingsRegistryKey = deleteDeveloperSettingsRegistryKey;
exports.disableRuntimeLogging = disableRuntimeLogging;
exports.enableDebugging = enableDebugging;
exports.enableLiveReload = enableLiveReload;
exports.enableRuntimeLogging = enableRuntimeLogging;
exports.getDeveloperSettingsRegistryKey = getDeveloperSettingsRegistryKey;
exports.getProvidersRegistryKey = getProvidersRegistryKey;
exports.getEnabledDebuggingMethods = getEnabledDebuggingMethods;
exports.getOpenDevTools = getOpenDevTools;
exports.getRegisteredAddIns = getRegisteredAddIns;
exports.getRuntimeLoggingPath = getRuntimeLoggingPath;
exports.getSourceBundleUrl = getSourceBundleUrl;
exports.getWebView = getWebView;
exports.isDebuggingEnabled = isDebuggingEnabled;
exports.isLiveReloadEnabled = isLiveReloadEnabled;
exports.registerAddIn = registerAddIn;
exports.setSourceBundleUrl = setSourceBundleUrl;
exports.setWebView = setWebView;
exports.toWebViewTypeName = toWebViewTypeName;
exports.unregisterAddIn = unregisterAddIn;
exports.unregisterAllAddIns = unregisterAllAddIns;
exports.disableRefreshAddins = disableRefreshAddins;
exports.enableSourceBundleOverrideFile = enableSourceBundleOverrideFile;
exports.disableSourceBundleOverrideFile = disableSourceBundleOverrideFile;
exports.isSourceBundleOverriden = isSourceBundleOverriden;
exports.getSourceBundleOverrideFilePath = getSourceBundleOverrideFilePath;
exports.enableDiskManifests = enableDiskManifests;
exports.disableDiskManifests = disableDiskManifests;
exports.areDiskManifestsEnabled = areDiskManifestsEnabled;
exports.getDiskManifestsPath = getDiskManifestsPath;
exports.getOutlookEnableDebugging = getOutlookEnableDebugging;
const tslib_1 = require("tslib");
const office_addin_manifest_1 = require("office-addin-manifest");
const dev_settings_1 = require("./dev-settings");
const office_addin_usage_data_1 = require("office-addin-usage-data");
const registry = tslib_1.__importStar(require("./registry"));
const publish_1 = require("./publish");
const path_1 = tslib_1.__importDefault(require("path"));
/* global process */
const DeveloperSettingsRegistryKey = `HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Office\\16.0\\Wef\\Developer`;
const ProvidersRegistryKey = `HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\16.0\\WEF\\Providers`;
const OpenDevTools = "OpenDevTools";
exports.OutlookSideloadManifestPath = "OutlookSideloadManifestPath";
const RefreshAddins = "RefreshAddins";
const RuntimeLogging = "RuntimeLogging";
const SourceBundleExtension = "SourceBundleExtension";
const SourceBundleHost = "SourceBundleHost";
const SourceBundlePath = "SourceBundlePath";
const SourceBundlePort = "SourceBundlePort";
const TitleId = "TitleId";
const UseDirectDebugger = "UseDirectDebugger";
const UseLiveReload = "UseLiveReload";
const UseProxyDebugger = "UseWebDebugger";
const WebViewSelection = "WebViewSelection";
const JsBundle = "JsBundle";
const Outlook = "Outlook";
const EnableDebugging = "EnableDebugging";
const OutlookDiskProvider = "OutlookDiskProvider";
function clearDevSettings(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield disableDiskManifests();
return deleteDeveloperSettingsRegistryKey(addinId);
});
}
function deleteDeveloperSettingsRegistryKey(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
return registry.deleteKey(key);
});
}
function disableRuntimeLogging() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(RuntimeLogging);
return registry.deleteKey(key);
});
}
function enableDebugging(addinId_1) {
return tslib_1.__awaiter(this, arguments, void 0, function* (addinId, enable = true, method = dev_settings_1.DebuggingMethod.Proxy, openDevTools = false) {
const key = getDeveloperSettingsRegistryKey(addinId);
const useDirectDebugger = enable && method === dev_settings_1.DebuggingMethod.Direct;
const useProxyDebugger = enable && method === dev_settings_1.DebuggingMethod.Proxy;
yield registry.addBooleanValue(key, UseDirectDebugger, useDirectDebugger);
yield registry.addBooleanValue(key, UseProxyDebugger, useProxyDebugger);
if (enable && openDevTools) {
yield registry.addBooleanValue(key, OpenDevTools, true);
}
else {
yield registry.deleteValue(key, OpenDevTools);
}
});
}
function enableLiveReload(addinId_1) {
return tslib_1.__awaiter(this, arguments, void 0, function* (addinId, enable = true) {
const key = getDeveloperSettingsRegistryKey(addinId);
return registry.addBooleanValue(key, UseLiveReload, enable);
});
}
function enableRuntimeLogging(path) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(RuntimeLogging);
return registry.addStringValue(key, "", path); // empty string for the default value
});
}
function getDeveloperSettingsRegistryKey(addinId) {
if (!addinId) {
throw new office_addin_usage_data_1.ExpectedError("The addIn parameter is required.");
}
if (typeof addinId !== "string") {
throw new office_addin_usage_data_1.ExpectedError("The addIn parameter should be a string.");
}
return new registry.RegistryKey(`${DeveloperSettingsRegistryKey}\\${addinId}`);
}
function getProvidersRegistryKey() {
return new registry.RegistryKey(`${ProvidersRegistryKey}`);
}
function getEnabledDebuggingMethods(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const methods = [];
if (isRegistryValueTrue(yield registry.getValue(key, UseDirectDebugger))) {
methods.push(dev_settings_1.DebuggingMethod.Direct);
}
if (isRegistryValueTrue(yield registry.getValue(key, UseProxyDebugger))) {
methods.push(dev_settings_1.DebuggingMethod.Proxy);
}
return methods;
});
}
function getOpenDevTools(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
return isRegistryValueTrue(yield registry.getValue(key, OpenDevTools));
});
}
function getRegisteredAddIns() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
const values = yield registry.getValues(key);
const filteredValues = values.filter((value) => value.name !== RefreshAddins);
// if the registry value name and data are the same, then the manifest path was used as the name
return filteredValues.map((value) => new dev_settings_1.RegisteredAddin(value.name !== value.data ? value.name : "", value.data));
});
}
function getRuntimeLoggingPath() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(RuntimeLogging);
return registry.getStringValue(key, ""); // empty string for the default value
});
}
function getSourceBundleUrl(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const components = new dev_settings_1.SourceBundleUrlComponents(yield registry.getStringValue(key, SourceBundleHost), yield registry.getStringValue(key, SourceBundlePort), yield registry.getStringValue(key, SourceBundlePath), yield registry.getStringValue(key, SourceBundleExtension));
return components;
});
}
function getWebView(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const webViewString = yield registry.getStringValue(key, WebViewSelection);
return toWebViewType(webViewString);
});
}
function isDebuggingEnabled(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const useDirectDebugger = isRegistryValueTrue(yield registry.getValue(key, UseDirectDebugger));
const useWebDebugger = isRegistryValueTrue(yield registry.getValue(key, UseProxyDebugger));
return useDirectDebugger || useWebDebugger;
});
}
function isLiveReloadEnabled(addinId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
const enabled = isRegistryValueTrue(yield registry.getValue(key, UseLiveReload));
return enabled;
});
}
function isRegistryValueTrue(value) {
if (value) {
switch (value.type) {
case registry.RegistryTypes.REG_DWORD:
case registry.RegistryTypes.REG_QWORD:
case registry.RegistryTypes.REG_SZ:
return parseInt(value.data, undefined) !== 0;
}
}
return false;
}
function registerAddIn(manifestPath, registration) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
const appsInManifest = (0, office_addin_manifest_1.getOfficeAppsForManifestHosts)(manifest.hosts);
// Register using the service
if (manifest.manifestType === office_addin_manifest_1.ManifestType.JSON ||
appsInManifest.indexOf(office_addin_manifest_1.OfficeApp.Outlook) >= 0) {
if (!registration) {
let filePath = "";
if (manifest.manifestType === office_addin_manifest_1.ManifestType.JSON) {
const targetPath = path_1.default.join(process.env.TEMP, "manifest.zip");
filePath = yield (0, office_addin_manifest_1.exportMetadataPackage)(targetPath, manifestPath);
}
else if (manifest.manifestType === office_addin_manifest_1.ManifestType.XML) {
filePath = manifestPath;
}
registration = yield (0, publish_1.registerWithTeams)(filePath);
yield enableRefreshAddins();
}
const key = getDeveloperSettingsRegistryKey(exports.OutlookSideloadManifestPath);
yield registry.addStringValue(key, TitleId, registration);
}
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
yield registry.deleteValue(key, manifestPath); // in case the manifest path was previously used as the key
return registry.addStringValue(key, manifest.id || "", manifestPath);
});
}
function setSourceBundleUrl(addinId, components) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
if (components.host !== undefined) {
if (components.host) {
yield registry.addStringValue(key, SourceBundleHost, components.host);
}
else {
yield registry.deleteValue(key, SourceBundleHost);
}
}
if (components.port !== undefined) {
if (components.port) {
yield registry.addStringValue(key, SourceBundlePort, components.port);
}
else {
yield registry.deleteValue(key, SourceBundlePort);
}
}
if (components.path !== undefined) {
if (components.path) {
yield registry.addStringValue(key, SourceBundlePath, components.path);
}
else {
yield registry.deleteValue(key, SourceBundlePath);
}
}
if (components.extension !== undefined) {
if (components.extension) {
yield registry.addStringValue(key, SourceBundleExtension, components.extension);
}
else {
yield registry.deleteValue(key, SourceBundleExtension);
}
}
});
}
function setWebView(addinId, webViewType) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = getDeveloperSettingsRegistryKey(addinId);
switch (webViewType) {
case undefined:
case dev_settings_1.WebViewType.Default:
yield registry.deleteValue(key, WebViewSelection);
break;
case dev_settings_1.WebViewType.EdgeChromium: {
const webViewString = webViewType;
yield registry.addStringValue(key, WebViewSelection, webViewString);
break;
}
default:
throw new office_addin_usage_data_1.ExpectedError(`The webViewType ${webViewType} is not supported.`);
}
});
}
function toWebViewType(webViewString) {
switch (webViewString ? webViewString.toLowerCase() : undefined) {
case "edge chromium":
return dev_settings_1.WebViewType.EdgeChromium;
default:
return undefined;
}
}
function toWebViewTypeName(webViewType) {
switch (webViewType) {
case dev_settings_1.WebViewType.EdgeChromium:
return "Microsoft Edge (Chromium)";
default:
return undefined;
}
}
function unregisterAddIn(addinId, manifestPath) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
if (addinId) {
const manifest = yield office_addin_manifest_1.OfficeAddinManifest.readManifestFile(manifestPath);
const appsInManifest = (0, office_addin_manifest_1.getOfficeAppsForManifestHosts)(manifest.hosts);
// Unregister using the service
// TODO: remove if statement when the service supports all hosts
if (manifest.manifestType === office_addin_manifest_1.ManifestType.JSON ||
appsInManifest.indexOf(office_addin_manifest_1.OfficeApp.Outlook) >= 0) {
yield unacquire(key, addinId);
}
yield registry.deleteValue(key, addinId);
}
// since the key used to be manifest path, delete it too
if (manifestPath) {
yield registry.deleteValue(key, manifestPath);
}
});
}
function unregisterAllAddIns() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const registeredAddins = yield getRegisteredAddIns();
for (const addin of registeredAddins) {
yield unregisterAddIn(addin.id, addin.manifestPath);
}
});
}
function unacquire(key, id) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const manifest = yield registry.getStringValue(key, id);
if (manifest != undefined) {
const key = getDeveloperSettingsRegistryKey(exports.OutlookSideloadManifestPath);
const registration = yield registry.getStringValue(key, TitleId);
// Try manifest id first, fall back to titleId from registry
const uninstallId = id || registration;
if (uninstallId && (yield (0, publish_1.uninstallWithTeams)(uninstallId))) {
if (registration != undefined) {
registry.deleteValue(key, TitleId);
}
yield enableRefreshAddins();
}
}
});
}
function enableRefreshAddins() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
yield registry.addBooleanValue(key, RefreshAddins, true);
});
}
function disableRefreshAddins() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const key = new registry.RegistryKey(`${DeveloperSettingsRegistryKey}`);
yield registry.deleteValue(key, RefreshAddins);
});
}
function enableSourceBundleOverrideFile(addInId, path) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const developerSettingsRegKey = getDeveloperSettingsRegistryKey(addInId);
yield registry.addStringValue(developerSettingsRegKey, JsBundle, path);
});
}
function disableSourceBundleOverrideFile(addInId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const developerSettingsRegKey = getDeveloperSettingsRegistryKey(addInId);
yield registry.deleteValue(developerSettingsRegKey, JsBundle);
});
}
function isSourceBundleOverriden(addInId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const sourceBundleOverridePath = yield getSourceBundleOverrideFilePath(addInId);
if (sourceBundleOverridePath && (sourceBundleOverridePath.length > 0)) {
return `Source bundle override. Add-in: ${addInId}. Override file: ${sourceBundleOverridePath}`;
}
return `Source bundle has not been overriden for add-in ${addInId}`;
});
}
function getSourceBundleOverrideFilePath(addInId) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const developerSettingsRegKey = getDeveloperSettingsRegistryKey(addInId);
const sourceBundleOverridePath = yield registry.getStringValue(developerSettingsRegKey, JsBundle);
return sourceBundleOverridePath;
});
}
function enableDiskManifests(path) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const providersRegKey = getProvidersRegistryKey();
yield registry.addStringValue(providersRegKey, OutlookDiskProvider, path);
const outlookDeveloperRegKey = getDeveloperSettingsRegistryKey(Outlook);
yield registry.addNumberValue(outlookDeveloperRegKey, EnableDebugging, 1);
});
}
function disableDiskManifests() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const providersRegKey = getProvidersRegistryKey();
yield registry.deleteValue(providersRegKey, OutlookDiskProvider);
const outlookDeveloperRegKey = getDeveloperSettingsRegistryKey(Outlook);
yield registry.deleteKey(outlookDeveloperRegKey);
});
}
function areDiskManifestsEnabled() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const diskManifestsPath = yield getDiskManifestsPath();
const enableDebugging = yield getOutlookEnableDebugging();
if (diskManifestsPath && enableDebugging && enableDebugging > 0) {
return "Disk manifests are enabled. Path = " + diskManifestsPath;
}
return "Disk manifests are disabled";
});
}
function getDiskManifestsPath() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const providersRegKey = getProvidersRegistryKey();
const diskManifestsPath = yield registry.getStringValue(providersRegKey, OutlookDiskProvider);
return diskManifestsPath;
});
}
function getOutlookEnableDebugging() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const outlookDeveloperRegKey = getDeveloperSettingsRegistryKey(Outlook);
const enableDebugging = yield registry.getNumberValue(outlookDeveloperRegKey, EnableDebugging);
return enableDebugging;
});
}
//# sourceMappingURL=dev-settings-windows.js.map