Skip to content

Commit 24fa13c

Browse files
Merge pull request #16 from Ruby-Network/iframe-exit
Fullscreen exit, version management
2 parents 0dbef0e + 5f4400d commit 24fa13c

File tree

10 files changed

+74
-24
lines changed

10 files changed

+74
-24
lines changed

main.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@
4646
uvPath()
4747

4848
# Other routes
49-
get '/?:unlock?' do
49+
get '/:unlock?' do
5050
erb :index, :layout => :"layouts/index"
5151
end
5252

53-
5453
#Auth to login to the site
5554
post '/auth' do
5655
if params[:password] == Settings.password && params[:username] == Settings.username
@@ -60,4 +59,4 @@
6059
else
6160
redirect '/'
6261
end
63-
end
62+
end

node-server/server.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ const __dirname = path.resolve();
1212
const settings = YAML.parse(fs.readFileSync(path.join(__dirname, '/config/settings.yml'), 'utf8'));
1313
import chalk from 'chalk';
1414
import compile from './compile.js';
15+
import getLatestRelease from './version.js';
1516
let rubyPort = process.argv.find((arg) => arg.startsWith('--ruby-port')).split('=')[1] || 9292;
1617
let nodePort = process.argv.find((arg) => arg.startsWith('--node-port')).split('=')[1] || 9293;
1718

19+
const latestRelease = await getLatestRelease();
1820
const bare = createBareServer('/bare/');
1921
const rh = createRammerhead();
2022
const rammerheadScopes = [ "/rammerhead.js", "/hammerhead.js", "/transport-worker.js", "/task.js", "/iframe-task.js", "/worker-hammerhead.js", "/messaging", "/sessionexists", "/deletesession", "/newsession", "/editsession", "/needpassword", "/syncLocalStorage", "/api/shuffleDict", "/mainport" ];
@@ -80,6 +82,9 @@ app.get('/search=:query', async (req, res) => {
8082
reply.code(500).send({ error: "Internal Server Error" });
8183
}
8284
});
85+
app.get('/version', async (req, res) => {
86+
res.send({ version: latestRelease });
87+
});
8388

8489
app.listen({ port: nodePort, host: '0.0.0.0' });
8590
console.log(chalk.green(`Server listening on port ${chalk.red(nodePort)}`));

node-server/version.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
async function getLatestRelease() {
2+
console.log('Fetching latest release...')
3+
let version = await fetch('https://api.github.com/repos/Ruby-Network/ruby/releases/latest').then((res) => res.json());
4+
console.log('Latest release fetched.')
5+
return version.tag_name;
6+
}
7+
8+
export default getLatestRelease;

require.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
require './ruby/utils.rb'
1414
require './ruby/uv.rb'
1515
require './ruby/auth.rb'
16-
require './ruby/yamlValidator.rb'
16+
require './ruby/yamlValidator.rb'

ruby/auth.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ def call(env)
2424
end
2525
def auth
2626
if session[:auth] != true
27-
halt erb :'edu/v1/index'
27+
halt erb :'edu/v1/index', :layout => :"layouts/index"
2828
end
2929
end

src/public/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/js/controls.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,11 @@ function fullscreen() {
9090
iframe.style.zIndex = '9998';
9191
//add a transition
9292
iframe.style.transition = 'all 0.5s ease-in-out';
93+
document.getElementById('exit-iframe').classList.remove('dnone');
9394
//listen for escape key
9495
document.addEventListener('keydown', function(e) {
9596
if (e.key === 'Escape') {
96-
//reset all styles
97-
iframe.style.position = '';
98-
iframe.style.top = '';
99-
iframe.style.left = '';
100-
iframe.style.width = '';
101-
iframe.style.height = '';
102-
iframe.style.zIndex = '';
103-
iframe.style.transition = '';
104-
}
105-
else if (e.key === 'Escape' && e.altKey) {
106-
//reset all styles
107-
iframe.style.position = '';
108-
iframe.style.top = '';
109-
iframe.style.left = '';
110-
iframe.style.width = '';
111-
iframe.style.height = '';
112-
iframe.style.zIndex = '';
113-
iframe.style.transition = '';
97+
exitIframe();
11498
}
11599
});
116100
}
@@ -137,3 +121,13 @@ function isIframeLoaded() {
137121
updateURLBar(iframe.contentWindow.location.href);
138122
});
139123
}
124+
function exitIframe() {
125+
iframe.style.position = '';
126+
iframe.style.top = '';
127+
iframe.style.left = '';
128+
iframe.style.width = '';
129+
iframe.style.height = '';
130+
iframe.style.zIndex = '';
131+
iframe.style.transition = '';
132+
document.getElementById('exit-iframe').classList.add('dnone');
133+
}

src/public/js/updates.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//This file is here to handle updated of the website.
2+
function getLatestRelease() {
3+
let xhr = new XMLHttpRequest();
4+
xhr.open('GET', '/version', false);
5+
xhr.send();
6+
let textResp = xhr.responseText;
7+
return JSON.parse(textResp)
8+
}
9+
const userVersion = localStorage.getItem('version');
10+
let latestRelease = getLatestRelease();
11+
if (userVersion != latestRelease.version || userVersion == null || userVersion == undefined) {
12+
localStorage.setItem('updated', true);
13+
localStorage.setItem('version', latestRelease.version);
14+
uninstallAllSW();
15+
}

0 commit comments

Comments
 (0)