Skip to content

Commit 0f37add

Browse files
committed
using capacitor browser plugin
1 parent 41b4b06 commit 0f37add

File tree

10 files changed

+118
-6
lines changed

10 files changed

+118
-6
lines changed

ghcjs/currency-converter/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ in rec {
8888
${./static}/web.js -o $out/web.js --compress --mangle --source-map
8989
${functora-pkgs.terser}/bin/terser \
9090
${./static}/web2.js -o $out/web2.js --compress --mangle --source-map
91+
${functora-pkgs.terser}/bin/terser \
92+
${./static}/web3.js -o $out/web3.js --compress --mangle --source-map
9193
${functora-pkgs.terser}/bin/terser \
9294
${./static}/main.js -o $out/main.js --compress --mangle --source-map
9395
${functora-pkgs.html-minifier}/bin/html-minifier \

ghcjs/currency-converter/package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ghcjs/currency-converter/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"dependencies": {
1010
"@capacitor/android": "^6.0.0",
11+
"@capacitor/browser": "^6.0.1",
1112
"@capacitor/core": "^6.0.0",
1213
"@capacitor/ios": "^6.0.0",
1314
"@capacitor/preferences": "^6.0.1",

ghcjs/currency-converter/src/App/Misc.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module App.Misc
1818
newAssetAction,
1919
newFieldPairAction,
2020
newPaymentMethodAction,
21+
openBrowserPageAction,
2122
)
2223
where
2324

@@ -27,6 +28,7 @@ import Functora.Miso.Prelude
2728
import Functora.Money hiding (Text)
2829
import qualified Language.Javascript.JSaddle as JS
2930
import qualified Material.Snackbar as Snackbar
31+
import qualified Text.URI as URI
3032
import qualified Prelude
3133

3234
getConverterAmountOptic ::
@@ -244,3 +246,9 @@ newPaymentMethodAction optic =
244246
. ChanItem 0
245247
$ (textPopupPure @MisoString "Added payment!")
246248
. (& cloneTraversal optic %~ (<> [item]))
249+
250+
openBrowserPageAction :: URI -> Action
251+
openBrowserPageAction uri =
252+
PushUpdate $ do
253+
void $ JS.global ^. JS.js1 @MisoString "openBrowserPage" (URI.render uri)
254+
pure $ ChanItem 0 id

ghcjs/currency-converter/src/App/Widgets/Main.hs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import qualified App.Widgets.Qr as Qr
1212
import qualified App.Widgets.SwapAmounts as SwapAmounts
1313
import Functora.Miso.Prelude
1414
import Functora.Money hiding (Text)
15+
import qualified Functora.Prelude as Prelude
1516
import qualified Material.Button as Button
1617
import qualified Material.LayoutGrid as LayoutGrid
1718
import qualified Material.Snackbar as Snackbar
@@ -180,6 +181,7 @@ ratesWidget st =
180181
. #currencyOutput
181182
. #currencyInfoCode
182183
. #unCurrencyCode
184+
. to toMisoString
183185
bottom = st ^. #modelState . #stDoc . #stDocBottomMoney
184186
bottomAmt = bottom ^. #moneyAmount . #fieldOutput
185187
bottomCur =
@@ -188,6 +190,7 @@ ratesWidget st =
188190
. #currencyOutput
189191
. #currencyInfoCode
190192
. #unCurrencyCode
193+
. to toMisoString
191194
bottomPerTop =
192195
if topAmt == 0
193196
then 0
@@ -236,12 +239,49 @@ tosWidget =
236239
[ ("text-align", "center")
237240
]
238241
]
239-
[ Miso.text "\169 2024 Functora. All rights reserved. ",
242+
[ Miso.text "\169 2024 ",
243+
browserLink "https://functora.github.io/" "Functora",
244+
Miso.text ". All rights reserved. ",
240245
Miso.text "By continuing to use this software, you agree to the ",
241-
a_ [href_ "license.html"] [Miso.text "Terms of Service"],
246+
a_
247+
[ href_ "license.html"
248+
]
249+
[ Miso.text "Terms of Service"
250+
],
242251
Miso.text " and ",
243-
a_ [href_ "privacy.html"] [Miso.text "Privacy Policy"],
244-
Miso.text
245-
". This software is 100% organic and AI-free. It is built and tested exclusively by humans. ",
246-
Miso.text $ "Version " <> vsn <> "."
252+
a_
253+
[ href_ "privacy.html"
254+
]
255+
[ Miso.text "Privacy Policy"
256+
],
257+
Miso.text ". To install the ",
258+
browserLink
259+
"https://play.google.com/apps/testing/com.functora.currency_converter"
260+
"Android app",
261+
Miso.text ", either join the ",
262+
browserLink
263+
"https://groups.google.com/g/currency-converter"
264+
"testing group",
265+
Miso.text " or download the ",
266+
browserLink
267+
( "https://github.com/functora/functora.github.io/releases/download/currency-converter-v"
268+
<> fromMisoString vsn
269+
<> "/currency-converter-v"
270+
<> fromMisoString vsn
271+
<> ".apk"
272+
)
273+
"APK file",
274+
Miso.text $ ". Version " <> vsn <> "."
275+
]
276+
277+
browserLink :: Prelude.Text -> MisoString -> View Action
278+
browserLink uri txt =
279+
a_
280+
[ href_ "#!",
281+
onClick
282+
. Misc.openBrowserPageAction
283+
. either impureThrow id
284+
$ URI.mkURI uri
285+
]
286+
[ Miso.text txt
247287
]

ghcjs/currency-converter/src/Main.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ runApp app = do
9191
("static" : _) -> staticApp (defaultWebAppSettings ".") req
9292
("web.js" : _) -> staticApp (defaultWebAppSettings "static") req
9393
("web2.js" : _) -> staticApp (defaultWebAppSettings "static") req
94+
("web3.js" : _) -> staticApp (defaultWebAppSettings "static") req
9495
("main.js" : _) -> staticApp (defaultWebAppSettings "static") req
9596
("site.webmanifest" : _) -> staticApp (defaultWebAppSettings "static") req
9697
_ -> JS.jsaddleAppWithJs (JS.jsaddleJs False <> js) req

ghcjs/currency-converter/static/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ body {
1010
justify-content: center;
1111
}
1212

13+
a {
14+
color: inherit;
15+
}
16+
1317
textarea {
1418
resize: vertical;
1519
pointer-events: auto;

ghcjs/currency-converter/static/cap.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { WebviewPrint } from "capacitor-webview-print";
22
import { Preferences } from "@capacitor/preferences";
3+
import { Browser } from "@capacitor/browser";
34

45
async function printCurrentPage(name) {
56
await WebviewPrint.print({ name: name });
@@ -14,6 +15,15 @@ async function insertStorage(key, value) {
1415
await Preferences.set({ key: key, value: value });
1516
}
1617

18+
async function openBrowserPage(url) {
19+
try {
20+
await Browser.open({ url: url });
21+
} catch (e) {
22+
window.open(url, "_blank").focus();
23+
}
24+
}
25+
1726
globalThis.printCurrentPage = printCurrentPage;
1827
globalThis.selectStorage = selectStorage;
1928
globalThis.insertStorage = insertStorage;
29+
globalThis.openBrowserPage = openBrowserPage;

ghcjs/currency-converter/static/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ const WebviewPrint = registerPlugin("WebviewPrint", {
579579
const Preferences = registerPlugin("Preferences", {
580580
web: () => __vitePreload(() => import("./web2.js"), true ? [] : void 0).then((m) => new m.PreferencesWeb())
581581
});
582+
const Browser = registerPlugin("Browser", {
583+
web: () => __vitePreload(() => import("./web3.js"), true ? [] : void 0).then((m) => new m.BrowserWeb())
584+
});
582585
async function printCurrentPage(name) {
583586
await WebviewPrint.print({ name });
584587
}
@@ -589,9 +592,17 @@ async function selectStorage(key) {
589592
async function insertStorage(key, value) {
590593
await Preferences.set({ key, value });
591594
}
595+
async function openBrowserPage(url) {
596+
try {
597+
await Browser.open({ url });
598+
} catch (e) {
599+
window.open(url, "_blank").focus();
600+
}
601+
}
592602
globalThis.printCurrentPage = printCurrentPage;
593603
globalThis.selectStorage = selectStorage;
594604
globalThis.insertStorage = insertStorage;
605+
globalThis.openBrowserPage = openBrowserPage;
595606
export {
596607
WebPlugin as W
597608
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { W as WebPlugin } from "./main.js";
2+
class BrowserWeb extends WebPlugin {
3+
constructor() {
4+
super();
5+
this._lastWindow = null;
6+
}
7+
async open(options) {
8+
this._lastWindow = window.open(options.url, options.windowName || "_blank");
9+
}
10+
async close() {
11+
return new Promise((resolve, reject) => {
12+
if (this._lastWindow != null) {
13+
this._lastWindow.close();
14+
this._lastWindow = null;
15+
resolve();
16+
} else {
17+
reject("No active window to close!");
18+
}
19+
});
20+
}
21+
}
22+
const Browser = new BrowserWeb();
23+
export {
24+
Browser,
25+
BrowserWeb
26+
};

0 commit comments

Comments
 (0)