thedesk/app/js/common/version.js

279 lines
7.3 KiB
JavaScript
Raw Permalink Normal View History

2018-01-28 23:22:43 +11:00
//バージョンチェッカー
2020-07-10 23:33:12 +10:00
async function verck(ver) {
2020-05-03 00:32:46 +10:00
console.log('%c Welcome😊 ' + ver, 'color: red;font-size:200%;')
2020-07-10 15:16:39 +10:00
document.querySelector('body').classList.add(localStorage.getItem('platform'))
const date = new Date()
let showVer = false
2019-12-01 22:28:20 +11:00
if (localStorage.getItem('ver') != ver && localStorage.getItem('winstore')) {
2020-05-03 23:32:41 +10:00
showVer = true
2019-12-01 22:28:20 +11:00
console.log('%c Thank you for your update🎉', 'color: red;font-size:200%;')
2020-07-10 15:16:39 +10:00
if (localStorage.getItem('winstore') && !pwa) {
2020-07-10 23:33:12 +10:00
openRN()
2020-07-10 15:16:39 +10:00
}
2018-05-26 02:37:35 +10:00
}
2019-12-01 22:28:20 +11:00
localStorage.setItem('ver', ver)
2020-05-03 23:32:41 +10:00
if (!showVer) {
console.log(showVer)
2019-12-01 22:28:20 +11:00
if (
date.getFullYear() * 100 + date.getMonth() + 1 >= localStorage.getItem('showSupportMe') ||
!localStorage.getItem('showSupportMe')
) {
2019-06-04 02:26:00 +10:00
if (date.getMonth() == 11) {
2020-07-10 15:16:39 +10:00
yrs = date.getFullYear() + 1
nextmonth = yrs * 100 + 1
2019-06-04 02:26:00 +10:00
} else {
2020-07-10 15:16:39 +10:00
yrs = date.getFullYear()
nextmonth = yrs * 100 + date.getMonth() + 2
2019-06-04 02:26:00 +10:00
}
2019-12-01 22:28:20 +11:00
if (lang.language != 'ja') {
2020-07-10 15:16:39 +10:00
document.querySelector('#support-btm-ja').classList.add('hide')
document.querySelector('#support-btm-en').classList.remove('hide')
2019-06-04 23:29:47 +10:00
}
2019-12-01 22:28:20 +11:00
localStorage.setItem('showSupportMe', nextmonth)
2020-07-10 15:16:39 +10:00
document.querySelector('#support-btm').classList.remove('hide')
document.querySelector('#support-btm').animate([
2019-10-31 02:30:26 +11:00
{
2020-07-10 15:16:39 +10:00
bottom: '-500px'
2019-10-31 02:30:26 +11:00
},
{
2020-07-10 15:16:39 +10:00
bottom: '0'
2019-10-31 02:30:26 +11:00
}
2020-07-10 15:16:39 +10:00
], 300);
2019-06-04 02:26:00 +10:00
}
}
2020-07-10 15:16:39 +10:00
const platform = localStorage.getItem('platform')
2019-12-01 22:28:20 +11:00
console.log('Your platform:' + platform)
2020-05-06 19:09:00 +10:00
if (!localStorage.getItem('winstore') && !pwa) {
2020-07-10 15:16:39 +10:00
document.querySelector('#start').style.display = 'flex'
2019-05-19 17:39:30 +10:00
}
2020-07-10 15:16:39 +10:00
let winstore = false
2019-12-01 22:28:20 +11:00
if (
localStorage.getItem('winstore') == 'brewcask' ||
localStorage.getItem('winstore') == 'snapcraft' ||
localStorage.getItem('winstore') == 'winstore'
) {
2020-07-10 15:16:39 +10:00
winstore = true
2019-05-19 17:39:30 +10:00
} else {
2020-07-10 15:16:39 +10:00
winstore = false
2019-05-19 17:39:30 +10:00
}
2020-07-10 15:16:39 +10:00
const l = 5
2018-07-07 03:51:48 +10:00
// 生成する文字列に含める文字セット
2020-07-10 15:16:39 +10:00
const c = 'abcdefghijklmnopqrstuvwxyz0123456789'
const cl = c.length
2020-07-10 23:33:12 +10:00
let r = ''
2019-05-19 17:39:30 +10:00
for (var i = 0; i < l; i++) {
2019-12-01 22:28:20 +11:00
r += c[Math.floor(Math.random() * cl)]
2018-03-14 05:31:31 +11:00
}
2020-07-10 15:16:39 +10:00
const start = 'https://thedesk.top/ver.json'
2020-07-21 10:06:58 +10:00
let mess
try {
mess = await getApi(start, null)
} catch {
return false
}
2020-07-10 15:16:39 +10:00
console.table(mess)
if (mess) {
let newest = null
if (platform == 'darwin') {
newest = mess.desk_mac
} else {
newest = mess.desk
}
if (newest == ver) {
todo(lang.lang_version_usever.replace('{{ver}}', mess.desk))
//betaかWinstoreならアプデチェックしない
} else if (ver.indexOf('beta') != -1 || winstore) {
//skipped
} else {
if (localStorage.getItem('new-ver-skip')) {
if (localStorage.getItem('next-ver') != newest) {
postMessage(['sendSinmpleIpc', 'update'], '*')
2019-10-31 02:30:26 +11:00
} else {
2020-07-10 15:16:39 +10:00
console.warn(lang.lang_version_skipver)
todo(lang.lang_version_skipver)
2018-07-22 23:03:46 +10:00
}
2020-07-10 15:16:39 +10:00
} else {
postMessage(['sendSinmpleIpc', 'update'], '*')
2018-01-28 23:22:43 +11:00
}
2020-07-10 15:16:39 +10:00
}
}
let lni = localStorage.getItem('last-notice-id')
if (!lni) {
2019-12-01 22:28:20 +11:00
localStorage.setItem('last-notice-id', 0)
2020-07-10 15:16:39 +10:00
lni = 0
2018-08-24 01:15:57 +10:00
}
2020-07-10 15:16:39 +10:00
const getNotice = 'https://thedesk.top/notice/index.php?since_id=' + lni
2020-07-21 10:06:58 +10:00
let notices
try {
notices = await getApi(getNotice, null)
} catch {
return false
}
2020-07-10 15:16:39 +10:00
if (notices.length < 1) {
return false
} else {
localStorage.setItem('last-notice-id', notices[0].ID)
for (i = 0; i < notices.length; i++) {
var obj = notices[i]
if (obj.ID * 1 <= lni) {
break
2019-10-31 02:30:26 +11:00
} else {
2020-07-10 15:16:39 +10:00
toastInterpret(obj)
2019-08-08 00:27:00 +10:00
}
2020-07-10 15:16:39 +10:00
}
}
2019-08-08 00:27:00 +10:00
}
2020-07-10 15:16:39 +10:00
let infostreaming = false
2019-08-08 00:27:00 +10:00
function infowebsocket() {
2019-12-01 22:28:20 +11:00
infows = new WebSocket('wss://thedesk.top/ws/')
2020-07-10 15:16:39 +10:00
infows.onopen = function (mess) {
2019-12-01 22:28:20 +11:00
console.log([tlid, ':Connect Streaming Info:', mess])
infostreaming = true
}
2020-07-10 15:16:39 +10:00
infows.onmessage = function (mess) {
2019-12-01 22:28:20 +11:00
console.log([tlid, ':Receive Streaming:', JSON.parse(mess.data)])
2020-07-10 15:16:39 +10:00
const obj = JSON.parse(mess.data)
localStorage.setItem('last-notice-id', obj.id)
2019-12-01 22:28:20 +11:00
if (obj.type != 'counter') {
2020-07-10 15:16:39 +10:00
toastInterpret(obj)
2019-05-19 17:39:30 +10:00
} else {
2020-07-10 23:33:12 +10:00
const people = document.querySelector('#persons')
if(people) {
people.innerText = obj.text
}
2019-05-19 17:39:30 +10:00
}
2019-12-01 22:28:20 +11:00
}
2020-07-10 15:16:39 +10:00
infows.onerror = function (error) {
2019-12-01 22:28:20 +11:00
infostreaming = false
console.error('Error closing:info')
console.error(error)
return false
}
2020-07-10 15:16:39 +10:00
infows.onclose = function () {
2019-12-01 22:28:20 +11:00
infostreaming = false
console.error('Closing:info')
}
2019-03-23 01:10:23 +11:00
}
2020-07-10 15:16:39 +10:00
setInterval(function () {
2019-05-19 17:39:30 +10:00
if (!infostreaming) {
2019-12-01 22:28:20 +11:00
console.log('try to connect to base-streaming')
infowebsocket()
2019-03-23 01:10:23 +11:00
}
2019-12-01 22:28:20 +11:00
}, 10000)
2020-07-10 15:21:24 +10:00
async function toastInterpret(obj) {
2020-07-10 15:16:39 +10:00
if (obj.type == 'textv2') {
if (~obj.languages.indexOf(lang.language)) {
let showVer = true
let toot = null
if (obj.toot != '') {
toot = `<button class="btn-flat toast-action" data-toot="${obj.toot}">Show</button>`
}
if (obj.ver == ver) {
showVer = true
} else {
showVer = false
}
if (obj.domain != '') {
const multi = localStorage.getItem('multi')
if (multi) {
showVer = false
const accts = JSON.parse(multi)
const keys = Object.keys(accts)
for (let i = 0; i < accts.length; i++) {
const key = keys[i]
const acct = accts[key]
if (acct.domain == obj.domain) {
showVer = true
break
}
}
}
}
if (showVer) {
M.toast({
html: `${escapeHTML(obj.text)} ${toot} <span class="sml grey-text">(スライドして消去)</span>`,
displayLength: 86400
})
await sleep(500)
2020-07-10 23:33:12 +10:00
const targets = document.querySelectorAll('.toast-action')
for (let j = 0; j < targets.length; j++) {
2020-07-10 15:16:39 +10:00
const target = targets[j]
const toot = target.getAttribute('data-toot')
2020-07-10 23:33:12 +10:00
target.addEventListener('click', () => detEx(toot, 'main'))
2020-07-10 15:16:39 +10:00
}
}
}
}
}
2019-05-19 17:39:30 +10:00
function openRN() {
2020-07-10 23:33:12 +10:00
console.log(kirishima)
2020-07-10 15:16:39 +10:00
M.Modal.getInstance(document.querySelector('#releasenote')).open()
2019-12-01 22:28:20 +11:00
if (lang.language == 'ja') {
2020-07-10 15:16:39 +10:00
verp = ver.replace('(', '').replace('.', '-').replace('.', '-').replace('[', '-').replace(']', '').replace(')', '').replace(' ', '_')
showElm(`#release-${verp}`)
2019-05-19 17:39:30 +10:00
} else {
2020-07-10 15:16:39 +10:00
showElm('#release-en')
2019-05-19 16:17:05 +10:00
}
2019-06-04 02:26:00 +10:00
}
2020-07-10 15:16:39 +10:00
async function closeSupport() {
document.querySelector('#support-btm').animate([
2019-10-31 02:30:26 +11:00
{
2020-07-10 15:16:39 +10:00
bottom: '0'
2019-10-31 02:30:26 +11:00
},
{
2020-07-10 15:16:39 +10:00
bottom: '-300px'
2019-10-31 02:30:26 +11:00
}
2020-07-10 15:16:39 +10:00
], 300);
await sleep(300)
document.querySelector('#support-btm').classList.add('hide')
2019-06-26 00:15:52 +10:00
}
function storeDialog(platform, ver) {
2020-07-10 15:16:39 +10:00
if (document.querySelector('body').classList.contain('accessibility')) return false
let mes = false
2019-12-01 22:28:20 +11:00
if (platform == 'win32') {
2020-07-10 15:16:39 +10:00
mes = lang.lang_version_platform
2019-12-01 22:28:20 +11:00
} else if (platform == 'linux') {
2020-07-10 15:16:39 +10:00
mes = lang.lang_version_platform_linux
2019-12-01 22:28:20 +11:00
} else if (platform == 'darwin') {
2020-07-10 15:16:39 +10:00
mes = lang.lang_version_platform_mac
2019-06-26 00:15:52 +10:00
}
2020-02-08 02:59:56 +11:00
if (mes) {
Swal.fire({
title: 'Select your platform',
text: mes,
type: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#3085d6',
confirmButtonText: lang.lang_no,
cancelButtonText: lang.lang_yesno
}).then(result => {
//逆にしてる
if (!result.value) {
localStorage.setItem('winstore', 'winstore')
2019-06-26 00:15:52 +10:00
} else {
2020-02-08 02:59:56 +11:00
localStorage.setItem('winstore', 'localinstall')
2019-06-26 00:15:52 +10:00
}
2020-02-08 02:59:56 +11:00
localStorage.setItem('ver', ver)
2020-05-03 23:32:41 +10:00
showVer = true
2020-07-10 15:16:39 +10:00
if (pwa) return false
2020-02-08 02:59:56 +11:00
console.log('%c Thank you for your update🎉', 'color: red;font-size:200%;')
2020-07-10 15:16:39 +10:00
openRN()
2019-12-01 22:28:20 +11:00
})
2020-02-08 02:59:56 +11:00
} else {
localStorage.setItem('ver', ver)
2020-07-10 15:16:39 +10:00
showVer = true
console.log('%c Thank you for your update🎉', 'color: red;font-size:200%;')
openRN()
2020-02-08 02:59:56 +11:00
}
2020-07-10 15:16:39 +10:00
2019-09-13 00:25:27 +10:00
}
function closeStart() {
2019-12-01 22:28:20 +11:00
$('#start').css('display', 'none')
2020-07-10 15:16:39 +10:00
document.querySelector('#start').style.display = 'none'
const platform = localStorage.getItem('platform')
const ver = localStorage.getItem('ver')
2019-12-01 22:28:20 +11:00
storeDialog(platform, ver)
2019-10-31 02:30:26 +11:00
}