Skip to content

Commit

Permalink
Adjust favicon and title for both staging (canary) and dev (local)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhousel committed Dec 13, 2024
1 parent c8fde60 commit 9ce8306
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
7 changes: 7 additions & 0 deletions dist/img/rapid_favicon-dev.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 32 additions & 15 deletions modules/core/UiSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,7 @@ export class UiSystem extends AbstractSystem {
.then(() => {
window.addEventListener('resize', this.resize);

// If we detect this is Rapid Canary, change the title and favicon.
const detected = utilDetect();
if (/\/canary$/.test(detected.host)) {
urlhash.titleBase = 'Rapid Canary';

const $head = select('head');
let $favicon = $head.select(`link[rel~='icon']`);
if (!$favicon.size()) {
$favicon = $head
.append('link')
.attr('rel', 'icon')
.attr('type', 'image/svg');
}
$favicon.attr('href', assets.getFileURL('img/rapid_favicon-canary.svg'));
}
this._checkEnvironment(); // are we in a dev or staging environment?

// Create UI components
this.ApiStatus = new UiApiStatus(context);
Expand Down Expand Up @@ -524,6 +510,37 @@ dims = vecAdd(dims, [overscan * 2, overscan * 2]);
}


/**
* _checkEnvironment
* This adjusts the favicon and document title if we detect a development or staging environment.
* called by `initAsync()`
*/
_checkEnvironment() {
const context = this.context;
const assets = context.systems.assets;
const urlhash = context.systems.urlhash;
const detected = utilDetect();

const $head = select('head');
let $favicon = $head.select(`link[rel~='icon']`);
if (!$favicon.size()) {
$favicon = $head
.append('link')
.attr('rel', 'icon')
.attr('type', 'image/svg');
}

if (/\/canary/.test(detected.host)) {
urlhash.titleBase = 'Rapid Canary';
$favicon.attr('href', assets.getFileURL('img/rapid_favicon-canary.svg'));

} else if (/(localhost|127\.0\.0\.1)/.test(detected.host)) {
urlhash.titleBase = 'Rapid Dev';
$favicon.attr('href', assets.getFileURL('img/rapid_favicon-dev.svg'));
}
}


/**
* _copyRect
* ClientRects are immutable, so copy them to an Object in case we need to trim the height/width.
Expand Down

0 comments on commit 9ce8306

Please sign in to comment.