Skip to content

Commit e2d6f4d

Browse files
committed
fix ui & login system
1 parent e8f4bc0 commit e2d6f4d

File tree

11 files changed

+47
-36
lines changed

11 files changed

+47
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tacxtv/miratopia-launcher",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Launcher officiel du serveur Minecraft Miratopia",
55
"main": "dist-electron/main.js",
66
"repository": "https://github.com/tacxtv/miratopia-launcher.git",

src/app.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ nuxt-layout
44
</template>
55

66
<script lang="ts">
7-
import { ref, reactive } from 'vue'
87
import axios from 'axios'
98
import type { Launcher } from '../types/launcher.type'
109
import type { Modpack } from '../types/modpack.type'
1110
1211
// @ts-ignore
1312
export default defineNuxtComponent({
1413
async setup() {
15-
const launcher = (await axios.get('https://raw.githubusercontent.com/tacxtv/miratopia-launcher/config/launcher.json')).data
16-
const modpack = (await axios.get('https://raw.githubusercontent.com/tacxtv/miratopia-launcher/config/modpacks/miratopia/modpack.json')).data
14+
const launcher: Launcher = (await axios.get('https://raw.githubusercontent.com/tacxtv/miratopia-launcher/config/launcher.json')).data
15+
const modpack: Modpack = (await axios.get('https://raw.githubusercontent.com/tacxtv/miratopia-launcher/config/modpacks/miratopia/modpack.json')).data
1716
1817
return {
1918
launcher,

src/components/modpack/display.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export default defineNuxtComponent({
4646
}),
4747
methods: {
4848
openSettings() {
49-
; (this['settings-dialog'] as { data: boolean }).data = true
50-
; (this['settings-tab'] as { data: string }).data = this.modpack.name
49+
(this['settings-dialog'] as { data: boolean }).data = true;
50+
(this['settings-tab'] as { data: string }).data = this.modpack.name;
5151
},
5252
launchMinecraft() {
5353
this.logsDisplay = true

src/components/modpack/settings.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,8 @@ q-card(flat)
8686

8787
<script lang="ts">
8888
import type { PropType } from 'vue'
89-
import { useQuasar } from 'quasar'
9089
import type { Modpack, ModpackFile } from '~~/types/modpack.type'
9190
92-
const $q = useQuasar()
93-
9491
export default defineNuxtComponent({
9592
props: {
9693
modpack: {

src/electron/events/settings.event.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { join } from 'path'
77
import { rmSync } from 'fs'
88

99
const store = new Store()
10+
const root = join(app.getPath('userData'), '/instances')
1011

1112
export class SettingsEvent {
1213
public static name = 'SettingsEvent'
@@ -76,7 +77,7 @@ export class SettingsEvent {
7677
}
7778
})
7879
ipcMain.on('openFolderModPack', (_, modpack: Modpack) => {
79-
shell.showItemInFolder(join(app.getAppPath(), 'instances', modpack.id, 'assets'))
80+
shell.showItemInFolder(join(root, modpack.id))
8081
})
8182

8283
ipcMain.handle('getLauncherStayInOpen', () => {

src/electron/preload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ declare global {
1414
checkForUpdates: () => void
1515
quitAndInstallUpdate: () => void
1616

17-
getAccessToken: () => void
17+
getAccessToken: (reset?: boolean) => void
1818
getAccounts: () => Promise<any[]>
1919
currentAccount: () => Promise<string>
2020
changeAccount: (accountName: string) => Promise<void>
@@ -57,7 +57,7 @@ contextBridge.exposeInMainWorld('electron', {
5757
checkForUpdates: () => ipcRenderer.send('checkForUpdates'),
5858
quitAndInstallUpdate: () => ipcRenderer.send('quitAndInstallUpdate'),
5959

60-
getAccessToken: () => ipcRenderer.send('getAccessToken'),
60+
getAccessToken: (reset?: boolean) => ipcRenderer.send('getAccessToken', !!reset),
6161
getAccounts: () => ipcRenderer.invoke('getAccounts'),
6262
currentAccount: () => ipcRenderer.invoke('currentAccount'),
6363
changeAccount: (accountName: string) => ipcRenderer.send('changeAccount', accountName),

src/electron/services/auth.service.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ export class AuthService {
8181
await AuthService.logout()
8282
})
8383

84-
ipcMain.on('getAccessToken', async () => {
84+
ipcMain.on('getAccessToken', async (event, reset: boolean = false) => {
8585
log.info('storeb', store.store)
8686
log.info('(<any>global).share.auth', (<any>global).share.auth)
87+
if (reset) {
88+
await AuthService.logout(false)
89+
}
8790
await AuthService.authWithMicrosoft()
8891
})
8992

@@ -187,7 +190,7 @@ export class AuthService {
187190
await AuthService.authWithMicrosoft(!changeAccount)
188191
return
189192
}
190-
console.log('transparent', transparent)
193+
// console.log('transparent', transparent)
191194
await AuthService.saveUserInfos(accessToken, refreshToken, mcInfo, transparent)
192195
}
193196

@@ -223,7 +226,7 @@ export class AuthService {
223226
sendLoginWindowWebContent('setLoginBtn', false)
224227
}
225228
})
226-
console.log('authHandler.forwardUrl', authHandler.forwardUrl)
229+
// console.log('authHandler.forwardUrl', authHandler.forwardUrl)
227230
// noinspection ES6MissingAwait
228231
authWindow.loadURL(authHandler.forwardUrl)
229232
const filter = { urls: [REDIRECT_URL] }
@@ -232,7 +235,7 @@ export class AuthService {
232235
authWindowclosedByUser = false
233236
authWindow.close()
234237
const code = details.url.split('=')[1].split('&')[0]
235-
console.log('code', code)
238+
// console.log('code', code)
236239
if (!code) {
237240
log.error('ERROR: The MC code is null.')
238241
sendLoginWindowWebContent('setLoginBtn', false)
@@ -265,7 +268,7 @@ export class AuthService {
265268

266269
public static async refreshCurrentAccessToken(): Promise<void> {
267270
const currAccount = store.get('current-account')
268-
console.log('currAccount', currAccount)
271+
// console.log('currAccount', currAccount)
269272
const accounts: any = store.get('accounts')
270273
const index = accounts.findIndex((account: any) => account.username === currAccount)
271274
await AuthService.loginUser(accounts[index], false, true)
@@ -280,15 +283,18 @@ export class AuthService {
280283
}
281284
}
282285

283-
public static async logout(): Promise<void> {
286+
public static async logout(recreateWindow: boolean = true): Promise<void> {
284287
store.set('current-account', null)
285288
;(<any>global).share.auth.access_token = ''
286289
;(<any>global).share.auth.xuid = ''
287290
;(<any>global).share.auth.uuid = ''
288291
;(<any>global).share.auth.name = ''
289292
await session.defaultSession.clearCache()
290293
await session.defaultSession.clearStorageData()
291-
await createLoginWindow()
292-
destroyMainWindow()
294+
295+
if (recreateWindow) {
296+
await createLoginWindow()
297+
destroyMainWindow()
298+
}
293299
}
294300
}

src/electron/services/minecraft.service.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { isNumber, throttle } from 'radash'
99
import type { Modpack, ModpackFile } from '../../../types/modpack.type'
1010
import { sendMainWindowWebContent } from '../windows/main.window'
1111
import { AuthService } from './auth.service'
12+
import axios from 'axios'
1213

1314
const store = new Store()
1415
const root = join(app.getPath('userData'), '/instances')
@@ -26,6 +27,10 @@ export class MinecraftService {
2627
public async registerEvents(): Promise<void> {
2728
ipcMain.handle('launchMinecraft', async (_, modpack: Modpack) => {
2829
log.info('launchMinecraft', modpack.id)
30+
31+
modpack = (await axios.get(`https://raw.githubusercontent.com/tacxtv/miratopia-launcher/config/modpacks/${modpack.id}/modpack.json`))
32+
.data as Modpack
33+
2934
const launch = new Launch()
3035
const loader = {} as any
3136
for (const l of modpack.loaders) {
@@ -39,12 +44,6 @@ export class MinecraftService {
3944
const githubFiles = await this.fetchGithubFiles(modpack)
4045
files = files.concat(githubFiles)
4146

42-
// let i = 0
43-
// while (i < 100) {
44-
// sendMainWindowWebContent('windowLogEvent', { message: `Downloading ${i}` })
45-
// i++
46-
// }
47-
4847
sendMainWindowWebContent('windowLogEvent', { message: `Authenticate Minecraft account...` })
4948
await AuthService.refreshCurrentAccessToken()
5049
sendMainWindowWebContent('windowLogEvent', { message: `Authentication successful !` })

src/pages/index.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,10 @@ export default defineNuxtComponent({
163163
}
164164
]
165165
const runtimeConfig = useRuntimeConfig()
166-
const backgroundUrl = ref('https://www.oxygenserv.com/wp-content/uploads/2023/03/171177.jpg')
167166
const splitter = ref(25)
168167
169-
console.log('runtimeConfig.app.installDir', runtimeConfig.app.installDir.replace(/\\/g, '/'))
170-
171168
return {
172169
videos,
173-
backgroundUrl,
174170
splitter,
175171
packageVersion: runtimeConfig.app.packageVersion,
176172
baseVideoUrl: 'https://github.com/tacxtv/miratopia-launcher/raw/config/launcher',

src/pages/login.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,33 @@ div.fit.flex(:style='{flexFlow: "column"}')
44
q-btn(label='Connexion' color='primary' icon="mdi-login-variant" size='lg' @click='getAccessToken')
55
q-bar
66
q-space
7-
small v1.0.0
7+
small(v-text="'v' + packageVersion")
88
</template>
99

1010
<script lang='ts'>
1111
import type { Launcher } from '~~/types/launcher.type'
12-
import type { UnwrapNestedRefs } from '@vue/reactivity'
1312
1413
definePageMeta({
1514
layout: 'simple',
1615
})
1716
1817
export default defineNuxtComponent({
1918
inject: ['global-launcher'],
19+
setup() {
20+
const runtimeConfig = useRuntimeConfig()
21+
22+
return {
23+
packageVersion: runtimeConfig.app.packageVersion,
24+
}
25+
},
2026
computed: {
2127
launcher(): Launcher {
22-
return (this['global-launcher'])
28+
return (this['global-launcher']) as Launcher
2329
},
2430
},
2531
methods: {
2632
getAccessToken() {
27-
window.electron?.getAccessToken()
33+
window.electron?.getAccessToken(true)
2834
},
2935
},
3036
})

0 commit comments

Comments
 (0)