Commit eecbefee by Anveeg
parents 2dd55061 506b1999
...@@ -289,6 +289,10 @@ var getUserDetails = null ...@@ -289,6 +289,10 @@ var getUserDetails = null
return return
} }
} }
if (loggedIn && request.action === 'limitExceed') {
sendMessageToActiveTab("limitExceed")
return
}
if (request.action === 'logout') { if (request.action === 'logout') {
loggedIn = false; loggedIn = false;
recording = false; recording = false;
...@@ -335,6 +339,7 @@ var getUserDetails = null ...@@ -335,6 +339,7 @@ var getUserDetails = null
} }
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
if (tabs && tabs.length) { // if any tab is active if (tabs && tabs.length) { // if any tab is active
console.log("🚀 ~ tabs:", tabs)
var activeTab = tabs[0] var activeTab = tabs[0]
chrome.tabs.captureVisibleTab({ format: "png" }, async function (dataUrl) { chrome.tabs.captureVisibleTab({ format: "png" }, async function (dataUrl) {
let message = { let message = {
......
...@@ -223,7 +223,8 @@ async function login() { ...@@ -223,7 +223,8 @@ async function login() {
let userDetails = { let userDetails = {
uid: localStorage.getItem('userId'), uid: localStorage.getItem('userId'),
name: localStorage.getItem('name'), name: localStorage.getItem('name'),
email: localStorage.getItem('email') email: localStorage.getItem('email'),
userOid:localStorage.getItem('userOid')
} }
if (userDetails?.uid || userDetails?.email) { // can login if (userDetails?.uid || userDetails?.email) { // can login
chrome.runtime.sendMessage({ action: "login", userDetails }) chrome.runtime.sendMessage({ action: "login", userDetails })
...@@ -388,7 +389,7 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon ...@@ -388,7 +389,7 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon
document.body.append(finalizingOverlay) document.body.append(finalizingOverlay)
finalizingOverlay.innerHTML = ` finalizingOverlay.innerHTML = `
<div> <div>
No Image found. No screenshots have been captured for video creation yet.
</div> </div>
` `
setTimeout(() => { setTimeout(() => {
...@@ -402,6 +403,23 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon ...@@ -402,6 +403,23 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon
}, 2000) }, 2000)
reRenderFloatingBar(data) reRenderFloatingBar(data)
} }
else if (message.message == 'limitExceed') {
finalizingOverlay = document.createElement('div')
finalizingOverlay.setAttribute('class', 'tutor-shot-overlay')
finalizingOverlay.setAttribute('style', `all: unset; position: fixed; top: 0px; bottom: 0px; left: 0px; right: 0px; background-color: #000000a0; pointer-events: inherit; z-index: 101; display: flex; color: white; justify-content: center; align-items: center; font-size: 28px;`)
document.body.append(finalizingOverlay)
finalizingOverlay.innerHTML = `
<div>
Video creation limit reached.
Upgrade to continue or contact support.
</div>
`
setTimeout(() => {
finalizingOverlay.remove()
reRenderFloatingBar(data)
}, 2000)
reRenderFloatingBar(data)
}
else if (message.message == 'generatingVideo') { else if (message.message == 'generatingVideo') {
finalizingOverlay = document.createElement('div') finalizingOverlay = document.createElement('div')
finalizingOverlay.setAttribute('class', 'tutor-shot-overlay') finalizingOverlay.setAttribute('class', 'tutor-shot-overlay')
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
let logoutBtn = document.getElementById('logout-btn') let logoutBtn = document.getElementById('logout-btn')
myCapturesBtn.addEventListener('click',(e)=>{ window.open(origin+'/tutor-shot-list') }) myCapturesBtn.addEventListener('click',(e)=>{ window.open(origin+'/tutor-shot-list') })
let userDetails = {}; let userDetails = {};
let maxTutorShotLimit = {};
let savedTutorShot = {};
let inProgress = false; let inProgress = false;
logoutBtn.addEventListener('click', ()=>{ logoutBtn.addEventListener('click', ()=>{
...@@ -42,6 +45,17 @@ ...@@ -42,6 +45,17 @@
} }
inProgress = true inProgress = true
try{ try{
let limitExceed = await getSubscriptions()
if(limitExceed){
window.close()
chrome.runtime.sendMessage({ action: "limitExceed" }, async function (response) {
loggedIn = false
userDetails.email = ""
userDetails.uid = ""
modifyPopupUI()
})
return;
}
let { data } = await api.post('/tutor-shot', { title: "No Title" }, { headers: { userId: userDetails.uid } } ) let { data } = await api.post('/tutor-shot', { title: "No Title" }, { headers: { userId: userDetails.uid } } )
if (data.success){ if (data.success){
chrome.runtime.sendMessage({ action: "startRecording", tutorShotId:data.tutorShot._id }, async function (response) { chrome.runtime.sendMessage({ action: "startRecording", tutorShotId:data.tutorShot._id }, async function (response) {
...@@ -85,7 +99,32 @@ ...@@ -85,7 +99,32 @@
} }
} }
let getAuthHeader = function(){
return {
headers: {
username: userDetails.name,
userid: userDetails.uid,
useroid: userDetails.userOid,
}
}
}
async function getSubscriptions(){
try{
if(!userDetails.uid) return
let { data } = await api.get("common/subscriptions", { headers: getAuthHeader().headers })
if (data.success){
const moduleObject = data.subscriptionData.feature.find(obj => obj.module === 'TUTOR_SHOT');
maxTutorShotLimit = moduleObject ? moduleObject.quantity : null;
api.defaults.headers.userId = userDetails.uid
const tutorData = await api.get("tutor-shot/")
savedTutorShot = tutorData.data.list.length
if(maxTutorShotLimit<=savedTutorShot) return true
else return false
}
}catch(err){
console.log(err)
}
}
function domLoadHandler() { function domLoadHandler() {
chrome.runtime.sendMessage({ action: "checkStatus" }, function (response) { chrome.runtime.sendMessage({ action: "checkStatus" }, function (response) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment