Skip to content
Draft

Android #1281

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ node_modules/
.vscode

# Built files
dist
dist-renderer-webpack
dist-library-files
dist-extensions
/dist
/dist-renderer-webpack
/dist-library-files
/dist-extensions
src-renderer/packager/standalone.html

# Debian release scripts create files that shouldn't be committed
Expand Down
15 changes: 15 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
68 changes: 68 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}

android {
namespace = "org.turbowarp.android"
compileSdk {
version = release(36)
}

defaultConfig {
applicationId = "org.turbowarp.android"
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
buildFeatures {
compose = true
buildConfig = true
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.graphics)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.webkit)
implementation(libs.brotlidec)
implementation(libs.androidx.navigation.compose)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)
}
21 changes: 21 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.turbowarp.android

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("org.turbowarp.android", appContext.packageName)
}
}
27 changes: 27 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.TurboWarp">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.TurboWarp"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
1 change: 1 addition & 0 deletions android/app/src/main/assets/dist-extensions
1 change: 1 addition & 0 deletions android/app/src/main/assets/dist-library-files
1 change: 1 addition & 0 deletions android/app/src/main/assets/dist-renderer-webpack
1 change: 1 addition & 0 deletions android/app/src/main/assets/l10n
87 changes: 87 additions & 0 deletions android/app/src/main/assets/preload/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const {contextBridge, ipcRenderer} = require('electron');

contextBridge.exposeInMainWorld('EditorPreload', {
isInitiallyFullscreen: () => ipcRenderer.sendSync('is-initially-fullscreen'),
getInitialFile: async () => null,
getFile: (id) => ipcRenderer.invoke('get-file', id),
openedFile: (id) => ipcRenderer.invoke('opened-file', id),
closedFile: () => ipcRenderer.invoke('closed-file'),
showSaveFilePicker: (suggestedName) => ipcRenderer.invoke('show-save-file-picker', suggestedName),
showOpenFilePicker: () => ipcRenderer.invoke('show-open-file-picker'),
setLocale: (locale) => ipcRenderer.sendSync('set-locale', locale),
setChanged: (changed) => {},
// openNewWindow: () => ipcRenderer.invoke('open-new-window'),
openAddonSettings: (search) => ipcRenderer.sendSync('open-addon-settings', search),
//openPackager: () => ipcRenderer.invoke('open-packager'),
//openDesktopSettings: () => ipcRenderer.invoke('open-desktop-settings'),
openPrivacy: () => ipcRenderer.sendSync('open-privacy'),
openAbout: () => ipcRenderer.sendSync('open-about'),
//getPreferredMediaDevices: () => ipcRenderer.invoke('get-preferred-media-devices'),
getAdvancedCustomizations: async () => ({}),
setExportForPackager: (callback) => {},
setIsFullScreen: (isFullScreen) => {}
});

//let exportForPackager = () => Promise.reject(new Error('exportForPackager missing'));

//ipcRenderer.on('export-project-to-port', (e) => {
// const port = e.ports[0];
// exportForPackager()
// .then(({data, name}) => {
// port.postMessage({ data, name });
// })
// .catch((error) => {
// console.error(error);
// port.postMessage({ error: true });
// });
//});

//window.addEventListener('message', (e) => {
// if (e.source === window) {
// const data = e.data;
// if (data && typeof data.ipcStartWriteStream === 'string') {
// ipcRenderer.postMessage('start-write-stream', data.ipcStartWriteStream, e.ports);
// }
// }
//});

//ipcRenderer.on('enumerate-media-devices', (e) => {
// navigator.mediaDevices.enumerateDevices()
// .then((devices) => {
// e.sender.send('enumerated-media-devices', {
// devices: devices.map((device) => ({
// deviceId: device.deviceId,
// kind: device.kind,
// label: device.label
// }))
// });
// })
// .catch((error) => {
// console.error(error);
// e.sender.send('enumerated-media-devices', {
// error: `${error}`
// });
// });
//});

//contextBridge.exposeInMainWorld('PromptsPreload', {
// alert: (message) => ipcRenderer.sendSync('alert', message),
// confirm: (message) => ipcRenderer.sendSync('confirm', message),
//});

// In some Linux environments, people may try to drag & drop files that we don't have access to.
// Remove when https://github.com/electron/electron/issues/30650 is fixed.
//if (navigator.userAgent.includes('Linux')) {
// document.addEventListener('drop', (e) => {
// if (e.isTrusted) {
// for (const file of e.dataTransfer.files) {
// // Using webUtils is safe as we don't have a legacy build for Linux
// const {webUtils} = require('electron');
// const path = webUtils.getPathForFile(file);
// ipcRenderer.invoke('check-drag-and-drop-path', path);
// }
// }
// }, {
// capture: true
// });
//}
63 changes: 63 additions & 0 deletions android/app/src/main/assets/preload/ipc-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const require = (function() {
let globalIpcCounter = 0;
const ipcInFlight = {};

AndroidIpcAsync.onmessage = (e) => {
const data = e.data;
const ipcObject = ipcInFlight[data.messageId];
if (!ipcObject) {
throw new Error(`Received async IPC with unknown ID ${data.messageId}`);
}

if (data.success) {
ipcObject.resolve(data.result);
} else {
ipcObject.reject(data.result);
}

delete ipcObject[data.messageId];
};

const contextBridge = {
exposeInMainWorld: (objectName, objectImplementation) => {
window[objectName] = objectImplementation;
}
};

const ipcRenderer = {
sendSync: (method, ...args) => {
const response = AndroidIpcSync.sendSync(JSON.stringify({
method,
args
}));
return JSON.parse(response);
},

invoke: (method, ...args) => new Promise((resolve, reject) => {
const messageId = globalIpcCounter++;
ipcInFlight[messageId] = {
resolve,
reject
};

console.log('Sending', method, args);

AndroidIpcAsync.postMessage({
messageId,
method,
arguments: args
});
}),
};

return (moduleName) => {
if (moduleName === "electron") {
return {
contextBridge,
ipcRenderer
};
}

throw new Error(`Mock require() found unknown module: ${moduleName}`);
};
}());
Binary file added android/app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions android/app/src/main/java/org/turbowarp/android/AboutView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.turbowarp.android

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp

@Composable
fun AboutView() {
Surface(
modifier = Modifier.fillMaxSize(),
color = Color(0xffff4c4c)
) {
Column (
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = "TurboWarp for Android",
fontSize = 30.sp,
color = Color.White,
textAlign = TextAlign.Center
)
Text(
text = "${BuildConfig.APPLICATION_ID}/${BuildConfig.VERSION_NAME}",
fontSize = 20.sp,
color = Color.White,
textAlign = TextAlign.Center
)
}
}
}
10 changes: 10 additions & 0 deletions android/app/src/main/java/org/turbowarp/android/AddonsView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.turbowarp.android

import androidx.compose.runtime.Composable

@Composable
fun AddonsView() {
TurboWarpWebView(
url = "https://editor.android-assets.turbowarp.org/addons/addons.html",
)
}
Loading