Skip to content

Commit

Permalink
修正加载顺序问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanxven committed Oct 24, 2024
1 parent e9f35c2 commit a443379
Show file tree
Hide file tree
Showing 30 changed files with 1,102 additions and 827 deletions.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

15 changes: 0 additions & 15 deletions .idea/league-akari.iml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/prettier.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

Binary file modified .yarn/install-state.gz
Binary file not shown.
77 changes: 77 additions & 0 deletions resources/update.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@echo off
chcp 65001 >nul

if "%~1"=="" goto :EOF
if "%~2"=="" goto :EOF
if "%~3"=="" goto :EOF

set "SOURCE_A=%~1"
set "TARGET_C=%~2"
set "EXECUTABLE_NAME=%~3"

:: Wait for a specific process to end
echo Waiting for process %EXECUTABLE_NAME% to end...
:WAIT_PROCESS
set "PROCESS_NAME=%EXECUTABLE_NAME%"
tasklist | find /i "%PROCESS_NAME%" >nul
if not errorlevel 1 (
timeout /t 1 >nul
goto :WAIT_PROCESS
)

echo Process %EXECUTABLE_NAME% has ended.

:: Get directory B (the parent directory of C)
echo Getting the parent directory of target %TARGET_C%...
for %%I in ("%TARGET_C%") do (
set "DEST_B=%%~dpI"
)

:: Remove trailing backslash
set "DEST_B=%DEST_B:~0,-1%"

:: Check if source directory A exists, if not, exit
echo Checking if source directory %SOURCE_A% exists...
if not exist "%SOURCE_A%" goto :EOF

echo Source directory %SOURCE_A% exists.

:: Copy directory A to B
echo Copying directory %SOURCE_A% to %DEST_B%\A...
xcopy /E /I /Y "%SOURCE_A%" "%DEST_B%\A" >nul

echo Copy completed.

:: Delete target directory C (if it exists)
echo Deleting target directory %TARGET_C% (if it exists)...
if exist "%TARGET_C%" (
rd /S /Q "%TARGET_C%"
echo Target directory %TARGET_C% has been deleted.
)

:: Rename directory A in B to C
echo Renaming %DEST_B%\A to %~nx2...
rename "%DEST_B%\A" "%~nx2"
echo Rename completed.

:: Delete original directory A
echo Deleting original directory %SOURCE_A%...
rd /S /Q "%SOURCE_A%"
echo Original directory %SOURCE_A% has been deleted.

:: Change to new C directory
echo Changing to new target directory %TARGET_C%...
pushd "%TARGET_C%"

:: Start executable without waiting for it to finish
echo Starting executable %EXECUTABLE_NAME%...
start "" "%EXECUTABLE_NAME%"
echo Executable has been started.

:: Return to previous directory
echo Returning to the previous directory...
popd

:: Delete the script itself
echo Deleting the script itself...
del /f /q "%~f0"
40 changes: 32 additions & 8 deletions src/main/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RiotClientMain } from '@main/shards/riot-client'
import { SavedPlayerMain } from '@main/shards/saved-player'
import { SelfUpdateMain } from '@main/shards/self-update'
import { SettingFactoryMain } from '@main/shards/setting-factory'
import { SettingMigrateMain } from '@main/shards/setting-migrate'
import { SgpMain } from '@main/shards/sgp'
import { StorageMain } from '@main/shards/storage'
import { TrayMain } from '@main/shards/tray'
Expand All @@ -31,10 +32,10 @@ import relativeTime from 'dayjs/plugin/relativeTime'
import { app, dialog, protocol } from 'electron'
import { configure } from 'mobx'
import EventEmitter from 'node:events'
import { Logger } from 'winston'
import { Logger, level } from 'winston'

import toolkit from '../../native/laToolkitWin32x64.node'
import { readBaseConfig, writeBaseConfig } from './base-config'
import toolkit from '../native/la-tools-win64.node'
import { BaseConfig, readBaseConfig, writeBaseConfig } from './base-config'

interface AkariAppEventMap {
'second-instance': [commandLine: string[], workingDirectory: string]
Expand All @@ -61,9 +62,20 @@ declare module '@shared/akari-shard/manager' {
* 基础全局设置
*/
baseConfig: {
value: any
write: (config: any) => void
value: BaseConfig | null
write: (config: BaseConfig) => void
}

/**
* 退出应用
*/
quit: () => void

/**
* app.relaunch() + app.quit()
* @returns
*/
restart: () => void
}
}

Expand Down Expand Up @@ -148,17 +160,24 @@ export function bootstrap() {
write: (config: any) => writeBaseConfig(config)
}
manager.global.isAdministrator = isAdministrator
manager.global.quit = () => app.quit()
manager.global.restart = () => {
app.relaunch()
app.quit()
}

