Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(desktop): unify native theme to follow webview, update dark to #100D0A

Gener0fda3cb97b58
diff --git a/src/desktop/src-tauri/gen/android/app/src/main/java/ai/alook/desktop/MainActivity.kt b/src/desktop/src-tauri/gen/android/app/src/main/java/ai/alook/desktop/MainActivity.kt
index 92b124255..0d35b0d3d 100644
--- a/src/desktop/src-tauri/gen/android/app/src/main/java/ai/alook/desktop/MainActivity.kt
+++ b/src/desktop/src-tauri/gen/android/app/src/main/java/ai/alook/desktop/MainActivity.kt
@@ -6,14 +6,38 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
+import android.webkit.JavascriptInterface
+import android.webkit.WebView
import androidx.activity.enableEdgeToEdge
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
+import androidx.webkit.WebViewCompat
+import androidx.webkit.WebViewFeature
class MainActivity : TauriActivity() {
private var isReady = false
+ companion object {
+ const val COLOR_LIGHT = "#ECE8DE"
+ const val COLOR_DARK = "#100D0A"
+
+ const val THEME_OBSERVER_SCRIPT = """
+ (function() {
+ if (window.__alookThemeObserverInstalled) return;
+ window.__alookThemeObserverInstalled = true;
+ function sync() {
+ var dark = document.documentElement.classList.contains('dark');
+ if (window.AlookNative) window.AlookNative.setWindowTheme(dark);
+ }
+ sync();
+ new MutationObserver(sync).observe(document.documentElement, {
+ attributes: true, attributeFilter: ['class']
+ });
+ })();
+ """
+ }
+
override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
enableEdgeToEdge()
@@ -21,13 +45,12 @@ class MainActivity : TauriActivity() {
splashScreen.setKeepOnScreenCondition { !isReady }
- // Dismiss splash after max 2 seconds regardless
Handler(Looper.getMainLooper()).postDelayed({ isReady = true }, 2000)
val rootView: View = findViewById(android.R.id.content)
val isDark = (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
- val bgColor = if (isDark) Color.parseColor("#22201E") else Color.parseColor("#ECE8DE")
+ val bgColor = if (isDark) Color.parseColor(COLOR_DARK) else Color.parseColor(COLOR_LIGHT)
rootView.setBackgroundColor(bgColor)
ViewCompat.setOnApplyWindowInsetsListener(rootView) { v, insets ->
@@ -40,4 +63,28 @@ class MainActivity : TauriActivity() {
insets
}
}
+
+ override fun onWebViewCreate(webView: WebView) {
+ super.onWebViewCreate(webView)
+ webView.addJavascriptInterface(ThemeBridge(this), "AlookNative")
+
+ if (WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) {
+ WebViewCompat.addDocumentStartJavaScript(webView, THEME_OBSERVER_SCRIPT, setOf("*"))
+ }
+ }
+
+ fun setTheme(dark: Boolean) {
+ val rootView: View = findViewById(android.R.id.content)
+ val color = if (dark) Color.parseColor(COLOR_DARK) else Color.parseColor(COLOR_LIGHT)
+ runOnUiThread {
+ rootView.setBackgroundColor(color)
+ }
+ }
+
+ class ThemeBridge(private val activity: MainActivity) {
+ @JavascriptInterface
+ fun setWindowTheme(dark: Boolean) {
+ activity.setTheme(dark)
+ }
+ }
}
diff --git a/src/desktop/src-tauri/gen/android/app/src/main/res/values-night/themes.xml b/src/desktop/src-tauri/gen/android/app/src/main/res/values-night/themes.xml
index 4dbc0f704..f3b9a0e83 100644
--- a/src/desktop/src-tauri/gen/android/app/src/main/res/values-night/themes.xml
+++ b/src/desktop/src-tauri/gen/android/app/src/main/res/values-night/themes.xml
@@ -4,7 +4,7 @@
</style>
<!-- Splash screen theme (dark) -->
<style name="Theme.alook_desktop.Splash" parent="Theme.SplashScreen">
- <item name="windowSplashScreenBackground">#22201E</item>
+ <item name="windowSplashScreenBackground">#100D0A</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/splash_icon</item>
<item name="windowSplashScreenAnimationDuration">300</item>
<item name="postSplashScreenTheme">@style/Theme.alook_desktop</item>
diff --git a/src/desktop/src-tauri/gen/apple/Assets.xcassets/SplashBackground.colorset/Contents.json b/src/desktop/src-tauri/gen/apple/Assets.xcassets/SplashBackground.colorset/Contents.json
index 791301738..82c9b8b75 100644
--- a/src/desktop/src-tauri/gen/apple/Assets.xcassets/SplashBackground.colorset/Contents.json
+++ b/src/desktop/src-tauri/gen/apple/Assets.xcassets/SplashBackground.colorset/Contents.json
@@ -22,9 +22,9 @@
"color": {
"color-space": "srgb",
"components": {
- "red": "0.133",
- "green": "0.125",
- "blue": "0.118",
+ "red": "0.063",
+ "green": "0.051",
+ "blue": "0.039",
"alpha": "1.000"
}
},
diff --git a/src/desktop/src-tauri/gen/apple/Sources/alook-desktop/main.mm b/src/desktop/src-tauri/gen/apple/Sources/alook-desktop/main.mm
index beec889c9..d1c6c794f 100644
--- a/src/desktop/src-tauri/gen/apple/Sources/alook-desktop/main.mm
+++ b/src/desktop/src-tauri/gen/apple/Sources/alook-desktop/main.mm
@@ -3,7 +3,43 @@
#import <WebKit/WebKit.h>
#import <objc/runtime.h>
-// Constrain WKWebView frame to safe area so viewport height matches visible area
+static UIColor *alookLightColor(void) {
+ return [UIColor colorWithRed:0.929 green:0.910 blue:0.871 alpha:1.0];
+}
+
+static UIColor *alookDarkColor(void) {
+ return [UIColor colorWithRed:0.063 green:0.051 blue:0.039 alpha:1.0];
+}
+
+static NSString *const kThemeObserverScript =
+ @"(function(){"
+ "if(window.__alookThemeObserverInstalled)return;"
+ "window.__alookThemeObserverInstalled=true;"
+ "function sync(){var d=document.documentElement.classList.contains('dark');"
+ "window.webkit.messageHandlers.alookTheme.postMessage(d?'dark':'light');}"
+ "sync();"
+ "new MutationObserver(sync).observe(document.documentElement,"
+ "{attributes:true,attributeFilter:['class']});"
+ "})();";
+
+@interface AlookThemeHandler : NSObject <WKScriptMessageHandler>
+@property (nonatomic, weak) UIViewController *viewController;
+@end
+
+@implementation AlookThemeHandler
+
+- (void)userContentController:(WKUserContentController *)userContentController
+ didReceiveScriptMessage:(WKScriptMessage *)message {
+ if (![message.name isEqualToString:@"alookTheme"]) return;
+ NSString *theme = message.body;
+ BOOL isDark = [theme isEqualToString:@"dark"];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ self.viewController.view.backgroundColor = isDark ? alookDarkColor() : alookLightColor();
+ });
+}
+
+@end
+
@implementation UIViewController (AlookSafeArea)
+ (void)load {
@@ -27,11 +63,23 @@
bounds.size.width - insets.left - insets.right,
bounds.size.height - insets.top - insets.bottom
);
- // Set background color matching theme
+
+ WKWebView *webView = (WKWebView *)subview;
+ static dispatch_once_t scriptToken;
+ dispatch_once(&scriptToken, ^{
+ AlookThemeHandler *handler = [[AlookThemeHandler alloc] init];
+ handler.viewController = self;
+ [webView.configuration.userContentController
+ addScriptMessageHandler:handler name:@"alookTheme"];
+ WKUserScript *script = [[WKUserScript alloc]
+ initWithSource:kThemeObserverScript
+ injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
+ forMainFrameOnly:YES];
+ [webView.configuration.userContentController addUserScript:script];
+ });
+
BOOL isDark = (self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark);
- self.view.backgroundColor = isDark
- ? [UIColor colorWithRed:0.133 green:0.125 blue:0.118 alpha:1.0]
- : [UIColor colorWithRed:0.929 green:0.910 blue:0.871 alpha:1.0];
+ self.view.backgroundColor = isDark ? alookDarkColor() : alookLightColor();
}
}
}
diff --git a/src/desktop/src-tauri/src/commands.rs b/src/desktop/src-tauri/src/commands.rs
index a765d80b2..ce6306eae 100644
--- a/src/desktop/src-tauri/src/commands.rs
+++ b/src/desktop/src-tauri/src/commands.rs
@@ -458,7 +458,7 @@ pub fn set_window_theme(window: tauri::WebviewWindow, dark: bool) {
unsafe {
let ns_window = window.ns_window().unwrap() as *mut AnyObject;
let (r, g, b) = if dark {
- (0.137f64, 0.129f64, 0.118f64)
+ (0.063f64, 0.051f64, 0.039f64)
} else {
(0.929f64, 0.910f64, 0.871f64)
};