Skip to content

Commit

Permalink
add button that opens server in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
olibia committed Oct 2, 2017
1 parent cedcaf1 commit 65756d1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
17 changes: 15 additions & 2 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ const HotelManager = new Lang.Class({
this._toggleServer(id, true);
},

_openServerUrl: function (id) {
let url = 'http://' + id + '.dev';
Util.spawn(['xdg-open', url]);
},

_getServers: function () {
let items = {};

Expand All @@ -131,7 +136,7 @@ const HotelManager = new Lang.Class({
servers.map(Lang.bind(this, function(id, index) {
let server = this._entries[id];
let active = this._checkServer(server);
let serverItem = new PopupServerItem(id, active, { 'restartButton': true });
let serverItem = new PopupServerItem(id, active, { 'restartButton': true, 'launchButton': true });

this.container.menu.addMenuItem(serverItem);

Expand All @@ -143,6 +148,10 @@ const HotelManager = new Lang.Class({
this._reloadServer(id);
this.container.menu.close();
}));

serverItem.launchButton.connect('clicked', Lang.bind(this, function() {
this._openServerUrl(id);
}));
}));
}
},
Expand All @@ -153,7 +162,7 @@ const HotelManager = new Lang.Class({
this._running = this._checkHotel();
this._entries = this._getServers();

let hotelItem = new PopupServerItem('Hotel', this._running, { 'restartButton': true });
let hotelItem = new PopupServerItem('Hotel', this._running, { 'restartButton': true, 'launchButton': true });
this.container.menu.addMenuItem(hotelItem);

Mainloop.idle_add(Lang.bind(this, this._addServerItems));
Expand All @@ -167,6 +176,10 @@ const HotelManager = new Lang.Class({
this.container.menu.close();
}));

hotelItem.launchButton.connect('clicked', Lang.bind(this, function() {
this._openServerUrl('hotel');
}));

return true;
},

Expand Down
37 changes: 26 additions & 11 deletions [email protected]/popupServerItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,33 @@ const PopupServerItem = new Lang.Class({
this.parent(text, active);

if (params.restartButton) {
this.restartButton = new St.Button(
{
x_align: 1,
reactive: true,
can_focus: true,
track_hover: true,
accessible_name: 'restart',
style_class: 'system-menu-action services-systemd-button-reload'
});
this.restartButton = new St.Button(
{
x_align: 1,
reactive: true,
can_focus: true,
track_hover: false,
accessible_name: 'restart',
style_class: 'system-menu-action hotel-manager-button'
});

this.restartButton.child = new St.Icon({ icon_name: 'view-refresh-symbolic' });
this.actor.add(this.restartButton, { expand: false, x_align: St.Align.END });
this.restartButton.child = new St.Icon({ icon_name: 'view-refresh-symbolic' });
this.actor.add(this.restartButton, { expand: false, x_align: St.Align.END });
}

if (params.launchButton) {
this.launchButton = new St.Button(
{
x_align: 1,
reactive: true,
can_focus: true,
track_hover: false,
accessible_name: 'launch',
style_class: 'system-menu-action hotel-manager-button'
});

this.launchButton.child = new St.Icon({ icon_name: 'network-workgroup-symbolic' });
this.actor.add(this.launchButton, { expand: false, x_align: St.Align.END });
}
}
});

0 comments on commit 65756d1

Please sign in to comment.