upload to github
This commit is contained in:
commit
7be0570f7f
10 changed files with 399 additions and 0 deletions
73
extension.js
Normal file
73
extension.js
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue