Skip to content

Commit 3b9011f

Browse files
authored
Merge pull request #4 from albert118/feature/vue-plugin
Feature/vue plugin + demo + Safari Support + Unsupported Platform Check
2 parents 8d47f68 + 2afac72 commit 3b9011f

27 files changed

Lines changed: 1320 additions & 333 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ A Smart App Banner for promoting mobile app installs based on the Safari Apple E
2727
- Platform specific
2828
- custom banner for iOS (non-Safari) and Android user agents
2929
- Safari specific config
30+
- Option, use Sass variables to configure the banner as needed
3031

3132
> TODO: Examples per platform
3233
@@ -84,6 +85,10 @@ The price tagline defaults to FREE with platform specific defaults for both Andr
8485
}
8586
```
8687

88+
### SCSS Variables
89+
90+
> TODO link here to vars file
91+
8792
### Vue usage (plugin TODO)
8893

8994
> TODO

demo/vue/src/App.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<script setup lang="ts">
2+
import Logger from 'js-logger';
23
import HelloWorld from './components/HelloWorld.vue';
34
import TheWelcome from './components/TheWelcome.vue';
5+
import { useSmartAppBanner } from './smartAppBannerPlugin';
6+
7+
const smartAppBanner = useSmartAppBanner();
8+
9+
try {
10+
// mount the component
11+
smartAppBanner.mount();
12+
} catch (error) {
13+
Logger.error(error);
14+
}
415
</script>
516

617
<template>

demo/vue/src/assets/main.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
font-weight: normal;
88
}
99

10-
a,
10+
#app a,
1111
.green {
1212
text-decoration: none;
1313
color: hsla(160, 100%, 37%, 1);
@@ -16,7 +16,7 @@ a,
1616
}
1717

1818
@media (hover: hover) {
19-
a:hover {
19+
#app a:hover {
2020
background-color: hsla(160, 100%, 37%, 0.2);
2121
}
2222
}

demo/vue/src/main.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,17 @@ import './assets/main.css';
22

33
import { createApp } from 'vue';
44
import App from './App.vue';
5+
import { default as createSmartAppBanner } from './smartAppBannerPlugin';
6+
import type { SmartBannerOptions } from 'smart-app-banner';
57

6-
createApp(App).mount('#app');
8+
createApp(App)
9+
.use(createSmartAppBanner, {
10+
title: 'Hello world!',
11+
author: 'Albert Ferguson',
12+
// using the create-vue asset logo
13+
icon: '/src/assets/logo.svg',
14+
verbose: true,
15+
googlePlayStoreUrl: 'https://play-store-application-url',
16+
appStoreUrl: 'https://app-store-application-url',
17+
} as SmartBannerOptions)
18+
.mount('#app');
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type { App, InjectionKey } from 'vue';
2+
import { SmartAppBanner, type SmartBannerOptions } from 'smart-app-banner';
3+
import Logger from 'js-logger';
4+
5+
Logger.useDefaults({
6+
// default to warning until we disable it with options
7+
defaultLevel: Logger.WARN,
8+
formatter: function (messages, context) {
9+
messages.unshift('[🛍️ Smart App Banner - Plugin]');
10+
},
11+
});
12+
13+
export const SmartAppBannerInjectionKey = Symbol(
14+
'SmartAppBanner',
15+
) as InjectionKey<SmartAppBanner>;
16+
17+
export function useSmartAppBanner() {
18+
const instance = inject(SmartAppBannerInjectionKey);
19+
20+
if (!instance) {
21+
// see more here for in-depth, but usually this is as the error describes
22+
// https://antfu.me/posts/async-with-composition-api
23+
throw new Error(
24+
'No Smart App Banner instance was provided! Double check that the Smart App Banner plugin has been registered and that the service is not called within an async setup',
25+
);
26+
}
27+
28+
return instance;
29+
}
30+
31+
export default {
32+
install(app: App, options: SmartBannerOptions) {
33+
let instance: SmartAppBanner | undefined = undefined;
34+
35+
try {
36+
instance = new SmartAppBanner(options);
37+
} catch (error) {
38+
Logger.warn(error);
39+
}
40+
41+
if (instance) {
42+
app.config.globalProperties.$smartAppBanner = instance;
43+
} else {
44+
Logger.warn(
45+
'failed to initialise the plugin, check the logs for further details',
46+
);
47+
}
48+
},
49+
};

0 commit comments

Comments
 (0)