thedesk/app/js/common/version.js

308 lines
8.0 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
//バージョンチェッカー
2022-10-10 17:06:10 +11:00
async function verck(ver, jp) {
2020-09-09 17:58:41 +10:00
if (store) return false
2020-05-03 00:32:46 +10:00
console.log('%c Welcome😊 ' + ver, 'color: red;font-size:200%;')
2020-05-06 19:02:14 +10:00
$('body').addClass(localStorage.getItem('platform'))
2022-10-10 17:06:10 +11:00
const date = new Date()
let showVer = false
2020-08-02 14:16:31 +10: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%;')
2022-10-10 17:06:10 +11:00
$(document).ready(function () {
2020-05-06 19:09:00 +10:00
if (localStorage.getItem('winstore') && !pwa) {
2019-12-01 22:28:20 +11:00
$('#releasenote').modal('open')
2019-09-13 00:25:27 +10:00
}
2022-10-10 17:06:10 +11:00
let verp = ver.replace('(', '')
2019-12-01 22:28:20 +11:00
verp = verp.replace('.', '-')
verp = verp.replace('.', '-')
verp = verp.replace('[', '-')
verp = verp.replace(']', '')
verp = verp.replace(')', '')
verp = verp.replace(' ', '_')
console.log('%c ' + verp, 'color: red;font-size:200%;')
if (lang.language == 'ja') {
$('#release-' + verp).show()
2019-05-19 17:39:30 +10:00
} else {
2019-12-01 22:28:20 +11:00
$('#release-en').show()
2019-03-16 16:05:04 +11:00
}
2019-12-01 22:28:20 +11: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)
2022-10-10 17:06:10 +11:00
let nextmonth
if (!localStorage.getItem('showSupportMe')) {
2019-06-04 02:26:00 +10:00
if (date.getMonth() == 11) {
2022-10-10 17:06:10 +11:00
const yrs = date.getFullYear() + 1
nextmonth = yrs * 100 + 1
2019-06-04 02:26:00 +10:00
} else {
2022-10-10 17:06:10 +11:00
const 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
localStorage.setItem('showSupportMe', nextmonth)
} else {
if (
date.getFullYear() * 100 + date.getMonth() + 1 >= localStorage.getItem('showSupportMe')
) {
if (date.getMonth() == 11) {
2022-10-10 17:06:10 +11:00
const yrs = date.getFullYear() + 1
nextmonth = yrs * 100 + 1
} else {
2022-10-10 17:06:10 +11:00
const yrs = date.getFullYear()
nextmonth = yrs * 100 + date.getMonth() + 2
}
localStorage.setItem('showSupportMe', nextmonth)
if (lang.language != 'ja') {
$('#support-btm-ja').addClass('hide')
$('#support-btm-en').removeClass('hide')
2019-10-31 02:30:26 +11:00
}
$('#support-btm').removeClass('hide')
$('#support-btm').animate(
{
bottom: '0'
},
{
duration: 300
}
)
}
2019-06-04 02:26:00 +10:00
}
2022-10-10 17:06:10 +11:00
2019-06-04 02:26:00 +10:00
}
2022-10-10 17:06:10 +11:00
const platform = localStorage.getItem('platform')
2019-12-01 22:28:20 +11:00
console.log('Your platform:' + platform)
2021-01-09 23:19:21 +11:00
//if (!localStorage.getItem('winstore') && !pwa) {
// $('#start').css('display', 'flex')
//}
2022-10-10 17:06:10 +11:00
const winstore = localStorage.getItem('winstore') == 'brewcask' ||
2019-12-01 22:28:20 +11:00
localStorage.getItem('winstore') == 'snapcraft' ||
localStorage.getItem('winstore') == 'winstore'
2022-10-10 17:06:10 +11:00
const l = 5
2018-07-07 03:51:48 +10:00
// 生成する文字列に含める文字セット
2022-10-10 17:06:10 +11:00
const c = 'abcdefghijklmnopqrstuvwxyz0123456789'
const cl = c.length
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
}
2022-10-10 17:06:10 +11:00
const start1 = 'https://thedesk.top/ver.json'
const response = await fetch(start1, { method: 'GET' })
if (!response.ok) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
2019-10-31 02:30:26 +11:00
})
2022-10-10 17:06:10 +11:00
}
const mess = await response.json()
console.table(mess)
if (mess) {
const platform = localStorage.getItem('platform')
const newest = platform == 'darwin' ? mess.desk_mac : mess.desk
if (newest == ver) {
todo(lang.lang_version_usever.replace('{{ver}}', mess.desk))
//betaかWinstoreならアプデチェックしない
} else if (ver.indexOf('beta') != -1 || winstore) {
} else {
localStorage.removeItem('instance')
if (localStorage.getItem('new-ver-skip')) {
if (localStorage.getItem('next-ver') != newest) {
postMessage(['sendSinmpleIpc', 'update'], '*')
2019-10-31 02:30:26 +11:00
} else {
2022-10-10 17:06:10 +11:00
console.warn(lang.lang_version_skipver)
todo(lang.lang_version_skipver)
2018-07-22 23:03:46 +10:00
}
2022-10-10 17:06:10 +11:00
} else {
postMessage(['sendSinmpleIpc', 'update'], '*')
2018-01-28 23:22:43 +11:00
}
2022-10-10 17:06:10 +11:00
}
}
2019-12-01 22:28:20 +11:00
if (!localStorage.getItem('last-notice-id')) {
localStorage.setItem('last-notice-id', 0)
2018-08-24 01:15:57 +10:00
}
2020-05-03 23:46:55 +10:00
var start = 'https://thedesk.top/notice/index.php?since_id=' + localStorage.getItem('last-notice-id')
2018-08-24 01:15:57 +10:00
fetch(start, {
2020-05-03 23:46:55 +10:00
method: 'GET',
cors: true
2019-10-31 02:30:26 +11:00
})
2022-10-10 17:06:10 +11:00
.then(function (response) {
2019-10-31 02:30:26 +11:00
if (!response.ok) {
2022-10-10 17:06:10 +11:00
response.text().then(function (text) {
2019-12-01 22:28:20 +11:00
setLog(response.url, response.status, text)
})
2019-10-31 02:30:26 +11:00
}
2019-12-01 22:28:20 +11:00
return response.json()
2019-10-31 02:30:26 +11:00
})
2022-10-10 17:06:10 +11:00
.catch(function (error) {
2019-12-01 22:28:20 +11:00
todo(error)
setLog(start, 'JSON', error)
console.error(error)
2019-10-31 02:30:26 +11:00
})
2022-10-10 17:06:10 +11:00
.then(function (mess) {
2019-10-31 02:30:26 +11:00
if (mess.length < 1) {
2019-12-01 22:28:20 +11:00
return false
2019-10-31 02:30:26 +11:00
} else {
2019-12-01 22:28:20 +11:00
var last = localStorage.getItem('last-notice-id')
localStorage.setItem('last-notice-id', mess[0].ID)
2019-10-31 02:30:26 +11:00
for (i = 0; i < mess.length; i++) {
2019-12-01 22:28:20 +11:00
var obj = mess[i]
2019-10-31 02:30:26 +11:00
if (obj.ID * 1 <= last) {
2019-12-01 22:28:20 +11:00
break
2019-10-31 02:30:26 +11:00
} else {
2019-12-01 22:28:20 +11:00
if (obj.type == 'textv2') {
2019-10-31 02:30:26 +11:00
if (~obj.languages.indexOf(lang.language)) {
2020-05-03 23:32:41 +10:00
var showVer = true
2019-12-01 22:28:20 +11:00
if (obj.toot != '') {
var toot =
'<button class="btn-flat toast-action" onclick="detEx(\'' +
obj.toot +
"','main')\">Show</button>"
2019-08-08 00:27:00 +10:00
} else {
2019-12-01 22:28:20 +11:00
var toot = ''
2019-08-08 00:27:00 +10:00
}
2019-12-01 22:28:20 +11:00
if (obj.ver != '') {
2019-10-31 02:30:26 +11:00
if (obj.ver == ver) {
2020-05-03 23:32:41 +10:00
showVer = true
2019-10-31 02:30:26 +11:00
} else {
2020-05-03 23:32:41 +10:00
showVer = false
2019-10-31 02:30:26 +11:00
}
}
2019-12-01 22:28:20 +11:00
if (obj.domain != '') {
var multi = localStorage.getItem('multi')
2019-10-31 02:30:26 +11:00
if (multi) {
2020-05-03 23:32:41 +10:00
showVer = false
2019-12-01 22:28:20 +11:00
var accts = JSON.parse(multi)
2022-10-10 17:06:10 +11:00
Object.keys(accts).forEach(function (key) {
2019-12-01 22:28:20 +11:00
var acct = accts[key]
2019-10-31 02:30:26 +11:00
if (acct.domain == obj.domain) {
2020-05-03 23:32:41 +10:00
showVer = true
2019-10-31 02:30:26 +11:00
}
2019-12-01 22:28:20 +11:00
})
2019-10-31 02:30:26 +11:00
}
}
2020-05-03 23:32:41 +10:00
if (showVer) {
2019-12-01 22:28:20 +11:00
M.toast({
html:
escapeHTML(obj.text) +
toot +
'<span class="sml grey-text">(スライドして消去)</span>',
displayLength: 86400
})
2019-08-08 00:27:00 +10:00
}
}
}
}
}
}
2019-12-01 22:28:20 +11:00
})
2019-08-08 00:27:00 +10:00
}
2019-12-01 22:28:20 +11:00
var 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/')
2022-10-10 17:06:10 +11:00
infows.onopen = function (mess) {
2019-12-01 22:28:20 +11:00
console.log([tlid, ':Connect Streaming Info:', mess])
infostreaming = true
}
2022-10-10 17:06:10 +11:00
infows.onmessage = function (mess) {
2019-12-01 22:28:20 +11:00
console.log([tlid, ':Receive Streaming:', JSON.parse(mess.data)])
var obj = JSON.parse(mess.data)
if (obj.type != 'counter') {
if (obj.type == 'textv2') {
2019-08-08 00:27:00 +10:00
if (~obj.languages.indexOf(lang.language)) {
2019-12-01 22:28:20 +11:00
localStorage.setItem('last-notice-id', obj.id)
2020-05-03 23:32:41 +10:00
var showVer = true
2019-12-01 22:28:20 +11:00
if (obj.toot != '') {
var toot =
'<button class="btn-flat toast-action" onclick="detEx(\'' +
obj.toot +
"','main')\">Show</button>"
2019-05-19 17:39:30 +10:00
} else {
2019-12-01 22:28:20 +11:00
var toot = ''
2018-08-24 01:15:57 +10:00
}
2019-12-01 22:28:20 +11:00
if (obj.ver != '') {
2019-06-15 02:01:07 +10:00
if (obj.ver == ver) {
2020-05-03 23:32:41 +10:00
showVer = true
2019-05-19 17:39:30 +10:00
} else {
2020-05-03 23:32:41 +10:00
showVer = false
2019-05-19 17:39:30 +10:00
}
}
2019-12-01 22:28:20 +11:00
if (obj.domain != '') {
var multi = localStorage.getItem('multi')
2019-05-19 17:39:30 +10:00
if (multi) {
2020-05-03 23:32:41 +10:00
showVer = false
2019-12-01 22:28:20 +11:00
var accts = JSON.parse(multi)
2022-10-10 17:06:10 +11:00
Object.keys(accts).forEach(function (key) {
2019-12-01 22:28:20 +11:00
var acct = accts[key]
2019-06-15 02:01:07 +10:00
if (acct.domain == obj.domain) {
2020-05-03 23:32:41 +10:00
showVer = true
2019-05-19 17:39:30 +10:00
}
2019-12-01 22:28:20 +11:00
})
2019-05-19 17:39:30 +10:00
}
}
2020-05-03 23:32:41 +10:00
if (showVer) {
2019-12-01 22:28:20 +11:00
console.log(obj.text)
console.log(escapeHTML(obj.text))
M.toast({
html:
escapeHTML(obj.text) +
toot +
'<span class="sml grey-text">(スライドして消去)</span>',
displayLength: 86400
})
2018-08-24 01:15:57 +10:00
}
}
}
2019-05-19 17:39:30 +10:00
} else {
2019-12-01 22:28:20 +11:00
$('#persons').text(obj.text)
2019-05-19 17:39:30 +10:00
}
2019-12-01 22:28:20 +11:00
}
2022-10-10 17:06:10 +11: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
}
2022-10-10 17:06:10 +11: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
}
2022-10-10 17:06:10 +11: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)
2019-05-19 17:39:30 +10:00
function openRN() {
2019-12-01 22:28:20 +11:00
$('#releasenote').modal('open')
if (lang.language == 'ja') {
verp = ver.replace('(', '')
verp = verp.replace('.', '-')
verp = verp.replace('.', '-')
verp = verp.replace('[', '-')
verp = verp.replace(']', '')
verp = verp.replace(')', '')
verp = verp.replace(' ', '_')
$('#release-' + verp).show()
2019-05-19 17:39:30 +10:00
} else {
2019-12-01 22:28:20 +11:00
$('#release-en').show()
2019-05-19 16:17:05 +10:00
}
2019-06-04 02:26:00 +10:00
}
function closeSupport() {
2019-12-01 22:28:20 +11:00
$('#support-btm').animate(
2019-10-31 02:30:26 +11:00
{
2019-12-01 22:28:20 +11:00
bottom: '-300px'
2019-10-31 02:30:26 +11:00
},
{
duration: 300,
2022-10-10 17:06:10 +11:00
complete: function () {
2019-12-01 22:28:20 +11:00
$('#support-btm').addClass('hide')
2019-06-04 02:26:00 +10:00
}
2019-10-31 02:30:26 +11:00
}
2019-12-01 22:28:20 +11:00
)
2019-06-26 00:15:52 +10:00
}
2019-09-13 00:25:27 +10:00
function closeStart() {
2019-12-01 22:28:20 +11:00
$('#start').css('display', 'none')
var platform = localStorage.getItem('platform')
var ver = localStorage.getItem('ver')
2019-10-31 02:30:26 +11:00
}