Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import android.os.Build
import android.view.Window
import androidx.core.view.WindowCompat

internal const val DEFAULT_DARK_THEME = "black"

internal fun normalizedDarkTheme(value: String?): String =
if (value == "solarized") value else DEFAULT_DARK_THEME

internal fun androidAppearanceIsDark(appearance: String, configuration: Configuration): Boolean =
when (appearance) {
"dark" -> true
Expand All @@ -29,12 +34,11 @@ internal fun applyAndroidApplicationAppearance(context: Context, appearance: Str
}
}

internal fun applyAndroidSystemBarAppearance(window: Window, dark: Boolean) {
internal fun applyAndroidSystemBarAppearance(window: Window, dark: Boolean, background: Int) {
// These colors are honored on pre-edge-to-edge releases. Newer Android
// versions draw the app's Scaffold behind the transparent system bars.
@Suppress("DEPRECATION")
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
val background = if (dark) 0xff101318.toInt() else 0xfffcfcfc.toInt()
window.statusBarColor = background
window.navigationBarColor = background
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AndroidPlatformServices(private val context: Context) {
"composerDraft" to preferences.getString("logseq.composerDraft", "").orEmpty(),
"settings" to mapOf(
"appearance" to preferences.getString("logseq.appearance", "system").orEmpty(),
"darkTheme" to normalizedDarkTheme(preferences.getString("logseq.darkTheme", null)),
"language" to preferences.getString("logseq.language", "system").orEmpty(),
"spellCheck" to preferences.getBoolean("logseq.editor.spellCheck", true),
"autoCorrection" to preferences.getBoolean(
Expand All @@ -71,6 +72,9 @@ class AndroidPlatformServices(private val context: Context) {
val settings = JSONObject(encoded)
preferences.edit()
.putString("logseq.appearance", settings.optString("appearance", "system"))
.putString("logseq.darkTheme", normalizedDarkTheme(settings.optString(
"darkTheme", preferences.getString("logseq.darkTheme", DEFAULT_DARK_THEME),
)))
.putString("logseq.language", settings.optString("language", "system"))
.putBoolean("logseq.editor.spellCheck", settings.optBoolean("spellCheck", true))
.putBoolean(
Expand Down
7 changes: 5 additions & 2 deletions android/app/src/main/kotlin/com/logseq/logseq/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import android.os.Build
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.ui.graphics.toArgb
import androidx.core.view.doOnPreDraw
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.logseq.logseq.runtime.AndroidLaunchMetrics
import com.logseq.logseq.runtime.LogseqRuntime
import com.logseq.logseq.ui.LogseqApp
import com.logseq.logseq.ui.LogseqTheme
import kotlinx.coroutines.launch
import com.logseq.logseq.AndroidE2EECrypto
import com.logseq.logseq.AndroidHttpTransport
Expand All @@ -31,8 +33,9 @@ class MainActivity : ComponentActivity() {
if (hasFocus && ::runtime.isInitialized) {
// Window/decor focus can restore flags from the platform theme
// after Compose's first SideEffect, including after a dialog closes.
applyAndroidSystemBarAppearance(window,
androidAppearanceIsDark(runtime.effectiveAppearance, resources.configuration))
val dark = androidAppearanceIsDark(runtime.effectiveAppearance, resources.configuration)
val background = LogseqTheme.colorScheme(dark, runtime.effectiveDarkTheme).background
applyAndroidSystemBarAppearance(window, dark, background.toArgb())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.logseq.logseq.AndroidPlatformServices
import com.logseq.logseq.CognitoAuthProvider
import com.logseq.logseq.CognitoSessionUnavailableException
import com.logseq.logseq.DEFAULT_BASE_URL
import com.logseq.logseq.DEFAULT_DARK_THEME
import com.logseq.logseq.normalizedDarkTheme
import org.json.JSONArray
import org.json.JSONObject

Expand Down Expand Up @@ -92,6 +94,7 @@ internal data class AndroidHostUpdate(val kind: String, val payload: String)

internal data class AndroidHostSettings(
val appearance: String,
val darkTheme: String,
val language: String,
val spellCheck: Boolean,
val autoCorrection: Boolean,
Expand All @@ -103,6 +106,7 @@ internal data class AndroidHostSettings(
val hostPayload: Map<String, Any?>
get() = mapOf(
"appearance" to appearance,
"darkTheme" to darkTheme,
"language" to language,
"systemLanguage" to java.util.Locale.getDefault().toLanguageTag(),
"spellCheck" to spellCheck,
Expand All @@ -116,6 +120,7 @@ internal data class AndroidHostSettings(
companion object {
val defaults = AndroidHostSettings(
appearance = "system",
darkTheme = DEFAULT_DARK_THEME,
language = "system",
spellCheck = true,
autoCorrection = true,
Expand All @@ -132,6 +137,7 @@ internal data class AndroidHostSettings(
?.mapNotNull { it as? String } ?: defaults.sidebarTabs
return AndroidHostSettings(
appearance = value["appearance"] as? String ?: defaults.appearance,
darkTheme = normalizedDarkTheme(value["darkTheme"] as? String),
language = value["language"] as? String ?: defaults.language,
spellCheck = value["spellCheck"] as? Boolean ?: defaults.spellCheck,
autoCorrection = value["autoCorrection"] as? Boolean ?: defaults.autoCorrection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.logseq.logseq.AndroidAudioRecorder
import com.logseq.logseq.AndroidAudioTranscriber
import com.logseq.logseq.AndroidPlatformServices
import com.logseq.logseq.CognitoAuthProvider
import com.logseq.logseq.DEFAULT_DARK_THEME
import com.logseq.logseq.isNetworkUnavailable
import com.logseq.logseq.ui.extensions.LogseqDialogs
import dev.lui.LuiBackend
Expand Down Expand Up @@ -136,6 +137,7 @@ internal class LogseqRuntime(
private var activeBootstrap: kotlinx.coroutines.Job? = null
private var activeBootstrapHadSession = false
private var appearance by mutableStateOf("system")
private var darkTheme by mutableStateOf(DEFAULT_DARK_THEME)

init {
bridge.onCoreIdle = { scope.launch { effectDrain?.drain(scope) } }
Expand All @@ -155,6 +157,7 @@ internal class LogseqRuntime(
val authenticationCode = platformEffects.initialAuthenticationCode()
val storage = platformEffects.loadStorageState()
appearance = storage.settings.appearance
darkTheme = storage.settings.darkTheme
storageBaseUrl = storage.baseUrl

val lifecycle = AndroidGraphLifecycle(
Expand Down Expand Up @@ -547,6 +550,7 @@ internal class LogseqRuntime(
if (effect.kind == "save-settings" && resolution.succeeded) {
val storage = platformEffects.loadStorageState()
appearance = storage.settings.appearance
darkTheme = storage.settings.darkTheme
if (storage.baseUrl != storageBaseUrl) {
graphCatalogAutoRefresh?.stopPeriodic()
hasOpenGraph = false
Expand Down Expand Up @@ -934,6 +938,7 @@ internal class LogseqRuntime(
}

val effectiveAppearance: String get() = appearance
val effectiveDarkTheme: String get() = darkTheme
}

// Recorded audio asset produced by the recording sheet — payload shape
Expand Down
6 changes: 4 additions & 2 deletions android/app/src/main/kotlin/com/logseq/logseq/ui/LogseqApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
Expand Down Expand Up @@ -82,13 +83,14 @@ internal fun LogseqApp(runtime: LogseqRuntime) {
else -> systemDark
}
val window = LocalActivity.current?.window
val colorScheme = LogseqTheme.colorScheme(dark, runtime.effectiveDarkTheme)
SideEffect {
if (window != null) {
applyAndroidSystemBarAppearance(window, dark)
applyAndroidSystemBarAppearance(window, dark, colorScheme.background.toArgb())
}
}
MaterialExpressiveTheme(
colorScheme = if (dark) LogseqTheme.darkScheme else LogseqTheme.lightScheme,
colorScheme = colorScheme,
typography = LogseqTheme.typography,
) {
androidx.compose.runtime.CompositionLocalProvider(
Expand Down
55 changes: 41 additions & 14 deletions android/app/src/main/kotlin/com/logseq/logseq/ui/LogseqTheme.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.logseq.logseq.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Typography
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.text.TextStyle
Expand Down Expand Up @@ -57,7 +54,7 @@ internal object LogseqTheme {

val accent = Color(0xff1b6898)
val lightSurface = Color(0xfff8f9ff)
val darkSurface = Color(0xff101318)
private val solarizedBackground = Color(0xff002d38)

// Material Expressive menus read the tertiary container roles for selection.
private fun ColorScheme.withMenuSelectionColors() = copy(
Expand Down Expand Up @@ -92,20 +89,50 @@ internal object LogseqTheme {
secondary = Color(0xffb8cad6),
secondaryContainer = Color(0xff3a4a55),
onSecondaryContainer = Color(0xffd4e6f2),
surface = darkSurface,
background = darkSurface,
surfaceContainerLowest = Color(0xff0b0e12),
surfaceContainerLow = Color(0xff14171d),
surfaceContainer = Color(0xff181c22),
surfaceContainerHigh = Color(0xff1d2229),
surfaceContainerHighest = Color(0xff22272f),
surface = solarizedBackground,
background = solarizedBackground,
onBackground = Color(0xffedfdfd),
onSurface = Color(0xffedfdfd),
onSurfaceVariant = Color(0xff9ab1b5),
surfaceVariant = Color(0xff19394d),
surfaceDim = solarizedBackground,
surfaceBright = Color(0xff315860),
surfaceContainerLowest = Color(0xff00242e),
surfaceContainerLow = Color(0xff0b3540),
surfaceContainer = Color(0xff143d48),
surfaceContainerHigh = Color(0xff1e4651),
surfaceContainerHighest = Color(0xff274f5a),
).withMenuSelectionColors()

val blackScheme = darkScheme.copy(
surface = Color.Black,
background = Color.Black,
secondaryContainer = Color(0xff38383a),
onSecondaryContainer = Color(0xfff4f4f5),
onBackground = Color(0xfff4f4f5),
onSurface = Color(0xfff4f4f5),
onSurfaceVariant = Color(0xffa1a1aa),
surfaceVariant = Color(0xff242424),
surfaceDim = Color.Black,
surfaceBright = Color(0xff333333),
surfaceContainerLowest = Color.Black,
surfaceContainerLow = Color(0xff1c1c1e),
surfaceContainer = Color(0xff222224),
surfaceContainerHigh = Color(0xff28282a),
surfaceContainerHighest = Color(0xff303032),
)

fun colorScheme(dark: Boolean, darkTheme: String): ColorScheme = when {
!dark -> lightScheme
darkTheme == "solarized" -> darkScheme
else -> blackScheme
}

fun semanticColors(scheme: ColorScheme): Map<String, Color> {
val groupedRowBackground = if (scheme.background == darkSurface) {
Color.White.copy(alpha = 0.08f).compositeOver(scheme.background)
} else {
val groupedRowBackground = if (scheme.background == lightScheme.background) {
Color.White
} else {
Color.White.copy(alpha = 0.08f).compositeOver(scheme.background)
}
return mapOf(
"background" to scheme.background,
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="app_background">#101318</color>
<color name="app_background">#000000</color>
<color name="widget_background">#1B1B1F</color>
<color name="widget_on_surface">#E5E1E9</color>
<color name="widget_secondary">#C8C5CE</color>
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<resources>
<style name="SystemBarThemeBase" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:colorBackground">@color/app_background</item>
<item name="android:statusBarColor">#101318</item>
<item name="android:navigationBarColor">#101318</item>
<item name="android:statusBarColor">@color/app_background</item>
<item name="android:navigationBarColor">@color/app_background</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightStatusBar">false</item>
</style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"appearances": [{ "appearance": "luminosity", "value": "dark" }],
"color": { "color-space": "srgb", "components": { "red": "0.000", "green": "0.1764705882", "blue": "0.2196078431", "alpha": "1.000" } },
"color": { "color-space": "srgb", "components": { "red": "0.000", "green": "0.000", "blue": "0.000", "alpha": "1.000" } },
"idiom": "universal"
}
],
Expand Down
25 changes: 0 additions & 25 deletions apple/App/Assets.xcassets/LaunchLogo.imageset/Contents.json

This file was deleted.

Binary file not shown.
Binary file not shown.
3 changes: 0 additions & 3 deletions apple/App/Assets.xcassets/LaunchLogo.imageset/README.md

This file was deleted.

7 changes: 2 additions & 5 deletions apple/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
<dict>
<key>UILaunchScreen</key>
<dict>
<!-- Use a blank system launch canvas. Rename the asset if its background changes to refresh stored snapshots. -->
<key>UIColorName</key>
<string>LaunchBackground</string>
<key>UIImageName</key>
<string>LaunchLogo</string>
<key>UIImageRespectsSafeAreaInsets</key>
<false/>
<string>LaunchCanvas</string>
</dict>
<key>LogseqRevision</key>
<string>$(LOGSEQ_BUILD_REVISION)</string>
Expand Down
1 change: 1 addition & 0 deletions apple/Sources/Logseq/LGEffects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public struct LGEffectResolution: Equatable, Sendable {

public struct LGSettingsPayload: Decodable, Equatable, Sendable {
public let appearance: String
public let darkTheme: String?
public let language: String
public let spellCheck: Bool
public let autoCorrection: Bool
Expand Down
7 changes: 5 additions & 2 deletions apple/Sources/Logseq/LGMediaPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct LGMediaPanel: View {
let onPhotoData: (Data, String) -> Void
@Environment(\.dismiss) private var dismiss
@Environment(\.colorScheme) private var colorScheme
@Environment(\.logseqDarkTheme) private var darkTheme
@State private var mode: LGAttachmentService
@State private var selection: [PhotosPickerItem] = []
@State private var allPhotos = false
Expand All @@ -22,7 +23,9 @@ struct LGMediaPanel: View {
@State private var isImporting = false

private var isDark: Bool { colorScheme == .dark }
private var sheetBackground: Color { LogseqThemePolicy.sheetBackground(isDark: isDark) }
private var sheetBackground: Color {
LogseqThemePolicy.sheetBackground(isDark: isDark, darkTheme: darkTheme)
}

init(initialService: LGAttachmentService,
onPhotos: @escaping ([PhotosPickerItem]) -> Void,
Expand Down Expand Up @@ -170,7 +173,7 @@ struct LGMediaPanel: View {
.background {
Circle().fill(mode == .camera
? Color.black.opacity(0.35)
: (isDark ? LogseqThemePolicy.dark : LogseqThemePolicy.light).surface)
: (isDark ? LogseqThemePolicy.darkPalette(darkTheme) : LogseqThemePolicy.light).surface)
}
}

Expand Down
Loading
Loading