text: // Copyright (c) Microsoft Corporation. All rights reserved.
  // Licensed under the MIT license.
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
      function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
      return new (P || (P = Promise))(function (resolve, reject) {
          function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
          function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
          function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
          step((generator = generator.apply(thisArg, _arguments || [])).next());
      });
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.unregisterAllAddIns = exports.unregisterAddIn = exports.setWebView = exports.setSourceBundleUrl = exports.registerAddIn = exports.isLiveReloadEnabled = exports.isDebuggingEnabled = exports.getWebView = exports.getSourceBundleUrl = exports.getRuntimeLoggingPath = exports.getOpenDevTools = exports.getEnabledDebuggingMethods = exports.getRegisterAddIns = exports.enableRuntimeLogging = exports.enableLiveReload = exports.enableDebugging = exports.disableRuntimeLogging = exports.disableLiveReload = exports.disableDebugging = exports.clearDevSettings = exports.SourceBundleUrlComponents = exports.RegisteredAddin = exports.WebViewType = exports.DebuggingMethod = void 0;
  const fs = require("fs");
  const office_addin_manifest_1 = require("office-addin-manifest");
  const fspath = require("path");
  const devSettingsMac = require("./dev-settings-mac");
  const devSettingsWindows = require("./dev-settings-windows");
  const defaultRuntimeLogFileName = "OfficeAddins.log.txt";
  var DebuggingMethod;
  (function (DebuggingMethod) {
      DebuggingMethod[DebuggingMethod["Direct"] = 0] = "Direct";
      DebuggingMethod[DebuggingMethod["Proxy"] = 1] = "Proxy";
      /** @deprecated use Proxy */
      DebuggingMethod[DebuggingMethod["Web"] = 1] = "Web";
  })(DebuggingMethod = exports.DebuggingMethod || (exports.DebuggingMethod = {}));
  var WebViewType;
  (function (WebViewType) {
      WebViewType["Default"] = "Default";
      WebViewType["IE"] = "IE";
      WebViewType["Edge"] = "Edge";
      WebViewType["EdgeChromium"] = "Edge Chromium";
  })(WebViewType = exports.WebViewType || (exports.WebViewType = {}));
  class RegisteredAddin {
      constructor(id, manifestPath) {
          this.id = id;
          this.manifestPath = manifestPath;
      }
  }
  exports.RegisteredAddin = RegisteredAddin;
  class SourceBundleUrlComponents {
      constructor(host, port, path, extension) {
          this.host = host;
          this.port = port;
          this.path = path;
          this.extension = extension;
      }
      get url() {
          const host = (this.host !== undefined) ? this.host : "localhost";
          const port = (this.port !== undefined) ? this.port : "8081";
          const path = (this.path !== undefined) ? this.path : "{path}";
          const extension = (this.extension !== undefined) ? this.extension : ".bundle";
          return `http://${host}${host && port ? ":" : ""}${port}/${path}${extension}`;
      }
  }
  exports.SourceBundleUrlComponents = SourceBundleUrlComponents;
  function clearDevSettings(addinId) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.clearDevSettings(addinId);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.clearDevSettings = clearDevSettings;
  function disableDebugging(addinId) {
      return __awaiter(this, void 0, void 0, function* () {
          return enableDebugging(addinId, false);
      });
  }
  exports.disableDebugging = disableDebugging;
  function disableLiveReload(addinId) {
      return __awaiter(this, void 0, void 0, function* () {
          return enableLiveReload(addinId, false);
      });
  }
  exports.disableLiveReload = disableLiveReload;
  function disableRuntimeLogging() {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.disableRuntimeLogging();
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.disableRuntimeLogging = disableRuntimeLogging;
  function enableDebugging(addinId, enable = true, method = DebuggingMethod.Direct, openDevTools = false) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.enableDebugging(addinId, enable, method, openDevTools);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.enableDebugging = enableDebugging;
  function enableLiveReload(addinId, enable = true) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.enableLiveReload(addinId, enable);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.enableLiveReload = enableLiveReload;
  function enableRuntimeLogging(path) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  if (!path) {
                      const tempDir = process.env.TEMP;
                      if (!tempDir) {
                          throw new Error("The TEMP environment variable is not defined.");
                      }
                      path = fspath.normalize(`${tempDir}/${defaultRuntimeLogFileName}`);
                  }
                  const pathExists = fs.existsSync(path);
                  if (pathExists) {
                      const stat = fs.statSync(path);
                      if (stat.isDirectory()) {
                          throw new Error(`You need to specify the path to a file. This is a directory: "${path}".`);
                      }
                  }
                  try {
                      const file = fs.openSync(path, "a+");
                      fs.closeSync(file);
                  }
                  catch (err) {
                      throw new Error(pathExists
                          ? `You need to specify the path to a writable file. Unable to write to: "${path}".`
                          : `You need to specify the path where the file can be written. Unable to write to: "${path}".`);
                  }
                  yield devSettingsWindows.enableRuntimeLogging(path);
                  return path;
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.enableRuntimeLogging = enableRuntimeLogging;
  /**
   * Returns the manifest paths for the add-ins that are registered
   */
  function getRegisterAddIns() {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "darwin":
                  return devSettingsMac.getRegisteredAddIns();
              case "win32":
                  return devSettingsWindows.getRegisteredAddIns();
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.getRegisterAddIns = getRegisterAddIns;
  function getEnabledDebuggingMethods(addinId) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.getEnabledDebuggingMethods(addinId);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.getEnabledDebuggingMethods = getEnabledDebuggingMethods;
  function getOpenDevTools(addinId) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.getOpenDevTools(addinId);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.getOpenDevTools = getOpenDevTools;
  function getRuntimeLoggingPath() {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.getRuntimeLoggingPath();
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.getRuntimeLoggingPath = getRuntimeLoggingPath;
  function getSourceBundleUrl(addinId) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.getSourceBundleUrl(addinId);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.getSourceBundleUrl = getSourceBundleUrl;
  function getWebView(addinId) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.getWebView(addinId);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.getWebView = getWebView;
  function isDebuggingEnabled(addinId) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.isDebuggingEnabled(addinId);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.isDebuggingEnabled = isDebuggingEnabled;
  function isLiveReloadEnabled(addinId) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.isLiveReloadEnabled(addinId);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.isLiveReloadEnabled = isLiveReloadEnabled;
  function registerAddIn(manifestPath) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  const manifest = yield office_addin_manifest_1.readManifestFile(manifestPath);
                  const realManifestPath = fs.realpathSync(manifestPath);
                  return devSettingsWindows.registerAddIn(manifest.id || "", realManifestPath);
              case "darwin":
                  return devSettingsMac.registerAddIn(manifestPath);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.registerAddIn = registerAddIn;
  function setSourceBundleUrl(addinId, components) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.setSourceBundleUrl(addinId, components);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.setSourceBundleUrl = setSourceBundleUrl;
  function setWebView(addinId, webViewType) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "win32":
                  return devSettingsWindows.setWebView(addinId, webViewType);
                  ;
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.setWebView = setWebView;
  function unregisterAddIn(manifestPath) {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "darwin":
                  return devSettingsMac.unregisterAddIn(manifestPath);
              case "win32":
                  const manifest = yield office_addin_manifest_1.readManifestFile(manifestPath);
                  const realManifestPath = fs.realpathSync(manifestPath);
                  return devSettingsWindows.unregisterAddIn(manifest.id || "", realManifestPath);
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.unregisterAddIn = unregisterAddIn;
  function unregisterAllAddIns() {
      return __awaiter(this, void 0, void 0, function* () {
          switch (process.platform) {
              case "darwin":
                  return devSettingsMac.unregisterAllAddIns();
              case "win32":
                  return devSettingsWindows.unregisterAllAddIns();
              default:
                  throw new Error(`Platform not supported: ${process.platform}.`);
          }
      });
  }
  exports.unregisterAllAddIns = unregisterAllAddIns;
  //# sourceMappingURL=dev-settings.js.map