Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
a387ff2f
Commit
a387ff2f
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Hotfix/version update check
parent
28707f66
No related branches found
No related tags found
2 merge requests
!60
Revert "Fail a test to be sure it works"
,
!57
Hotfix/version update check
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.go
+2
-0
2 additions, 0 deletions
main.go
storage/version.go
+51
-3
51 additions, 3 deletions
storage/version.go
wasm/version.go
+61
-1
61 additions, 1 deletion
wasm/version.go
with
114 additions
and
4 deletions
main.go
+
2
−
0
View file @
a387ff2f
...
@@ -196,6 +196,8 @@ func main() {
...
@@ -196,6 +196,8 @@ func main() {
js
.
Global
()
.
Set
(
"GetClientVersion"
,
js
.
FuncOf
(
wasm
.
GetClientVersion
))
js
.
Global
()
.
Set
(
"GetClientVersion"
,
js
.
FuncOf
(
wasm
.
GetClientVersion
))
js
.
Global
()
.
Set
(
"GetClientGitVersion"
,
js
.
FuncOf
(
wasm
.
GetClientGitVersion
))
js
.
Global
()
.
Set
(
"GetClientGitVersion"
,
js
.
FuncOf
(
wasm
.
GetClientGitVersion
))
js
.
Global
()
.
Set
(
"GetClientDependencies"
,
js
.
FuncOf
(
wasm
.
GetClientDependencies
))
js
.
Global
()
.
Set
(
"GetClientDependencies"
,
js
.
FuncOf
(
wasm
.
GetClientDependencies
))
js
.
Global
()
.
Set
(
"GetWasmSemanticVersion"
,
js
.
FuncOf
(
wasm
.
GetWasmSemanticVersion
))
js
.
Global
()
.
Set
(
"GetXXDKSemanticVersion"
,
js
.
FuncOf
(
wasm
.
GetXXDKSemanticVersion
))
<-
make
(
chan
bool
)
<-
make
(
chan
bool
)
os
.
Exit
(
0
)
os
.
Exit
(
0
)
...
...
This diff is collapsed.
Click to expand it.
storage/version.go
+
51
−
3
View file @
a387ff2f
...
@@ -11,9 +11,11 @@ package storage
...
@@ -11,9 +11,11 @@ package storage
import
(
import
(
"os"
"os"
"sync"
"github.com/pkg/errors"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/bindings"
"gitlab.com/elixxir/client/v4/bindings"
)
)
...
@@ -38,17 +40,23 @@ func CheckAndStoreVersions() error {
...
@@ -38,17 +40,23 @@ func CheckAndStoreVersions() error {
func
checkAndStoreVersions
(
func
checkAndStoreVersions
(
currentWasmVer
,
currentClientVer
string
,
ls
*
LocalStorage
)
error
{
currentWasmVer
,
currentClientVer
string
,
ls
*
LocalStorage
)
error
{
// Get the stored client
and WASM
version
s
, if t
hey
exists
// Get the stored client version, if
i
t exists
storedClientVer
,
err
:=
initOrLoadStoredSemver
(
storedClientVer
,
err
:=
clientVerKey
,
currentClientVer
,
ls
)
initOrLoadStoredSemver
(
clientVerKey
,
currentClientVer
,
ls
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// Get the stored WASM versions, if it exists
storedWasmVer
,
err
:=
initOrLoadStoredSemver
(
semverKey
,
currentWasmVer
,
ls
)
storedWasmVer
,
err
:=
initOrLoadStoredSemver
(
semverKey
,
currentWasmVer
,
ls
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// Store old versions to memory
setOldClientSemVersion
(
storedClientVer
)
setOldWasmSemVersion
(
storedWasmVer
)
// Check if client needs an update
// Check if client needs an update
if
storedClientVer
!=
currentClientVer
{
if
storedClientVer
!=
currentClientVer
{
jww
.
INFO
.
Printf
(
"xxDK client out of date; upgrading version: v%s → v%s"
,
jww
.
INFO
.
Printf
(
"xxDK client out of date; upgrading version: v%s → v%s"
,
...
@@ -96,3 +104,43 @@ func initOrLoadStoredSemver(
...
@@ -96,3 +104,43 @@ func initOrLoadStoredSemver(
// Return the stored version
// Return the stored version
return
string
(
storedVersion
),
nil
return
string
(
storedVersion
),
nil
}
}
// oldVersions contains the old versions of xxdk WASM and xxdk client that were
// stored in storage before being overwritten on update.
var
oldVersions
struct
{
wasm
string
client
string
sync
.
Mutex
}
// GetOldWasmSemVersion returns the old version of xxdk WASM before being
// updated.
func
GetOldWasmSemVersion
()
string
{
oldVersions
.
Lock
()
defer
oldVersions
.
Unlock
()
return
oldVersions
.
wasm
}
// GetOldClientSemVersion returns the old version of xxdk client before being
// updated.
func
GetOldClientSemVersion
()
string
{
oldVersions
.
Lock
()
defer
oldVersions
.
Unlock
()
return
oldVersions
.
client
}
// setOldWasmSemVersion sets the old version of xxdk WASM. This should be called
// before it is updated.
func
setOldWasmSemVersion
(
v
string
)
{
oldVersions
.
Lock
()
defer
oldVersions
.
Unlock
()
oldVersions
.
wasm
=
v
}
// setOldClientSemVersion sets the old version of xxdk client. This should be
// called before it is updated.
func
setOldClientSemVersion
(
v
string
)
{
oldVersions
.
Lock
()
defer
oldVersions
.
Unlock
()
oldVersions
.
client
=
v
}
This diff is collapsed.
Click to expand it.
wasm/version.go
+
61
−
1
View file @
a387ff2f
...
@@ -10,9 +10,12 @@
...
@@ -10,9 +10,12 @@
package
wasm
package
wasm
import
(
import
(
"encoding/json"
"syscall/js"
"gitlab.com/elixxir/client/v4/bindings"
"gitlab.com/elixxir/client/v4/bindings"
"gitlab.com/elixxir/xxdk-wasm/storage"
"gitlab.com/elixxir/xxdk-wasm/storage"
"
syscall/j
s"
"
gitlab.com/elixxir/xxdk-wasm/util
s"
)
)
// GetVersion returns the current xxDK WASM semantic version.
// GetVersion returns the current xxDK WASM semantic version.
...
@@ -49,3 +52,60 @@ func GetClientGitVersion(js.Value, []js.Value) any {
...
@@ -49,3 +52,60 @@ func GetClientGitVersion(js.Value, []js.Value) any {
func
GetClientDependencies
(
js
.
Value
,
[]
js
.
Value
)
any
{
func
GetClientDependencies
(
js
.
Value
,
[]
js
.
Value
)
any
{
return
bindings
.
GetDependencies
()
return
bindings
.
GetDependencies
()
}
}
// VersionInfo contains information about the current and old version of the
// API.
type
VersionInfo
struct
{
Current
string
`json:"current"`
Updated
bool
`json:"updated"`
Old
string
`json:"old"`
}
// GetWasmSemanticVersion returns the current version of the WASM client, it's
// old version before being updated, and if it has been updated.
//
// Returns:
// - JSON of [VersionInfo] (Uint8Array).
// - Throws a TypeError if getting the version failed.
func
GetWasmSemanticVersion
(
js
.
Value
,
[]
js
.
Value
)
any
{
vi
:=
VersionInfo
{
Current
:
storage
.
SEMVER
,
Updated
:
false
,
Old
:
storage
.
GetOldWasmSemVersion
(),
}
if
vi
.
Current
!=
vi
.
Old
{
vi
.
Updated
=
true
}
data
,
err
:=
json
.
Marshal
(
vi
)
if
err
!=
nil
{
utils
.
Throw
(
utils
.
TypeError
,
err
)
}
return
utils
.
CopyBytesToJS
(
data
)
}
// GetXXDKSemanticVersion returns the current version of the xxdk client, it's
// old version before being updated, and if it has been updated.
//
// Returns:
// - JSON of [VersionInfo] (Uint8Array).
// - Throws a TypeError if getting the version failed.
func
GetXXDKSemanticVersion
(
js
.
Value
,
[]
js
.
Value
)
any
{
vi
:=
VersionInfo
{
Current
:
bindings
.
GetVersion
(),
Updated
:
false
,
Old
:
storage
.
GetOldClientSemVersion
(),
}
if
vi
.
Current
!=
vi
.
Old
{
vi
.
Updated
=
true
}
data
,
err
:=
json
.
Marshal
(
vi
)
if
err
!=
nil
{
utils
.
Throw
(
utils
.
TypeError
,
err
)
}
return
utils
.
CopyBytesToJS
(
data
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment