Skip to content

Commit

Permalink
Add update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
xianfei committed Sep 6, 2022
1 parent fef5e4b commit 6d4529e
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 24 deletions.
181 changes: 168 additions & 13 deletions mainview/framework.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<div
class="mdui-color-theme clickable"
style="
height: 28px;
height: 24px;
width: 4px;
border-radius: 2px;
position: fixed;
Expand Down Expand Up @@ -203,8 +203,21 @@
v-bind:class="tab=='settings'?'mdui-btn select':'mdui-btn'"
onclick="sysmocapApp.tab='settings'"
>
<span class="material-icons-outlined"> settings </span
>{{language.titlebar.settings}}
<span class="material-icons-outlined"> settings </span>
<div
style="
display: inline-block;
width: 8px;
border-radius: 50%;
height: 8px;
margin-left: -13px;
margin-top: 5px;
background: rgb(219, 46, 46);
position: absolute;
"
v-show="hasUpdate"
></div>
{{language.titlebar.settings}}
</button>
</div>
</div>
Expand Down Expand Up @@ -576,12 +589,154 @@ <h1>{{model.name}}</h1>
<div class="mdui-text-color-theme">
{{language.app.name}}
</div>
<div style="color: #555; margin-top: 20px; font-size: 14px">
v{{appVersion}}
<div style="height: 10px"></div>
{{language.tabSettings.desc}}
<div
style="color: #555; margin-top: 20px; font-size: 14px"
></div>
<div
class="model-importer"
v-bind:style="{height:hasUpdate?'58px':checkingUpdate?'30px':'16px'}"
style="
width: 490px;
padding: 15px;
position: relative;
"
>
<span
class="material-icons-outlined"
style="font-size: 16px"
mdui-tooltip="{content: 'SysMocap Version'}"
>
widgets
</span>
<span
style="
line-height: 8px;
top: -3px;
font-size: 14px;
position: inherit;
margin-left: 3px;
"
>v{{appVersion}}</span
>
<svg
xmlns="http://www.w3.org/2000/svg"
style="
height: 15px;
fill: var(--md-sys-color-on-primary-container);
stroke: var(
--md-sys-color-on-primary-container
);
stroke-width: 0.3px;
margin-left: 40px;
"
mdui-tooltip="{content: 'Electron Version'}"
enable-background="new 0 0 24 24"
viewBox="0 0 24 24"
>
<path
d="M12.12 24c-1.909 0-3.607-1.754-4.661-4.812-.135-.392.073-.818.465-.953.39-.135.818.072.953.465.808 2.344 2.05 3.801 3.243 3.801.78 0 1.595-.62 2.294-1.746.219-.353.681-.46 1.033-.242.352.219.46.681.242 1.033C14.691 23.151 13.457 24 12.12 24zM16.628 17.642c-.05 0-.101-.005-.152-.016-.406-.083-.667-.48-.583-.886.275-1.337.415-2.768.415-4.251 0-5.9-2.207-10.011-4.188-10.011-.414 0-.75-.336-.75-.75s.336-.75.75-.75c3.189 0 5.688 5.056 5.688 11.511 0 1.585-.15 3.117-.446 4.554C17.289 17.397 16.976 17.642 16.628 17.642z"
/>
<path
d="M12.12 3.457c-.958 0-1.738-.775-1.738-1.729C10.382.775 11.162 0 12.12 0s1.738.775 1.738 1.728C13.857 2.681 13.078 3.457 12.12 3.457zM12.12 1.5c-.131 0-.238.103-.238.228 0 .252.476.252.476 0C12.357 1.603 12.251 1.5 12.12 1.5zM12.12 14.226c-.958 0-1.738-.775-1.738-1.728 0-.953.78-1.729 1.738-1.729s1.738.775 1.738 1.729C13.857 13.45 13.078 14.226 12.12 14.226zM12.12 12.269c-.131 0-.238.103-.238.229 0 .251.476.251.476 0C12.357 12.372 12.251 12.269 12.12 12.269zM19.591 13.365c-.168 0-.338-.057-.478-.172-.319-.264-.363-.737-.099-1.056 1.584-1.913 2.18-3.721 1.555-4.719-.501-.801-1.657-.99-2.539-1.008-.414-.008-.743-.351-.735-.765.008-.415.326-.732.765-.735 1.794.037 3.102.628 3.78 1.712 1.009 1.612.399 3.971-1.671 6.472C20.021 13.272 19.807 13.365 19.591 13.365zM2.738 19.108c-.25 0-.494-.125-.636-.352-.477-.762-.598-1.724-.349-2.783.616-2.626 3.384-5.723 7.224-8.081 1.56-.958 3.217-1.735 4.794-2.249.394-.128.816.087.945.481.128.394-.087.817-.481.945-1.465.477-3.012 1.203-4.473 2.1-3.458 2.124-6.029 4.928-6.549 7.145-.157.67-.104 1.224.16 1.645.22.351.113.814-.238 1.034C3.012 19.072 2.875 19.108 2.738 19.108z"
/>
<path
d="M2.741 20.086c-.581 0-1.15-.289-1.479-.814-.246-.392-.323-.856-.217-1.306.106-.452.383-.834.779-1.078 0 0 0 0 .001 0 .812-.498 1.883-.248 2.387.558.246.393.322.856.217 1.306-.106.452-.383.834-.78 1.078C3.367 20.003 3.052 20.086 2.741 20.086zM2.609 18.167c-.067.042-.093.1-.103.142-.009.041-.012.103.028.168.07.111.218.146.331.075.068-.042.094-.101.104-.142.01-.041.013-.103-.028-.167C2.872 18.13 2.724 18.096 2.609 18.167L2.609 18.167zM3.206 11.554c-.254 0-.502-.129-.643-.363-1.119-1.855-1.32-3.562-.565-4.805.983-1.623 3.372-2.163 6.56-1.482C8.962 4.99 9.22 5.389 9.134 5.794s-.488.663-.89.577C5.795 5.848 3.893 6.152 3.28 7.164c-.451.743-.249 1.898.567 3.253.214.354.1.815-.255 1.029C3.471 11.519 3.338 11.554 3.206 11.554zM17.819 20c-2.464 0-5.642-.97-8.795-2.846-1.33-.792-2.546-1.68-3.615-2.639-.308-.277-.334-.751-.057-1.059.275-.308.751-.334 1.059-.057.996.894 2.133 1.724 3.38 2.466 5.112 3.043 9.81 3.288 10.83 1.605.215-.355.677-.468 1.03-.252.354.215.467.676.252 1.03C21.189 19.425 19.715 20 17.819 20z"
/>
<path
d="M21.258,19.586c-0.304,0-0.61-0.079-0.888-0.244c0,0,0,0,0,0c-0.4-0.238-0.682-0.617-0.794-1.067c-0.112-0.448-0.041-0.913,0.199-1.309c0.493-0.813,1.562-1.078,2.38-0.59c0.4,0.238,0.682,0.617,0.794,1.067c0.112,0.449,0.042,0.914-0.198,1.309C22.424,19.289,21.848,19.586,21.258,19.586z M21.137,18.053c0.114,0.068,0.262,0.033,0.331-0.08c0.04-0.064,0.036-0.127,0.025-0.167c-0.01-0.042-0.037-0.1-0.106-0.141c-0.114-0.068-0.263-0.032-0.331,0.08c-0.04,0.065-0.036,0.127-0.025,0.167C21.042,17.954,21.068,18.012,21.137,18.053L21.137,18.053z"
/>
</svg>
<span
style="
line-height: 8px;
top: -3px;
font-size: 14px;
position: inherit;
margin-left: 3px;
"
>v{{process.versions.electron}}</span
>
<button
v-show="!hasUpdate"
onclick="window.checkUpdate()"
class="mdui-btn xf-button-2"
style="
height: 25px !important;
line-height: 24px !important;
width: 150px;
font-size: 12px;
margin-top: -5px;
right: 20px;
position: absolute;
"
>
<i
class="mdui-icon material-icons"
style="font-size: 18px; margin-left: -8px"
>{{isLatest?'check':'update'}}</i
>
{{isLatest?'is latest':checkingUpdate?'checking...':'check update'}}
</button>
<div style="margin-top: 10px; position: relative" v-show="checkingUpdate">
<div class="mdui-progress">
<div class="mdui-progress-indeterminate"></div>
</div>
</div>
<div style="margin-top: 10px; position: relative" v-show="hasUpdate" >
<span
class="material-icons-outlined"
style="font-size: 28px"
>
info </span
><span
style="
line-height: 8px;
top: -8px;
font-size: 15px;
position: inherit;
margin-left: 10px;
"
>Update Available: {{hasUpdate?.name}}</span
>
<button
onclick="window.openInGithub()"
class="mdui-btn xf-button-2"
style="
height: 25px !important;
line-height: 24px !important;
width: 150px;
font-size: 12px;
bottom: 2px;
right: 5px;
position: absolute;
"
>
<i
class="mdui-icon material-icons"
style="font-size: 18px; margin-left: -8px"
>open_in_browser</i
>
open in github
</button>
</div>
</div>
<div style="height: 20px"></div>
<div class="settings-item">
<label class="mdui-switch">
<span
><i
class="mdui-icon material-icons"
style="margin-right: 10px; margin-top: -3px"
>update</i
>{{language.tabSettings.disableUpdate}}</span
>
<input
type="checkbox"
v-model="disableAutoUpdate"
/>
<i class="mdui-switch-icon"></i>
</label>
</div>
<!-- Setting Tab: Show Document -->
<h1 class="mdui-text-color-theme" v-show="platform!=='web'">
{{language.tabSettings.document.name}}
Expand Down Expand Up @@ -676,16 +831,16 @@ <h1 class="mdui-text-color-theme">
<i class="mdui-switch-icon"></i>
</label>
</div>
<!-- Setting Tab: input -->
<h1 class="mdui-text-color-theme">
<!-- Setting Tab: input -->
<h1 class="mdui-text-color-theme">
{{language.tabSettings.input.name}}
</h1>
<div class="settings-item">
<span
><span class="material-icons-outlined">
camera </span
>{{language.tabMocap.chooseCamera}}</span
>
><span class="material-icons-outlined">
camera </span
>{{language.tabMocap.chooseCamera}}</span
>
<select
v-model="camera"
class="mdui-select"
Expand Down
73 changes: 62 additions & 11 deletions mainview/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ if (typeof require != "undefined") {
document: document,
camera: "",
cameras: [],
process: process,
checkingUpdate: false,
hasUpdate: null,
updateError:null,
isLatest:false,
disableAutoUpdate:localStorage.getItem('disableUpdate')

},
computed: {
bg: function () {
Expand Down Expand Up @@ -287,15 +294,25 @@ if (typeof require != "undefined") {
},
deep: true,
},
camera:(newVal, oldVal)=>{
console.log({a:'last-choosed-camera',b:newVal,c:oldVal,d:localStorage.getItem('last-choosed-camera')})
if(oldVal!='')localStorage.setItem('last-choosed-camera',newVal)
camera: (newVal, oldVal) => {
console.log({
a: "last-choosed-camera",
b: newVal,
c: oldVal,
d: localStorage.getItem("last-choosed-camera"),
});
if (oldVal != "")
localStorage.setItem("last-choosed-camera", newVal);
},
disableAutoUpdate: (newVal, oldVal) => {
if(newVal)localStorage.setItem('disableUpdate',true)

}
},
});

