Skip to content

Commit 112b09b

Browse files
authored
Merge pull request #119 from 2skydev/feat/restore-window-position
창 위치 복원 기능 추가
2 parents 15bb881 + a69bd3a commit 112b09b

File tree

9 files changed

+101
-7
lines changed

9 files changed

+101
-7
lines changed

resources/locales/en_US.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"showHome": "Show LADA Home",
6060
"setAppZoom": "Set App Display Scale",
6161
"quit": "Quit LADA",
62-
"nowValue": "Now"
62+
"nowValue": "Now",
63+
"resetWindowPosition": "Reset Window Position"
6364
}
6465
},
6566
"renderer": {
@@ -188,6 +189,10 @@
188189
"title": "Developer Mode Settings",
189190
"description": "Enables or disables developer mode.\nWhen enabled, developer tools are activated."
190191
},
192+
"restoreWindowPosition": {
193+
"title": "Restore Window Position",
194+
"description": "Opens to the previous location when the LADA window is lit.\nIt always opens in the center of the screen when disabled."
195+
},
191196
"appVersion": {
192197
"title": "App Version",
193198
"description": "Displays the current version of the app.\nYou can check the changes through the following link.",

resources/locales/ko_KR.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@
127127
"showHome": "LADA 홈 화면 보기",
128128
"setAppZoom": "앱 비율 설정",
129129
"quit": "앱 끄기",
130-
"nowValue": "현재값"
130+
"nowValue": "현재값",
131+
"resetWindowPosition": "창 위치 초기화"
131132
}
132133
},
133134
"renderer": {
@@ -256,6 +257,10 @@
256257
"title": "개발자모드 설정",
257258
"description": "개발자모드를 활성화할지 설정합니다.\n개발자모드가 활성화되면 개발자 도구가 활성화됩니다."
258259
},
260+
"restoreWindowPosition": {
261+
"title": "창 위치 복원",
262+
"description": "LADA 창이 켜질 때 이전 위치로 열립니다.\n비활성화 시 항상 화면 중앙에 열립니다."
263+
},
259264
"appVersion": {
260265
"title": "앱 버전",
261266
"description": "현재 앱 버전이 몇인지 확인하실 수 있습니다.\n아래 링크를 통해 변경된 사항을 확인하실 수 있습니다.",

src/main/modules/config/config.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ConfigService {
1717
oldValue: FieldPathValue<ConfigStoreValues, Key>,
1818
) => void,
1919
) {
20-
// @ts-ignore
20+
// @ts-ignore: key 타입 무시
2121
return this.store.onDidChange(key, callback)
2222
}
2323

