Skip to content

Commit

Permalink
📰 Never miss a Pluto.jl update again
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Apr 2, 2020
1 parent 0f082ee commit bd3e068
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
18 changes: 10 additions & 8 deletions assets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class PlutoConnection {

try {
const update = JSON.parse(event.data)
console.log(update)

const forMe = !(("notebookID" in update) && (update.notebookID != this.notebookID))
if (!forMe) {
Expand Down Expand Up @@ -186,11 +185,8 @@ class PlutoConnection {
})
}

plutoVersionIsLatest(onResult, onError=undefined){
if(!this.versionInfo){
onError(new Error("Remote version info not yet acquired."))
}
fetch("https://api.github.com/repos/fonsp/Pluto.jl/releases", {
fetchPlutoVersions(){
const githubPromise = fetch("https://api.github.com/repos/fonsp/Pluto.jl/releases", {
method: 'GET',
cache: 'no-cache',
headers: {
Expand All @@ -201,8 +197,14 @@ class PlutoConnection {
}).then((response) => {
return response.json()
}).then((response) => {
onResult(response[0].tag_name, this.versionInfo.plutoVersionStr)
}).catch(undefined)
return response[0].tag_name
}).catch(e => null)

const plutoPromise = this.sendreceive("getversion", {}).then(u => {
return u.message.pluto
})

return Promise.all([githubPromise, plutoPromise])
}

// TODO: reconnect with a delay if the last request went poorly
Expand Down
47 changes: 33 additions & 14 deletions assets/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ document.addEventListener("DOMContentLoaded", () => {
window.remoteNotebookList = null

function updateRemoteNotebooks(list) {
console.log(list)
remoteNotebookList = list
list.forEach(nb => {
console.log(nb)
if (nb.uuid == notebookID) {
updateLocalNotebookName(nb.path)
}
Expand Down Expand Up @@ -339,7 +337,6 @@ document.addEventListener("DOMContentLoaded", () => {
/* SERVER CONNECTION */

function onUpdate(update, byMe) {
console.log("asdfff")
var message = update.message

switch (update.type) {
Expand Down Expand Up @@ -383,21 +380,43 @@ document.addEventListener("DOMContentLoaded", () => {
client.send("getallnotebooks", {})

client.sendreceive("getallcells", {}).then(update => {
const promises = []

update.message.cells.forEach((cell, index) => {
const cellNode = createLocalCell(index, cell.uuid, "")
client.sendreceive("getinput", {}, cell.uuid).then(update => {
updateLocalCellInput(true, cell.uuid, update.message.code)
})
client.sendreceive("getoutput", {}, cell.uuid).then(update => {
const message = update.message
updateLocalCellOutput(window.localCells[update.cellID], message.mime, message.output, message.errormessage, message.runtime)
})
promises.push(
client.sendreceive("getinput", {}, cell.uuid).then(update => {
updateLocalCellInput(true, cell.uuid, update.message.code)
})
)
promises.push(
client.sendreceive("getoutput", {}, cell.uuid).then(update => {
const message = update.message
updateLocalCellOutput(window.localCells[update.cellID], message.mime, message.output, message.errormessage, message.runtime)
})
)
})

Promise.all(promises).then(() => {
document.body.classList.remove("loading")
})
}).catch(console.error)
// TODO: we should when exactly this happens
setTimeout(() => {
document.body.classList.remove("loading")
}, 3000)

client.fetchPlutoVersions().then(versions => {
const remote = versions[0]
const local = versions[1]

console.log(local)
if(remote != local){
var rs = remote.split(".")
var ls = local.split(".")

// while we are in alpha, we also notify for patch updates.
if(rs[0] != ls[0] || rs[1] != ls[1] || true){
alert("A new version of Pluto.jl is available! 🎉\n\n You have " + local + ", the latest is " + remote + ".\n\nYou can update Pluto.jl using the julia package manager.\nAfterwards, exit Pluto.jl and restart julia.")
}
}
})

}

Expand Down
1 change: 1 addition & 0 deletions src/Pluto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Pkg
const PKG_ROOT_DIR = normpath(joinpath(@__DIR__, ".."))
const PLUTO_VERSION = VersionNumber(Pkg.TOML.parsefile(joinpath(PKG_ROOT_DIR, "Project.toml"))["version"])
const PLUTO_VERSION_STR = 'v' * string(PLUTO_VERSION)
const JULIA_VERSION_STR = 'v' * string(VERSION)

@info """\n
Welcome to Pluto $(PLUTO_VERSION_STR)! âš¡
Expand Down
7 changes: 7 additions & 0 deletions src/webserver/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ responses[:connect] = (body, notebook=nothing; initiator::Union{Initiator, Missi
putclientupdates!(initiator, UpdateMessage(:👋, Dict(), nothing, nothing, initiator))
end

responses[:getversion] = (body, notebook=nothing; initiator::Union{Initiator, Missing}=missing) -> begin
putclientupdates!(initiator, UpdateMessage(:versioninfo, Dict(
:pluto => PLUTO_VERSION_STR,
:julia => JULIA_VERSION_STR,
), nothing, nothing, initiator))
end


# TODO: actions on the notebook are not thread safe
responses[:addcell] = (body, notebook::Notebook; initiator::Union{Initiator, Missing}=missing) -> begin
Expand Down

1 comment on commit bd3e068

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on bd3e068 Apr 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#31

Please sign in to comment.