Skip to content

Commit

Permalink
fixed nasty bug for smartphones
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunpat committed Sep 19, 2018
1 parent 49d966c commit b827b7e
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 71 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "period-countdown",
"version": "2.1.3",
"version": "2.1.4",
"description": "A simple way to keep track of the remaining time in class",
"main": "server.js",
"scripts": {
Expand Down
72 changes: 72 additions & 0 deletions public/js/extras.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Logger from './Logger.js';

export function addServiceWorker(path) {
if (navigator.serviceWorker) {
navigator.serviceWorker.register(path).then((reg) => {
Logger.log('main', 'service worker registered');
}).catch(err => {
Logger.log('main', 'service worker registration failed');
console.error(err);
})
return true;
}
return false;
}

export function googleApiDidLoad(render) {
return () => gapi.load('auth2', () => {
gapi.auth2.init({
client_id: '770077939711-hbanoschq9p65gr8st8grsfbku4bsnhl.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
scope: 'profile email'
}).then(GoogleAuth => {
let gSuccess = user => {
if (view.modal.open) view.closeModal();

let data = user.getBasicProfile();

let account = {
email: data.U3,
first_name: data.ofa,
last_name: data.wea,
profile_pic: data.Paa
}

RequestManager.login(account).then(res => {
if (res.data.status === 'returning_user') {
prefManager.setGoogleAccount(res.data.user_data);
view.settingChangesSaved();
} else if (res.data.status === 'new_user') {
prefManager.setGoogleAccount(res.data.user_data);
} else {
view.showModal('modal-server-down');
}

render.showPrefs();
}).catch(err => {
view.showModal('modal-server-down');
});
}

let gFail = () => window.alert('Google had trouble signing you in. Please try again later.');

document.querySelector('#modal-body .modal-login').innerHTML = 'After logging in with Google, you will gain a whole host of new features including the ability to have personalized period names and custom themes.<br><br><a class="google-login-button">Click here</a> to log in with your Google Account.';

for (let element of document.getElementsByClassName('google-login-button'))
GoogleAuth.attachClickHandler(element, {}, gSuccess, gFail);
});
});
}

export function greeting() {
let greeting = ['Welcome', '欢迎', 'स्वागत हे', 'Bienvenido', 'خوش آمدی', 'Bienvenue', 'желанный', 'Bem vinda', 'Benvenuto', 'Gratus mihi venis', 'Welkom', 'ברוך הבא', 'ようこそ'][Math.floor(Math.random() * 13)];
console.log(`%c${greeting}`, 'background: #fccb0b; color: #000; font-size: 34px; padding: 6px 20px; font-family: \'sans-serif\'; border-radius: 4px;');
console.log('https://github.com/arjunpat/period-countdown');
}

export function getVersion() {
for (let node of document.querySelectorAll('script')) {
if (node.src.includes('/js/bundle.js?v='))
return node.src.substring(node.src.indexOf('?v=') + 3);
}
}
80 changes: 11 additions & 69 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import Storage from './Storage.js';
import ScheduleBuilder from './ScheduleBuilder.js';
import TimingEngine from './TimingEngine.js';

import {render, load} from './render.js';
import { render, load } from './render.js';
import { addServiceWorker, googleApiDidLoad, greeting, getVersion } from './extras.js';


window.timingEngine = new TimingEngine();
window.view = new View();
window.analytics = new Analytics;
window.prefManager = new PrefManager;
window.analytics = new Analytics();
window.prefManager = new PrefManager();
window.scheduleBuilder = new ScheduleBuilder();
window.RequestManager = RequestManager;

// has to global fro google
window.googleApiDidLoad = googleApiDidLoad(render);

// inital page render
load(window.location.pathname);

Expand Down Expand Up @@ -60,23 +65,11 @@ window.onbeforeunload = () => {
analytics.leaving();
}

// gets version
for (let node of document.querySelectorAll('script')) {
if (node.src.includes('/js/bundle.js?v='))
analytics.setVersion(node.src.substring(node.src.indexOf('?v=') + 3));
}

analytics.setVersion(getVersion());
analytics.setPathname(window.location.pathname);

// add service workers
/*if (navigator.serviceWorker) {
navigator.serviceWorker.register('/sw.js').then((reg) => {
Logger.log('main', 'service worker registered');
}).catch(err => {
Logger.log('main', 'service worker registration failed');
console.error(err);
})
}*/
//addServiceWorker('/sw.js');

if (window.chrome && !window.localStorage.chrome_extension_installed) {
setTimeout(() => {
Expand All @@ -97,55 +90,4 @@ window.setInterval(() => {
}, 5 * 60 * 1000 /* five minutes */);

// welcome, cause what else is the computer going to do?
let greeting = ['Welcome', '欢迎', 'स्वागत हे', 'Bienvenido', 'خوش آمدی', 'Bienvenue', 'желанный', 'Bem vinda', 'Benvenuto', 'Gratus mihi venis', 'Welkom', 'ברוך הבא', 'ようこそ'][Math.floor(Math.random() * 13)];
console.log(`%c${greeting}`, 'background: #fccb0b; color: #000; font-size: 34px; padding: 6px 20px; font-family: \'sans-serif\'; border-radius: 4px;');
console.log('https://github.com/arjunpat/period-countdown');


// has to be global for google api
window.googleApiDidLoad = () => {

gapi.load('auth2', () => {
gapi.auth2.init({
client_id: '770077939711-hbanoschq9p65gr8st8grsfbku4bsnhl.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
scope: 'profile email'
}).then(GoogleAuth => {
let gSuccess = user => {
if (view.modal.open) view.closeModal();

let data = user.getBasicProfile();

let account = {
email: data.U3,
first_name: data.ofa,
last_name: data.wea,
profile_pic: data.Paa
}

RequestManager.login(account).then(res => {
if (res.data.status === 'returning_user') {
prefManager.setGoogleAccount(res.data.user_data);
view.settingChangesSaved();
} else if (res.data.status === 'new_user') {
prefManager.setGoogleAccount(res.data.user_data);
} else {
view.showModal('modal-server-down');
}

render.showPrefs();
}).catch(err => {
view.showModal('modal-server-down');
});
}

let gFail = () => window.alert('Google had trouble signing you in. Please try again later.');

document.querySelector('#modal-body .modal-login').innerHTML = 'After logging in with Google, you will gain a whole host of new features including the ability to have personalized period names and custom themes.<br><br><a class="google-login-button">Click here</a> to log in with your Google Account.';

for (let element of document.getElementsByClassName('google-login-button'))
GoogleAuth.attachClickHandler(element, {}, gSuccess, gFail);
});
});

}
greeting();
1 change: 0 additions & 1 deletion public/js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ render.index = () => {
}

window.onresize = resizeScreen;
window.screen.orientation.onchange = resizeScreen;

view.index.settingsButton.querySelector('div').onclick = () => {
load('/settings', true);
Expand Down

0 comments on commit b827b7e

Please sign in to comment.