Skip to content

Commit c4b2dfd

Browse files
Concluding work on Import/Export functionality. And some small fixes. Version bump to 1.3.0
1 parent 0645270 commit c4b2dfd

File tree

6 files changed

+41
-15
lines changed

6 files changed

+41
-15
lines changed

src/extension/extButtonAction.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,28 @@ if (typeof browser === "undefined") {
77
var browser = chrome;
88
}
99

10+
var extension_tab_id = null;
11+
12+
function onCreated(tab) {
13+
extension_tab_id = tab.id;
14+
console.debug(`Created new tab: ${tab.id}`);
15+
}
16+
17+
function onError(error) {
18+
console.error(`Error: ${error}`);
19+
}
20+
1021
function openWindow() {
1122
console.log("injecting");
12-
browser.tabs.create({
13-
"url": "/window/window.html",
14-
});
23+
if (extension_tab_id) {
24+
browser.tabs.update(extension_tab_id, { active: true });
25+
}
26+
else {
27+
let creating = browser.tabs.create({
28+
"url": "/window/window.html",
29+
});
30+
creating.then(onCreated, onError);
31+
}
1532
}
1633

1734
browser.action.onClicked.addListener(openWindow);

src/extension/manifest_chrome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Time Tracker",
4-
"version": "1.2.5",
4+
"version": "1.3.0",
55

66
"author": "Anna Molodtsova and Kirill Shakirov",
77

src/extension/manifest_firefox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Time Tracker",
4-
"version": "1.2.3",
4+
"version": "1.3.0",
55

66
"author": "Anna Molodtsova and Kirill Shakirov",
77

src/extension/window/window.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ footer {
3737
gap: 0.6rem;
3838
margin-top: 1rem;
3939
background-color: #ed556408;
40-
border: 1px solid #d55642;
40+
border: 2px solid #d55642;
4141
border-radius: 2px;
4242

4343

src/extension/window/window.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</li>
3232
</template>
3333

34-
<input type="file" id="file_input" style="display: none;" />
34+
<input type="file" id="file_input" accept=".json" style="display: none;" />
3535

3636
<main>
3737
<section id="main-section">

src/extension/window/window.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ function main() {
5454
if (menu_section.classList.toggle("show")) {
5555
console.log("Toggle show!");
5656
}
57-
else
58-
{
57+
else {
5958
console.log("Toggle Hide!");
6059
}
6160
}
@@ -64,21 +63,29 @@ function main() {
6463
export_button.onclick = () => {
6564
export_db(db);
6665
}
66+
6767
export_button.disabled = false;
6868

6969
file_input.onchange = (e) => {
7070
if (e.target.files.length > 0) {
71-
const file = e.target.files[0];
72-
const reader = new FileReader();
71+
let file = e.target.files[0];
72+
// Reset the input value to allow same file selection
73+
e.target.value = null;
74+
75+
let reader = new FileReader();
7376
reader.onload = (e) => {
7477
import_db(db, e.target.result);
7578
};
7679
reader.onerror = (e) => {
7780
console.error("Error reading file: ", e);
7881
alert("Error reading file!");
7982
};
80-
reader.readAsText(file);
81-
console.log('Selected file:', file.name);
83+
84+
let confirm_result = confirm("This will replace records if they present in import file. Do you wish to continue?");
85+
if (confirm_result === true) {
86+
//console.debug('Selected file:', file.name);
87+
reader.readAsText(file);
88+
}
8289
}
8390
}
8491

@@ -144,7 +151,7 @@ function main() {
144151
let blob_url = URL.createObjectURL(blob);
145152
let a = document.createElement("a");
146153
a.href = blob_url;
147-
a.download = `time_tracker_export-${new Date().toISOString()}.json`;
154+
a.download = `timetracker_export_${new Date().toISOString()}.json`;
148155
a.click();
149156
URL.revokeObjectURL(blob_url);
150157
}
@@ -158,7 +165,7 @@ function main() {
158165
function import_db(db, import_data) {
159166
let json_data = null;
160167
try {
161-
json_data = JSON.parse(e.target.result);
168+
json_data = JSON.parse(import_data);
162169
} catch (err) {
163170
console.error('Invalid JSON:', err);
164171
alert("Error reading file! (Invalid JSON)");
@@ -172,6 +179,8 @@ function main() {
172179
console.error("Error importing record from json to DB: ", e);
173180
};
174181
});
182+
// refreshing window content
183+
window.location.reload();
175184
}
176185
}
177186

0 commit comments

Comments
 (0)