Skip to content

Commit 20bcddf

Browse files
author
Suhas Hariharan
authored
Merge pull request #252 from sas-fossdev/fix-options-page
Fix options page and remove extension info option
2 parents 6ba9416 + 3576022 commit 20bcddf

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

src/js/helpers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,15 @@ async function getLocalConfig () {
253253
return data;
254254
}
255255

256+
/**
257+
* Retrieves the default extension config for new users.
258+
* @returns {Config} an object representing the default config.
259+
*/
260+
function getDefaultConfig () {
261+
const data = { opted_in: { changed: false, value: false }, percent_main_page: { changed: false, value: true } };
262+
return data;
263+
}
264+
256265
export {
257266
gradeToFP,
258267
grade_fp,
@@ -266,4 +275,6 @@ export {
266275
calculate_credit_hours,
267276
getSavedGrades,
268277
saveGradesLocally,
278+
getLocalConfig,
279+
getDefaultConfig,
269280
};

src/js/saspowerschoolff.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import {
3636
gradeToGPA,
3737
saveGradesLocally,
3838
getSavedGrades,
39+
getLocalConfig,
40+
getDefaultConfig,
3941
} from './helpers';
4042

4143
// Vue Components
@@ -113,20 +115,32 @@ function class_page () {
113115

114116
async function login_page () {
115117
$('<div id="saspes-info"></div>').insertAfter('div#content');
116-
browser.storage.local.get("showExtensionInfo").then(output => {
117-
new (Vue.extend(ExtensionInfo))({
118-
data: {
119-
showInfo: output.showExtensionInfo.value,
120-
},
121-
}).$mount('#saspes-info');
122-
});
118+
new (Vue.extend(ExtensionInfo))({
119+
data: {
120+
showInfo: true,
121+
},
122+
}).$mount('#saspes-info');
123123

124124
const LastGradesDiv = document.createElement('div');
125125
LastGradesDiv.classList.add("last-grade-div-fixed");
126126
LastGradesDiv.id = "saspes-last-grades";
127127
document.body.appendChild(LastGradesDiv);
128128

129-
if ((await browser.storage.local.get("opted_in")).opted_in.value) {
129+
let current_config = await getLocalConfig();
130+
// disables last seen grades temporarily for anyone who has it enabled, until a proper opt in can be added.
131+
132+
if (current_config.opted_in === undefined) {
133+
current_config = getDefaultConfig();
134+
} else if (current_config.opted_in.value === undefined) {
135+
current_config = getDefaultConfig();
136+
} else if (current_config.opted_in.changed !== undefined && current_config.opted_in.changed === false) {
137+
current_config.opted_in = {
138+
value: false,
139+
changed: false,
140+
};
141+
}
142+
await browser.storage.local.set(current_config);
143+
if ((await browser.storage.local.get("opted_in"))?.opted_in?.value || false) {
130144
(browser.storage.local.get("most_recent_user")).then(output => {
131145
const most_recent_user = output.most_recent_user;
132146
if (most_recent_user !== undefined) {

src/js/views/Options.vue

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ import browser from 'webextension-polyfill';
4545
function defaultOptions () {
4646
return {
4747
id: "Not set yet",
48+
ignoreNextReset: false,
4849
percent_main_page: true,
49-
save_last_grades: true,
50+
save_last_grades: false,
5051
};
5152
}
5253
@@ -55,7 +56,6 @@ export default {
5556
data () {
5657
return {
5758
options: defaultOptions(),
58-
ignoreNextReset: false,
5959
copiedRecently: false,
6060
thirdPartyLibraries: browser.extension.getURL('web_accessible_resources/libraries.txt'),
6161
version: SASPES_VERSION_NAME,
@@ -64,12 +64,12 @@ export default {
6464
watch: {
6565
options: {
6666
deep: true,
67-
handler (val) {
67+
async handler (val) {
6868
if (this.ignoreNextReset) {
6969
this.ignoreNextReset = false;
7070
return;
7171
}
72-
browser.storage.local.set(JSON.parse(JSON.stringify(val)));
72+
await browser.storage.local.set({ "percent_main_page": { changed: true, value: val.percent_main_page }, "opted_in": { changed: true, value: val.save_last_grades } });
7373
},
7474
},
7575
},
@@ -79,14 +79,9 @@ export default {
7979
},
8080
methods: {
8181
async resetData () {
82-
const options = await browser.storage.local.get(defaultOptions());
82+
const stored_options = await browser.storage.local.get(null);
8383
this.ignoreNextReset = true;
84-
this.options = Object.assign({}, this.options, options);
85-
},
86-
copyId () {
87-
this.copiedRecently = true;
88-
navigator.clipboard.writeText(this.options.id);
89-
setTimeout(() => { this.copiedRecently = false; }, 1500);
84+
this.options = { "percent_main_page": stored_options?.percent_main_page?.value || this.options.percent_main_page, "save_last_grades": stored_options?.opted_in?.value || this.options.save_last_grades };
9085
},
9186
},
9287
};

0 commit comments

Comments
 (0)