Skip to content

Commit

Permalink
Automatic update checking and an update README to reflect this
Browse files Browse the repository at this point in the history
  • Loading branch information
fjwillemsen committed Jul 28, 2022
1 parent c688ab1 commit 65f4d7e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ However, would it not be even better if it were to behave like a native app on y
- [x] system-based dark / light mode switching
- [x] notifications of comments and comment threads
- [x] notifications of chat
- [x] preferences pane integrated in the Overleaf menu
- [x] preferences pane integrated in the Overleaf sidemenu
- [x] automatic update checking

<img src="Assets/showcase/notifications/badgecount.png" alt="notification badgecount">
<img src="Assets/showcase/notifications/notificationcenter_light.png" width="250" alt="notification center showcase">
<img src="Assets/showcase/preferences/preferences_pane_extended.png" width="200" alt="preferences pane">


## To Do
- [ ] updates checker
- [ ] automated local backups of projects (planned for next version)
- [ ] notifications for tracked changes (planned for future version)

[Looking to contribute?](#ideas-questions-contributions)

## Tips
- The preferences pane can be found in the normal Overleaf menu.
- The preferences pane can be found in the same left-side menu as the other Overleaf settings.
- You can run multiple instances of Native Overleaf, allowing you to keep multiple projects open at the same time and receive notifications for each project.
- Notice on notifications: For notifications to work, the app must be allowed to by your system. You will only receive notifications for projects that are opened in the background, so you will not get notifications while working in a project. **Important**: to get notifications for chats, the chat window must have been opened at least once after loading a project (you can close it again). This is a limitation of the way we listen for new chat messages. If someone has a better idea, please get in touch.

Expand Down
2 changes: 1 addition & 1 deletion Scripts/appversion.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const appversion = "1.2.1"
const appversion = "1.3.0"
2 changes: 2 additions & 0 deletions Scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ if (window.matchMedia) {
<<insert="notificationsbadge.js">>
<<insert="preferences.js">>
<<insert="css.js">>
<<insert="update.js">>

// start
setupColormode()
setupNotifications()
setupPreferencesPane()
addCSS()
setAutoUpdateChecking()
41 changes: 41 additions & 0 deletions Scripts/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This file is not intended to run by itself, but is inserted into main.js

async function fetchAsync(url) {
let response = await fetch(url);
let data = await response.json();
return data;
}

function semanticVersionCompare(a, b) {
// from https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb
if (a.startsWith(b + "-")) return -1
if (b.startsWith(a + "-")) return 1
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" })
}

async function checkForUpdate() {
tags = await fetchAsync("https://api.github.com/repos/fjwillemsen/NativeOverleaf/tags")
latest_version = tags[0].name.replace('v', '')
comparison = semanticVersionCompare(latest_version, appversion)
if (comparison == 0 && comparison !== "") {
console.log("Update check completed, no update available.")
} else if (comparison == 1) {
goToUpdate = confirm(`Update available!
Current: ${appversion}, latest: ${latest_version}.
Go to downloads page?`)
if (goToUpdate) {
window.open("https://github.com/fjwillemsen/NativeOverleaf/releases/tag/v1.2.0")
}
} else if (comparison == -1) {
console.warn(`No update needed, current version (${appversion}) is newer than latest publicly available version (${latest_version}).`)
} else {
console.error(`Invalid semantic version comparison outcome: ${comparison}`)
}
}

function setAutoUpdateChecking() {
// check for updates straight away
checkForUpdate()
// check for updates every six hours
setInterval(checkForUpdate, 6*60*60*1000);
}
45 changes: 44 additions & 1 deletion bundled_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var colorscheme

// get app version
// Contents Inserted from appversion.js
const appversion = "1.2.1"
const appversion = "1.3.0"

// global variables
var notificationCounter = 0
Expand Down Expand Up @@ -539,9 +539,52 @@ function addCSS() {
var styleSheet = document.createElement("style")
styleSheet.innerText = css_text
document.head.appendChild(styleSheet)
}// Contents Inserted from update.js
// This file is not intended to run by itself, but is inserted into main.js

async function fetchAsync(url) {
let response = await fetch(url);
let data = await response.json();
return data;
}

function semanticVersionCompare(a, b) {
// from https://gist.github.com/iwill/a83038623ba4fef6abb9efca87ae9ccb
if (a.startsWith(b + "-")) return -1
if (b.startsWith(a + "-")) return 1
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" })
}

async function checkForUpdate() {
tags = await fetchAsync("https://api.github.com/repos/fjwillemsen/NativeOverleaf/tags")
latest_version = tags[0].name.replace('v', '')
comparison = semanticVersionCompare(latest_version, appversion)
if (comparison == 0 && comparison !== "") {
console.log("Update check completed, no update available.")
} else if (comparison == 1) {
goToUpdate = confirm(`Update available!
Current: ${appversion}, latest: ${latest_version}.
Go to downloads page?`)
if (goToUpdate) {
window.open("https://github.com/fjwillemsen/NativeOverleaf/releases/tag/v1.2.0")
}
} else if (comparison == -1) {
console.warn(`No update needed, current version (${appversion}) is newer than latest publicly available version (${latest_version}).`)
} else {
console.error(`Invalid semantic version comparison outcome: ${comparison}`)
}
}

function setAutoUpdateChecking() {
// check for updates straight away
checkForUpdate()
// check for updates every six hours
setInterval(checkForUpdate, 6*60*60*1000);
}

// start
setupColormode()
setupNotifications()
setupPreferencesPane()
addCSS()
setAutoUpdateChecking()

0 comments on commit 65f4d7e

Please sign in to comment.