summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/www/js/lib/etc
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-08-31 23:07:20 +0200
committerJules Laplace <julescarbon@gmail.com>2020-08-31 23:07:20 +0200
commit22721a013bdd10d5eb395ba18453585f5f3f1f7f (patch)
tree5a920e31d6026ed5dc55265e5fd057febccc50e3 /StoneIsland/platforms/ios/www/js/lib/etc
parentd22d51a1ae49680015326857360eb699f31efced (diff)
rebuild the ios platform and the plugins
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/etc')
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/etc/analytics.js21
-rwxr-xr-xStoneIsland/platforms/ios/www/js/lib/etc/push.js144
-rw-r--r--StoneIsland/platforms/ios/www/js/lib/etc/sim.js43
3 files changed, 122 insertions, 86 deletions
diff --git a/StoneIsland/platforms/ios/www/js/lib/etc/analytics.js b/StoneIsland/platforms/ios/www/js/lib/etc/analytics.js
new file mode 100644
index 00000000..f5f871f5
--- /dev/null
+++ b/StoneIsland/platforms/ios/www/js/lib/etc/analytics.js
@@ -0,0 +1,21 @@
+var analytics = (function() {
+ var analytics = {}
+
+ analytics.init = function() {
+ console.log("Analytics init")
+ if (window.FirebasePlugin) {
+ window.FirebasePlugin.setAnalyticsCollectionEnabled(true)
+ }
+ analytics.sendPageView('/')
+ }
+
+ analytics.sendPageView = function(path) {
+ console.log("/a\\ send", path)
+ FirebasePlugin.logEvent("select_content", {
+ content_type: "page_view",
+ item_id: path,
+ })
+ }
+
+ return analytics
+})()
diff --git a/StoneIsland/platforms/ios/www/js/lib/etc/push.js b/StoneIsland/platforms/ios/www/js/lib/etc/push.js
index 74aaf7b5..1f0ab9b6 100755
--- a/StoneIsland/platforms/ios/www/js/lib/etc/push.js
+++ b/StoneIsland/platforms/ios/www/js/lib/etc/push.js
@@ -1,34 +1,68 @@
var push = (function(){
var push = { settings: {}, disabled: false }
- var pushPlugin
+ // var pushPlugin
push.init = function(){
if (! ('device' in window) || (device.platform || "").toLowerCase() !== "ios") {
console.log("push disabled")
push.disabled = true
return
}
-
- pushPlugin = PushNotification.init({
- ios: {
- alert: true,
- badge: true,
- sound: false,
- clearBadge: true,
- },
- })
console.log("push init")
-
- PushNotification.hasPermission(push.did_initialize)
- pushPlugin.on('registration', push.got_registration)
- pushPlugin.on('notification', push.got_push_notification)
+
+ // Register handlers
+ FirebasePlugin.onMessageReceived(function(message) {
+ try {
+ console.log("onMessageReceived")
+ console.dir(message)
+ if (message.messageType === "notification") {
+ push.got_push_notification(message)
+ }
+ } catch(e) {
+ console.error("Exception in onMessageReceived callback: " + e.message)
+ }
+ }, function(error) {
+ console.error("Failed receiving FirebasePlugin message", error);
+ })
+
+ checkNotificationPermission(false) // Check permission then get token
+ FirebasePlugin.setBadgeNumber(0)
}
- push.did_initialize = function(data) {
- // console.log(data)
- if (! data.isEnabled) {
- console.log("push did not initialize")
- return
- }
+
+ var checkNotificationPermission = function(requested) {
+ FirebasePlugin.hasPermission(function(hasPermission) {
+ if (hasPermission) {
+ // Granted
+ console.log("Remote notifications permission granted")
+ push.disabled = false
+ getAPNSToken()
+ } else if (!requested) {
+ // Request permission
+ console.log("Requesting remote notifications permission")
+ FirebasePlugin.grantPermission(checkNotificationPermission.bind(this, true))
+ } else {
+ // Denied
+ push.disabled = true
+ console.error("Notifications won't be shown as permission is denied")
+ }
+ })
+ }
+
+ var getAPNSToken = function() {
+ FirebasePlugin.getAPNSToken(function(token) {
+ console.log("Got APNS token: " + token)
+ if (!token) {
+ console.log("Token is null, probably in simulator")
+ return
+ }
+ push.did_initialize()
+ push.got_registration(token)
+ }, function(error) {
+ console.error("Failed to get APNS token", error)
+ })
+ }
+
+ push.did_initialize = function() {
console.log("push did initialize")
var hub_status = localStorage.getItem("yoox.push_hub")
var store_status = localStorage.getItem("yoox.push_store")
@@ -36,30 +70,19 @@ var push = (function(){
push.settings.requested = localStorage.getItem("yoox.push_requested") == "true"
push.settings.hub = hub_status == "true"
push.settings.store = store_status == "true"
-
- if (push.settings.requested) {
- return
- }
- // not sure why we're also signing up for notifications here??
- if (! hub_status || hub_status == "true") {
- push.subscribe("hub")
- }
- if (! store_status || store_status == "true") {
- push.subscribe("store")
- }
}
- push.got_registration = function(data){
- var registrationId = data.registrationId
+
+ push.got_registration = function(registrationId){
var oldRegistrationId = localStorage.getItem("yoox.registrationId")
- // console.log(registrationId, oldRegistrationId)
-
if (registrationId !== oldRegistrationId || ! push.settings.requested) {
+ localStorage.setItem("yoox.push_requested", "true")
localStorage.setItem("yoox.registrationId", registrationId)
- push.subscribe("hub", function(){
- push.subscribe("store")
- })
+ push.settings.requested = true
+ push.subscribe("hub")
+ push.subscribe("store")
}
}
+
push.subscribe = function(channel, cb){
if (push.disabled) return
push.settings[channel] = true
@@ -69,8 +92,10 @@ var push = (function(){
channel: channel,
platform: device.platform,
}
- pushPlugin.subscribe(channel, function(){
- console.log("subscribed to", channel)
+ FirebasePlugin.subscribe(channel, function(){
+ console.log("Subscribed to topic")
+ }, function(error){
+ console.error("Error subscribing to topic: " + error)
})
$.ajax({
method: "POST",
@@ -93,6 +118,11 @@ var push = (function(){
channel: channel,
platform: device.platform,
}
+ FirebasePlugin.unsubscribe(channel, function(){
+ console.log("Unsubscribed from topic");
+ }, function(error){
+ console.error("Error unsubscribing from topic: " + error);
+ })
$.ajax({
method: "POST",
url: push.url('remove'),
@@ -108,42 +138,26 @@ var push = (function(){
push.url = function(key){
return sdk.cms() + '/_services/push/' + key
}
- push.got_push_notification = function(push_obj) {
+ push.got_push_notification = function(message) {
// console.log('We received this push notification: ' + JSON.stringify(push_obj));
-
app.blog.refresh()
- push_obj.additionalData = push_obj.additionalData || {}
-
var is_hub = true
+ FirebasePlugin.setBadgeNumber(0)
+
try {
- is_hub = JSON.stringify(push_obj || {}).match(/hub/i)
- }
- catch (e) {
- }
+ is_hub = !! JSON.stringify(push_obj || {}).match(/hub/i)
+ } catch (e) { }
if (is_hub) {
app.intro.$alert.show().html("[ HUB UPDATED ]")
- }
- else if (! push_obj.additionalData.url) {
+ analytics.sendPageView("push/open/hub")
+ app.router.go("intro")
+ } else {
auth.clear_cart()
app.intro.$alert.show().html("[ STORE UPDATED ]")
- }
-
- if (push_obj.additionalData.foreground === false) {
- // TODO: route the user to the uri in push_obj
- pushPlugin.finish(function(){}, function(){})
-
- if (push_obj.additionalData.url) {
- app.deepLinkRoute = push_obj.additionalData.url
- app.router.go(push_obj.additionalData.url)
- }
- }
- else if (is_hub) {
- app.router.go("hub")
- }
- else {
+ analytics.sendPageView("push/open/store")
app.router.go("intro")
}
}
diff --git a/StoneIsland/platforms/ios/www/js/lib/etc/sim.js b/StoneIsland/platforms/ios/www/js/lib/etc/sim.js
index 65be02b0..19d2e3c3 100644
--- a/StoneIsland/platforms/ios/www/js/lib/etc/sim.js
+++ b/StoneIsland/platforms/ios/www/js/lib/etc/sim.js
@@ -1,49 +1,50 @@
-var sim = (function(){
- var sim = {}
+var simcard = (function(){
+ var simcard = {}
- sim.loaded = false
- sim.data = {
+ simcard.loaded = false
+ simcard.data = {
carrierName: 'unknown',
countryCode: 'us',
mcc: '0',
mnc: '0',
}
- sim.fetch = function(cb){
+ simcard.fetch = function(cb){
console.log('fetching sim data')
- sim.afterFetch = cb
- window.plugins.sim.getSimInfo(sim.success, sim.error)
+ simcard.afterFetch = cb
+ window.plugins.sim.getSimInfo(simcard.success, simcard.error)
+ // cordova.exec(simcard.success, simcard.error, 'Sim', 'getSimInfo', [])
}
- sim.afterFetch = function(){}
+ simcard.afterFetch = function(){}
- sim.success = function(data){
+ simcard.success = function(data){
console.log(data)
- if (sim.data.countryCode) {
- sim.data = data
- sim.data.countryCode = sim.data.countryCode.toLowerCase()
+ if (simcard.data.countryCode) {
+ simcard.data = data
+ simcard.data.countryCode = simcard.data.countryCode.toLowerCase()
// app is only available in US or Canada, so call the US API regardless
- if (sim.data.countryCode !== 'ca') {
- sim.data.countryCode = 'us'
+ if (simcard.data.countryCode !== 'ca') {
+ simcard.data.countryCode = 'us'
}
}
- sim.loaded = true
- sim.afterFetch()
+ simcard.loaded = true
+ simcard.afterFetch()
}
- sim.error = function(){
+ simcard.error = function(){
console.log("no SIM card detected")
$.ajax({
url: "http://ip-api.com/json/",
jsonp: "callback",
dataType: "jsonp",
- success: sim.success,
+ success: simcard.success,
error: function(){
- sim.loaded = true
- sim.afterFetch()
+ simcard.loaded = true
+ simcard.afterFetch()
}
})
}
- return sim
+ return simcard
})() \ No newline at end of file