Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Add quick launch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirasawaSama committed Apr 29, 2020
1 parent 3a176dd commit 2884a16
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 265 deletions.
2 changes: 1 addition & 1 deletion .github/actions/upload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const { promisify } = require('util')
Body: hashesData
})
try {
core.info(await new Refresher(options).purgeDirsCache('https://dl.pl.apisium.cn/'))
core.info(JSON.stringify(await new Refresher(options).purgeDirsCache('https://dl.pl.apisium.cn/')))
} catch (e) {
core.warning(e)
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Use taobao registry:
set REGISTRY=https://registry.npm.taobao.org/
set dist-url=http://npm.taobao.org/mirrors/atom-shell
set ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/
set ELECTRON_CUSTOM_DIR=8.2.3
set ELECTRON_CUSTOM_DIR=8.2.4
```

### Development
Expand Down
2 changes: 1 addition & 1 deletion app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pure-launcher",
"main": "main.js",
"private": true,
"version": "0.0.2",
"version": "0.0.3",
"author": "Shirasawa",
"description": "An awesome Minecraft Launcher."
}
3 changes: 3 additions & 0 deletions langs/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"Servers": "服务器",
"Worlds": "地图",
"world": "地图",
"Quick Launch": "快速启动",
"ShaderPacks": "光影",
"shader pack": "光影",
"Clear": "清理已完成项",
Expand All @@ -39,12 +40,14 @@
"Launching...": "启动中...",
"Downloading...": "下载中...",
"Download": "下载文件",
"Creating...": "创建中...",
"Preparing...": "准备中...",
"Launched": "游戏运行中",
"Fail to launch": "启动失败",
"No such version:": "没有这个版本:",
"Launching Animation": "启动动画",
"Incorrect java version!": "Java 版本不正确!",
"CREATE SHORTCUT": "创建桌面快捷方式",
"Current account is invalid, please re-login!": "当前帐号已失效, 请重新登陆!",
"Have already logged in? Click here!": "已经登陆了? 点击这里切换账户!",
"ResourcesInstaller": "资源管理和安装器",
Expand Down
346 changes: 113 additions & 233 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pure-launcher",
"private": true,
"version": "0.0.2",
"version": "0.0.3",
"description": "An awesome Minecraft Launcher.",
"main": "dist/src/main.js",
"scripts": {
Expand Down Expand Up @@ -60,16 +60,16 @@
"@types/minimist": "^1.2.0",
"@types/node": "^13.13.4",
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.6",
"@types/react-dom": "^16.9.7",
"@types/react-router-dom": "^5.1.5",
"@types/semver": "^7.1.0",
"@types/url-join": "^4.0.0",
"@types/yauzl": "^2.9.1",
"@types/yazl": "^2.4.2",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"@xmcl/core": "^2.2.0",
"@xmcl/installer": "^2.8.0",
"@xmcl/installer": "^2.8.1",
"@xmcl/nbt": "^2.0.3",
"@xmcl/resourcepack": "^1.0.12",
"@xmcl/task": "^2.1.7",
Expand All @@ -80,8 +80,8 @@
"babel-plugin-module-resolver": "^4.0.0",
"cos-nodejs-sdk-v5": "^2.5.20",
"del-cli": "^3.0.0",
"electron": "^8.2.3",
"electron-builder": "^22.5.1",
"electron": "^8.2.4",
"electron-builder": "^22.6.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
"eslint-config-standard-react": "^9.2.0",
Expand Down Expand Up @@ -140,12 +140,12 @@
"watcherGlob": "**"
},
"browserslist": [
"electron 6.1.6"
"electron 8.0.0"
],
"dependencies": {
"@xmcl/client": "^2.0.5",
"asar": "^3.0.3",
"bili": "^4.9.2",
"bili": "^4.9.4",
"chalk": "^4.0.0",
"fs-extra": "^9.0.0",
"globby": "^11.0.0",
Expand Down
6 changes: 4 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { join } from 'path'
import { ensureDirSync } from 'fs-extra'
import { remote } from 'electron'

export const APP_ROOT = remote.app.getAppPath()
export const UNPACKED_PATH = join(APP_ROOT, 'unpacked')
export const MC_LOGO_PATH = join(UNPACKED_PATH, 'mc-logo.ico')
export const GAME_ROOT = join(process.platform === 'linux' ? remote.app.getPath('home') : remote.app.getPath('appData'),
process.platform === 'darwin' ? 'minecraft' : '.minecraft')
export const APP_PATH = remote.app.getPath('userData')
Expand Down Expand Up @@ -36,12 +39,11 @@ export const RESOURCES_RESOURCE_PACKS_INDEX_PATH = join(RESOURCES_PATH, 'resourc
export const RESOURCES_PLUGINS_INDEX = join(RESOURCES_PATH, 'plugins-index.json')
export const RESOURCES_MODS_INDEX_FILE_NAME = 'mods-index.json'

export const MC_LOGO = join(process.cwd(), 'unpacked/mc-logo.ico')

export const DEFAULT_EXT_FILTER = ['exe', 'com']
export const ALLOW_PLUGIN_EXTENSIONS = ['.js', '.mjs', '.asar']

export const DEFAULT_LOCATE = (navigator.languages[0] || 'zh-cn').toLowerCase()
export const IS_WINDOWS = process.platform === 'win32'

export const LAUNCHING_IMAGE = join(APP_PATH, 'launching.webp')
export const DOWNLOAD_EXE_URL = 'https://dl.pl.apisium.cn/PureLauncher.exe'
Expand Down
12 changes: 10 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { exists } from 'fs'
import { remote, shell } from 'electron'
import { update } from './protocol/check-update'
import { ResourceVersion } from './protocol/types'
import { version } from '../package.json'
import { download, genId, getJson, openServerHome } from './utils/index'
import { TEMP_PATH, DEFAULT_LOCATE, LAUNCHING_IMAGE, LAUNCHER_MANIFEST_URL,
RESOURCES_VERSIONS_INDEX_PATH } from './constants'
RESOURCES_VERSIONS_INDEX_PATH, IS_WINDOWS } from './constants'
import { downloader } from './plugin/DownloadProviders'

const main = document.getElementsByTagName('main')[0]
Expand Down Expand Up @@ -120,7 +121,7 @@ pluginMaster.once('loaded', () => {
process.nextTick(() => (top.style.transition = ''))
}
pluginMaster.emit('rendered')
if (process.platform === 'win32' && !remote.systemPreferences.isAeroGlassEnabled()) {
if (IS_WINDOWS && !remote.systemPreferences.isAeroGlassEnabled()) {
notice({ content: $('Aero is not enabled in the current system, resulting in abnormal GUI!'), error: true })
}
})
Expand Down Expand Up @@ -156,6 +157,13 @@ pluginMaster.once('rendered', () => {
.then((it: Record<string, ResourceVersion>) => it && it[rid] && openServerHome(it[rid].serverHome))
)
.catch(() => {})
console.log(
`%cPureLauncher%c${version}%c Official website: https://pl.apisium.cn\n%cCopyright © 2020 %cApisium%c. All rights reserved.`,
'background-color:#096dd9;padding:2px 7px;border-top-left-radius:3px;border-bottom-left-radius:3px',
'background-color:#389e0d;padding:2px 7px;border-top-right-radius:3px;border-bottom-right-radius:3px',
'', 'color:#aaa;font-size:.6rem', 'font-size:.7rem;font-weight:bold', 'color:#aaa;font-size:.6rem'
)

