UNPKG

gpii-windows

Version:

Components of the GPII personalization infrastructure for use on Microsoft's "Windows" ™

78 lines (66 loc) 2.62 kB
/* Reload the ribbon on Office Applications. * * Copyright 2019 Raising the Floor - International * * Licensed under the New BSD license. You may not use this file except in * compliance with this License. * * The R&D leading to these results received funding from the * Department of Education - Grant H421A150005 (GPII-APCP). However, * these results do not necessarily represent the policy of the * Department of Education, and you should not assume endorsement by the * Federal Government. * * You may obtain a copy of the License at * https://github.com/GPII/universal/blob/master/LICENSE.txt */ "use strict"; var fluid = require("gpii-universal"), path = require("path"), fs = require("fs"), edge = process.versions.electron ? require("electron-edge-js") : require("edge-js"); var gpii = fluid.registerNamespace("gpii"); fluid.registerNamespace("gpii.windows.office"); gpii.windows.office.reloadRibbonNative = edge.func({ source: path.join(__dirname, "ribbonReload.cs"), typeName: "GPIIOffice.RibbonReload", references: ["System.Runtime.dll"] }); /** * Reloads the ribbon for a given Office Application. * @param {String} applicationName Name of the application, such as "Word" or "Excel" * @param {String} targetPath Path of the customUI file. * @param {Object} applicationObject Something that looks like an office automation COM object (for testing) * @return {Promise} Resolves when complete, with a boolean indicating if it succeeded. */ gpii.windows.office.reloadRibbon = function (applicationName, targetPath, applicationObject) { var promise = fluid.promise(); fluid.log("Reloading ribbon for " + applicationName); if (targetPath && !fs.existsSync(targetPath)) { // When performing a live update, a non-existing file doesn't remove new the items added by the last update. // Set it to a special file to make it reset. fs.copyFileSync(path.join(__dirname, "reset.xml"), targetPath); var cleanup = function () { fs.unlinkSync(targetPath); }; promise.then(cleanup, cleanup); } gpii.windows.office.reloadRibbonNative({ applicationName: applicationName, applicationObject: applicationObject }, function (err, result) { if (err) { fluid.log("ReloadRibbon:", err); promise.reject(err); } else { promise.resolve(result); } }); return promise; }; fluid.defaults("gpii.windows.office.reloadRibbon", { gradeNames: "fluid.function", argumentMap: { application: 0, path: 1 } });