Skip to content

Commit

Permalink
fix: Logger window dark mode button is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jun 19, 2024
1 parent b829a63 commit 0d40516
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 176 deletions.
14 changes: 7 additions & 7 deletions xmcl-electron-app/main/ElectronController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ export class ElectronController implements LauncherAppController {
trafficLightPosition: this.app.platform.os === 'osx' ? { x: 14, y: 10 } : undefined,
minWidth: 400,
minHeight: 600,
width: Math.max(config.width || 0, 400),
height: Math.max(config.height || 0, 600),
width: config.getWidth(400),
height: config.getHeight(600),
x: config.x,
y: config.y,
show: false,
Expand Down Expand Up @@ -420,8 +420,8 @@ export class ElectronController implements LauncherAppController {

const browser = new BrowserWindow({
title: man.name,
width: (config.width || 0) < minWidth ? minWidth : config.width,
height: (config.height || 0) < minHeight ? minHeight : config.height,
width: config.getWidth(minWidth),
height: config.getHeight(minHeight),
minWidth: man.minWidth,
minHeight: man.minHeight,
frame: this.getFrameOption(),
Expand Down Expand Up @@ -489,8 +489,8 @@ export class ElectronController implements LauncherAppController {
const config = await tracker.getConfig()
const browser = new BrowserWindow({
title: 'KeyStone Monitor',
width: config.width,
height: config.height,
width: config.getWidth(600),
height: config.getHeight(400),
x: config.x,
y: config.y,
minWidth: 600,
Expand All @@ -502,7 +502,7 @@ export class ElectronController implements LauncherAppController {
icon: darkIcon,
webPreferences: {
preload: monitorPreload,
session: session.fromPartition('persist:logger'),
session: await this.getSharedSession(),
},
})

Expand Down
6 changes: 6 additions & 0 deletions xmcl-electron-app/main/utils/windowSizeTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export function createWindowTracker(app: LauncherApp, role: string, man: Install
height: undefined as undefined | number,
x: undefined as undefined | number,
y: undefined as undefined | number,
getWidth(min: number) {
return Math.max(this.width || 0, min)
},
getHeight(min: number) {
return Math.max(this.height || 0, min)
},
}
async function getConfig() {
const configData = await readFile(configPath, 'utf-8').then((v) => JSON.parse(v)).catch(() => ({
Expand Down
5 changes: 2 additions & 3 deletions xmcl-keystone-ui/src/components/MarketProjectDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,13 @@
<script setup lang="ts">
import unknownServer from '@/assets/unknown_server.png'
import Hint from '@/components/Hint.vue'
import { kVuetify } from '@/composables/vuetify'
import { injection } from '@/util/inject'
import { getExpectedSize } from '@/util/size'
import ModDetailVersion, { ProjectVersion } from './MarketProjectDetailVersion.vue'
import AppCopyChip from './AppCopyChip.vue'
import { kImageDialog } from '@/composables/imageDialog'
import { useDateString } from '@/composables/date'
import { kTheme } from '@/composables/theme'

const props = defineProps<{
detail: ProjectDetail
Expand Down Expand Up @@ -801,8 +801,7 @@ const goCurseforgeProject = (id: number) => {
const goModrinthProject = (id: string) => {
replace({ query: { ...currentRoute.query, id: `modrinth:${id}` } })
}
const vuetify = injection(kVuetify)
const isDark = computed(() => vuetify.theme.dark)
const { isDark } = injection(kTheme)

const selectedVersion = inject('selectedVersion', ref(props.versions.find(v => v.installed) || props.versions[0] as ProjectVersion | undefined))
const onVersionClicked = (version: ProjectVersion) => {
Expand Down
6 changes: 0 additions & 6 deletions xmcl-keystone-ui/src/composables/compatible.ts

This file was deleted.

64 changes: 3 additions & 61 deletions xmcl-keystone-ui/src/composables/curseforgeInstall.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import { clientCurseforgeV1 } from '@/util/clients'
import { injection } from '@/util/inject'
import { generateDistinctName } from '@/util/instanceName'
import { resolveModpackInstanceConfig } from '@/util/modpackFilesResolver'
import { File, FileIndex, HashAlgo } from '@xmcl/curseforge'
import { CurseForgeServiceKey, CurseforgeUpstream, InstanceInstallServiceKey, InstanceServiceKey, ModpackServiceKey, ProjectType, Resource, ResourceServiceKey, getCurseforgeFileUri } from '@xmcl/runtime-api'
import { InjectionKey, Ref } from 'vue'
import { getCurseforgeProjectModel } from './curseforge'
import { useDialog } from './dialog'
import { File, HashAlgo } from '@xmcl/curseforge'
import { CurseForgeServiceKey, CurseforgeUpstream, InstanceInstallServiceKey, InstanceServiceKey, ModpackServiceKey, Resource, ResourceServiceKey, getCurseforgeFileUri } from '@xmcl/runtime-api'
import { Ref } from 'vue'
import { kInstanceFiles } from './instanceFiles'
import { AddInstanceDialogKey } from './instanceTemplates'
import { InstanceInstallDialog } from './instanceUpdate'
import { kInstanceVersionDiagnose } from './instanceVersionDiagnose'
import { kInstances } from './instances'
import { useNotifier } from './notifier'
import { useResourceUrisDiscovery } from './resources'
import { useService } from './service'
import { useSWRVModel } from './swrv'

export const kCurseforgeInstall: InjectionKey<ReturnType<typeof useCurseforgeInstall>> = Symbol('CurseforgeInstall')

export function useCurseforgeInstanceResource() {
const { getResourceByHash, getResourcesByUris } = useService(ResourceServiceKey)
Expand Down Expand Up @@ -53,54 +43,6 @@ export function useCurseforgeInstanceResource() {
}
}

export function useCurseforgeInstall(modId: Ref<number>, files: Ref<Pick<File, 'modId' | 'id'>[]>, from: Ref<string | undefined>, type: Ref<ProjectType>, currentFileResource: Ref<Resource | undefined>) {
const { install: installResource } = useService(ResourceServiceKey)
const { t } = useI18n()
const { notify } = useNotifier()
const { installFile } = useService(CurseForgeServiceKey)

const { show: showAddInstanceDialog } = useDialog(AddInstanceDialogKey)
const { show: showInstanceUpdateDialog } = useDialog(InstanceInstallDialog)
const { resources } = useResourceUrisDiscovery(computed(() => files.value.map(getCurseforgeFileUri)))
const isDownloaded = (file: Pick<File, 'modId' | 'id'>) => {
return !!resources.value[getCurseforgeFileUri(file)]
}
const { data: project } = useSWRVModel(getCurseforgeProjectModel(modId))
async function install(input: File | FileIndex) {
const file = 'modId' in input ? input : await clientCurseforgeV1.getModFile(modId.value, input.fileId)
const resource = resources.value[getCurseforgeFileUri(file)]
if (resource) {
if (currentFileResource.value) {
showInstanceUpdateDialog({
type: 'curseforge',
currentResource: currentFileResource.value,
resource,
})
} else if (type.value === 'modpacks') {
showAddInstanceDialog({ type: 'resource', resource })
} else if (from.value) {
installResource({ instancePath: from.value, resource }).then(() => {
notify({ title: t('installResource.success', { file: resource.fileName }), level: 'success', full: true })
}, (e) => {
notify({
title: t('installResource.fail', { file: resource.fileName }),
level: 'error',
body: e.toString(),
full: true,
})
})
}
} else {
await installFile({ file, type: type.value, icon: project.value?.logo.url, instancePath: from.value })
}
}
return {
install,
resources,
isDownloaded,
}
}

export function useCurseforgeInstallModpack(icon: Ref<string | undefined>) {
const { instances, selectedInstance } = injection(kInstances)
const { getModpackInstallFiles } = useService(ModpackServiceKey)
Expand Down
39 changes: 0 additions & 39 deletions xmcl-keystone-ui/src/composables/curseforgeResource.ts

This file was deleted.

10 changes: 2 additions & 8 deletions xmcl-keystone-ui/src/composables/vuetify.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { InjectionKey } from 'vue'
import { Framework } from 'vuetify'
import { injection } from '../util/inject'
import colors from 'vuetify/lib/util/colors'

export const kVuetify: InjectionKey<Framework> = Symbol('vuetify')
import { vuetify } from '@/vuetify'

export function useVuetifyColor() {
const vuetify = injection(kVuetify)

const getColorCode = (code: string) => {
return vuetify.theme.currentTheme[code] ?? (colors as any)[code]?.base ?? ''
return vuetify.framework.theme.currentTheme[code] ?? (colors as any)[code]?.base ?? ''
}

return {
Expand Down
14 changes: 3 additions & 11 deletions xmcl-keystone-ui/src/views/Setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,15 @@
<script lang=ts setup>
import { useService } from '@/composables'
import { useBootstrap } from '@/composables/bootstrap'
import { kVuetify } from '@/composables/vuetify'
import { injection } from '@/util/inject'
import { BaseServiceKey, Drive } from '@xmcl/runtime-api'
import SetupAppearance from './SetupAppearance.vue'
import SetDataRoot from './SetupDataRoot.vue'
import SetupFooter from './SetupFooter.vue'
import SetupAccount from './SetupAccount.vue'
import SetLocale from './SetupLocale.vue'
import { usePreferredDark } from '@vueuse/core'
import { kSettingsState } from '@/composables/setting'
import { kTheme } from '@/composables/theme'
const emit = defineEmits(['ready'])
const { validateDataDictionary } = useService(BaseServiceKey)
Expand Down Expand Up @@ -176,17 +175,10 @@ watch(() => data.path, (newPath) => {
})
})
const vuetify = injection(kVuetify)
const preferDark = usePreferredDark()
const { darkTheme } = injection(kTheme)
const updateTheme = (theme: 'dark' | 'system' | 'light') => {
if (theme === 'system') {
vuetify.theme.dark = preferDark.value
} else if (theme === 'dark') {
vuetify.theme.dark = true
} else if (theme === 'light') {
vuetify.theme.dark = false
}
darkTheme.value = theme
}
updateTheme(data.theme as any)
Expand Down
8 changes: 4 additions & 4 deletions xmcl-keystone-ui/src/views/SetupAppearance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
@click="toggle"
>
<SetupLayoutPreview
:dark="vuetify.theme.dark"
:dark="isDark"
:type="'default'"
/>
</v-card>
Expand All @@ -81,7 +81,7 @@
@click="toggle"
>
<SetupLayoutPreview
:dark="vuetify.theme.dark"
:dark="isDark"
:type="'focus'"
/>
</v-card>
Expand All @@ -104,14 +104,14 @@
</template>
<script lang=ts setup>
import SetupLayoutPreview from '@/components/SetupLayoutPreview.vue'
import { kTheme } from '@/composables/theme'
import { kUILayout } from '@/composables/uiLayout'
import { kVuetify } from '@/composables/vuetify'
import { injection } from '@/util/inject'
defineProps<{ value: string }>()
const data = injection('setup' as any) as any
const vuetify = injection(kVuetify)
const { isDark } = injection(kTheme)
const layoutModel = computed({
get() { return layout.value === 'default' ? 0 : 1 },
Expand Down
6 changes: 3 additions & 3 deletions xmcl-keystone-ui/src/windows/app/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<v-app
class="h-full max-h-[100vh] overflow-auto overflow-x-hidden"
:class="{ 'dark': vuetify.theme.dark }"
:class="{ 'dark': isDark }"
>
<AppSystemBar
no-task
Expand All @@ -27,13 +27,13 @@ import '@/assets/common.css'
import AppSharedTooltip from '@/components/AppSharedTooltip.vue'
import { useDefaultErrorHandler } from '@/composables/errorHandler'
import { useNotifier } from '@/composables/notifier'
import { kVuetify } from '@/composables/vuetify'
import { kTheme } from '@/composables/theme'
import { injection } from '@/util/inject'
import AppContextMenu from '@/views/AppContextMenu.vue'
import AppSystemBar from '@/views/AppSystemBar.vue'
import Multiplayer from '@/views/Multiplayer.vue'
const vuetify = injection(kVuetify)
const { isDark } = injection(kTheme)
const { notify } = useNotifier()
useDefaultErrorHandler(notify)
Expand Down
2 changes: 0 additions & 2 deletions xmcl-keystone-ui/src/windows/app/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import { kTheme, useTheme } from '@/composables/theme'
import { kUILayout, useUILayout } from '@/composables/uiLayout'
import { kUserContext, useUserContext } from '@/composables/user'
import { kLocalVersions, useLocalVersions } from '@/composables/versionLocal'
import { kVuetify } from '@/composables/vuetify'
import { vuetify } from '@/vuetify'
import 'virtual:windi.css'
import { provide } from 'vue'

export default defineComponent({
setup(props, ctx) {
provide(kVuetify, vuetify.framework)
provide(kExceptionHandlers, useExceptionHandlers())
provide(kServerStatusCache, useServerStatusCache())
provide(kNotificationQueue, useNotificationQueue())
Expand Down
2 changes: 0 additions & 2 deletions xmcl-keystone-ui/src/windows/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { kServiceFactory, useServiceFactory } from '@/composables'
import { kDialogModel, useDialogModel } from '@/composables/dialog'
import { kSWRVConfig, useSWRVConfig } from '@/composables/swrvConfig'
import { kTaskManager, useTaskManager } from '@/composables/taskManager'
import { kVuetify } from '@/composables/vuetify'
import { i18n } from '@/i18n'
import { vuetify } from '@/vuetify'
import 'virtual:windi.css'
Expand All @@ -22,7 +21,6 @@ const app = new Vue(defineComponent({
i18n,
vuetify,
setup() {
provide(kVuetify, vuetify.framework)
provide(kServiceFactory, useServiceFactory())
provide(kDialogModel, useDialogModel())
provide(kSWRVConfig, useSWRVConfig())
Expand Down
Loading

0 comments on commit 0d40516

Please sign in to comment.