Skip to content

Commit

Permalink
Notification permission for pwa
Browse files Browse the repository at this point in the history
  • Loading branch information
easafe committed Jul 23, 2024
1 parent 58ff71d commit 519945a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
1 change: 0 additions & 1 deletion src/Client/Common/Dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function customEventDetail_(event) {
}

export function mediaMatches_(displayMode) {
console.log(displayMode, window.matchMedia('(display-mode: ' + displayMode + ')').matches);
return window.matchMedia('(display-mode: ' + displayMode + ')').matches;
}

Expand Down
26 changes: 9 additions & 17 deletions src/Client/Im/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,9 @@ main = do
setUpWebSocket webSocketRef
width ← CCD.screenWidth
let smallScreen = width < mobileBreakpoint
if smallScreen then do
--keep track of mobile (-like) screens for things that cant be done with media queries
FS.send imId SetSmallScreen
checkMobileNotifications
else
checkDesktopNotifications
--keep track of mobile (-like) screens for things that cant be done with media queries
when smallScreen $ FS.send imId SetSmallScreen
checkNotifications smallScreen
--disable the back button on desktop/make the back button go back to previous screen on mobile
CCD.pushState $ routes.im.get {}
historyChange smallScreen
Expand Down Expand Up @@ -731,18 +728,13 @@ toggleConnectedWebSocket isConnected model@{ hasTriedToConnectYet, errorMessage
preventStop Event ImModel NextMessage
preventStop event model = CIF.nothingNext model <<< liftEffect $ CCD.preventStop event

checkMobileNotifications Effect Unit
checkMobileNotifications = do
status ← CCD.notificationPermission
when (status /= "granted") do
--check if we are running as pwa instead of a web page
matches ← DT.traverse CCD.mediaMatches [ "fullscreen", "standalone", "minimal-ui" ]
when (DT.or matches) CCD.requestNotificationPermission

checkDesktopNotifications Effect Unit
checkDesktopNotifications = do
checkNotifications Boolean -> Effect Unit
checkNotifications smallScreen = do
status ← CCD.notificationPermission
when (status == "default") $ FS.send imId ToggleAskNotification
when (status == "default") $ do
matches ← DT.traverse CCD.mediaMatches [ "fullscreen", "standalone", "minimal-ui" ] --check if we are running as pwa instead of a web page
{- when (DT.or matches || not smallScreen) $ -}
FS.send imId ToggleAskNotification

--refactor use popstate subscription
historyChange Boolean Effect Unit
Expand Down
2 changes: 1 addition & 1 deletion src/Server/3000/Data.purs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ grammaticalClasses =
, Tuple 9 [ "Structure", "Alligator", "Cassowary", "Deliverer", "Afternoon", "Passenger", "Appliance", "Conductor", "Assistant", "Agreement", "Goldfinch", "Acoustics", "Englander", "Invention", "Breakfast", "Goosander", "Rainstorm", "Butterfly", "Homemaker", "Astronaut", "Treatment", "Existence", "Secretary", "Albatross", "Carpenter", "Sandpiper", "Operation", "Armadillo", "Red Panda", "Selection", "Expansion", "Apparatus", "Furniture", "Jellyfish", "Cormorant", "Transport", "Substance", "Porcupine", "Direction", "Quicksand", "Aftermath", "Insurance", "Authority", "Scapegoat", "Territory", "Amusement", "Crocodile", "Attention", "Dragonfly", "Partridge", "Go-getter", "Digestion", "Wolverine", "Enchanter", "Lunchroom", "Education", "Discovery", "Vegetable", "Knowledge", "Condition", "Scarecrow", "Committee", "Statement", "Principal", "Ecologist", "Economist", "Executive", "Caregiver", "Chauffeur", "Concierge", "Custodian", "Messenger", "Scientist", "Violinist", "Librarian", "Zookeeper", "Zoologist" ]
, Tuple 6 [ "Porter", "Battle", "Flight", "Curlew", "Galley", "Drawer", "Rabbit", "Bubble", "Friend", "Sister", "Cattle", "Weight", "Cheese", "Pencil", "Pigeon", "Sponge", "Dinner", "Attack", "Bottle", "Walrus", "Parrot", "Coyote", "Wealth", "Sneeze", "Potato", "Quartz", "Crayon", "Eggnog", "Locket", "Riddle", "Cobweb", "Qualia", "Basket", "Turkey", "Engine", "Stitch", "Thread", "Memory", "Effect", "Square", "Vessel", "Street", "Recess", "Silver", "Icicle", "Profit", "Mitten", "Income", "Minute", "Marble", "Credit", "Person", "Button", "Nation", "Motion", "Oyster", "Amount", "Camera", "Canvas", "Poison", "Expert", "Quince", "Church", "Sailor", "Zipper", "Banana", "Anchor", "Thrill", "Ferret", "Lawyer", "Magpie", "Weasel", "Finger", "Flower", "Salmon", "Clover", "Cactus", "Harbor", "Gerbil", "Chance", "Falcon", "Pocket", "Summer", "Polish", "Kettle", "Degree", "Reason", "Turtle", "Alpaca", "Doctor", "Temper", "Breath", "Faucet", "System", "Beetle", "Advice", "Ticket", "Locust", "Cleric", "Letter", "Health", "Answer", "Border", "Beaver", "Hornet", "Voyage", "Garden", "School", "Theory", "Parcel", "Muscle", "Cellar", "Guitar", "Orange", "Cherry", "Runner", "Middle", "Baboon", "Throne", "Singer", "Hammer", "Monkey", "Pickle", "Cannon", "Number", "Farmer", "Chough", "Grouse", "Beggar", "Plough", "Flavor", "Animal", "Powder", "Lumber", "Needle", "Branch", "Change", "Wombat", "Jaguar", "Dunlin", "Kitten", "Spider", "Celery", "Wrench", "Parent", "Belief", "Design", "Insect", "Action", "Rhythm", "Copper", "Stream", "Office", "Window", "Detail", "Market", "Zephyr", "Record", "Winter", "Circle", "Regret", "Priest", "Butter", "Badger", "Dugong", "Jackal", "Spring", "Collar", "Quiver", "Bucket", "Writer", "String", "Liquid", "Island", "Reward", "Bridge", "Growth", "Ground", "Editor", "Consul", "Marine", "Archer", "Artist", "Author" ]
, Tuple 4 [ "Club", "Swan", "Unit", "Fire", "Yoke", "Trip", "Beef", "Bead", "Cast", "Duck", "Mice", "Iron", "Sand", "Rail", "Crib", "Rock", "Soap", "Side", "Bird", "Hope", "Drug", "Look", "Snow", "Sack", "Talk", "Idea", "Card", "Lamp", "Gaur", "Love", "Goat", "Swim", "Lock", "Drop", "Body", "Comb", "Nest", "Wine", "Gold", "Pony", "Drum", "Pipe", "Meal", "Debt", "Slip", "Lead", "Back", "Mine", "Heat", "Hare", "Pail", "Skin", "Song", "Pest", "Coil", "Stew", "Dirt", "Face", "Sign", "Home", "Chin", "Size", "Yarn", "Wood", "Heir", "Bulb", "Push", "Frog", "Whip", "Fact", "Knee", "Mole", "Wish", "Move", "Root", "Bean", "Dust", "Self", "Base", "Hole", "Moon", "Wind", "Newt", "Glue", "Kudu", "Baby", "Game", "Room", "Bear", "Seed", "Fall", "Mask", "Fear", "Joke", "View", "Tent", "Kite", "Male", "Tray", "Wool", "Fold", "Vase", "Boot", "Play", "Sofa", "Wave", "Hill", "Work", "Head", "Pain", "Team", "Bomb", "List", "Word", "Lion", "Twig", "Fang", "Cook", "Beam", "Edge", "Hall", "Cart", "Knot", "Soup", "Crab", "Mass", "Stem", "Copy", "Mint", "Soda", "Nail", "Sink", "Mink", "Fish", "Name", "Ship", "Lace", "Vest", "Bite", "Hour", "Wash", "Plot", "Wing", "Sock", "Hose", "Zinc", "Wall", "Veil", "Coal", "Town", "Cake", "Stop", "Ibex", "Loaf", "Deer", "Hook", "Wire", "Burn", "Join", "Form", "Seat", "Star", "Rook", "Turn", "Maid", "Wren", "Lake", "Bone", "Step", "Rule", "Mist", "Line", "Desk", "Rest", "Week", "Corn", "Gull", "Rose", "Shoe", "Rice", "Door", "Road", "Cord", "Jail", "Hate", "Feet", "Doll", "Pear", "Dime", "Hero", "Cork", "Salt", "Foot", "Dove", "Book", "Food", "Arch", "Crow", "Boss", "Spot", "Silk", "Tree", "Cent", "Sail", "Land", "Time", "Nose", "Gnat", "Rate", "Jump", "Ring", "Army", "Pull", "Bath", "Fork", "Lark", "Oven", "Ball", "Park", "Tail", "Dock", "Walk", "Help", "Suit", "Need", "Camp", "Rain", "Shop", "Vein", "Loss", "Fuel", "Mark", "Clam", "Part", "Horn", "News", "Bike", "Coat", "Boat", "Boar", "Rake", "Milk", "Toad", "Wolf", "Mind", "Meat", "Worm", "Leaf", "Show", "Able", "Year", "Lift", "Bait", "Tank", "Gate", "Farm", "Roof", "Seal", "Bell", "Neck", "Kick", "Flag", "Page", "Yard", "Hawk", "Fowl", "Test", "Wasp", "Note", "Care", "Band", "Hair", "Sort", "Ibis", "Roll", "Cave", "Chef", "Monk" ]
, Tuple 5 [ "Thumb", "Actor", "Print", "Tiger", "Shark", "Diver", "Quiet", "Title", "Glass", "Apple", "Metal", "Taste", "Finch", "Quail", "Smile", "Crate", "Flesh", "Waves", "Slope", "Paper", "Waste", "Crush", "Fifth", "Quill", "Spoon", "Humor", "Music", "Stamp", "Honey", "Peace", "Drink", "Lemur", "Jeans", "Class", "Lunch", "Crime", "Fight", "Trail", "Usher", "Feast", "Scarf", "Smoke", "Kitty", "Otter", "Night", "Sleep", "Linen", "Scene", "Robot", "Chair", "Frame", "Wound", "Magic", "Sloth", "River", "Error", "Color", "Goose", "Crook", "House", "Horse", "Laugh", "Spark", "Geese", "Group", "Crowd", "Cable", "Straw", "Price", "Wheel", "Tramp", "Knife", "Crack", "Teeth", "Grade", "Order", "Water", "Sense", "Crown", "Chess", "Birth", "Shape", "Koala", "Brain", "Party", "Cause", "Front", "Cover", "Scent", "Plane", "Plate", "Range", "Paint", "Death", "Guide", "Floor", "Watch", "Table", "Okapi", "Blade", "Stone", "Whale", "Power", "Place", "Route", "Steel", "Truck", "Month", "Sleet", "Patch", "Drain", "Hippo", "Train", "Flock", "Juror", "Brush", "Limit", "Coati", "Eagle", "Board", "Cobra", "Shake", "Heart", "Event", "Skate", "Voice", "Space", "Spade", "Match", "North", "Brass", "Field", "Skunk", "Snail", "Glove", "Juice", "Panda", "Money", "Basin", "Llama", "Light", "Plant", "Thing", "Clock", "Fruit", "Sheet", "Anger", "Slave", "Stage", "Owner", "Moose", "Zebra", "Start", "Cloth", "Nerve", "Beast", "Louse", "Bison", "Noise", "Cloud", "Mouth", "Jelly", "Coast", "Bread", "Coach", "Camel", "Tapir", "Cream", "Hyena", "Brick", "Dress", "Fixer", "Shame", "Cough", "Shelf", "Chalk", "Earth", "Eland", "Shade", "Shock", "Trick", "Alley", "Grass", "Store", "Staff", "Shrew", "Skirt", "Heron", "Level", "Flame", "Shirt", "Stove", "Story", "Blood", "Sound", "Force", "Scale", "Robin", "Wrist", "Steam", "Chain", "Mouse", "Point", "Berry", "Raven", "Prose", "Twist", "Ghost", "Quilt", "Snake", "Sugar", "Tooth", "Badge", "Brake", "Judge", "Smell", "Queen", "Verse", "Trade", "Rifle", "Crane", "Sheep", "Grape", "Loris", "Elbow", "Curve", "Grain", "Jewel", "Value", "Alarm", "Paste", "Offer", "Angle", "Touch", "Ocean", "Clerk", "Mason", "Mayor", "Miner", "Model", "Scout", "Smith", "Valet", "Vicar" ]
, Tuple 5 [ "Thumb", "Actor", "Print", "Tiger", "Shark", "Diver", "Quiet", "Title", "Glass", "Apple", "Metal", "Taste", "Finch", "Quail", "Smile", "Crate", "Flesh", "Waves", "Slope", "Paper", "Waste", "Crush", "Fifth", "Quill", "Spoon", "Humor", "Music", "Stamp", "Honey", "Peace", "Drink", "Lemur", "Jeans", "Class", "Lunch", "Crime", "Fight", "Trail", "Usher", "Feast", "Scarf", "Smoke", "Kitty", "Otter", "Night", "Sleep", "Linen", "Scene", "Robot", "Chair", "Frame", "Wound", "Magic", "Sloth", "River", "Error", "Color", "Goose", "Crook", "House", "Horse", "Laugh", "Spark", "Geese", "Group", "Crowd", "Cable", "Straw", "Price", "Wheel", "Tramp", "Knife", "Crack", "Teeth", "Grade", "Order", "Water", "Sense", "Crown", "Chess", "Birth", "Shape", "Koala", "Brain", "Party", "Cause", "Front", "Cover", "Scent", "Plane", "Plate", "Range", "Paint", "Death", "Guide", "Floor", "Watch", "Table", "Okapi", "Blade", "Stone", "Whale", "Power", "Place", "Route", "Steel", "Truck", "Month", "Sleet", "Patch", "Drain", "Hippo", "Train", "Flock", "Juror", "Brush", "Limit", "Coati", "Eagle", "Board", "Cobra", "Shake", "Heart", "Event", "Skate", "Voice", "Space", "Spade", "Match", "North", "Brass", "Field", "Skunk", "Snail", "Glove", "Juice", "Panda", "Money", "Basin", "Llama", "Light", "Plant", "Thing", "Clock", "Fruit", "Sheet", "Anger", "Slave", "Stage", "Owner", "Moose", "Zebra", "Start", "Cloth", "Nerve", "Beast", "Louse", "Bison", "Noise", "Cloud", "Mouth", "Jelly", "Coast", "Bread", "Coach", "Camel", "Tapir", "Cream", "Hyena", "Brick", "Dress", "Fixer", "Cough", "Shelf", "Chalk", "Earth", "Eland", "Shade", "Shock", "Trick", "Alley", "Grass", "Store", "Staff", "Shrew", "Skirt", "Heron", "Level", "Flame", "Shirt", "Stove", "Story", "Blood", "Sound", "Force", "Scale", "Robin", "Wrist", "Steam", "Chain", "Mouse", "Point", "Berry", "Raven", "Prose", "Twist", "Ghost", "Quilt", "Snake", "Sugar", "Tooth", "Badge", "Brake", "Judge", "Smell", "Queen", "Verse", "Trade", "Rifle", "Crane", "Sheep", "Grape", "Loris", "Elbow", "Curve", "Grain", "Jewel", "Value", "Alarm", "Paste", "Offer", "Angle", "Touch", "Ocean", "Clerk", "Mason", "Mayor", "Miner", "Model", "Scout", "Smith", "Valet", "Vicar" ]
, Tuple 8 [ "Stranger", "Question", "Mandrill", "Boundary", "Learning", "Good-bye", "Kinkajou", "Forester", "Creature", "Calendar", "Dinosaur", "Starling", "Argument", "Business", "Relation", "Industry", "Cemetery", "Birthday", "Friction", "Surprise", "Ancestor", "Mosquito", "Downtown", "Lyrebird", "Sorcerer", "Trousers", "Mountain", "Airplane", "Reporter", "Vacation", "Achiever", "Activity", "Comedian", "Governor", "Increase", "Notebook", "Squirrel", "Children", "Newcomer", "Building", "Seahorse", "Behavior", "Religion", "Approval", "Carriage", "Teaching", "Tendency", "Umbrella", "Sculptor", "Hedgehog", "Decision", "Graduate", "Aardvark", "Beginner", "Anteater", "Porpoise", "Addition", "Pleasure", "Enlistee", "Cherries", "Division", "Position", "Ornament", "Mongoose", "Flamingo", "Antelope", "Stocking", "Kangaroo", "Seashore", "Reaction", "Goldfish", "Minister", "Sidewalk", "Scissors", "Exchange", "Distance", "Sea Lion", "Pheasant", "Dotterel", "Reindeer", "Red Deer", "Property", "Hospital", "Interest", "Baseball", "Language", "Elephant", "Educator", "Engineer", "Explorer", "Exporter", "Chaplain", "Composer", "Magician", "Marketer", "Mechanic", "Muralist", "Musician", "Surveyor", "Animator", "Attorney" ]
, Tuple 10 [ "Toothbrush", "Doorkeeper", "Comparison", "Toothpaste", "Salamander", "Polar Bear", "Plantation", "Volleyball", "Playground", "Experience", "Fellowship", "Chinchilla", "Arithmetic", "Suggestion", "Earthquake", "Basketball", "Calculator", "Sea Urchin", "Punishment", "Attraction", "Connection", "Discussion", "Instrument", "Adjustment", "Guinea Pig", "Compatriot", "Chimpanzee", "Government", "Wilderness", "Cab Driver", "Cartoonist", "Contractor", "Ambassador", "Astronomer", "Auctioneer", "Undertaker" ]
, Tuple 11 [ "Observation", "Housekeeper", "Floorwalker", "Development", "Guinea Fowl", "Caterpillar", "Nightingale", "Firefighter", "Prairie Dog", "Hummingbird", "Stegosaurus", "Competition", "Flesh Eater", "Grasshopper", "Destruction", "Sand Dollar", "Giant Panda", "Electrician", "Entertainer", "Salesperson", "Saxophonist", "Scuba Diver", "Stockbroker", "Xylophonist" ]
Expand Down
18 changes: 9 additions & 9 deletions src/Shared/Im/View.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ import Shared.Unsafe ((!@))
import Shared.Im.Types

view Boolean ImModel Html ImMessage
view isClientRender model@{ enableNotificationsVisible, errorMessage, fortune, initialScreen, chatting, contacts, imUpdated, smallScreen } = HE.div [ HA.class' "im" ]
[ HE.div (HA.class' { "contact-box": true, "current-mobile-screen": initialScreen })
view isClientRender model = HE.div [ HA.class' "im" ]
[ HE.div (HA.class' { "contact-box": true, "current-mobile-screen": model.initialScreen })
[ SIVU.userMenu model
, HE.div (HA.class' { "suggestion-box-error": true, flexed: smallScreen && (not $ DS.null errorMessage) }) errorMessage
, SIVN.reloadPage imUpdated
, SIVN.prompt $ not smallScreen && enableNotificationsVisible
, HE.div (HA.class' { "suggestion-box-error": true, flexed: model.smallScreen && (not $ DS.null model.errorMessage) }) model.errorMessage
, SIVN.reloadPage model.imUpdated
, SIVN.prompt model.enableNotificationsVisible
, SIVS.suggestionCall model
, SIVCN.contactList isClientRender model
, SIVL.logoMenu fortune
, SIVL.logoMenu model.fortune
, SIVM.modals model
]
, HE.div [ HA.class' { "suggestion-box": true, "current-mobile-screen": not initialScreen }, HA.onDragenter' PreventStop, HA.onDragover' PreventStop, HA.onDrop' DropFile ]
[ HE.div (HA.class' { "suggestion-box-error": true, flexed: not $ DS.null errorMessage }) errorMessage
, HE.div [ HA.class' { "suggestion-box": true, "current-mobile-screen": not model.initialScreen }, HA.onDragenter' PreventStop, HA.onDragover' PreventStop, HA.onDrop' DropFile ]
[ HE.div (HA.class' { "suggestion-box-error": true, flexed: not $ DS.null model.errorMessage }) model.errorMessage
, SIVNM.unreadNotification model
, SIVP.suggestionProfile model
, SIVH.chatHistory model $ map (contacts !@ _) chatting
, SIVH.chatHistory model $ map (model.contacts !@ _) model.chatting
, SIVC.chat model
]
]

0 comments on commit 519945a

Please sign in to comment.