Skip to content

Commit 3cd4d3e

Browse files
committed
extensions: Simplify code used for loading xlets, improve startup
speed, fix backtrace uselessness. - Drop 'custom' importer code, use native cjs importer - Leave compatibility functions for require() and module.exports Fixes/improves: - Faster Cinnamon startup (for my random configuration, ~1550ms down to ~1200ms). - Improved logging. - More consistent code (use of deprecated features will start getting flagged and/or blocked for PRs in Cinnamon and spice repositories. - Previous code was practically unmaintainable by sane people. Logging - where before we'd see this useless garbage: (cinnamon:4334): St-CRITICAL **: 22:19:57.081: st_widget_get_theme_node called on the widget [0x622f6579b3c0 StLabel.hourly-data ("...")] which is not in the stage. == Stack trace for context 0x622f63105b50 == 0 7ffd484001c0 b /usr/share/cinnamon/js/misc/fileUtils.js line 211 > Function:19086 (359f8e6c9c0 @ 279) 1 622f632b5d08 i /usr/share/cinnamon/js/misc/fileUtils.js line 211 > Function:19059 (359f8e6c970 @ 23) 2 7ffd48400ca0 b /usr/share/cinnamon/js/misc/fileUtils.js line 211 > Function:18976 (359f8e6c6a0 @ 807) 3 622f632b5b68 i /usr/share/cinnamon/js/misc/fileUtils.js line 211 > Function:19550 (359f8e6d650 @ 104) 4 622f632b5ab8 i /usr/share/cinnamon/js/misc/fileUtils.js line 211 > Function:19842 (359f8e6e2e0 @ 681) 5 622f632b5a08 i self-hosted:1461 (1eb5245b46f0 @ 30) 6 7ffd484015a0 b self-hosted:852 (359f8e92dd0 @ 15) we now get: (cinnamon:4334): St-CRITICAL **: 22:20:36.263: st_widget_get_theme_node called on the widget [0x58cf71ab5180 StLabel.hourly-data ("...")] which is not in the stage. == Stack trace for context 0x58cf6ee74250 == 0 7fffae294e10 b /home/mtwebster/.local/share/cinnamon/applets/weather@mockturtl/3.8/weather-applet.js:19084 (387d8e1fd1a0 @ 279) 1 58cf6eeac1f8 i /home/mtwebster/.local/share/cinnamon/applets/weather@mockturtl/3.8/weather-applet.js:19057 (387d8e1fd150 @ 23) 2 7fffae2958f0 b /home/mtwebster/.local/share/cinnamon/applets/weather@mockturtl/3.8/weather-applet.js:18974 (387d8e1fce20 @ 807) 3 58cf6eeac058 i /home/mtwebster/.local/share/cinnamon/applets/weather@mockturtl/3.8/weather-applet.js:19548 (387d8e1fddd0 @ 104) 4 58cf6eeabfa8 i /home/mtwebster/.local/share/cinnamon/applets/weather@mockturtl/3.8/weather-applet.js:19840 (387d8e1fea60 @ 681) 5 58cf6eeabef8 i self-hosted:1461 (2daaca0bf470 @ 30) 6 7fffae2961f0 b self-hosted:852 (e85adf8c6a0 @ 15) Requires linuxmint/cjs#136 for xlet 'reload' functionality to work.
1 parent 9211718 commit 3cd4d3e

File tree

17 files changed

+454
-423
lines changed

17 files changed

+454
-423
lines changed

files/usr/share/cinnamon/applets/calendar@cinnamon.org/applet.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ const Util = imports.misc.util;
88
const PopupMenu = imports.ui.popupMenu;
99
const UPowerGlib = imports.gi.UPowerGlib;
1010
const Settings = imports.ui.settings;
11-
const Calendar = require('./calendar');
12-
const EventView = require('./eventView');
1311
const CinnamonDesktop = imports.gi.CinnamonDesktop;
1412
const Main = imports.ui.main;
1513
const Separator = imports.ui.separator;
1614

15+
const Me = imports.ui.extension.getCurrentExtension();
16+
const Calendar = Me.imports.calendar;
17+
const EventView = Me.imports.eventView;
18+
1719
const DAY_FORMAT = CinnamonDesktop.WallClock.lctime_format("cinnamon", "%A");
1820
const DATE_FORMAT_SHORT = CinnamonDesktop.WallClock.lctime_format("cinnamon", _("%B %-e, %Y"));
1921
const DATE_FORMAT_FULL = CinnamonDesktop.WallClock.lctime_format("cinnamon", _("%A, %B %-e, %Y"));

files/usr/share/cinnamon/applets/calendar@cinnamon.org/calendar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function _dateIntervalsOverlap(a0, a1, b0, b1)
145145
return true;
146146
}
147147

