Skip to content

Commit

Permalink
feat: Support switch back to legacy view
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Nov 27, 2022
1 parent 65a9964 commit bde8e75
Show file tree
Hide file tree
Showing 26 changed files with 1,709 additions and 407 deletions.
6 changes: 6 additions & 0 deletions xmcl-keystone-ui/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ instanceTemplate:
title: Template Setting
instances:
add: Add Local Game
choose: Select Instance
importFolder: Import from Folder
importFolderDescription: Import Minecraft to Launcher
refreshServers: Refresh Servers
Expand Down Expand Up @@ -947,6 +948,11 @@ setting:
language: Language
languageDescription: The display language
latestVersion: Latest Version
layout:
default: Default Layout
focus: Focus Layout
layoutDescription: The launcher layout reprensenting different UI logic
layoutTitle: Layout
location: Store Location
maxSockets: Per Host
maxSocketsDescription: >-
Expand Down
6 changes: 6 additions & 0 deletions xmcl-keystone-ui/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ instanceTemplate:
title: 模板设置
instances:
add: 新建本地游戏
choose: 选择实例
importFolder: 从文件夹导入
importFolderDescription: 导入 Minecraft 到启动器
refreshServers: 刷新服务器
Expand Down Expand Up @@ -944,6 +945,11 @@ setting:
language: 语言
languageDescription: 当前显示的语言
latestVersion: 最新版本
layout:
default: 默认布局
focus: 聚焦布局
layoutDescription: 不同的布局有不同的UI交互逻辑
layoutTitle: 布局
location: 数据存储位置
maxSockets: (每个网站)最大连接数
maxSocketsDescription: 控制最大的并发 HTTP 链接数量。0 代表不限制数量。
Expand Down
4 changes: 1 addition & 3 deletions xmcl-keystone-ui/src/composables/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ export function useInstanceIsServer(i: Ref<Instance>) {
* Use the general info of the instance
*/
export function useInstance() {
const { state, editInstance } = useService(InstanceServiceKey)
const { state } = useService(InstanceServiceKey)

const instance = computed(() => state.instance)
const path = computed(() => state.path)
return {
path,
instance,
refreshing: computed(() => useSemaphore('instance').value !== 0),
editInstance,
...useServiceOnly(InstanceIOServiceKey, 'exportInstance'),
}
}

Expand Down
26 changes: 26 additions & 0 deletions xmcl-keystone-ui/src/composables/instanceContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { InjectionKey } from 'vue'
import { useInstance, useInstanceVersion } from './instance'
import { useLaunchIssue } from './launchIssue'
import { useLaunchTask } from './launchTask'

export function useInstanceContext() {
const issue = useLaunchIssue()
const task = useLaunchTask()
const { path, instance, refreshing } = useInstance()
const name = computed(() => instance.value.name)
const version = computed(() => instance.value.runtime)
const { localVersion } = useInstanceVersion()

return {
issue,
task,
path,
name,
version,
localVersion,
instance,
refreshing,
}
}

export const kInstanceContext: InjectionKey<ReturnType<typeof useInstanceContext>> = Symbol('InstanceContext')
33 changes: 33 additions & 0 deletions xmcl-keystone-ui/src/composables/launchIssue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AssetIndexIssueKey, AssetsIssueKey, InstallProfileIssueKey, isIssue, LibrariesIssueKey, VersionIssueKey, VersionJarIssueKey, VersionJsonIssueKey } from '@xmcl/runtime-api'
import { useIssues } from './issues'

export function useLaunchIssue() {
const { issues } = useIssues()
const issue = computed(() => {
for (const i of issues.value) {
if (isIssue(AssetsIssueKey, i)) {
return i
}
if (isIssue(LibrariesIssueKey, i)) {
return i
}
if (isIssue(AssetIndexIssueKey, i)) {
return i
}
if (isIssue(VersionIssueKey, i)) {
return i
}
if (isIssue(VersionJsonIssueKey, i)) {
return i
}
if (isIssue(VersionJarIssueKey, i)) {
return i
}
if (isIssue(InstallProfileIssueKey, i)) {
return i
}
}
return undefined
})
return issue
}
44 changes: 44 additions & 0 deletions xmcl-keystone-ui/src/composables/launchTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { TaskState } from '@xmcl/task'
import { useInstance, useInstanceVersion } from './instance'
import { useTask } from './task'

export function useLaunchTask() {
const { path, instance } = useInstance()
const version = computed(() => instance.value.runtime)
const { localVersion } = useInstanceVersion()
return useTask((i) => {
const p = i.param as any
if (i.state === TaskState.Cancelled || i.state === TaskState.Succeed || i.state === TaskState.Failed) {
return false
}
if (i.path === 'installVersion' && p?.id === version.value.minecraft) {
return true
}
if (i.path === 'installVersion.jar' && (p?.id === localVersion.value.id || p?.id === version.value.minecraft)) {
return true
}
if (i.path === 'installLibraries' && (p?.id === localVersion.value.id || p?.id === version.value.minecraft)) {
return true
}
if (i.path === 'installAssets' && (p?.id === localVersion.value.id || p?.id === version.value.minecraft || p?.id === version.value.minecraft.substring(version.value.minecraft.lastIndexOf('.')))) {
return true
}
if (i.path === 'installForge' && (p?.id === version.value.forge || p?.id === localVersion.value.id)) {
return true
}
if (i.path === 'installOptifine' && p?.id === version.value.optifine) {
return true
}
if (i.path === 'installByProfile' && p?.id === localVersion.value.id) {
return true
}
if (i.path === 'installFabric' && p?.id === version.value.minecraft) {
return true
}
if (i.path === 'installInstance' && p.instance === path.value) {
// installing this instance
return true
}
return false
})
}
5 changes: 5 additions & 0 deletions xmcl-keystone-ui/src/composables/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export function useUpdateSettings() {
}
}

export function useInFocusMode() {
const { state } = useService(BaseServiceKey)
return computed(() => state.layout === 'focus')
}

export function useSettings() {
const { state } = useService(BaseServiceKey)

Expand Down

0 comments on commit bde8e75

Please sign in to comment.