73 lines
No EOL
2.1 KiB
JavaScript
73 lines
No EOL
2.1 KiB
JavaScript
const { Gio, St } = imports.gi;
|
|
const Main = imports.ui.main;
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
|
const Me = ExtensionUtils.getCurrentExtension();
|
|
const Settings = ExtensionUtils.getSettings();
|
|
|
|
let appLaunchers = [];
|
|
|
|
class AppLauncher {
|
|
constructor(appExecutable, appIcon, iconSize) {
|
|
this.appExecutable = appExecutable;
|
|
this.appIcon = appIcon;
|
|
|
|
this.button = new St.Bin({
|
|
style_class: 'panel-button',
|
|
reactive: true,
|
|
can_focus: true,
|
|
track_hover: true
|
|
});
|
|
|
|
let icon = new St.Icon({
|
|
gicon: Gio.icon_new_for_string(appIcon),
|
|
icon_size: iconSize
|
|
});
|
|
|
|
this.button.set_child(icon);
|
|
this.button.set_width(iconSize * 2);
|
|
|
|
this.button.connect('button-press-event', () => {
|
|
let appInfo = Gio.AppInfo.create_from_commandline(appExecutable, null, Gio.AppInfoCreateFlags.NONE);
|
|
if (appInfo) {
|
|
appInfo.launch([], null);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function updateTopBar() {
|
|
// remove all existing launchers
|
|
appLaunchers.forEach(launcher => {
|
|
Main.panel._leftBox.remove_child(launcher.button);
|
|
});
|
|
appLaunchers = [];
|
|
|
|
// Add launchers based on current settings
|
|
for (let i = 0; i < 10; i++) {
|
|
let appExecutable = Settings.get_string(`app-executable-${i}`);
|
|
let appIcon = Settings.get_string(`app-icon-${i}`);
|
|
let iconSize = Settings.get_int(`icon-size-${i}`);
|
|
|
|
// create a launcher If executable and icon are set,
|
|
if (appExecutable && appIcon) {
|
|
let appLauncher = new AppLauncher(appExecutable, appIcon, iconSize);
|
|
|
|
// Insert the launcher at the end of the left box
|
|
Main.panel._leftBox.add_child(appLauncher.button);
|
|
appLaunchers.push(appLauncher);
|
|
}
|
|
}
|
|
}
|
|
|
|
function enable() {
|
|
updateTopBar();
|
|
Settings.connect('changed', updateTopBar);
|
|
}
|
|
|
|
function disable() {
|
|
appLaunchers.forEach(launcher => {
|
|
Main.panel._leftBox.remove_child(launcher.button);
|
|
});
|
|
appLaunchers = [];
|
|
Settings.disconnect('changed', updateTopBar);
|
|
} |