Skip to content

Commit

Permalink
Set a flag variable that indicates Electron use
Browse files Browse the repository at this point in the history
This will enable us to do certain things differently in the Electron
version of MetagenomeScope (e.g. interact with Node.js' sqlite3
module instead of sql.js), without having to actually modify the JS
code between the versions.

The variable's name is METAGENOMESCOPE_ELECTRON_BEING_USED, for
reference.

An aside, which I already sort of knew about but realized more
clearly as I read up on global variables in JS: using globals as much
as MetagenomeScope's viewer interface does is not a good idea! It
looks like the general solution for web apps which have to maintain
least some persistent storage in a page instance is to create a
namespace (which is, itself, a JS object that is a single global
variable), and then just declare every global variable as an attribute
of that object. That way, the only namespace collision we'd need to
worry about would be the main namespace name.

This isn't a significant problem now, but it's worth registering
as its own issue. So I'm gonna go do that.
  • Loading branch information
fedarko committed Aug 22, 2018
1 parent 68975f2 commit 5b890ba
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion electron/index.min.html

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions minify_files.fish
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ sed -i'' 's/\(src\|href\)=\([\"\']\)\(js\|css\)\//\1=\2\.\.\/viewer\/\3\//g' ele
# and we don't have bubble.ico in the electron/ folder anyway
sed -i'' 's/<link rel=\"shortcut icon\" href=\"bubble\.ico\">//' electron/index.min.html

# Step 4: Set a global flag variable that lets my JavaScript code in xdot2cy.js
# know that Electron is being used (so that it can do certain things).
# The question marks allow for some variability in how the <script> is
# minified.
sed -i'' 's/window\.METAGENOMESCOPE_ELECTRON_BEING_USED \?= \?0;\?/window\.METAGENOMESCOPE_ELECTRON_BEING_USED = 1;/' electron/index.min.html

# Finally, print ending messages
echo "File minification complete."
echo "Make sure that the version of index.min.html you're uploading somewhere is renamed to index.html in its new location."
4 changes: 4 additions & 0 deletions viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
will mess up the Electron version HTML generation.
-->
<script src='js/jquery-3.2.1.min.js'></script>
<!-- The following variable declaration will be modified by
minify_files for the Electron version HTML.
-->
<script>window.METAGENOMESCOPE_ELECTRON_BEING_USED = 0;</script>
<script src='js/cytoscape.min.js'></script>
<!-- NOTE if including Cytoscape.js layout plugins for testing, those
can go here -->
Expand Down
2 changes: 1 addition & 1 deletion viewer/index.min.html

Large diffs are not rendered by default.

0 comments on commit 5b890ba

Please sign in to comment.