convenience.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. Copyright (c) 2011-2012, Giovanni Campagna <scampa.giovanni@gmail.com>
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are met:
  5. * Redistributions of source code must retain the above copyright
  6. notice, this list of conditions and the following disclaimer.
  7. * Redistributions in binary form must reproduce the above copyright
  8. notice, this list of conditions and the following disclaimer in the
  9. documentation and/or other materials provided with the distribution.
  10. * Neither the name of the GNOME nor the
  11. names of its contributors may be used to endorse or promote products
  12. derived from this software without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  17. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  20. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. 'use strict';
  25. import Gio from 'gi://Gio';
  26. var debugEnabled = false;
  27. /**
  28. * @param {boolean} d Enable/Disable debug logging
  29. */
  30. export function setDebugEnabled(d) {
  31. debugEnabled = d;
  32. }
  33. /**
  34. * @param {string} msg the message to log
  35. * @class
  36. */
  37. export function TalkativeLog(msg) {
  38. if (debugEnabled)
  39. console.log(`[ESC]${msg}`);
  40. }
  41. /**
  42. * Gets the full (semantic) version of this extension.
  43. *
  44. * <p>Note: The actual value is added during build time.
  45. *
  46. * @returns {string} the version
  47. */
  48. export function getFullVersion() {
  49. return '1.11.0'; // FULL_VERSION
  50. }
  51. /**
  52. * Loads an icon from the extension's subdirectory "images".
  53. *
  54. * @param {Gio.File} extensionDir dir of the extension
  55. * @param {string} name filename of the image
  56. * @returns {Gio.FileIcon} the icon
  57. */
  58. export function loadIcon(extensionDir, name) {
  59. return new Gio.FileIcon({
  60. file: Gio.File.new_for_path(
  61. getImagePath(extensionDir, name)
  62. ),
  63. });
  64. }
  65. /**
  66. * Gets the path to the image from the extension's subdirectory "images".
  67. *
  68. * @param {Gio.File} extensionDir dir of the extension
  69. * @param {string} name filename of the image
  70. * @returns {string} the path
  71. */
  72. export function getImagePath(extensionDir, name) {
  73. return extensionDir.get_child(`images/${name}`).get_path();
  74. }