manager.use(
// basic fundamental shards
AkariIpcMain,
AppCommonMain,
LoggerFactoryMain,
MobxUtilsMain,
// SettingMigrateMain, // TODO
SettingFactoryMain,
StorageMain,

// connection & data provider shards
AkariProtocolMain,
GameClientMain,
LeagueClientMain,
LeagueClientUxMain,
Expand All @@ -174,7 +193,6 @@ export function bootstrap() {
AutoGameflowMain,
AutoReplyMain,
AutoSelectMain,
AutoSelectMain,
OngoingGameMain,
RespawnTimerMain,
SavedPlayerMain,
Expand Down Expand Up @@ -203,7 +221,8 @@ export function bootstrap() {
namespace: 'akari-shard-manager'
})
dialog.showErrorBox('功能初始化时出现错误', formatError(error))
app.exit(10002)
logger.on('finish', () => app.exit(10002))
logger.end()
}
})

Expand All @@ -230,6 +249,10 @@ export function bootstrap() {
.finally(() => {
shardDisposed = true
events.removeAllListeners()
logger.info({
message: `应用退出`,
namespace: 'bootstrap'
})
logger.on('finish', () => app.quit())
logger.end()
})
Expand All @@ -240,6 +263,7 @@ export function bootstrap() {
namespace: 'bootstrap'
})
dialog.showErrorBox('应用启动时出现错误', formatError(error))
app.exit(10001)
logger.on('finish', () => app.exit(10001))
logger.end()
}
}
57 changes: 57 additions & 0 deletions src/main/main copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'reflect-metadata'

import { electronApp } from '@electron-toolkit/utils'
import { AKARI_USER_MODEL_ID } from '@shared/constants/common'
import { formatError } from '@shared/utils/errors'
import { app, dialog } from 'electron'
import { configure } from 'mobx'
import EventEmitter from 'node:events'

import { bootstrap } from './bootstrap'
import { setupLeagueAkariModules } from './modules'
import { appModule } from './modules/app'
import { logModule } from './modules/log'
import { mainWindowModule } from './modules/main-window'

// EventEmitter.defaultMaxListeners = 1000

// configure({ enforceActions: 'observed' })

// const logger = logModule.createLogger('init')

// const gotTheLock = app.requestSingleInstanceLock()

// if (!gotTheLock) {
// logger.info(`League Akari 已启动,将退出当前实例`)
// app.quit()
// }

// appModule.registerAkariProtocolAsPrivileged()

// const baseConfig = appModule.readBaseConfig()
// if (
// baseConfig &&
// baseConfig.disableHardwareAcceleration &&
// baseConfig.disableHardwareAcceleration === true
// ) {
// logger.info('禁用硬件加速')
// app.disableHardwareAcceleration()
// }

// app.whenReady().then(async () => {
// electronApp.setAppUserModelId(AKARI_USER_MODEL_ID)
// appModule.state.setReady(true)

// try {
// logger.info(`League Akari ${app.getVersion()}`)
// await setupLeagueAkariModules()
// mainWindowModule.createWindow()
// } catch (e) {
// logger.error(`初始化时出现错误 ${formatError(e)}`)
// dialog.showErrorBox('在初始化时出现错误', e && (e as any).message)
// app.quit()
// }
// })

// 新的启动方式
bootstrap()
54 changes: 1 addition & 53 deletions src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,5 @@
import 'reflect-metadata'

import { electronApp } from '@electron-toolkit/utils'
import { AKARI_USER_MODEL_ID } from '@shared/constants/common'
import { formatError } from '@shared/utils/errors'
import { app, dialog } from 'electron'
import { configure } from 'mobx'
import EventEmitter from 'node:events'

import { setupLeagueAkariModules } from './modules'
import { appModule } from './modules/app'
import { logModule } from './modules/log'
import { mainWindowModule } from './modules/main-window'
import { bootstrap } from './bootstrap'

EventEmitter.defaultMaxListeners = 1000

configure({ enforceActions: 'observed' })

const logger = logModule.createLogger('init')

const gotTheLock = app.requestSingleInstanceLock()

if (!gotTheLock) {
logger.info(`League Akari 已启动,将退出当前实例`)
app.quit()
}

appModule.registerAkariProtocolAsPrivileged()

const baseConfig = appModule.readBaseConfig()
if (
baseConfig &&
baseConfig.disableHardwareAcceleration &&
baseConfig.disableHardwareAcceleration === true
) {
logger.info('禁用硬件加速')
app.disableHardwareAcceleration()
}

app.whenReady().then(async () => {
electronApp.setAppUserModelId(AKARI_USER_MODEL_ID)
appModule.state.setReady(true)

try {
logger.info(`League Akari ${app.getVersion()}`)
await setupLeagueAkariModules()
mainWindowModule.createWindow()
} catch (e) {
logger.error(`初始化时出现错误 ${formatError(e)}`)
dialog.showErrorBox('在初始化时出现错误', e && (e as any).message)
app.quit()
}
})

// 新的启动方式
// bootstrap()
bootstrap()
2 changes: 1 addition & 1 deletion src/main/node-addon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ declare module '@main/native/la-input-win64.node' {
* 将会收到类似于 `132,DOWN` 或 `132,UP` 的类似的字符串
* @param cb 回调
*/
OnKeyEvent(cb: (raw: string) => void): void
onKeyEvent(cb: (raw: string) => void): void

/**
* 开始和停止监听
Expand Down
Loading

0 comments on commit a443379

Please sign in to comment.