mirror of
https://github.com/MarshalX/telegram-crawler.git
synced 2025-01-11 12:41:37 +01:00
Update content of files
This commit is contained in:
parent
1254e5e141
commit
4d267badde
5 changed files with 319 additions and 4 deletions
|
@ -1094,6 +1094,231 @@
|
|||
return cloudStorage;
|
||||
})();
|
||||
|
||||
var BiometricManager = (function() {
|
||||
var isInited = false;
|
||||
var isBiometricAvailable = false;
|
||||
var biometricType = 'unknown';
|
||||
var isAccessRequested = false;
|
||||
var isAccessGranted = false;
|
||||
var isBiometricTokenSaved = false;
|
||||
|
||||
var biometricManager = {};
|
||||
Object.defineProperty(biometricManager, 'isInited', {
|
||||
get: function(){ return isInited; },
|
||||
enumerable: true
|
||||
});
|
||||
Object.defineProperty(biometricManager, 'isBiometricAvailable', {
|
||||
get: function(){ return isInited && isBiometricAvailable; },
|
||||
enumerable: true
|
||||
});
|
||||
Object.defineProperty(biometricManager, 'biometricType', {
|
||||
get: function(){ return biometricType || 'unknown'; },
|
||||
enumerable: true
|
||||
});
|
||||
Object.defineProperty(biometricManager, 'isAccessRequested', {
|
||||
get: function(){ return isAccessRequested; },
|
||||
enumerable: true
|
||||
});
|
||||
Object.defineProperty(biometricManager, 'isAccessGranted', {
|
||||
get: function(){ return isAccessRequested && isAccessGranted; },
|
||||
enumerable: true
|
||||
});
|
||||
Object.defineProperty(biometricManager, 'isBiometricTokenSaved', {
|
||||
get: function(){ return isBiometricTokenSaved; },
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
var initRequestState = {callbacks: []};
|
||||
var accessRequestState = false;
|
||||
var authRequestState = false;
|
||||
var tokenRequestState = false;
|
||||
|
||||
WebView.onEvent('biometry_info_received', onBiometryInfoReceived);
|
||||
WebView.onEvent('biometry_auth_requested', onBiometryAuthRequested);
|
||||
WebView.onEvent('biometry_token_updated', onBiometryTokenUpdated);
|
||||
|
||||
function onBiometryInfoReceived(eventType, eventData) {
|
||||
isInited = true;
|
||||
if (eventData.available) {
|
||||
isBiometricAvailable = true;
|
||||
biometricType = eventData.type || 'unknown';
|
||||
if (eventData.access_requested) {
|
||||
isAccessRequested = true;
|
||||
isAccessGranted = !!eventData.access_granted;
|
||||
isBiometricTokenSaved = !!eventData.token_saved;
|
||||
} else {
|
||||
isAccessRequested = false;
|
||||
isAccessGranted = false;
|
||||
isBiometricTokenSaved = false;
|
||||
}
|
||||
} else {
|
||||
isBiometricAvailable = false;
|
||||
biometricType = 'unknown';
|
||||
isAccessRequested = false;
|
||||
isAccessGranted = false;
|
||||
isBiometricTokenSaved = false;
|
||||
}
|
||||
|
||||
if (initRequestState.callbacks.length > 0) {
|
||||
for (var i = 0; i < initRequestState.callbacks.length; i++) {
|
||||
var callback = initRequestState.callbacks[i];
|
||||
callback();
|
||||
}
|
||||
}
|
||||
if (accessRequestState) {
|
||||
var state = accessRequestState;
|
||||
accessRequestState = false;
|
||||
if (state.callback) {
|
||||
state.callback(isAccessGranted);
|
||||
}
|
||||
}
|
||||
receiveWebViewEvent('biometricManagerUpdated');
|
||||
}
|
||||
function onBiometryAuthRequested() {
|
||||
var isAuthenticated = (eventData.status == 'authorized'),
|
||||
biometricToken = eventData.token || '';
|
||||
if (authRequestState) {
|
||||
var state = authRequestState;
|
||||
authRequestState = false;
|
||||
if (state.callback) {
|
||||
state.callback(isAuthenticated, isAuthenticated ? biometricToken : null);
|
||||
}
|
||||
}
|
||||
receiveWebViewEvent('biometricAuthRequested', isAuthenticated ? {
|
||||
isAuthenticated: true,
|
||||
biometricToken: biometricToken
|
||||
} : {
|
||||
isAuthenticated: false
|
||||
});
|
||||
}
|
||||
function onBiometryTokenUpdated() {
|
||||
var applied = false;
|
||||
if (isBiometricAvailable &&
|
||||
isAccessRequested) {
|
||||
if (eventData.status == 'updated') {
|
||||
isBiometricTokenSaved = true;
|
||||
applied = true;
|
||||
}
|
||||
else if (eventData.status == 'removed') {
|
||||
isBiometricTokenSaved = false;
|
||||
applied = true;
|
||||
}
|
||||
}
|
||||
if (tokenRequestState) {
|
||||
var state = tokenRequestState;
|
||||
tokenRequestState = false;
|
||||
if (state.callback) {
|
||||
state.callback(applied);
|
||||
}
|
||||
}
|
||||
receiveWebViewEvent('biometricTokenUpdated', {
|
||||
isUpdated: applied
|
||||
});
|
||||
}
|
||||
|
||||
function checkVersion() {
|
||||
if (!versionAtLeast('7.2')) {
|
||||
console.warn('[Telegram.WebApp] BiometricManager is not supported in version ' + webAppVersion);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
biometricManager.init = function(callback) {
|
||||
if (!checkVersion()) {
|
||||
return biometricManager;
|
||||
}
|
||||
if (isInited) {
|
||||
return biometricManager;
|
||||
}
|
||||
if (callback) {
|
||||
initRequestState.callbacks.push(callback);
|
||||
}
|
||||
WebView.postEvent('web_app_biometry_get_info', false);
|
||||
return biometricManager;
|
||||
};
|
||||
biometricManager.requestAccess = function(callback) {
|
||||
if (!checkVersion()) {
|
||||
return biometricManager;
|
||||
}
|
||||
if (!isInited) {
|
||||
console.error('[Telegram.WebApp] BiometricManager should be inited before using.');
|
||||
throw Error('WebAppBiometricManagerNotInited');
|
||||
}
|
||||
if (!isBiometricAvailable) {
|
||||
console.error('[Telegram.WebApp] Biometrics is not available on this device.');
|
||||
throw Error('WebAppBiometricManagerBiometricsNotAvailable');
|
||||
}
|
||||
if (accessRequestState) {
|
||||
console.error('[Telegram.WebApp] Access is already requested');
|
||||
throw Error('WebAppBiometricManagerAccessRequested');
|
||||
}
|
||||
accessRequestState = {
|
||||
callback: callback
|
||||
};
|
||||
WebView.postEvent('web_app_biometry_request_access', false);
|
||||
return biometricManager;
|
||||
};
|
||||
biometricManager.authenticate = function(callback) {
|
||||
if (!checkVersion()) {
|
||||
return biometricManager;
|
||||
}
|
||||
if (!isInited) {
|
||||
console.error('[Telegram.WebApp] BiometricManager should be inited before using.');
|
||||
throw Error('WebAppBiometricManagerNotInited');
|
||||
}
|
||||
if (!isBiometricAvailable) {
|
||||
console.error('[Telegram.WebApp] Biometrics is not available on this device.');
|
||||
throw Error('WebAppBiometricManagerBiometricsNotAvailable');
|
||||
}
|
||||
if (!isAccessGranted) {
|
||||
console.error('[Telegram.WebApp] Biometric access was not granted by the user.');
|
||||
throw Error('WebAppBiometricManagerBiometricAccessNotGranted');
|
||||
}
|
||||
if (authRequestState) {
|
||||
console.error('[Telegram.WebApp] Authentication request is already in progress.');
|
||||
throw Error('WebAppBiometricManagerAuthenticationRequested');
|
||||
}
|
||||
authRequestState = {
|
||||
callback: callback
|
||||
};
|
||||
WebView.postEvent('web_app_biometry_request_auth', false);
|
||||
return biometricManager;
|
||||
};
|
||||
biometricManager.saveBiometricToken = function(token, callback) {
|
||||
if (!checkVersion()) {
|
||||
return biometricManager;
|
||||
}
|
||||
token = token || '';
|
||||
if (token.length > 1024) {
|
||||
console.error('[Telegram.WebApp] Token is too long', token);
|
||||
throw Error('WebAppBiometricManagerTokenInvalid');
|
||||
}
|
||||
if (!isInited) {
|
||||
console.error('[Telegram.WebApp] BiometricManager should be inited before using.');
|
||||
throw Error('WebAppBiometricManagerNotInited');
|
||||
}
|
||||
if (!isBiometricAvailable) {
|
||||
console.error('[Telegram.WebApp] Biometrics is not available on this device.');
|
||||
throw Error('WebAppBiometricManagerBiometricsNotAvailable');
|
||||
}
|
||||
if (!isAccessGranted) {
|
||||
console.error('[Telegram.WebApp] Biometric access was not granted by the user.');
|
||||
throw Error('WebAppBiometricManagerBiometricAccessNotGranted');
|
||||
}
|
||||
if (tokenRequestState) {
|
||||
console.error('[Telegram.WebApp] Token request is already in progress.');
|
||||
throw Error('WebAppBiometricManagerTokenUpdateRequested');
|
||||
}
|
||||
tokenRequestState = {
|
||||
callback: callback
|
||||
};
|
||||
WebView.postEvent('web_app_biometry_update_token', false, {token: token});
|
||||
return biometricManager;
|
||||
};
|
||||
return biometricManager;
|
||||
})();
|
||||
|
||||
var webAppInvoices = {};
|
||||
function onInvoiceClosed(eventType, eventData) {
|
||||
if (eventData.slug && webAppInvoices[eventData.slug]) {
|
||||
|
@ -1345,6 +1570,10 @@
|
|||
value: CloudStorage,
|
||||
enumerable: true
|
||||
});
|
||||
Object.defineProperty(WebApp, 'BiometricManager', {
|
||||
value: BiometricManager,
|
||||
enumerable: true
|
||||
});
|
||||
WebApp.setHeaderColor = function(color_key) {
|
||||
WebApp.headerColor = color_key;
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<meta name="MobileOptimized" content="176" />
|
||||
<meta name="HandheldFriendly" content="True" />
|
||||
<meta name="robots" content="noindex, nofollow" />
|
||||
<script src="https://tg.dev/js/telegram-web-app.js?41"></script>
|
||||
<script src="https://tg.dev/js/telegram-web-app.js?42"></script>
|
||||
<script>
|
||||
function setThemeClass() {
|
||||
document.documentElement.className = Telegram.WebApp.colorScheme;
|
||||
|
|
|
@ -208,6 +208,9 @@ pre {
|
|||
.err {
|
||||
color: red;
|
||||
}
|
||||
.txt {
|
||||
color: var(--tg-theme-text-color, #222);
|
||||
}
|
||||
.status_need {
|
||||
display: none;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<meta name="MobileOptimized" content="176" />
|
||||
<meta name="HandheldFriendly" content="True" />
|
||||
<meta name="robots" content="noindex,nofollow" />
|
||||
<script src="https://tg.dev/js/telegram-web-app.js?41"></script>
|
||||
<script src="https://tg.dev/js/telegram-web-app.js?42"></script>
|
||||
<script>
|
||||
function setThemeClass() {
|
||||
document.documentElement.className = Telegram.WebApp.colorScheme;
|
||||
|
@ -19,7 +19,7 @@
|
|||
</script>
|
||||
<link href="https://tg.dev/css/bootstrap.min.css?3" rel="stylesheet">
|
||||
<link href="https://tg.dev/css/bootstrap-extra.css?2" rel="stylesheet">
|
||||
<link href="/css/webappdemo.css?10" rel="stylesheet">
|
||||
<link href="/css/webappdemo.css?11" rel="stylesheet">
|
||||
</head>
|
||||
<body class="" style="visibility: hidden;">
|
||||
<section id="top_sect" class="second">
|
||||
|
@ -121,6 +121,18 @@
|
|||
</tfoot>
|
||||
</table>
|
||||
</form>
|
||||
<p>Biometrics:</p>
|
||||
<div class="columns">
|
||||
<ul>
|
||||
<li>isInited: <span class="txt" id="bm_inited">false</span></li>
|
||||
<li>available: <span class="txt" id="bm_available">false</span></li>
|
||||
<li>type: <span class="txt" id="bm_type"></span></li>
|
||||
<li>access_requested: <span class="txt" id="bm_access_requested">false</span> (<a href="javascript:;" onclick="return DemoApp.biometricRequestAccess(this);">Request access</a>) <span></span></li>
|
||||
<li>access_granted: <span class="txt" id="bm_access_granted">false</span></li>
|
||||
<li>token_saved: <span class="txt" id="bm_token_saved">false</span> (<a href="javascript:;" onclick="return DemoApp.biometricSetToken(this);">Set token</a>, <a href="javascript:;" onclick="return DemoApp.biometricRemoveToken(this);">Remove token</a>) <span></span></li>
|
||||
<li><a href="javascript:;" onclick="return DemoApp.biometricRequestAuth(this);">Request auth</a> <span></span></li>
|
||||
</ul>
|
||||
</div>
|
||||
<pre><code id="webview_data"></code></pre>
|
||||
<div class="hint">
|
||||
Data passed to webview.
|
||||
|
@ -139,7 +151,7 @@
|
|||
<div class="viewport-stable_border"></div>
|
||||
<script src="/js/jquery.min.js"></script>
|
||||
<script src="https://tg.dev/js/bootstrap.min.js"></script>
|
||||
<script src="/js/webappdemo.js?22"></script>
|
||||
<script src="/js/webappdemo.js?23"></script>
|
||||
<script>DemoApp.apiUrl = "/demo/api";
|
||||
|
||||
Telegram.WebApp.onEvent('themeChanged', function() {
|
||||
|
@ -258,6 +270,9 @@ try {
|
|||
try {
|
||||
DemoApp.loadCloudKeys();
|
||||
} catch(e) {}
|
||||
try {
|
||||
DemoApp.biometricInit();
|
||||
} catch(e) {}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -288,6 +288,74 @@ var DemoApp = {
|
|||
}
|
||||
});
|
||||
},
|
||||
biometricInit: function(el) {
|
||||
var biometricManager = Telegram.WebApp.BiometricManager;
|
||||
if (!DemoApp.biometricInited) {
|
||||
DemoApp.biometricInited = true;
|
||||
Telegram.WebApp.onEvent('biometricManagerUpdated', function() {
|
||||
$('#bm_inited').text(biometricManager.isInited ? 'true' : 'false');
|
||||
$('#bm_available').text(biometricManager.isBiometricAvailable ? 'true' : 'false');
|
||||
$('#bm_type').text(biometricManager.biometricType || '');
|
||||
$('#bm_access_requested').text(biometricManager.isAccessRequested ? 'true' : 'false');
|
||||
$('#bm_access_granted').text(biometricManager.isAccessGranted ? 'true' : 'false');
|
||||
$('#bm_token_saved').text(biometricManager.isBiometricTokenSaved ? 'true' : 'false');
|
||||
});
|
||||
}
|
||||
biometricManager.init();
|
||||
},
|
||||
biometricRequestAccess: function(el) {
|
||||
var biometricManager = Telegram.WebApp.BiometricManager;
|
||||
if (!biometricManager.isInited) {
|
||||
return DemoApp.showAlert('Biometric not inited yet!');
|
||||
}
|
||||
biometricManager.requestAccess(function(access_granted) {
|
||||
if (access_granted) {
|
||||
$(el).next('span').text('(Access granted)').attr('class', 'ok');
|
||||
} else {
|
||||
$(el).next('span').text('(Request declined)').attr('class', 'err');
|
||||
}
|
||||
});
|
||||
},
|
||||
biometricRequestAuth: function(el) {
|
||||
var biometricManager = Telegram.WebApp.BiometricManager;
|
||||
if (!biometricManager.isInited) {
|
||||
return DemoApp.showAlert('Biometric not inited yet!');
|
||||
}
|
||||
biometricManager.authenticate(function(success, token) {
|
||||
if (success) {
|
||||
$(el).next('span').text('(Success, token: ' + token + ')').attr('class', 'ok');
|
||||
} else {
|
||||
$(el).next('span').text('(Auth failed)').attr('class', 'err');
|
||||
}
|
||||
});
|
||||
},
|
||||
biometricSetToken: function(el) {
|
||||
var biometricManager = Telegram.WebApp.BiometricManager;
|
||||
if (!biometricManager.isInited) {
|
||||
return DemoApp.showAlert('Biometric not inited yet!');
|
||||
}
|
||||
var token = parseInt(Math.random().toString().substr(2)).toString(16);
|
||||
biometricManager.updateBiometricToken(token, function(updated) {
|
||||
if (updated) {
|
||||
$(el).next('span').text('(Updated)').attr('class', 'ok');
|
||||
} else {
|
||||
$(el).next('span').text('(Failed)').attr('class', 'err');
|
||||
}
|
||||
});
|
||||
},
|
||||
biometricRemoveToken: function(el) {
|
||||
var biometricManager = Telegram.WebApp.BiometricManager;
|
||||
if (!biometricManager.isInited) {
|
||||
return DemoApp.showAlert('Biometric not inited yet!');
|
||||
}
|
||||
biometricManager.updateBiometricToken('', function(updated) {
|
||||
if (updated) {
|
||||
$(el).next('span').text('(Removed)').attr('class', 'ok');
|
||||
} else {
|
||||
$(el).next('span').text('(Failed)').attr('class', 'err');
|
||||
}
|
||||
});
|
||||
},
|
||||
toggleMainButton: function(el) {
|
||||
if (DemoApp.MainButton.isVisible) {
|
||||
DemoApp.MainButton.hide();
|
||||
|
|
Loading…
Reference in a new issue