if (!navigator.onLine) return
const now = Date.now()
const updateCheckTime = parseInt(localStorage.getItem('updateCheckTime'))
Expand Down
4 changes: 2 additions & 2 deletions src/models/GameStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LaunchOption, Version, launch, LaunchPrecheck } from '@xmcl/core/index'
import { Installer } from '@xmcl/installer/index'
import { getVersionTypeText, addTask, installJava, findJavaPath,
getSuitableMemory, isX64, openServerHome } from '../utils/index'
import { GAME_ROOT, LIBRARIES_PATH, VERSIONS_PATH } from '../constants'
import { GAME_ROOT, LIBRARIES_PATH, VERSIONS_PATH, IS_WINDOWS } from '../constants'
import { version as launcherBrand } from '../../package.json'
import { remote, ipcRenderer, BrowserView } from 'electron'
import { getDownloaders } from '../plugin/DownloadProviders'
Expand Down Expand Up @@ -299,7 +299,7 @@ System: ${process.platform} ${release()}, Arch: ${process.arch}`, 'b')
}
if (!javaPath || !await fs.pathExists(javaPath)) {
localStorage.removeItem('javaPath')
if (process.platform === 'win32' && await openConfirmDialog({
if (IS_WINDOWS && await openConfirmDialog({
text: $('Unable to find the Java, do you want to install Java automatically?'),
cancelButton: true
})) {
Expand Down
9 changes: 5 additions & 4 deletions src/models/ProfilesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { YGGDRASIL } from '../plugin/logins'
import { langs, applyLocate } from '../i18n'
import { ResourceVersion } from '../protocol/types'
import { getJavaVersion, cacheSkin, genUUID, vertifyJava, openServerHome } from '../utils/index'
import { LAUNCH_PROFILE_PATH, EXTRA_CONFIG_PATH, MC_LOGO, MODS_PATH, LAUNCH_PROFILE_FILE_NAME, VERSIONS_PATH,
GAME_ROOT, EXTRA_CONFIG_FILE_NAME, RESOURCES_VERSIONS_INDEX_PATH, APP_PATH, DEFAULT_LOCATE } from '../constants'
import { LAUNCH_PROFILE_PATH, EXTRA_CONFIG_PATH, MODS_PATH, LAUNCH_PROFILE_FILE_NAME,
VERSIONS_PATH, MC_LOGO_PATH, IS_WINDOWS, GAME_ROOT, EXTRA_CONFIG_FILE_NAME,
RESOURCES_VERSIONS_INDEX_PATH, APP_PATH, DEFAULT_LOCATE } from '../constants'
import fs from 'fs-extra'
import pAll from 'p-all'
import moment from 'moment'
Expand Down Expand Up @@ -154,7 +155,7 @@ export default class ProfilesStore extends Store {
title: $('Locate Java'),
message: $('Locate the path of Java 8'),
filters: [
{ name: $('Executable File (Javaw)'), extensions: process.platform === 'win32' ? ['exe'] : [''] }
{ name: $('Executable File (Javaw)'), extensions: IS_WINDOWS ? ['exe'] : [''] }
]
})
if (ret.canceled) return
Expand Down Expand Up @@ -403,7 +404,7 @@ export default class ProfilesStore extends Store {
type: 'tasks',
name: $('Recent play'),
items: versions.map(([version, v]) => ({
icon: MC_LOGO,
icon: MC_LOGO_PATH,
type: 'task',
iconIndex: 0,
program: process.execPath,
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export { default as ToolTip } from 'rc-tooltip'
export { default as ReactImage } from 'react-image'
export { default as IconPicker, resolveIcon } from '../components/IconPicker'
export { genId, genUUID, genUUIDOrigin, getJson, fetchJson, makeTempDir, cacheSkin,
isX64, createUnzipTask, openServerHome, getJavaVersion, validPath, sha1, md5, replace,
isX64, createUnzipTask, openServerHome, getJavaVersion, validPath, sha1, md5, replace, createShortcut,
getVersionTypeText, download, getSuitableMemory, unzip, playNoticeSound, removeFormatCodes, reloadPage,
autoNotices, readBuffer, addTask, createDownloadTask, addDirectoryToZipFile } from '../utils/index'
export { STATUS as LAUNCH_STATUS, IconButtonExports, skinView3d, ofs,
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/check-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { remote, ipcRenderer, shell } from 'electron'
import { getJson, download, genId } from '../utils/index'
import { RESOURCES_VERSIONS_INDEX_PATH, RESOURCES_MODS_INDEX_FILE_NAME, ENTRY_POINT_PATH,
RESOURCES_VERSIONS_PATH, ASAR_PATH, RESOURCES_RESOURCE_PACKS_INDEX_PATH, RESOURCES_PLUGINS_INDEX,
LATEST_URL, TEMP_PATH, DOWNLOAD_ASAR_URL, DOWNLOAD_EXE_URL } from '../constants'
LATEST_URL, TEMP_PATH, DOWNLOAD_ASAR_URL, DOWNLOAD_EXE_URL, IS_WINDOWS } from '../constants'

export default async (version: string) => {
const json: T.ResourceVersion = (await fs.readJson(RESOURCES_VERSIONS_INDEX_PATH, { throws: false }) || { })[version]
Expand Down Expand Up @@ -59,7 +59,7 @@ export const updateLauncher = async () => {
analytics.event('update', 'asar')
requestReload(true)
} else {
if (process.platform === 'win32') {
if (IS_WINDOWS) {
if (!downloaded) {
downloaded = join(TEMP_PATH, `PureLauncher-${json.version}-${genId()}.exe`)
await download({
Expand Down
21 changes: 18 additions & 3 deletions src/routes/manager/Versions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import analytics from '../../utils/analytics'
import Loading from '../../components/Loading'
import { join } from 'path'
import { useStore } from 'reqwq'
import { VERSIONS_PATH, RESOURCES_VERSIONS_INDEX_PATH } from '../../constants'
import { VERSIONS_PATH, RESOURCES_VERSIONS_INDEX_PATH, MC_LOGO_PATH, IS_WINDOWS } from '../../constants'
import { exportVersion } from '../../protocol/exporter'
import { uninstallVersion } from '../../protocol/uninstaller'
import { autoNotices } from '../../utils'
import { autoNotices, createShortcut } from '../../utils'
import { clipboard, shell } from 'electron'
import { ResourceVersion } from '../../protocol/types'

Expand Down Expand Up @@ -86,6 +86,21 @@ const VersionEdit: React.FC<{ version: string, onClose: () => void, installed: R
<label>{$('NAME')}</label>
<input name='name' defaultValue={ver.name} placeholder={$('Unnamed')} />
</div>
{IS_WINDOWS && <a
role='link'
className='quick-launch'
onClick={() => {
const text = $('Quick Launch')
notice({ content: $('Creating...') })
const name = ver.name || (ver.type === 'latest-release' ? $('last-release') : ver.type === 'latest-snapshot'
? $('last-snapshot') : ver.lastVersionId || $('No Title'))
autoNotices(createShortcut(`${name} - ${text}`, process.execPath,
JSON.stringify(JSON.stringify({
version: p.version,
type: 'Launch',
secret: localStorage.getItem('analyticsToken')
})), `${text} Minecraft: ${name} (PureLauncher)`, MC_LOGO_PATH))
}}>{$('CREATE SHORTCUT')}</a>}
</form>
<IconPicker onClose={it => (setIcon(it), setOpen(false))} open={open} />
</Dialog>
Expand Down Expand Up @@ -165,7 +180,7 @@ const Versions: React.FC = () => {
const [currentVersion, setCurrentVersion] = useState('')
const pm = useStore(ProfilesStore)
const noTitle = $('No Title')
const unknown = $('Unnamed')
const unknown = $('Unknown')
const lastPlayed = $('Last played')
const lastRelease = $('last-release')
const lastSnapshot = $('last-snapshot')
Expand Down
9 changes: 9 additions & 0 deletions src/routes/manager/list.less
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@
height: 60px;
margin: auto;
}
.quick-launch {
font-size: 12px;
text-decoration: none;
&::after {
content: ' >';
font-size: 13px;
font-family: minecraft;
}
}
}

.resource-packs {
Expand Down
14 changes: 11 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import { ZipFile } from 'yazl'
import { version } from '../../package.json'
import { join, resolve, extname, basename } from 'path'
import { createHash, BinaryLike } from 'crypto'
import { exec } from 'child_process'
import { exec, spawn } from 'child_process'
import { Profile } from '../plugin/Authenticator'
import { Readable } from 'stream'
import { extractTaskFunction } from '@xmcl/unzip/task/index'
import { ILocateJavaHomeOptions, IJavaHomeInfo } from 'locate-java-home/js/es5/lib/interfaces'
import { DEFAULT_EXT_FILTER, SKINS_PATH, TEMP_PATH, LAUNCHER_MANIFEST_URL,
DEFAULT_LOCATE, APP_PATH, GAME_ROOT } from '../constants'
DEFAULT_LOCATE, APP_PATH, GAME_ROOT, UNPACKED_PATH, IS_WINDOWS } from '../constants'
import { DownloadOption } from '@xmcl/installer/index'
import { downloader } from '../plugin/DownloadProviders'
import { genUUIDOrigin } from './analytics'
Expand Down Expand Up @@ -259,7 +259,7 @@ export const vertifyJava = async (version: [string, boolean], dialog = false) =>

const locateJavaAsync: (options: ILocateJavaHomeOptions) => Promise<IJavaHomeInfo[] | null> = promisify(locateJava)
export const findJavaPath = async () => {
const ext = process.platform === 'win32' ? '.exe' : ''
const ext = IS_WINDOWS ? '.exe' : ''
const baseName = (process.platform === 'linux' ? 'java' : 'javaw') + ext
const name = 'bin/' + baseName
let path = join(getSelfInstalledJavaPath(), name)
Expand Down Expand Up @@ -327,3 +327,11 @@ export const watchFile = (path: string, onChange: () => any, time = 5000) => {
.catch(console.error)
return () => f?.close()
}

const CRIPT_FILE = join(UNPACKED_PATH, 'createShortcut.js')
export const createShortcut = (name: string, target: string, args = '', description = '', icon?: string) => {
if (!IS_WINDOWS) return Promise.reject(new Error('It does not running in Windows!'))
return new Promise((resolve, reject) => spawn('cscript', [CRIPT_FILE, name, target,
args.replace(/"/g, '*?#!*'), description, icon || (process.execPath + ', 0')])
.on('error', reject).on('close', resolve))
}
10 changes: 10 additions & 0 deletions unpacked/createShortcut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable no-var */
/* global WScript */
var args = WScript.Arguments
var Shell = WScript.CreateObject('WScript.Shell')
var link = Shell.CreateShortcut(Shell.SpecialFolders('Desktop') + '\\' + args(0) + '.lnk')
link.TargetPath = args(1)
link.Arguments = args(2).replace(/\*\?#!\*/g, '"')
link.Description = args(3)
link.IconLocation = args(4)
link.Save()
Binary file modified unpacked/mc-logo.ico
Binary file not shown.

0 comments on commit 2884a16

Please sign in to comment.