@adviverse/desktop 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -40
- package/dist/index.d.ts +2 -2
- package/package.json +18 -19
- package/dist/electron.d.ts +0 -9
- package/dist/electron.js +0 -45
- package/dist/preload.d.ts +0 -1
- package/dist/preload.js +0 -6
- package/dist/react.d.ts +0 -10
- package/dist/react.js +0 -52
package/README.md
CHANGED
|
@@ -14,29 +14,16 @@ core instead: [`@adviverse/desktop-native`](../desktop-native) (C ABI).
|
|
|
14
14
|
npm install @adviverse/desktop
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
| You use | Package | Repo |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| Any webview, no framework (Tauri, CEF, WKWebView, WebView2, Electron renderer) | `@adviverse/desktop` | [desktop-sdk](https://github.com/Adviverse/desktop-sdk) |
|
|
20
|
+
| React renderer | `@adviverse/desktop-react` | [desktop-react-sdk](https://github.com/Adviverse/desktop-react-sdk) |
|
|
21
|
+
| Electron main process (click → system browser) | `@adviverse/electron` | [electron-sdk](https://github.com/Adviverse/electron-sdk) |
|
|
22
|
+
|
|
17
23
|
Get a **serve token** (`ts_…`) from your Adviverse dashboard (Publisher →
|
|
18
24
|
Placements → terminal/SDK token). `ak_…` API keys and publisher placement tags
|
|
19
25
|
also work.
|
|
20
26
|
|
|
21
|
-
## Renderer — React
|
|
22
|
-
|
|
23
|
-
```tsx
|
|
24
|
-
import { AdviverseAd } from '@adviverse/desktop/react';
|
|
25
|
-
|
|
26
|
-
// A disclosed ad card. Renders nothing on no-fill; rotates if you pass refreshMs.
|
|
27
|
-
<AdviverseAd token="ts_yourtoken" refreshMs={60000} />
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Bring your own markup with a render prop:
|
|
31
|
-
|
|
32
|
-
```tsx
|
|
33
|
-
<AdviverseAd token="ts_yourtoken">
|
|
34
|
-
{(ad, onClick) => (
|
|
35
|
-
<button onClick={onClick}>{ad.label} · {ad.text} {ad.cta && `— ${ad.cta}`}</button>
|
|
36
|
-
)}
|
|
37
|
-
</AdviverseAd>
|
|
38
|
-
```
|
|
39
|
-
|
|
40
27
|
## Renderer — no framework
|
|
41
28
|
|
|
42
29
|
```ts
|
|
@@ -72,28 +59,10 @@ window. `openClick()` auto-detects the host:
|
|
|
72
59
|
- **Electron** — expose a bridge from the main process (below).
|
|
73
60
|
- **Fallback** — `window.open(url, '_blank')`.
|
|
74
61
|
|
|
75
|
-
### Electron bridge
|
|
62
|
+
### Electron bridge
|
|
76
63
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
import { app, BrowserWindow } from 'electron';
|
|
80
|
-
import { registerAdviverseIpc, adviversePreloadPath } from '@adviverse/desktop/electron';
|
|
81
|
-
|
|
82
|
-
app.whenReady().then(() => {
|
|
83
|
-
registerAdviverseIpc(); // handles openExternal, http(s) only
|
|
84
|
-
new BrowserWindow({
|
|
85
|
-
webPreferences: { contextIsolation: true, preload: adviversePreloadPath() },
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Already have a preload? Add one line to it instead:
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
// preload.ts
|
|
94
|
-
import { exposeAdviverse } from '@adviverse/desktop/electron';
|
|
95
|
-
exposeAdviverse(); // → window.adviverse.openExternal
|
|
96
|
-
```
|
|
64
|
+
Electron apps install [`@adviverse/electron`](https://github.com/Adviverse/electron-sdk)
|
|
65
|
+
in the main process (one call + a ready-made preload).
|
|
97
66
|
|
|
98
67
|
## What "done right" means (built in)
|
|
99
68
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Renderer entry (no React): core loop + a framework-free mount.
|
|
6
6
|
* import { mountAd, fetchAd } from '@adviverse/desktop';
|
|
7
|
-
* React:
|
|
8
|
-
* Electron
|
|
7
|
+
* React: @adviverse/desktop-react (<AdviverseAd/>)
|
|
8
|
+
* Electron: @adviverse/electron (main-process + preload bridge)
|
|
9
9
|
*/
|
|
10
10
|
export type { Ad, AdviverseConfig } from './core';
|
|
11
11
|
export { fetchAd, openClick, fireImpression, observeViewability } from './core';
|
package/package.json
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adviverse/desktop",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Adviverse ads for
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Adviverse ads for desktop apps that host a webview (Electron, Tauri, CEF, WKWebView, WebView2) \u2014 core loop + framework-free mount. React: @adviverse/desktop-react. Electron bridge: @adviverse/electron.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
13
14
|
},
|
|
14
|
-
"files": [
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
15
19
|
"scripts": {
|
|
16
20
|
"build": "tsc -p tsconfig.json",
|
|
17
21
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
18
22
|
},
|
|
19
|
-
"peerDependencies": {
|
|
20
|
-
"react": ">=17",
|
|
21
|
-
"electron": ">=22"
|
|
22
|
-
},
|
|
23
|
-
"peerDependenciesMeta": {
|
|
24
|
-
"react": { "optional": true },
|
|
25
|
-
"electron": { "optional": true }
|
|
26
|
-
},
|
|
27
23
|
"devDependencies": {
|
|
28
|
-
"@types/react": "^18.3.0",
|
|
29
|
-
"@types/node": "^22.0.0",
|
|
30
|
-
"electron": "^30.0.0",
|
|
31
|
-
"react": "^18.3.0",
|
|
32
24
|
"typescript": "^5.6.2"
|
|
33
25
|
},
|
|
34
|
-
"keywords": [
|
|
26
|
+
"keywords": [
|
|
27
|
+
"adviverse",
|
|
28
|
+
"ads",
|
|
29
|
+
"desktop",
|
|
30
|
+
"tauri",
|
|
31
|
+
"webview",
|
|
32
|
+
"electron"
|
|
33
|
+
]
|
|
35
34
|
}
|
package/dist/electron.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/** Call in the MAIN process: handle open-external requests, allowing http(s) only. */
|
|
2
|
-
export declare function registerAdviverseIpc(): void;
|
|
3
|
-
/** Call in the PRELOAD script: expose window.adviverse.openExternal to the renderer. */
|
|
4
|
-
export declare function exposeAdviverse(): void;
|
|
5
|
-
/** Path to a ready-made preload that calls exposeAdviverse(); use in webPreferences.preload. */
|
|
6
|
-
export declare function adviversePreloadPath(): string;
|
|
7
|
-
/** Convenience: register the IPC handler (main process). Pair with a preload that
|
|
8
|
-
* calls exposeAdviverse(), e.g. adviversePreloadPath(). */
|
|
9
|
-
export declare function registerAdviverse(): void;
|
package/dist/electron.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Electron MAIN-process helper. A renderer webview can't open the system
|
|
3
|
-
* browser directly (and shouldn't navigate the app window to an ad landing
|
|
4
|
-
* page), so the main process exposes a tiny bridge the renderer calls through
|
|
5
|
-
* `window.adviverse.openExternal()`.
|
|
6
|
-
*
|
|
7
|
-
* main.ts:
|
|
8
|
-
* import { registerAdviverse } from '@adviverse/desktop/electron';
|
|
9
|
-
* registerAdviverse(); // once, after app is ready
|
|
10
|
-
* // ...and in your BrowserWindow webPreferences: preload: adviversePreloadPath()
|
|
11
|
-
*
|
|
12
|
-
* If you already have a preload, instead add ONE line to it:
|
|
13
|
-
* import { exposeAdviverse } from '@adviverse/desktop/electron';
|
|
14
|
-
* exposeAdviverse(); // in the preload script
|
|
15
|
-
* and in main: registerAdviverseIpc();
|
|
16
|
-
*/
|
|
17
|
-
import { ipcMain, shell, contextBridge } from 'electron';
|
|
18
|
-
import * as path from 'path';
|
|
19
|
-
const CHANNEL = 'adviverse:openExternal';
|
|
20
|
-
/** Call in the MAIN process: handle open-external requests, allowing http(s) only. */
|
|
21
|
-
export function registerAdviverseIpc() {
|
|
22
|
-
ipcMain.handle(CHANNEL, (_evt, url) => {
|
|
23
|
-
if (typeof url === 'string' && /^https?:\/\//i.test(url)) {
|
|
24
|
-
return shell.openExternal(url);
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/** Call in the PRELOAD script: expose window.adviverse.openExternal to the renderer. */
|
|
30
|
-
export function exposeAdviverse() {
|
|
31
|
-
// Lazy require so this file is importable in the main process too.
|
|
32
|
-
const { ipcRenderer } = require('electron');
|
|
33
|
-
contextBridge.exposeInMainWorld('adviverse', {
|
|
34
|
-
openExternal: (url) => ipcRenderer.invoke(CHANNEL, url),
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
/** Path to a ready-made preload that calls exposeAdviverse(); use in webPreferences.preload. */
|
|
38
|
-
export function adviversePreloadPath() {
|
|
39
|
-
return path.join(__dirname, 'preload.js');
|
|
40
|
-
}
|
|
41
|
-
/** Convenience: register the IPC handler (main process). Pair with a preload that
|
|
42
|
-
* calls exposeAdviverse(), e.g. adviversePreloadPath(). */
|
|
43
|
-
export function registerAdviverse() {
|
|
44
|
-
registerAdviverseIpc();
|
|
45
|
-
}
|
package/dist/preload.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/preload.js
DELETED
package/dist/react.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Ad, AdviverseConfig } from './core';
|
|
2
|
-
export interface AdviverseAdProps extends AdviverseConfig {
|
|
3
|
-
/** Re-fetch on an interval (ms). Omit for a single fetch on mount. */
|
|
4
|
-
refreshMs?: number;
|
|
5
|
-
className?: string;
|
|
6
|
-
style?: React.CSSProperties;
|
|
7
|
-
/** Render your own card instead of the built-in one. */
|
|
8
|
-
children?: (ad: Ad, onClick: () => void) => React.ReactNode;
|
|
9
|
-
}
|
|
10
|
-
export declare function AdviverseAd(props: AdviverseAdProps): JSX.Element | null;
|
package/dist/react.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/**
|
|
3
|
-
* <AdviverseAd/> — drop-in React ad card for Electron/Tauri renderers.
|
|
4
|
-
*
|
|
5
|
-
* import { AdviverseAd } from '@adviverse/desktop/react';
|
|
6
|
-
* <AdviverseAd token="ts_yourtoken" />
|
|
7
|
-
*
|
|
8
|
-
* Fetches an ad, renders a disclosed card, fires the impression on true
|
|
9
|
-
* viewability, and opens clicks in the default browser. Renders nothing on
|
|
10
|
-
* no-fill. Styling is minimal + theme-aware; pass `className`/`style` to skin it.
|
|
11
|
-
*/
|
|
12
|
-
import { useEffect, useRef, useState } from 'react';
|
|
13
|
-
import { fetchAd, observeViewability, openClick } from './core';
|
|
14
|
-
export function AdviverseAd(props) {
|
|
15
|
-
const { refreshMs, className, style, children, ...cfg } = props;
|
|
16
|
-
const [ad, setAd] = useState(null);
|
|
17
|
-
const ref = useRef(null);
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
let alive = true;
|
|
20
|
-
const load = () => { fetchAd(cfg).then((a) => { if (alive)
|
|
21
|
-
setAd(a); }); };
|
|
22
|
-
load();
|
|
23
|
-
const id = refreshMs ? setInterval(load, refreshMs) : undefined;
|
|
24
|
-
return () => { alive = false; if (id)
|
|
25
|
-
clearInterval(id); };
|
|
26
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
-
}, [cfg.token, refreshMs]);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (!ad || !ref.current)
|
|
30
|
-
return;
|
|
31
|
-
return observeViewability(ref.current, ad);
|
|
32
|
-
}, [ad]);
|
|
33
|
-
if (!ad)
|
|
34
|
-
return null;
|
|
35
|
-
const onClick = () => openClick(ad);
|
|
36
|
-
if (children) {
|
|
37
|
-
return _jsx("div", { ref: ref, className: className, style: style, children: children(ad, onClick) });
|
|
38
|
-
}
|
|
39
|
-
return (_jsxs("div", { ref: ref, className: className, onClick: onClick, role: "link", tabIndex: 0, onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ')
|
|
40
|
-
onClick(); }, style: {
|
|
41
|
-
display: 'flex', alignItems: 'center', gap: 10, cursor: 'pointer',
|
|
42
|
-
padding: '10px 12px', borderRadius: 10, fontSize: 13, lineHeight: 1.35,
|
|
43
|
-
border: '1px solid rgba(127,127,127,0.22)', background: 'rgba(127,127,127,0.06)',
|
|
44
|
-
color: 'inherit', maxWidth: '100%', boxSizing: 'border-box', ...style,
|
|
45
|
-
}, children: [_jsx("span", { style: {
|
|
46
|
-
fontSize: 10, textTransform: 'uppercase', letterSpacing: '0.06em',
|
|
47
|
-
opacity: 0.6, flex: 'none',
|
|
48
|
-
}, children: ad.label || 'ad' }), _jsxs("span", { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, children: [ad.brand ? _jsx("b", { children: ad.brand }) : null, ad.brand ? ' — ' : '', ad.text, ad.body ? _jsx("span", { style: { opacity: 0.7 }, children: ' ' + ad.body }) : null] }), ad.cta ? (_jsxs("span", { style: {
|
|
49
|
-
flex: 'none', fontWeight: 600, color: '#1b50e0',
|
|
50
|
-
whiteSpace: 'nowrap',
|
|
51
|
-
}, children: [ad.cta, " \u2192"] })) : null] }));
|
|
52
|
-
}
|