working android example. File access still not working

This commit is contained in:
Iaphetes 2024-11-19 07:49:53 +01:00
parent a04fd0293f
commit 340833ea7b
6 changed files with 50 additions and 17 deletions

2
.gitignore vendored
View file

@ -11,7 +11,7 @@ node_modules
dist dist
dist-ssr dist-ssr
*.local *.local
src-tauri/gen/android/keystore.properties
# Editor directories and files # Editor directories and files
.vscode/* .vscode/*
!.vscode/extensions.json !.vscode/extensions.json

View file

@ -6,9 +6,15 @@
"main" "main"
], ],
"permissions": [ "permissions": [
{
"identifier": "fs:allow-read",
"allow": [{ "path": "$HOME/**" }]
},
"core:default", "core:default",
"shell:allow-open", "shell:allow-open",
"fs:default", "log:default",
"log:default" "fs:allow-home-read-recursive",
"fs:scope-home-recursive",
"fs:read-all"
] ]
} }

View file

@ -1,4 +1,5 @@
import java.util.Properties import java.util.Properties
import java.io.FileInputStream
plugins { plugins {
id("com.android.application") id("com.android.application")
@ -24,6 +25,22 @@ android {
versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt() versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt()
versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0") versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0")
} }
signingConfigs {
create("release") {
val keystorePropertiesFile = rootProject.file("keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
keyAlias = keystoreProperties["keyAlias"] as String
keyPassword = keystoreProperties["password"] as String
storeFile = file(keystoreProperties["storeFile"] as String)
storePassword = keystoreProperties["password"] as String
}
}
buildTypes { buildTypes {
getByName("debug") { getByName("debug") {
manifestPlaceholders["usesCleartextTraffic"] = "true" manifestPlaceholders["usesCleartextTraffic"] = "true"
@ -37,6 +54,7 @@ android {
} }
} }
getByName("release") { getByName("release") {
signingConfig = signingConfigs.getByName("release")
isMinifyEnabled = true isMinifyEnabled = true
proguardFiles( proguardFiles(
*fileTree(".") { include("**/*.pro") } *fileTree(".") { include("**/*.pro") }

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- AndroidTV support --> <!-- AndroidTV support -->
<uses-feature android:name="android.software.leanback" android:required="false" /> <uses-feature android:name="android.software.leanback" android:required="false" />

View file

@ -20,7 +20,8 @@
"assetProtocol": { "assetProtocol": {
"enable": true, "enable": true,
"scope": [ "scope": [
"$HOME/**" "$HOME/**",
"**"
] ]
} }

View file

@ -1,4 +1,5 @@
const { convertFileSrc, invoke } = window.__TAURI__.core; const { convertFileSrc, invoke } = window.__TAURI__.core;
// const { invoke } = window.__TAURI__.core;
const { homeDir, join } = window.__TAURI__.path; const { homeDir, join } = window.__TAURI__.path;
const { readFile } = window.__TAURI__.fs; const { readFile } = window.__TAURI__.fs;
@ -7,20 +8,25 @@ const filePath = await join(appDataDirPath, 'Pictures/wallpaper.png');
const assetUrl = convertFileSrc(filePath); const assetUrl = convertFileSrc(filePath);
let text = ""; let text = "";
window.addEventListener("DOMCharacterDataModified", () => { // window.addEventListener("DOMCharacterDataModified", () => {
// var tag_id = document.getElementById('rendered_markdown');
// tag_id.innerHTML = "<p>HI</p>"
// window.addEventListener("DOMContentLoaded", () => { // window.addEventListener("DOMContentLoaded", () => {
let textarea = document.getElementById('markdown_input'); let textarea = document.getElementById('markdown_input');
textarea.addEventListener('input', ()=> { textarea.addEventListener('input', ()=> {
text = textarea.innerText; text = textarea.innerText;
invoke("parse_markdown", { document: text }).then(
(ret)=>{
var tag_id = document.getElementById('rendered_markdown'); var tag_id = document.getElementById('rendered_markdown');
// tag_id.innerHTML = "<pre>".concat("", ret).concat("", "</pre>"); tag_id.innerHTML = "<p>HI</p>"
// invoke("parse_markdown", { document: text }).then(
// (ret)=>{
// var tag_id = document.getElementById('rendered_markdown');
// // tag_id.innerHTML = assetUrl.concat(" ", ' \n <img src="'.concat("", assetUrl).concat("", '" alt="Girl in a jacket" width="500" height="600">'))
// tag_id.innerHTML = "<p>HI</p>"
// // tag_id.innerHTML = "<pre>".concat("", ret).concat("", "</pre>");
tag_id.innerHTML = assetUrl.concat(" ", ' \n <img src="'.concat("", assetUrl).concat("", '" alt="Girl in a jacket" width="500" height="600">')) tag_id.innerHTML = assetUrl.concat(" ", ' \n <img src="'.concat("", assetUrl).concat("", '" alt="Girl in a jacket" width="500" height="600">'))
} // }
); // );
}); // });
}); });