148-
class Calendar {
148+
var Calendar = class Calendar {
149149
constructor(settings, events_manager) {
150150
this.events_manager = events_manager;
151151
this._weekStart = Cinnamon.util_get_week_start();

files/usr/share/cinnamon/applets/calendar@cinnamon.org/eventView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class EventDataList {
290290
}
291291
}
292292

293-
class EventsManager {
293+
var EventsManager = class EventsManager {
294294
constructor(settings, desktop_settings) {
295295
this.settings = settings;
296296
this.desktop_settings = desktop_settings;

files/usr/share/cinnamon/applets/grouped-window-list@cinnamon.org/appGroup.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ const Mainloop = imports.mainloop;
1212
const {SignalManager} = imports.misc.signalManager;
1313
const {unref} = imports.misc.util;
1414

15-
const createStore = require('./state');
16-
const {AppMenuButtonRightClickMenu, HoverMenuController, AppThumbnailHoverMenu} = require('./menus');
15+
const Me = imports.ui.extension.getCurrentExtension();
16+
const {createStore} = Me.imports.state;
17+
const {AppMenuButtonRightClickMenu, HoverMenuController, AppThumbnailHoverMenu} = Me.imports.menus;
1718
const {
1819
FLASH_INTERVAL,
1920
FLASH_MAX_COUNT,
2021
MAX_BUTTON_WIDTH,
2122
BUTTON_BOX_ANIMATION_TIME,
2223
RESERVE_KEYS,
2324
TitleDisplay
24-
} = require('./constants');
25+
} = Me.imports.constants;
2526

2627
const _reLetterRtl = new RegExp("\\p{Script=Hebrew}|\\p{Script=Arabic}", "u");
2728
const _reLetter = new RegExp("\\p{L}", "u");
@@ -60,7 +61,7 @@ const getFocusState = function(metaWindow) {
6061
return false;
6162
};
6263

63-
class AppGroup {
64+
var AppGroup = class AppGroup {
6465
constructor(params) {
6566
this.state = params.state;
6667
this.workspaceState = params.workspaceState;
@@ -1224,5 +1225,3 @@ class AppGroup {
12241225
}
12251226
}
12261227
}
1227-
1228-
module.exports = AppGroup;

files/usr/share/cinnamon/applets/grouped-window-list@cinnamon.org/applet.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ const {AppletSettings} = imports.ui.settings;
1414
const {SignalManager} = imports.misc.signalManager;
1515
const {throttle, unref, trySpawnCommandLine} = imports.misc.util;
1616

17-
const createStore = require('./state');
18-
const AppGroup = require('./appGroup');
19-
const Workspace = require('./workspace');
17+
const Me = imports.ui.extension.getCurrentExtension();
18+
const {createStore} = Me.imports.state;
19+
const {AppGroup} = Me.imports.appGroup;
20+
const {Workspace} = Me.imports.workspace;
2021
const {
21-
RESERVE_KEYS,
22-
TitleDisplay,
23-
autoStartStrDir
24-
} = require('./constants');
22+
RESERVE_KEYS,
23+
TitleDisplay,
24+
autoStartStrDir
25+
} = Me.imports.constants;
2526

2627
class PinnedFavs {
2728
constructor(params) {
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
const CLOSE_BTN_SIZE = 22;
2-
const constants = {
3-
CLOSE_BTN_SIZE,
4-
CLOSED_BUTTON_STYLE: 'padding: 0px; width: ' + CLOSE_BTN_SIZE + 'px; height: '
5-
+ CLOSE_BTN_SIZE + 'px; max-width: ' + CLOSE_BTN_SIZE
6-
+ 'px; max-height: ' + CLOSE_BTN_SIZE + 'px; ' + '-cinnamon-close-overlap: 0px;' +
7-
'background-size: ' + CLOSE_BTN_SIZE + 'px ' + CLOSE_BTN_SIZE + 'px;',
8-
THUMBNAIL_ICON_SIZE: 16,
9-
OPACITY_OPAQUE: 255,
10-
BUTTON_BOX_ANIMATION_TIME: 150,
11-
MAX_BUTTON_WIDTH: 150, // Pixels
12-
FLASH_INTERVAL: 500,
13-
FLASH_MAX_COUNT: 4,
14-
RESERVE_KEYS: ['willUnmount'],
15-
TitleDisplay: {
16-
None: 1,
17-
App: 2,
18-
Title: 3,
19-
Focused: 4
20-
},
21-
FavType: {
22-
favorites: 0,
23-
pinnedApps: 1,
24-
none: 2
25-
},
26-
autoStartStrDir: './.config/autostart',
1+
var CLOSE_BTN_SIZE = 22;
2+
var CLOSED_BUTTON_STYLE = 'padding: 0px; width: ' + CLOSE_BTN_SIZE + 'px; height: '
3+
+ CLOSE_BTN_SIZE + 'px; max-width: ' + CLOSE_BTN_SIZE
4+
+ 'px; max-height: ' + CLOSE_BTN_SIZE + 'px; ' + '-cinnamon-close-overlap: 0px;' +
5+
'background-size: ' + CLOSE_BTN_SIZE + 'px ' + CLOSE_BTN_SIZE + 'px;';
6+
var THUMBNAIL_ICON_SIZE = 16;
7+
var OPACITY_OPAQUE = 255;
8+
var BUTTON_BOX_ANIMATION_TIME = 150;
9+
var MAX_BUTTON_WIDTH = 150; // Pixels
10+
var FLASH_INTERVAL = 500;
11+
var FLASH_MAX_COUNT = 4;
12+
var RESERVE_KEYS = ['willUnmount'];
13+
var TitleDisplay = {
14+
None: 1,
15+
App: 2,
16+
Title: 3,
17+
Focused: 4
2718
};
28-
29-
module.exports = constants;
19+
var FavType = {
20+
favorites: 0,
21+
pinnedApps: 1,
22+
none: 2
23+
};
24+
var autoStartStrDir = './.config/autostart';

files/usr/share/cinnamon/applets/grouped-window-list@cinnamon.org/menus.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ const WindowUtils = imports.misc.windowUtils;
1010
const Mainloop = imports.mainloop;
1111

1212
const {tryFn, unref, trySpawnCommandLine, spawn_async, getDesktopActionIcon} = imports.misc.util;
13+
const Me = imports.ui.extension.getCurrentExtension();
1314
const {
1415
CLOSE_BTN_SIZE,
1516
CLOSED_BUTTON_STYLE,
1617
OPACITY_OPAQUE,
1718
RESERVE_KEYS,
1819
FavType,
1920
autoStartStrDir
20-
} = require('./constants');
21+
} = Me.imports.constants;
2122

2223
const convertRange = function(value, r1, r2) {
2324
return ((value - r1[0]) * (r2[1] - r2[0])) / (r1[1] - r1[0]) + r2[0];
@@ -39,7 +40,7 @@ const setOpacity = (peekTime, window_actor, targetOpacity, cb) => {
3940
window_actor.ease(easeConfig);
4041
};
4142

42-
class AppMenuButtonRightClickMenu extends Applet.AppletPopupMenu {
43+
var AppMenuButtonRightClickMenu = class AppMenuButtonRightClickMenu extends Applet.AppletPopupMenu {
4344
constructor(params, orientation) {
4445
super(params, orientation);
4546
this.state = params.state;
@@ -413,7 +414,7 @@ class AppMenuButtonRightClickMenu extends Applet.AppletPopupMenu {
413414
}
414415
}
415416

416-
class HoverMenuController extends PopupMenu.PopupMenuManager {
417+
var HoverMenuController = class HoverMenuController extends PopupMenu.PopupMenuManager {
417418
constructor(actor, groupState) {
418419
super({actor}, false); // owner, shouldGrab
419420
this.groupState = groupState;
@@ -860,7 +861,7 @@ class WindowThumbnail {
860861
}
861862
}
862863

863-
class AppThumbnailHoverMenu extends PopupMenu.PopupMenu {
864+
var AppThumbnailHoverMenu = class AppThumbnailHoverMenu extends PopupMenu.PopupMenu {
864865
_init(state, groupState) {
865866
super._init.call(this, groupState.trigger('getActor'), state.orientation, 0.5);
866867
this.state = state;
@@ -1227,9 +1228,3 @@ class AppThumbnailHoverMenu extends PopupMenu.PopupMenu {
12271228
unref(this, RESERVE_KEYS);
12281229
}
12291230
}
1230-
1231-
module.exports = {
1232-
AppMenuButtonRightClickMenu,
1233-
HoverMenuController,
1234-
AppThumbnailHoverMenu
1235-
};

files/usr/share/cinnamon/applets/grouped-window-list@cinnamon.org/state.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function clone(object, refs = [], cache = null) {
137137
* to be used at the end of the application life cycle.
138138
*
139139
*/
140-
function createStore(state = {}, listeners = [], connections = 0) {
140+
var createStore = function(state = {}, listeners = [], connections = 0) {
141141
const publicAPI = Object.freeze({
142142
get,
143143
set,
@@ -316,6 +316,4 @@ function createStore(state = {}, listeners = [], connections = 0) {
316316
}
317317

318318
return getAPIWithObject(state);
319-
}
320-
321-
module.exports = createStore;
319+
};

files/usr/share/cinnamon/applets/grouped-window-list@cinnamon.org/workspace.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ const Main = imports.ui.main;
33
const {SignalManager} = imports.misc.signalManager;
44
const {unref} = imports.misc.util;
55

6-
const createStore = require('./state');
7-
const AppGroup = require('./appGroup');
8-
const {RESERVE_KEYS} = require('./constants');
6+
const Me = imports.ui.extension.getCurrentExtension();
7+
const {createStore} = Me.imports.state;
8+
const {AppGroup} = Me.imports.appGroup;
9+
const {RESERVE_KEYS} = Me.imports.constants;
910

10-
class Workspace {
11+
var Workspace = class Workspace {
1112
constructor(params) {
1213
this.state = params.state;
1314
this.state.connect({
@@ -428,5 +429,3 @@ class Workspace {
428429
unref(this, RESERVE_KEYS);
429430
}
430431
}
431-
432-
module.exports = Workspace;

files/usr/share/cinnamon/applets/menu@cinnamon.org/applet.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const USER_DESKTOP_PATH = FileUtils.getUserDesktopDir();
3535
const PRIVACY_SCHEMA = "org.cinnamon.desktop.privacy";
3636
const REMEMBER_RECENT_KEY = "remember-recent-files";
3737

38-
const AppUtils = require('./appUtils');
38+
const Me = imports.ui.extension.getCurrentExtension();
39+
const AppUtils = Me.imports.appUtils;
3940

4041
let appsys = Cinnamon.AppSystem.get_default();
4142

0 commit comments

Comments
 (0)