extension.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Desktop Icons GNOME Shell extension
  2. *
  3. * Copyright (C) 2017 Carlos Soriano <csoriano@redhat.com>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. const Main = imports.ui.main;
  19. const ExtensionUtils = imports.misc.extensionUtils;
  20. const Me = ExtensionUtils.getCurrentExtension();
  21. const Prefs = Me.imports.prefs;
  22. const { DesktopManager } = Me.imports.desktopManager;
  23. const { TemplateManager } = Me.imports.templateManager;
  24. const DBusUtils = Me.imports.dbusUtils;
  25. var desktopManager = null;
  26. var templateManager = null;
  27. var addBackgroundMenuOrig = null;
  28. var _startupPreparedId;
  29. var lockActivitiesButton = false;
  30. var oldShouldToggleByCornerOrButtonFunction = null;
  31. function init() {
  32. addBackgroundMenuOrig = Main.layoutManager._addBackgroundMenu;
  33. Prefs.initTranslations();
  34. }
  35. function newShouldToggleByCornerOrButton() {
  36. if (lockActivitiesButton)
  37. return false;
  38. else
  39. return oldShouldToggleByCornerOrButtonFunction.bind(Main.overview);
  40. }
  41. function enable() {
  42. // register a new function to allow to lock the Activities button when doing a rubberband selection
  43. oldShouldToggleByCornerOrButtonFunction = Main.overview.shouldToggleByCornerOrButton;
  44. Main.overview.shouldToggleByCornerOrButton = newShouldToggleByCornerOrButton;
  45. // wait until the startup process has ended
  46. if (Main.layoutManager._startingUp)
  47. _startupPreparedId = Main.layoutManager.connect('startup-complete', () => innerEnable(true));
  48. else
  49. innerEnable(false);
  50. }
  51. function innerEnable(disconnectSignal) {
  52. if (disconnectSignal)
  53. Main.layoutManager.disconnect(_startupPreparedId);
  54. DBusUtils.init();
  55. Prefs.init();
  56. Main.layoutManager._addBackgroundMenu = function() {};
  57. desktopManager = new DesktopManager();
  58. templateManager = new TemplateManager();
  59. }
  60. function disable() {
  61. desktopManager.destroy();
  62. templateManager.destroy();
  63. Main.layoutManager._addBackgroundMenu = addBackgroundMenuOrig;
  64. Main.overview.shouldToggleByCornerOrButton = oldShouldToggleByCornerOrButtonFunction;
  65. }