├── .gitignore ├── CastControlCentre.js ├── CastMainMenu.js ├── LICENSE ├── README.md ├── extension.js ├── helpers ├── compatibility.js ├── convenience.js └── timers.js ├── icons ├── spotify-linux-256.png └── youtube-linux-256.png ├── metadata.json ├── prefs.js ├── schemas ├── com.hello.lukearran.gschema.xml └── gschemas.compiled ├── screen-shot-v2.png ├── screenshot.png └── stylesheet.css /.gitignore: -------------------------------------------------------------------------------- 1 | moveToInstall.sh 2 | -------------------------------------------------------------------------------- /CastControlCentre.js: -------------------------------------------------------------------------------- 1 | const GLib = imports.gi.GLib; 2 | const util = imports.misc.util; 3 | 4 | // trySpawnCommandLine: 5 | // @command_line: a command line 6 | // 7 | // Runs @command_line in the background. If launching @command_line 8 | // fails, this will throw an error. 9 | function trySpawnCommandLine(command_line) { 10 | let success, argv; 11 | 12 | try { 13 | [success, argv] = GLib.shell_parse_argv(command_line); 14 | } catch (err) { 15 | // Replace "Error invoking GLib.shell_parse_argv: " with 16 | // something nicer 17 | err.message = err.message.replace(/[^:]*: /, _("Could not parse command:") + "\n"); 18 | throw err; 19 | } 20 | util.trySpawn(argv); 21 | } 22 | 23 | 24 | function start(){ 25 | trySpawnCommandLine("cast-web-api-cli start"); 26 | } 27 | 28 | function stop(){ 29 | trySpawnCommandLine("cast-web-api-cli stop"); 30 | } -------------------------------------------------------------------------------- /CastMainMenu.js: -------------------------------------------------------------------------------- 1 | const St = imports.gi.St; 2 | const Gtk = imports.gi.Gtk; 3 | const Clutter = imports.gi.Clutter; 4 | const Gio = imports.gi.Gio; 5 | const Main = imports.ui.main; 6 | const PanelMenu = imports.ui.panelMenu; 7 | const PopupMenu = imports.ui.popupMenu; 8 | const Slider = imports.ui.slider; 9 | const Soup = imports.gi.Soup; 10 | const Lang = imports.lang; 11 | const ExtensionUtils = imports.misc.extensionUtils; 12 | const Me = ExtensionUtils.getCurrentExtension(); 13 | const Timers = Me.imports.helpers.timers; 14 | const compat = Me.imports.helpers.compatibility; 15 | const Config = imports.misc.config; 16 | 17 | 18 | const logMeta = (`${Me.metadata.name} ${Me.metadata.version}: `); 19 | 20 | var _signals; 21 | // Refresh settings 22 | var _refreshInterval; 23 | // HTTP Communication Settings 24 | let sessionSync, settings, settingChangesId, apiHostname, apiPort; 25 | 26 | var CastControl = new Lang.Class({ 27 | Name: 'CastControl', // Class Name 28 | Extends: PanelMenu.Button, // Parent Class 29 | 30 | _InvokeCastAPI : function(endPoint, requestType, callback){ 31 | try{ 32 | // Cancel any pending/ongoing connections before creating a new one 33 | this.sessionSync.abort(); 34 | 35 | if (this.apiHostname.length > 0 && this.apiPort > 0){ 36 | // Create the base address from the settings 37 | var baseAddress = "http://" + this.apiHostname + ":" + this.apiPort; 38 | // Write to log 39 | log(logMeta + requestType + " Request Started to Cast API at " + baseAddress + "/" + endPoint); 40 | // Create a GET message to the API /device 41 | let request = Soup.Message.new(requestType.toUpperCase(), baseAddress + "/" + endPoint); 42 | 43 | // Send the request to the server 44 | this.sessionSync.queue_message(request, Lang.bind(this, function() { 45 | // Parse the response from the server 46 | var response = JSON.parse(request.response_body.data); 47 | 48 | if (typeof callback !== "undefined"){ 49 | // Pass the data onto the callback function 50 | callback(response, this); 51 | } 52 | 53 | })); 54 | } 55 | else{ 56 | throw "Invalid hostname or port setting value of requesting Cast API"; 57 | } 58 | } 59 | catch (error){ 60 | log(logMeta + "Request Failed #" + requestId + ": Failed to get the list of connected Cast devices - is the Cast Web API running at " 61 | + this.apiHostname + ":" + this.apiPort + ": " + error); 62 | } 63 | }, 64 | 65 | _getDeviceHeading : function(_device){ 66 | // Refresh the Now Playing labels if the device array is not empty 67 | if (_device != undefined){ 68 | // Declare variables to store the string for the labels 69 | var playingLabelTextTitle, playingLabelTextSubTitle, playingLabeImageUri, deviceVolume; 70 | deviceVolume= _device.status.volume; 71 | // Ensure the Status member contains a string, and is not the default application of Nest Hub / Chromecast 72 | if (_device.status.application.length > 0 && _device.status.application != "Backdrop"){ 73 | // Ensure the title member contains a value and is present 74 | if (_device.status.title != undefined && _device.status.title.length > 0){ 75 | playingLabelTextTitle = _device.status.title; 76 | 77 | if (_device.status.subtitle != undefined && _device.status.subtitle.length > 0){ 78 | playingLabelTextTitle += " - " + _device.status.subtitle; 79 | } 80 | playingLabeImageUri = _device.status.image; 81 | playingLabelTextSubTitle = _device.status.application; 82 | } 83 | // Otherwise just display the application 84 | else{ 85 | playingLabelTextTitle = "Now Playing"; 86 | playingLabelTextSubTitle = _device.status.application; 87 | playingLabeImageUri = ""; 88 | } 89 | } 90 | else{ 91 | playingLabelTextTitle = "Nothing playing..."; 92 | playingLabelTextSubTitle = ""; 93 | playingLabeImageUri = ""; 94 | } 95 | } 96 | 97 | return new Array(playingLabelTextTitle, playingLabelTextSubTitle, playingLabeImageUri,deviceVolume); 98 | }, 99 | 100 | // Requests the list of all device items from the server, and creates 101 | // a menu item for each device 102 | _addCastDeviceMenuItems : function(_source, base){ 103 | try{ 104 | if (_source != undefined && _source.length > 0) { 105 | _source.forEach((device) => { 106 | // Create a parent sub-menu 107 | //Read Current Volume from array. 108 | let headingData = base._getDeviceHeading(device); 109 | let strTitle = headingData[0]; 110 | let deviceApp=headingData[1]; 111 | let imageUrl = headingData[2]; 112 | let currentDeviceVolume = headingData[3]; 113 | 114 | 115 | /* Set up Play/Pause Icon for Device Title */ 116 | let devicePlayingStatus = ""; 117 | switch (device.status.status) { 118 | case "PLAYING": 119 | devicePlayingStatus ="⏯️";break; 120 | case "PAUSED": 121 | devicePlayingStatus ="⏸";break; 122 | default: 123 | devicePlayingStatus =""; 124 | 125 | } 126 | 127 | /* Set Up Volume Indicator for Device Title */ 128 | let deviceVolumeIndicator = "🔇"; 129 | if (device.status.muted == false) { 130 | if (currentDeviceVolume>=0) deviceVolumeIndicator="🔈"; 131 | if (currentDeviceVolume>35) deviceVolumeIndicator="🔉"; 132 | if (currentDeviceVolume>75) deviceVolumeIndicator="🔊"; 133 | } 134 | 135 | 136 | /* Calculate Display Name */ 137 | let displayName = device.name; 138 | 139 | /* The Title of the device, with indicators. */ 140 | let menuName = "" + deviceVolumeIndicator + " " + devicePlayingStatus + " " + displayName; 141 | 142 | /* Create MenuExpander To nest Elements. */ 143 | let deviceMenuExpander = new PopupMenu.PopupSubMenuMenuItem(menuName); 144 | 145 | // Set the stylesheet which applies a margin to the label 146 | deviceMenuExpander.menu.box.style_class = 'PopupSubMenuMenuItemStyle'; 147 | 148 | 149 | /* LayOut Elements to Nest */ 150 | let titleLayout = new St.BoxLayout({style_class:"titleLayout"}); 151 | let titleLayoutImage = new St.BoxLayout({style_class:"titleLayoutImage"}); 152 | let titleLayoutTitle = new St.BoxLayout({style_class:"titleLayoutTitle"}); 153 | let titleLayoutTitleApp = new St.BoxLayout({style_class:"titleLayoutTitleApp"}); 154 | let titleLayoutTitleTitles = new St.BoxLayout({style_class:"titleLayoutTitleTitles", vertical:true}); 155 | 156 | 157 | // Set the application vs icons replacement array. 158 | let appsIcons = { 159 | Spotify: 'icons/spotify-linux-256.png', 160 | YouTube: 'icons/youtube-linux-256.png' 161 | }; 162 | 163 | /* If there is a app image, add it to its layout containter */ 164 | if (typeof appsIcons[deviceApp] != 'undefined') { 165 | let giconApp = Gio.icon_new_for_string(Me.path+"/"+appsIcons[deviceApp]); 166 | let currentAppImage = new St.Icon({ gicon: giconApp, style_class: 'appIcon' }); 167 | titleLayoutTitleApp.add(currentAppImage,{y_fill:false,y_align: St.Align.MIDDLE}); 168 | } 169 | 170 | /* If there is a cover image, add it to its layout containter */ 171 | if (typeof imageUrl != '') { 172 | let giconApp = Gio.icon_new_for_string(imageUrl); 173 | let currentAppImage = new St.Icon({ gicon: giconApp, style_class: 'mediaImage' }); 174 | titleLayoutImage.add_actor(currentAppImage); 175 | } 176 | 177 | 178 | // Create the title labels 179 | let strTitleSplit = strTitle.split("-"); 180 | /* Split the title by -, and add every line to a vertical containter */ 181 | strTitleSplit.forEach(element => { 182 | let tag=element.trim().substring(0,35); 183 | let labelMediaApp = new St.Label( 184 | { 185 | text: tag, 186 | style_class: 'labelTitle' 187 | }); 188 | titleLayoutTitleTitles.add_actor(labelMediaApp); 189 | }); 190 | 191 | 192 | /* Add elements in its containers */ 193 | titleLayoutTitle.add_actor(titleLayoutTitleTitles); 194 | titleLayoutTitle.add_actor(titleLayoutTitleApp); 195 | titleLayout.add_actor(titleLayoutImage); 196 | titleLayout.add_actor(titleLayoutTitle); 197 | 198 | /* Add the Title Layout on the menu. */ 199 | deviceMenuExpander.menu.box.add(titleLayout); 200 | 201 | /* Add a separator ... */ 202 | 203 | //deviceMenuExpander.menu.box.add(new PopupMenu.PopupSeperatorMenuItem()); 204 | 205 | 206 | // Create a Play Menu Item 207 | let playMenuItem = new PopupMenu.PopupImageMenuItem('', 'media-playback-start-symbolic'); 208 | playMenuItem.style_class="PopupImageMenuItem"; 209 | 210 | // Create a Pause Menu Item 211 | let pauseMenuItem = new PopupMenu.PopupImageMenuItem('', 'media-playback-pause-symbolic'); 212 | pauseMenuItem.style_class="PopupImageMenuItem"; 213 | // Create a Stop Menu Item 214 | let stopMenuItem = new PopupMenu.PopupImageMenuItem('', 'media-playback-stop-symbolic'); 215 | stopMenuItem.style_class="PopupImageMenuItem"; 216 | // Create a Next Menu Item 217 | let skipMenuItem = new PopupMenu.PopupImageMenuItem('', 'media-seek-forward-symbolic'); 218 | skipMenuItem.style_class="PopupImageMenuItem"; 219 | // Create a Next Menu Item 220 | let nextMenuItem = new PopupMenu.PopupImageMenuItem('', 'media-skip-forward-symbolic'); 221 | nextMenuItem.style_class="PopupImageMenuItem"; 222 | // Create a Next Menu Item 223 | let restartMenuItem = new PopupMenu.PopupImageMenuItem('', 'media-skip-backward-symbolic'); 224 | restartMenuItem.style_class="PopupImageMenuItem"; 225 | 226 | // Add Buttons to the box. 227 | let buttonsLayout = new St.BoxLayout(); 228 | buttonsLayout.add_actor(stopMenuItem); 229 | buttonsLayout.add_actor(restartMenuItem); 230 | buttonsLayout.add_actor(pauseMenuItem); 231 | buttonsLayout.add_actor(playMenuItem); 232 | buttonsLayout.add_actor(nextMenuItem); 233 | buttonsLayout.add_actor(skipMenuItem); 234 | 235 | 236 | // Create Volume Layout 237 | 238 | // Create Buttons Volume Up and Down. 239 | let volumeMenuItem0 = new PopupMenu.PopupImageMenuItem('', 'audio-volume-muted-symbolic'); 240 | volumeMenuItem0.style_class="PopupImageMenuVolume"; 241 | let volumeMenuItem25 = new PopupMenu.PopupImageMenuItem('', 'audio-volume-low-symbolic'); 242 | volumeMenuItem25.style_class="PopupImageMenuVolume"; 243 | let volumeMenuItem50 = new PopupMenu.PopupImageMenuItem('', 'audio-volume-medium-symbolic'); 244 | volumeMenuItem50.style_class="PopupImageMenuVolume"; 245 | let volumeMenuItem75 = new PopupMenu.PopupImageMenuItem('', 'audio-volume-high-symbolic'); 246 | volumeMenuItem75.style_class="PopupImageMenuVolume"; 247 | let volumeMenuItem100 = new PopupMenu.PopupImageMenuItem('', 'audio-volume-overamplified-symbolic'); 248 | volumeMenuItem100.style_class="PopupImageMenuVolume"; 249 | 250 | // Create Box and add buttons. 251 | let volumeLayout = new St.BoxLayout(); 252 | 253 | volumeLayout.add_actor(volumeMenuItem0); 254 | volumeLayout.add_actor(volumeMenuItem25); 255 | volumeLayout.add_actor(volumeMenuItem50); 256 | volumeLayout.add_actor(volumeMenuItem75); 257 | volumeLayout.add_actor(volumeMenuItem100); 258 | 259 | 260 | // Define two new items to put the boxes in. 261 | let buttonsLine = new PopupMenu.PopupBaseMenuItem({reactive: false}); 262 | let volumeLine = new PopupMenu.PopupBaseMenuItem({reactive: false}); 263 | 264 | buttonsLine.actor.add_child(buttonsLayout); 265 | volumeLine.actor.add_child(volumeLayout); 266 | //lineaButtons1.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); 267 | //deviceMenuExpander.menu.addMenuItem(headingLine); 268 | deviceMenuExpander.menu.addMenuItem(buttonsLine); 269 | deviceMenuExpander.menu.addMenuItem(volumeLine); 270 | //deviceMenuExpander.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); 271 | 272 | // Mute Switch 273 | let muteSwitchItem = new PopupMenu.PopupSwitchMenuItem('Mute', false, {}); 274 | deviceMenuExpander.menu.addMenuItem(muteSwitchItem); 275 | 276 | 277 | //hScale = Gtk.Scale.new_with_range (Gtk.Orientation.HORIZONTAL, 0.0, 100.0, 5.0); 278 | //deviceMenuExpander.menu.addMenuItem(hScale); 279 | 280 | if(device.status.muted){ 281 | muteSwitchItem.toggle(); 282 | } 283 | 284 | // Add this device drop-down menu to the parent menu 285 | base.menu.addMenuItem(deviceMenuExpander); 286 | 287 | // Connect event triggers to the media control buttons 288 | base._hookUpActionTriggers(playMenuItem, device.id, "play", base); 289 | base._hookUpActionTriggers(pauseMenuItem, device.id, "pause", base); 290 | base._hookUpActionTriggers(stopMenuItem, device.id, "stop", base); 291 | base._hookUpActionTriggers(volumeMenuItem0, device.id, "volume/0", base); 292 | base._hookUpActionTriggers(volumeMenuItem25, device.id, "volume/25", base); 293 | base._hookUpActionTriggers(volumeMenuItem50, device.id, "volume/50", base); 294 | base._hookUpActionTriggers(volumeMenuItem75, device.id, "volume/75", base); 295 | base._hookUpActionTriggers(volumeMenuItem100, device.id, "volume/100", base); 296 | base._hookUpActionTriggers(restartMenuItem, device.id, "seek/0", base); 297 | base._hookUpActionTriggers(skipMenuItem, device.id, "seek/10", base); 298 | base._hookUpActionTriggers(nextMenuItem, device.id, "seek/100000000", base); 299 | base._hookUpMuteSwitchTriggers(muteSwitchItem, device.id, base); 300 | }); 301 | } 302 | // Otherwise show a menu item indicating that the is no devices 303 | else{ 304 | let noItemsFoundMenu = new PopupMenu.PopupMenuItem("No devices found..."); 305 | base.menu.addMenuItem(noItemsFoundMenu); 306 | } 307 | } 308 | catch (menuExp){ 309 | //Remove all items in the menu list 310 | base._clearMenuItems(); 311 | //Show error menu 312 | let noItemsFoundMenu = new PopupMenu.PopupMenuItem("An error occurred..."); 313 | base.menu.addMenuItem(noItemsFoundMenu); 314 | //Add to log 315 | log(logMeta + "An error occurred on adding items to the menu. Reverting to error view: " + menuExp); 316 | } 317 | 318 | // Create a refresh button 319 | let refreshMenuItem = new PopupMenu.PopupImageMenuItem('Refresh', 'view-refresh-symbolic'); 320 | // Add a separator between the device list and the refresh button 321 | base.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); 322 | // Add the refresh button 323 | base.menu.addMenuItem(refreshMenuItem); 324 | 325 | // Hook up the refresh menu button to a click trigger, which will call the refresh method 326 | base._createNewSignalId(refreshMenuItem, 327 | refreshMenuItem.connect('activate', Lang.bind(this, function(){ 328 | base._createMenuItems(); 329 | }))); 330 | }, 331 | 332 | _setupRefreshInterval: function(interval){ 333 | if (interval >= 1000){ 334 | log(logMeta + "Cast API Refresh Interval Trigger set at interval " + interval + "ms..."); 335 | 336 | this._refreshInterval = Timers.setInterval(() => { 337 | if (!this.menu.isOpen){ 338 | 339 | this._createMenuItems(); 340 | 341 | log(logMeta + "Now refreshed with API... waiting until next " + interval + "ms"); 342 | 343 | } 344 | else{ 345 | log(logMeta + "Unable to refresh as menu is currently open. Refresh will only trigger when menu is closed."); 346 | } 347 | }, interval); 348 | } 349 | else{ 350 | throw "refresh interval has to be greater than 3000ms"; 351 | } 352 | }, 353 | 354 | _clearMenuItems : function(){ 355 | this._dropAllSignals(); 356 | this.menu.removeAll(); 357 | }, 358 | 359 | // Create device menu action triggers 360 | _hookUpActionTriggers : function(menuItem, deviceId, action, base){ 361 | this._createNewSignalId(menuItem, menuItem.connect('activate', Lang.bind(this, function(){ 362 | // Confusingly, the API uses a GET HTTP type for actions 363 | this._InvokeCastAPI("device/" + deviceId + "/" + action, "GET"); 364 | }))); 365 | }, 366 | 367 | _hookUpMuteSwitchTriggers : function (switchItem, deviceId, base){ 368 | this._createNewSignalId(switchItem, switchItem.connect('toggled', Lang.bind(this, function(object, value){ 369 | if (value){ 370 | // Confusingly, the API uses a GET HTTP type for actions 371 | this._InvokeCastAPI("device/" + deviceId + "/" + "muted/true", "GET"); 372 | } 373 | else{ 374 | this._InvokeCastAPI("device/" + deviceId + "/" + "muted/false", "GET"); 375 | } 376 | }))); 377 | }, 378 | 379 | _createMenuItems: function(){ 380 | // Set a fixed width to the menu to ensure consistency 381 | this.menu.box.width = 450; 382 | // Clear menu items, if items have already been created 383 | this._clearMenuItems(); 384 | // Create menu item for each Cast device 385 | this._InvokeCastAPI("device", "GET", this._addCastDeviceMenuItems); 386 | }, 387 | 388 | _createNewSignalId(object, signal){ 389 | var signal = { 390 | "source" : object, 391 | "signal" : signal 392 | }; 393 | 394 | this._signals.push(signal); 395 | }, 396 | 397 | _dropAllSignals(){ 398 | for (let index = 0; index < this._signals.length; index++) { 399 | const element = this._signals[index]; 400 | element.source.disconnect(element.signal); 401 | } 402 | 403 | this._signals = new Array(); 404 | }, 405 | 406 | // Constructor 407 | _init: function() { 408 | this.sessionSync = new Soup.SessionAsync(); 409 | 410 | this._signals = new Array(); 411 | 412 | // Load the schema values 413 | 414 | this.settings = compat.getExtensionUtilsSettings().getSettings('castcontrol.hello.lukearran.com'); 415 | 416 | // Get Setting Config 417 | var refreshIntervalSetting = this.settings.get_int("refresh-interval-ms"); 418 | this.apiHostname = this.settings.get_string("castapi-hostname"); 419 | this.apiPort = this.settings.get_int("castapi-port"); 420 | 421 | // Setup background refresh with the interval value 422 | this._setupRefreshInterval(refreshIntervalSetting); 423 | 424 | /* 425 | This is calling the parent constructor 426 | 1 is the menu alignment (1 is left, 0 is right, 0.5 is centered) 427 | `CastMainMenu` is the name 428 | true if you want to create a menu automatically, otherwise false 429 | */ 430 | this.parent(1, 'CastMainMenu', false); 431 | 432 | // We are creating a box layout with shell toolkit 433 | let box = new St.BoxLayout(); 434 | 435 | /* 436 | All icons are found in `/usr/share/icons/theme-being-used` 437 | */ 438 | let icon = new St.Icon({ icon_name: 'user-home-symbolic', style_class: 'system-status-icon'}); 439 | 440 | // A label expanded and center aligned in the y-axis 441 | let toplabel = new St.Label({ text: ' Home ', 442 | y_expand: true, 443 | y_align: Clutter.ActorAlign.CENTER }); 444 | 445 | // We add the icon, the label and a arrow icon to the box 446 | box.add(icon); 447 | box.add(toplabel); 448 | box.add(PopupMenu.arrowIcon(St.Side.BOTTOM)); 449 | 450 | // We add the box to the button 451 | // It will be showed in the Top Panel 452 | this.actor.add_child(box); 453 | 454 | // Create the drop-down menu items 455 | this._createMenuItems(); 456 | 457 | }, 458 | 459 | destroy: function() { 460 | // Clear the timer 461 | Timers.clearInterval(this._refreshInterval); 462 | 463 | // Disconnect signals 464 | this._dropAllSignals(); 465 | 466 | // Destroy objects 467 | this._refreshInterval = null; 468 | this.sessionSync = null; 469 | this.settings = null; 470 | this.settingChangesId = null; 471 | this.apiHostname = null; 472 | this.apiPort = null; 473 | this._signals = null; 474 | 475 | this.parent(); 476 | } 477 | }); 478 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2019] Luke Arran 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Google Cast Control for GNOME Shell 2 | 3 | ![screenshot](https://raw.githubusercontent.com/SamyGarib/GNOME-Cast-Control/master/screen-shot-v2.png) 4 | 5 | > NOTICE: This extension is no longer being actively maintained. It's likely that the extension may break in a future GNOME Shell release. If you wish to take over the repository then please open an issue on the GitHub repository. 6 | 7 | A simple GNOME extension client for [vervallsweg's Cast Web API Node application](https://github.com/vervallsweg/cast-web-api-cli) - control the playback of Google Cast devices from the GNOME shell. 8 | 9 | ## Features / To Do List 10 | 11 | - [X] Play / Resume 12 | - [X] Stop 13 | - [X] Mute Toggle 14 | - [X] Auto Refresh 15 | - [X] Change Cast API Port 16 | - [X] Settings / Setup Wizard 17 | - [X] Automatically start Cast Web API on the extension being created 18 | - [X] Control Device Volume. (v2) 19 | - [ ] Bundle cast-web-api-cli into an installable Snap package 20 | - [X] Display Now Playing Media Images (v2) 21 | - [X] Display Device Status in the List (v2) 22 | 23 | ## Requirements 24 | 25 | * GNOME Shell >= 3.32 26 | * [Node.JS application 'cast-web-api-cli'](https://github.com/lukearran/cast-web-api-cli) 27 | 28 | ## Automatic Installation via GNOME Extension site 29 | 30 | 1. [Install the Node.JS application 'cast-web-api-cli'](https://github.com/lukearran/cast-web-api-cli) 31 | 1. sudo apt-get install npm 32 | 2. sudo npm install cast-web-api-cli -g 33 | 2. [Install the extension via GNOME](https://extensions.gnome.org/extension/1955/cast-control/) 34 | 3. Wait up to 5 minutes for cast-web-api-cli to start and locate devices in your local network. 35 | 4. Enjoy! 36 | 37 | ## Manual Installation via GitHub 38 | 39 | 1. [Install the Node.JS application 'cast-web-api-cli'](https://github.com/lukearran/cast-web-api-cli) 40 | 1. sudo apt-get install npm 41 | 2. sudo npm install cast-web-api-cli -g 42 | 2. Git Clone or download a zip of this repository and extract to the root directory of *'~/.local/share/gnome-shell/extensions/castcontrol@hello.lukearran.com'* (create the directory if it does not exists) 43 | 3. Restart your desktop, or GNOME Shell 44 | 4. Enable "Cast Control" in the GNOME Tweaks Tool 45 | 5. Wait up to 5 minutes for cast-web-api-cli to detect devices in your local network 46 | 6. Enjoy 47 | -------------------------------------------------------------------------------- /extension.js: -------------------------------------------------------------------------------- 1 | const Main = imports.ui.main; 2 | const ExtensionUtils = imports.misc.extensionUtils; 3 | const Me = ExtensionUtils.getCurrentExtension(); 4 | const mainMenu = Me.imports.CastMainMenu; 5 | const controlCentre = Me.imports.CastControlCentre; 6 | const compat = Me.imports.helpers.compatibility; 7 | const Gio = imports.gi.Gio; 8 | 9 | let castControlButton; 10 | 11 | // Check if the extension should start / stop the API 12 | function isAutoControlEnabled(){ 13 | // Load the schema values 14 | this.settings = this.compat.getExtensionUtilsSettings().getSettings('castcontrol.hello.lukearran.com'); 15 | // Get Setting Config 16 | return this.settings.get_boolean("auto-castapi"); 17 | } 18 | 19 | /* 20 | Start services to launch Cast Control platform 21 | */ 22 | function startServices(){ 23 | // Add the panel menu button to the GNOME status area 24 | Main.panel.addToStatusArea('CastMainMenu', castControlButton, 0, 'right'); 25 | 26 | if (this.isAutoControlEnabled()){ 27 | // Start Cast Web API CLI from Terminal 28 | controlCentre.start(); 29 | } 30 | 31 | } 32 | 33 | function init() { 34 | log(`Initializing ${Me.metadata.name} ${Me.metadata.version}`); 35 | } 36 | 37 | function enable() { 38 | // Init the CastMainMenu which inherits a PanelMenu button 39 | castControlButton = new mainMenu.CastControl; 40 | // Start all services & functionality 41 | startServices(); 42 | } 43 | 44 | function disable() { 45 | if (this.isAutoControlEnabled()){ 46 | controlCentre.stop(); 47 | } 48 | 49 | castControlButton.destroy(); 50 | castControlButton = null; 51 | } 52 | -------------------------------------------------------------------------------- /helpers/compatibility.js: -------------------------------------------------------------------------------- 1 | const ExtensionUtils = imports.misc.extensionUtils; 2 | const Me = ExtensionUtils.getCurrentExtension(); 3 | 4 | // Check if the ExtensionUtils's getSettings function is avaliable, 5 | // otherwise fall back to convenience.js script 6 | function getExtensionUtilsSettings(){ 7 | try{ 8 | this.settings = ExtensionUtils.getSettings('castcontrol.hello.lukearran.com'); 9 | 10 | return ExtensionUtils; 11 | } 12 | catch(err){ 13 | return Me.imports.helpers.convenience; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /helpers/convenience.js: -------------------------------------------------------------------------------- 1 | /* -*- mode: js -*- */ 2 | /* 3 | Copyright (c) 2011-2012, Giovanni Campagna 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the GNOME nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | const Gettext = imports.gettext; 29 | const Gio = imports.gi.Gio; 30 | const GLib = imports.gi.GLib; 31 | const Lang = imports.lang; 32 | 33 | const Config = imports.misc.config; 34 | const ExtensionUtils = imports.misc.extensionUtils; 35 | 36 | /** 37 | * initTranslations: 38 | * @domain: (optional): the gettext domain to use 39 | * 40 | * Initialize Gettext to load translations from extensionsdir/locale. 41 | * If @domain is not provided, it will be taken from metadata['gettext-domain'] 42 | */ 43 | function initTranslations(domain) { 44 | let extension = ExtensionUtils.getCurrentExtension(); 45 | 46 | domain = domain || extension.metadata['gettext-domain']; 47 | 48 | // check if this extension was built with "make zip-file", and thus 49 | // has the locale files in a subfolder 50 | // otherwise assume that extension has been installed in the 51 | // same prefix as gnome-shell 52 | let localeDir = extension.dir.get_child('locale'); 53 | if (localeDir.query_exists(null)) 54 | Gettext.bindtextdomain(domain, localeDir.get_path()); 55 | else 56 | Gettext.bindtextdomain(domain, Config.LOCALEDIR); 57 | } 58 | 59 | /** 60 | * getSettings: 61 | * @schema: (optional): the GSettings schema id 62 | * 63 | * Builds and return a GSettings schema for @schema, using schema files 64 | * in extensionsdir/schemas. If @schema is not provided, it is taken from 65 | * metadata['settings-schema']. 66 | */ 67 | function getSettings(schema) { 68 | let extension = ExtensionUtils.getCurrentExtension(); 69 | 70 | schema = schema || extension.metadata['settings-schema']; 71 | 72 | const GioSSS = Gio.SettingsSchemaSource; 73 | 74 | // check if this extension was built with "make zip-file", and thus 75 | // has the schema files in a subfolder 76 | // otherwise assume that extension has been installed in the 77 | // same prefix as gnome-shell (and therefore schemas are available 78 | // in the standard folders) 79 | let schemaDir = extension.dir.get_child('schemas'); 80 | let schemaSource; 81 | if (schemaDir.query_exists(null)) 82 | schemaSource = GioSSS.new_from_directory(schemaDir.get_path(), 83 | GioSSS.get_default(), 84 | false); 85 | else 86 | schemaSource = GioSSS.get_default(); 87 | 88 | let schemaObj = schemaSource.lookup(schema, true); 89 | if (!schemaObj) 90 | throw new Error('Schema ' + schema + ' could not be found for extension ' 91 | + extension.metadata.uuid + '. Please check your installation.'); 92 | 93 | return new Gio.Settings({ settings_schema: schemaObj }); 94 | } 95 | 96 | /** 97 | * downloadFile: 98 | * @url: file url 99 | * @path: the image local path 100 | * @callback: function called after the download is complete 101 | * 102 | * Properly downloads an image for a given URL, saves it in the given path and 103 | * calls the given callback passing the local image path as an argument. 104 | */ 105 | 106 | function downloadFile(url, destination, callback) { 107 | let stream = Gio.file_new_for_uri(url); 108 | 109 | stream.read_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(src, res) { 110 | let inputStream; 111 | try { 112 | inputStream = stream.read_finish(res); 113 | } catch (e) { 114 | callback(false, null); 115 | return; 116 | } 117 | 118 | let out = Gio.file_new_for_path(destination); 119 | out.replace_async(null, false, Gio.FileCreateFlags.NONE, GLib.PRIORITY_DEFAULT, null, 120 | Lang.bind(this, function(src, res) { 121 | let outputStream = out.replace_finish(res); 122 | 123 | outputStream.splice_async(inputStream, 124 | Gio.OutputStreamSpliceFlags.CLOSE_SOURCE | Gio.OutputStreamSpliceFlags.CLOSE_TARGET, 125 | GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(src, res) { 126 | try { 127 | outputStream.splice_finish(res); 128 | } catch (e) { 129 | return; 130 | } 131 | 132 | callback(true, destination); 133 | })); 134 | })); 135 | })); 136 | } 137 | 138 | function loadJsonFromPath(path, callback) { 139 | let file = Gio.file_new_for_path(path); 140 | file.load_contents_async(null, Lang.bind(this, function(src, res) { 141 | try { 142 | let [success, contents] = file.load_contents_finish(res); 143 | 144 | if (success) { 145 | callback(true, JSON.parse(contents)); 146 | } 147 | } catch(e) { 148 | callback(false, null); 149 | } 150 | })); 151 | } 152 | 153 | function fileExists(path) { 154 | let file = Gio.File.new_for_path(path); 155 | 156 | return file.query_exists(null); 157 | } 158 | 159 | function listDirAsync(file, callback) { 160 | let allFiles = []; 161 | file.enumerate_children_async(Gio.FILE_ATTRIBUTE_STANDARD_NAME, 162 | Gio.FileQueryInfoFlags.NONE, 163 | GLib.PRIORITY_LOW, null, function (obj, res) { 164 | let enumerator = obj.enumerate_children_finish(res); 165 | function onNextFileComplete(obj, res) { 166 | let files = obj.next_files_finish(res); 167 | if (files.length) { 168 | allFiles = allFiles.concat(files); 169 | enumerator.next_files_async(100, GLib.PRIORITY_LOW, null, onNextFileComplete); 170 | } else { 171 | enumerator.close(null); 172 | callback(allFiles); 173 | } 174 | } 175 | enumerator.next_files_async(100, GLib.PRIORITY_LOW, null, onNextFileComplete); 176 | }); 177 | } 178 | -------------------------------------------------------------------------------- /helpers/timers.js: -------------------------------------------------------------------------------- 1 | const Mainloop = imports.mainloop; 2 | const app = "CastControl"; 3 | 4 | const setTimeout = function(func, millis /* , ... args */) { 5 | 6 | log(app + ": Timer interval has been set to " + millis); 7 | 8 | let args = []; 9 | if (arguments.length > 2) { 10 | args = args.slice.call(arguments, 2); 11 | } 12 | 13 | let id = Mainloop.timeout_add(millis, () => { 14 | func.apply(null, args); 15 | return false; // Stop repeating 16 | }, null); 17 | 18 | return id; 19 | }; 20 | 21 | const clearTimeout = function(id) { 22 | log(app + ": Timer " + id + " timeout has been cleared"); 23 | 24 | Mainloop.source_remove(id); 25 | }; 26 | 27 | const setInterval = function(func, millis /* , ... args */) { 28 | 29 | log(app + ": Timer interval has been set to " + millis); 30 | 31 | let args = []; 32 | if (arguments.length > 2) { 33 | args = args.slice.call(arguments, 2); 34 | } 35 | 36 | let id = Mainloop.timeout_add(millis, () => { 37 | func.apply(null, args); 38 | return true; // Repeat 39 | }, null); 40 | 41 | return id; 42 | }; 43 | 44 | const clearInterval = function(id) { 45 | 46 | log(app + ": Timer " + id + " interval has been cleared"); 47 | 48 | Mainloop.source_remove(id); 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /icons/spotify-linux-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukearran/GNOME-Cast-Control/42cff818a4d6412c0176d8b395d253ad4514ebb7/icons/spotify-linux-256.png -------------------------------------------------------------------------------- /icons/youtube-linux-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukearran/GNOME-Cast-Control/42cff818a4d6412c0176d8b395d253ad4514ebb7/icons/youtube-linux-256.png -------------------------------------------------------------------------------- /metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Cast Control", 3 | "description": "Control your Google Cast devices easily from the GNOME Shell. This extension requires the npm package 'cast-web-api-cli' to be installed. Please follow the instructions in the GitHub page below for more information. Credit: Luke Arran, SamyGarib and Hannes Rodel.", 4 | "version": 5, 5 | "uuid": "castcontrol@hello.lukearran.com", 6 | "url": "https://github.com/lukearran/GNOME-Cast-Control", 7 | "shell-version": ["3.32", "3.34", "3.36"] 8 | } -------------------------------------------------------------------------------- /prefs.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const Gio = imports.gi.Gio; 4 | const Gtk = imports.gi.Gtk; 5 | const GLib = imports.gi.GLib; 6 | const Lang = imports.lang; 7 | const GObject = imports.gi.GObject; 8 | 9 | const ExtensionUtils = imports.misc.extensionUtils; 10 | const Me = ExtensionUtils.getCurrentExtension(); 11 | const compat = Me.imports.helpers.compatibility; 12 | 13 | 14 | function init(){ 15 | 16 | } 17 | 18 | function buildPrefsWidget(){ 19 | // Load the schema values 20 | this.settings = this.compat.getExtensionUtilsSettings().getSettings('castcontrol.hello.lukearran.com'); 21 | 22 | // Create a parent widget that we'll return from this function 23 | let layout = new Gtk.Grid({ 24 | margin: 50, 25 | column_spacing: 12, 26 | row_spacing: 18, 27 | visible: true 28 | }); 29 | 30 | // Add a simple title and add it to the layout 31 | let title = new Gtk.Label({ 32 | label: `${Me.metadata.name} Settings`, 33 | halign: Gtk.Align.START, 34 | use_markup: true, 35 | visible: true 36 | }); 37 | layout.attach(title, 0, 0, 2, 1); 38 | 39 | // Auto Start Control 40 | let autoStartLabel = new Gtk.Label({ 41 | label: ' Automatic Start Cast API ', 42 | halign: Gtk.Align.START, 43 | visible: true 44 | }); 45 | layout.attach(autoStartLabel, 0, 1, 1, 1); 46 | 47 | let autoStartSwitchControl = new Gtk.Switch({ 48 | visible: true, 49 | margin_right: 100 50 | }); 51 | 52 | var isAuto = this.settings.get_boolean("auto-castapi"); 53 | 54 | autoStartSwitchControl.set_state(isAuto); 55 | 56 | layout.attach(autoStartSwitchControl, 1, 1, 1, 1); 57 | 58 | // API Hostname 59 | let hostnameLabel = new Gtk.Label({ 60 | label: ' API Hostname Custom Endpoint', 61 | halign: Gtk.Align.START, 62 | visible: true 63 | }); 64 | layout.attach(hostnameLabel, 0, 2, 1, 2); 65 | 66 | let hostnameTextbox = new Gtk.Entry({ 67 | visible: true 68 | }); 69 | 70 | var hostnameValue = this.settings.get_string("castapi-hostname"); 71 | 72 | hostnameTextbox.set_text(hostnameValue); 73 | 74 | layout.attach(hostnameTextbox, 1, 2, 2, 2); 75 | 76 | // API Port 77 | let portLabel = new Gtk.Label({ 78 | label: ' API Port Custom Endpoint ', 79 | halign: Gtk.Align.START, 80 | visible: true 81 | }); 82 | layout.attach(portLabel, 0, 4, 1, 3); 83 | 84 | let portTextbox = new Gtk.SpinButton({ 85 | visible: true, 86 | numeric: true, 87 | snap_to_ticks: true, 88 | climb_rate: 1 89 | }); 90 | 91 | var serverPortValue = this.settings.get_int("castapi-port"); 92 | 93 | portTextbox.set_range(1000, 9999); 94 | portTextbox.set_increments(1, 1); 95 | portTextbox.set_value(serverPortValue); 96 | 97 | layout.attach(portTextbox, 1, 4, 1, 3); 98 | 99 | // Refresh Interval 100 | let refreshIntervalLabel = new Gtk.Label({ 101 | label: ' Refresh Interval (Sec) ', 102 | halign: Gtk.Align.START, 103 | visible: true 104 | }); 105 | layout.attach(refreshIntervalLabel, 0, 7, 1, 3); 106 | 107 | let refreshIntervalTextbox = new Gtk.SpinButton({ 108 | visible: true, 109 | numeric: true, 110 | climb_rate: 1 111 | }); 112 | 113 | var serverRefreshIntervalValue = this.settings.get_int("refresh-interval-ms") / 1000; 114 | 115 | refreshIntervalTextbox.set_range(1, 9999); 116 | refreshIntervalTextbox.set_increments(1, 1); 117 | refreshIntervalTextbox.set_value(serverRefreshIntervalValue); 118 | 119 | layout.attach(refreshIntervalTextbox, 1, 7, 1, 3); 120 | 121 | // Save Button 122 | let saveButton = new Gtk.Button({ 123 | label: ' Save Changes ', 124 | visible: true 125 | }); 126 | 127 | // On the Save Button clicked, apply settings 128 | saveButton.connect('clicked', (button) => { 129 | // Auto Start API 130 | this.settings.set_boolean( 131 | 'auto-castapi', 132 | autoStartSwitchControl.get_state() 133 | ); 134 | // Hostname 135 | this.settings.set_string( 136 | 'castapi-hostname', 137 | hostnameTextbox.get_text() 138 | ); 139 | // Port 140 | this.settings.set_int( 141 | 'castapi-port', 142 | portTextbox.get_value() 143 | ); 144 | // Refresh Interval 145 | this.settings.set_int( 146 | 'refresh-interval-ms', 147 | refreshIntervalTextbox.get_value() * 1000 148 | ); 149 | }); 150 | 151 | layout.attach(saveButton, 1, 50, 1, 1); 152 | 153 | // Get Cast API Button 154 | let getApiButton = new Gtk.LinkButton({ 155 | label: " Don't have Cast API installed? ", 156 | halign: Gtk.Align.START, 157 | visible: true, 158 | uri: 'https://github.com/lukearran/GNOME-Cast-Control' 159 | }); 160 | 161 | layout.attach_next_to(getApiButton, saveButton, Gtk.PositionType.LEFT, 1, 1); 162 | 163 | return layout; 164 | } 165 | -------------------------------------------------------------------------------- /schemas/com.hello.lukearran.gschema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | Starts and stops the Cast Control API by command line. 7 | 8 | 9 | "localhost" 10 | The network hostname where the API end-point is accessible from. 11 | 12 | 13 | 3000 14 | The port where the API is accessible from. 15 | 16 | 17 | 15000 18 | The refresh interval to request the Cast Control API for changes. 19 | 20 | 21 | -------------------------------------------------------------------------------- /schemas/gschemas.compiled: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukearran/GNOME-Cast-Control/42cff818a4d6412c0176d8b395d253ad4514ebb7/schemas/gschemas.compiled -------------------------------------------------------------------------------- /screen-shot-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukearran/GNOME-Cast-Control/42cff818a4d6412c0176d8b395d253ad4514ebb7/screen-shot-v2.png -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lukearran/GNOME-Cast-Control/42cff818a4d6412c0176d8b395d253ad4514ebb7/screenshot.png -------------------------------------------------------------------------------- /stylesheet.css: -------------------------------------------------------------------------------- 1 | .PopupSubMenuMenuItemStyle { 2 | margin: 10px; 3 | padding-left: 20px; 4 | /*width:10%;*/ 5 | } 6 | 7 | .mediaImage { 8 | width: 50px; 9 | height: 50px; 10 | background-size: 50px; 11 | margin:0.2em; 12 | } 13 | 14 | .volumeLabel { 15 | font-size: larger; 16 | width: 20px; 17 | height: 20px; 18 | } 19 | 20 | 21 | .appIcon { 22 | width: 20px; 23 | height: 20px; 24 | margin:0.2em; 25 | } 26 | 27 | .titleLayout { 28 | width: 80%; 29 | /*background-color: red;*/ 30 | } 31 | 32 | .titleLayoutTitleTitles { 33 | margin: 1.5em; 34 | } 35 | 36 | .titleLayoutImage { 37 | /* background-color: green;*/ 38 | width: 50px; 39 | height: 50px; 40 | } 41 | 42 | 43 | .labelTitle { 44 | width: auto; 45 | line-height: 1.2em; 46 | } 47 | 48 | .titleLayoutTitleApp { 49 | /*background-color: blue;*/ 50 | width: 20px; 51 | height: 20px; 52 | } 53 | 54 | .PopupImageMenuItem { 55 | color: black; 56 | width: 50px; 57 | } 58 | 59 | .PopupImageMenuItem:hover { 60 | background-color: #777777; 61 | } 62 | 63 | 64 | .PopupImageMenuVolume { 65 | color: black; 66 | width: 50px; 67 | } 68 | 69 | .PopupImageMenuVolume:hover { 70 | background-color: #777777; 71 | } 72 | --------------------------------------------------------------------------------