navigator.mediaDevices.enumerateDevices().then((mediaDevices) => {
var lastChoosed = localStorage.getItem('last-choosed-camera')
var lastChoosed = localStorage.getItem("last-choosed-camera");
for (var mediaDevice of mediaDevices)
if (mediaDevice.kind === "videoinput") {
app.cameras.push({
Expand All @@ -304,14 +321,14 @@ if (typeof require != "undefined") {
});
}
if (app.cameras?.length > 0) app.camera = app.cameras[0].id;
if(lastChoosed){
if(app.cameras?.find((e)=>e.id==lastChoosed)){
app.camera = lastChoosed
if (lastChoosed) {
if (app.cameras?.find((e) => e.id == lastChoosed)) {
app.camera = lastChoosed;
}
}
app.$nextTick(()=>{
app.$nextTick(() => {
new mdui.Select("#demo-js-3");
})
});
});

window.sysmocapApp = app;
Expand All @@ -336,8 +353,6 @@ if (typeof require != "undefined") {
// var inst = new mdui.Select("#demo-js");

var inst2 = new mdui.Select("#demo-js-2");



var lightInput = new mdui.Dialog("#light-js");

Expand Down Expand Up @@ -640,3 +655,39 @@ if (window.sysmocapApp.settings.performance.useDescrertionProcess)
},
false
);

// require modules
const versionCheck = require("github-version-checker");

window.checkUpdate = () => {
if (window.sysmocapApp.checkingUpdate || window.sysmocapApp.isLatest) return;
window.sysmocapApp.checkingUpdate = true;

// version check options (for details see below)
const options = {
repo: 'SysMocap', // repository name
owner: 'xianfei', // repository owner
currentVersion: 'v' + window.sysmocapApp.appVersion, // your app's current version
};

versionCheck(options, function (error, update) { // callback function
if (error) throw error;
if (update) { // print some update info if an update is available
console.log('An update is available! ' + update.name);
window.sysmocapApp.hasUpdate = update
} else {
window.sysmocapApp.isLatest = true
}


window.sysmocapApp.checkingUpdate = false
// start your app
console.log('Check update finish');
//...
});
};

window.openInGithub = () =>
remote.shell.openExternal("https://github.com/xianfei/SysMocap/releases");

if(!window.sysmocapApp.disableAutoUpdate) window.checkUpdate()
Loading

0 comments on commit 6d4529e

Please sign in to comment.