Skip to content

Commit

Permalink
chrome extension done
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunpat committed Aug 16, 2018
1 parent 60df79e commit 168d8fe
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 18 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# remove dev_data from repo
dev_data/

# get out! .DS_Store
.DS_Store

Expand All @@ -25,5 +22,6 @@ extensions/chrome/js/Logger.js
extensions/chrome/js/ScheduleBuilder.js
extensions/chrome/js/PrefManager.js
extensions/chrome/js/Storage.js
extensions/chrome/js/Analytics.js

extensions/chrome/images/
11 changes: 11 additions & 0 deletions extensions/chrome/js/ExtnRequestManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ class ExtnRequestManager {
}).then(res => res.json);
}

static sendAnalytics(data) {
return this.ajax({
url: '/api/v1/write/analytics',
method: 'POST',
data: {
device_id: Storage.getDeviceId(),
data: data
}
}).then(res => res.json);
}

static sendError(data) {
console.error(data);
return this.ajax({
Expand Down
8 changes: 4 additions & 4 deletions extensions/chrome/js/ExtnView.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ExtnView {
if (this.currentValues.dayTypeText !== day_type) {
this.index.dayType.innerText = day_type;
this.currentValues.dayTypeText = day_type;
returnVal = true;
this.updateScreenDimensions();
}

if (this.currentValues.currentPeriodText !== period_name) {
Expand All @@ -68,7 +68,7 @@ class ExtnView {
this.index.currentPeriodText.style.animation = '.6s updatePeriod'
setTimeout(() => this.index.currentPeriodText.style.animation = 'none', 1e3);
this.currentValues.currentPeriodText = period_name;
returnVal = true;
this.updateScreenDimensions();
}

if (this.currentValues.timeLeftText !== timeString) {
Expand Down Expand Up @@ -109,9 +109,9 @@ class ExtnView {

updateScreenDimensions() {
let dimension = window.innerWidth;
this.index.dayType.parentElement.style.fontSize = Math.min(50, dimension / 17) + 'px';
this.index.dayType.parentElement.style.fontSize = Math.min(50, (dimension / this.index.dayType.parentElement.innerText.length) / .6) + 'px';
//this.index.dayType.parentElement.parentElement.style.padding = Math.min(50, dimension / 22) + 'px';
this.index.timeLeft.style.fontSize = Math.min(170, dimension / (this.index.timeLeft.innerText.length - 2)) + 'px';
this.index.timeLeft.style.fontSize = Math.min(120, dimension / (this.index.timeLeft.innerText.length - 2)) + 'px';
}

dimensionCanvas() { this.canvas.dimension(); }
Expand Down
13 changes: 12 additions & 1 deletion extensions/chrome/js/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const timingEngine = new TimingEngine(),
view = new ExtnView(),
//analytics = new Analytics,
analytics = new Analytics(),
prefManager = new PrefManager(),
scheduleBuilder = new ScheduleBuilder(),
RequestManager = ExtnRequestManager,
Expand Down Expand Up @@ -49,15 +49,26 @@ chrome.runtime.onMessageExternal.addListener((req, sender, sendResponse) => {

Storage.setDeviceId(device_id);
RequestManager.init().then(values => {

if (!values) {
Storage.clearAll();
window.open(URL_PREFIX);
}

if (values.error !== 'not_registered') {
analytics.setRegisteredTo(values.email);
prefManager.setGoogleAccount(values);
}
showPrefs();

let analyticsTime = timingEngine.getRemainingTime();

analytics.setPeriod(analyticsTime.period);
analytics.setPeriodName(prefManager.getPeriodName(analyticsTime.period) || analyticsTime.period);
analytics.setTheme(prefManager.getThemeNum());
analytics.setPathname('extn');
analytics.setNewLoad(false);
analytics.setDeviceId(Storage.getDeviceId());
});
});

Expand Down
3 changes: 2 additions & 1 deletion extensions/chrome/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<span style="font-size: 20px; padding-left: 5px; font-family: 'Product Sans';">
<div tooltip="Logout"><img></div>
</div>
<div style="bottom: 0; left: 0; position: fixed; padding: 12px; padding-bottom: 8px; user-select: none;">
<div style="bottom: 0; left: 0; position: fixed; padding: 12px; padding-bottom: 0; user-select: none;">
<span style="font-size: 50px; padding-left: 6px; font-family: 'Product Sans';">
<span href="https://bell.mvhs.club" id="day-type"></span>
&nbsp;&#x25B8;&nbsp;
Expand All @@ -55,6 +55,7 @@
<script type="text/javascript" src="/js/PrefManager.js"></script>
<script type="text/javascript" src="/js/ScheduleBuilder.js"></script>
<script type="text/javascript" src="/js/Storage.js"></script>
<script type="text/javascript" src="/js/Analytics.js"></script>
<script type="text/javascript" src="/js/ExtnRequestManager.js"></script>
<script type="text/javascript" src="/js/ExtnView.js"></script>
<script type="text/javascript" src="/js/main.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions public/js/Analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class Analytics {
await this.sleep(1);

let data = {};
if (this.pathname === '/' && typeof this.period === 'number' && this.period_name) { // index page
if ((this.pathname === '/' || this.pathname === 'extn') && typeof this.period === 'number' && this.period_name) { // index page or extn

data.prefs = {
theme: this.theme,
period: this.period
};
}
if (this.period !== this.period_name)
data.prefs.period_name = this.period_name;

Expand Down
2 changes: 1 addition & 1 deletion public/js/PrefManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PrefManager {
if (values.settings) {
if (values.settings.period_names)
this.period_names = values.settings.period_names;
if (values.settings.theme)
if (typeof values.settings.theme === 'number')
this.setTheme(values.settings.theme);
// do other loading stuff here
}
Expand Down
7 changes: 4 additions & 3 deletions public/js/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class View {

}

updateScheduleTable(periods, currentTime) {
updateScheduleTable(periods, periodNames, currentTime) {

let currentDate = (new Date(currentTime)).setHours(0, 0, 0, 0);

Expand All @@ -175,8 +175,9 @@ class View {
if ((new Date(p.f)).setHours(0, 0, 0, 0) !== currentDate)
continue;

if (typeof p.n === 'number')
p.n = formatPeriodNumber(p.n);
if (typeof p.n === 'number') {
p.n = periodNames[p.n] || formatPeriodNumber(p.n);
}

html += `
<tr>
Expand Down
5 changes: 2 additions & 3 deletions public/js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ render.index = () => {

let firstRun = true;
function mainLoop() {

if (window.location.pathname === '/') {

let time = timingEngine.getRemainingTime();
Expand All @@ -50,14 +50,13 @@ render.index = () => {

if (!document.hidden || document.hasFocus()) {
if (view.updateScreen(time, true)) {
view.updateScheduleTable(timingEngine.getUpcomingPeriods(), timingEngine.getCurrentTime());
view.updateScheduleTable(timingEngine.getUpcomingPeriods(), prefManager.getAllPreferences().period_names, timingEngine.getCurrentTime());
}
return window.setTimeout(mainLoop, 50);
}

view.updateScreen(time, false);
}

return window.setTimeout(mainLoop, 500); // .5s when user not on the page; helps with cpu usage
}

Expand Down
1 change: 1 addition & 0 deletions scripts/update-extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cat public/js/Logger.js > extensions/chrome/js/Logger.js
cat public/js/ScheduleBuilder.js > extensions/chrome/js/ScheduleBuilder.js
cat public/js/PrefManager.js > extensions/chrome/js/PrefManager.js
cat public/js/Storage.js > extensions/chrome/js/Storage.js
cat public/js/Analytics.js > extensions/chrome/js/Analytics.js

# ----- css
cat public/css/main.css > extensions/chrome/css/main.css
Expand Down

0 comments on commit 168d8fe

Please sign in to comment.