@@ -30,15 +30,15 @@ export class ConfigService {
3030
public get<Key extends FieldPath<ConfigStoreValues> = FieldPath<ConfigStoreValues>>(
3131
key: Key,
3232
): FieldPathValue<ConfigStoreValues, Key> {
33-
// @ts-ignore
33+
// @ts-ignore: key 타입 무시
3434
return this.store.get(key)
3535
}
3636

3737
public set<Key extends FieldPath<ConfigStoreValues> = FieldPath<ConfigStoreValues>>(
3838
key: Key,
3939
value: FieldPathValue<ConfigStoreValues, Key>,
4040
) {
41-
// @ts-ignore
41+
// @ts-ignore: key 타입 무시
4242
this.store.set(key, value)
4343
}
4444

src/main/modules/config/config.store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface ConfigStoreValues {
1111
openWindowWhenLeagueClientLaunch: boolean
1212
language: string | null
1313
zoom: number
14+
restoreWindowPosition: boolean
1415
}
1516
game: {
1617
statsProvider: StatsProvider
@@ -33,6 +34,7 @@ export const configStore = new Store<ConfigStoreValues>({
3334
openWindowWhenLeagueClientLaunch: true,
3435
language: null,
3536
zoom: 1.0,
37+
restoreWindowPosition: true,
3638
},
3739
game: {
3840
statsProvider: 'LOL.PS',

src/main/modules/electron/electron.service.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ import {
3232
ZOOM_PERCENT_ARRAY,
3333
} from '@main/modules/electron/electron.constants'
3434
import { ElectronController } from '@main/modules/electron/electron.controller'
35+
import { electronStore } from '@main/modules/electron/electron.store'
3536
import { AppControlAction } from '@main/modules/electron/types/app-control.type'
3637
import { LanguageOption } from '@main/modules/electron/types/language.types'
3738

3839
@Injectable()
3940
export class ElectronService implements OnModuleInit, OnApplicationBootstrap {
41+
private readonly store = electronStore
42+
4043
public readonly APP_PATH = app.getAppPath()
4144
public readonly PROTOCOL = protocols.name
4245
public readonly IS_MAC = process.platform === 'darwin'
@@ -254,6 +257,8 @@ export const generatedIpcOnContext = {`
254257
return
255258
}
256259

260+
const windowPosition = this.store.get('windowPosition')
261+
257262
this.window = new BrowserWindow({
258263
width: this.APP_WIDTH,
259264
height: this.APP_HEIGHT,
@@ -264,6 +269,7 @@ export const generatedIpcOnContext = {`
264269
frame: false,
265270
icon: this.ICON,
266271
resizable: false,
272+
...windowPosition,
267273
webPreferences: {
268274
preload: this.PRELOAD_PATH,
269275
},
@@ -288,6 +294,10 @@ export const generatedIpcOnContext = {`
288294
this.window = null
289295
})
290296

297+
this.window.on('moved', () => {
298+
this.saveCurrentWindowPosition()
299+
})
300+
291301
this.window.webContents.setWindowOpenHandler(({ url }) => {
292302
if (url.startsWith('https:')) {
293303
shell.openExternal(url)
@@ -388,6 +398,14 @@ export const generatedIpcOnContext = {`
388398
await i18next.changeLanguage(value!)
389399
this.controller.onChangeLanguage(value!)
390400
})
401+
402+
this.configService.onChange('general.restoreWindowPosition', value => {
403+
if (value) {
404+
this.saveCurrentWindowPosition()
405+
} else {
406+
this.store.delete('windowPosition')
407+
}
408+
})
391409
}
392410

393411
private createTray() {
@@ -399,13 +417,39 @@ export const generatedIpcOnContext = {`
399417
this.reloadContextMenu()
400418
}
401419

420+
private saveCurrentWindowPosition() {
421+
if (this.configService.get('general.restoreWindowPosition') === false || !this.window) return
422+
423+
const { x, y } = this.window.getBounds()
424+
425+
this.store.set('windowPosition', {
426+
x,
427+
y,
428+
})
429+
}
430+
431+
private resetWindowPosition() {
432+
if (this.window) {
433+
this.window.center()
434+
this.window.focus()
435+
this.saveCurrentWindowPosition()
436+
} else {
437+
this.store.delete('windowPosition')
438+
}
439+
}
440+
402441
private reloadContextMenu() {
403442
const template: MenuItemConstructorOptions[] = [
404443
{
405444
label: i18next.t('main.contextMenu.showHome'),
406445
type: 'normal',
407446
click: () => this.createWindow(),
408447
},
448+
{
449+
label: i18next.t('main.contextMenu.resetWindowPosition'),
450+
type: 'normal',
451+
click: () => this.resetWindowPosition(),
452+
},
409453
{
410454
label: i18next.t('main.contextMenu.setAppZoom'),
411455
type: 'submenu',
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Store from 'electron-store'
2+
3+
export interface ElectronStoreValues {
4+
windowPosition?: {
5+
x: number
6+
y: number
7+
}
8+
}
9+
10+
export const electronStore = new Store<ElectronStoreValues>({
11+
name: 'electron',
12+
accessPropertiesByDotNotation: true,
13+
defaults: {},
14+
})

src/main/modules/league/league.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class LeagueAPIClient {
129129
.catch(reject)
130130
}),
131131
{
132-
// @ts-ignore
132+
// @ts-ignore: 라이브러리 자체 타입 오류 무시
133133
retries: 100,
134134
},
135135
)

src/main/modules/migration/migration.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,10 @@ export class MigrationModule {
139139
configStore.set('general.language', null)
140140
}
141141
}
142+
143+
public static async 'v0.0.25'() {
144+
if (configStore.get('general.restoreWindowPosition') === undefined) {
145+
configStore.set('general.restoreWindowPosition', true)
146+
}
147+
}
142148
}

src/renderer/src/pages/settings/index.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ const SettingsPage = () => {
125125
/>
126126
</Section>
127127

128+
<Section
129+
title={t('setting.general.restoreWindowPosition.title')}
130+
description={t('setting.general.restoreWindowPosition.description')}
131+
>
132+
<Controller
133+
name="restoreWindowPosition"
134+
control={form.control}
135+
render={({ field }) => (
136+
<Switch
137+
checked={field.value}
138+
onChange={checked => field.onChange(checked)}
139+
checkedChildren={<i className="bx bx-check" />}
140+
unCheckedChildren={<i className="bx bx-x" />}
141+
/>
142+
)}
143+
/>
144+
</Section>
145+
128146
<Section
129147
title={t('setting.general.developerMode.title')}
130148
description={t('setting.general.developerMode.description')}
@@ -149,7 +167,7 @@ const SettingsPage = () => {
149167
<div>
150168
{t('setting.general.appVersion.description')}
151169
<div className="spacing" />
152-
<a href="https://github.com/2skydev/LADA/releases" target="_blank">
170+
<a href="https://github.com/2skydev/LADA/releases" target="_blank" rel="noreferrer">
153171
{t('setting.general.appVersion.releaseList')}
154172
</a>{' '}
155173
/{' '}

0 commit comments

Comments
 (0)