Skip to content

Commit

Permalink
Merge pull request #120 from 2skydev/dev
Browse files Browse the repository at this point in the history
v0.0.25
  • Loading branch information
2skydev authored Nov 1, 2023
2 parents 15bb881 + 112b09b commit 0a62332
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 7 deletions.
7 changes: 6 additions & 1 deletion resources/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"showHome": "Show LADA Home",
"setAppZoom": "Set App Display Scale",
"quit": "Quit LADA",
"nowValue": "Now"
"nowValue": "Now",
"resetWindowPosition": "Reset Window Position"
}
},
"renderer": {
Expand Down Expand Up @@ -188,6 +189,10 @@
"title": "Developer Mode Settings",
"description": "Enables or disables developer mode.\nWhen enabled, developer tools are activated."
},
"restoreWindowPosition": {
"title": "Restore Window Position",
"description": "Opens to the previous location when the LADA window is lit.\nIt always opens in the center of the screen when disabled."
},
"appVersion": {
"title": "App Version",
"description": "Displays the current version of the app.\nYou can check the changes through the following link.",
Expand Down
7 changes: 6 additions & 1 deletion resources/locales/ko_KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
"showHome": "LADA 홈 화면 보기",
"setAppZoom": "앱 비율 설정",
"quit": "앱 끄기",
"nowValue": "현재값"
"nowValue": "현재값",
"resetWindowPosition": "창 위치 초기화"
}
},
"renderer": {
Expand Down Expand Up @@ -256,6 +257,10 @@
"title": "개발자모드 설정",
"description": "개발자모드를 활성화할지 설정합니다.\n개발자모드가 활성화되면 개발자 도구가 활성화됩니다."
},
"restoreWindowPosition": {
"title": "창 위치 복원",
"description": "LADA 창이 켜질 때 이전 위치로 열립니다.\n비활성화 시 항상 화면 중앙에 열립니다."
},
"appVersion": {
"title": "앱 버전",
"description": "현재 앱 버전이 몇인지 확인하실 수 있습니다.\n아래 링크를 통해 변경된 사항을 확인하실 수 있습니다.",
Expand Down
6 changes: 3 additions & 3 deletions src/main/modules/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ConfigService {
oldValue: FieldPathValue<ConfigStoreValues, Key>,
) => void,
) {
// @ts-ignore
// @ts-ignore: key 타입 무시
return this.store.onDidChange(key, callback)
}

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

public set<Key extends FieldPath<ConfigStoreValues> = FieldPath<ConfigStoreValues>>(
key: Key,
value: FieldPathValue<ConfigStoreValues, Key>,
) {
// @ts-ignore
// @ts-ignore: key 타입 무시
this.store.set(key, value)
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/modules/config/config.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ConfigStoreValues {
openWindowWhenLeagueClientLaunch: boolean
language: string | null
zoom: number
restoreWindowPosition: boolean
}
game: {
statsProvider: StatsProvider
Expand All @@ -33,6 +34,7 @@ export const configStore = new Store<ConfigStoreValues>({
openWindowWhenLeagueClientLaunch: true,
language: null,
zoom: 1.0,
restoreWindowPosition: true,
},
game: {
statsProvider: 'LOL.PS',
Expand Down
44 changes: 44 additions & 0 deletions src/main/modules/electron/electron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ import {
ZOOM_PERCENT_ARRAY,
} from '@main/modules/electron/electron.constants'
import { ElectronController } from '@main/modules/electron/electron.controller'
import { electronStore } from '@main/modules/electron/electron.store'
import { AppControlAction } from '@main/modules/electron/types/app-control.type'
import { LanguageOption } from '@main/modules/electron/types/language.types'

@Injectable()
export class ElectronService implements OnModuleInit, OnApplicationBootstrap {
private readonly store = electronStore

public readonly APP_PATH = app.getAppPath()
public readonly PROTOCOL = protocols.name
public readonly IS_MAC = process.platform === 'darwin'
Expand Down Expand Up @@ -254,6 +257,8 @@ export const generatedIpcOnContext = {`
return
}

const windowPosition = this.store.get('windowPosition')

this.window = new BrowserWindow({
width: this.APP_WIDTH,
height: this.APP_HEIGHT,
Expand All @@ -264,6 +269,7 @@ export const generatedIpcOnContext = {`
frame: false,
icon: this.ICON,
resizable: false,
...windowPosition,
webPreferences: {
preload: this.PRELOAD_PATH,
},
Expand All @@ -288,6 +294,10 @@ export const generatedIpcOnContext = {`
this.window = null
})

this.window.on('moved', () => {
this.saveCurrentWindowPosition()
})

this.window.webContents.setWindowOpenHandler(({ url }) => {
if (url.startsWith('https:')) {
shell.openExternal(url)
Expand Down Expand Up @@ -388,6 +398,14 @@ export const generatedIpcOnContext = {`
await i18next.changeLanguage(value!)
this.controller.onChangeLanguage(value!)
})

this.configService.onChange('general.restoreWindowPosition', value => {
if (value) {
this.saveCurrentWindowPosition()
} else {
this.store.delete('windowPosition')
}
})
}

private createTray() {
Expand All @@ -399,13 +417,39 @@ export const generatedIpcOnContext = {`
this.reloadContextMenu()
}

private saveCurrentWindowPosition() {
if (this.configService.get('general.restoreWindowPosition') === false || !this.window) return

const { x, y } = this.window.getBounds()

this.store.set('windowPosition', {
x,
y,
})
}

private resetWindowPosition() {
if (this.window) {
this.window.center()
this.window.focus()
this.saveCurrentWindowPosition()
} else {
this.store.delete('windowPosition')
}
}

private reloadContextMenu() {
const template: MenuItemConstructorOptions[] = [
{
label: i18next.t('main.contextMenu.showHome'),
type: 'normal',
click: () => this.createWindow(),
},
{
label: i18next.t('main.contextMenu.resetWindowPosition'),
type: 'normal',
click: () => this.resetWindowPosition(),
},
{
label: i18next.t('main.contextMenu.setAppZoom'),
type: 'submenu',
Expand Down
14 changes: 14 additions & 0 deletions src/main/modules/electron/electron.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Store from 'electron-store'

export interface ElectronStoreValues {
windowPosition?: {
x: number
y: number
}
}

export const electronStore = new Store<ElectronStoreValues>({
name: 'electron',
accessPropertiesByDotNotation: true,
defaults: {},
})
2 changes: 1 addition & 1 deletion src/main/modules/league/league.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class LeagueAPIClient {
.catch(reject)
}),
{
// @ts-ignore
// @ts-ignore: 라이브러리 자체 타입 오류 무시
retries: 100,
},
)
Expand Down
6 changes: 6 additions & 0 deletions src/main/modules/migration/migration.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,10 @@ export class MigrationModule {
configStore.set('general.language', null)
}
}

public static async 'v0.0.25'() {
if (configStore.get('general.restoreWindowPosition') === undefined) {
configStore.set('general.restoreWindowPosition', true)
}
}
}
20 changes: 19 additions & 1 deletion src/renderer/src/pages/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ const SettingsPage = () => {
/>
</Section>

<Section
title={t('setting.general.restoreWindowPosition.title')}
description={t('setting.general.restoreWindowPosition.description')}
>
<Controller
name="restoreWindowPosition"
control={form.control}
render={({ field }) => (
<Switch
checked={field.value}
onChange={checked => field.onChange(checked)}
checkedChildren={<i className="bx bx-check" />}
unCheckedChildren={<i className="bx bx-x" />}
/>
)}
/>
</Section>

<Section
title={t('setting.general.developerMode.title')}
description={t('setting.general.developerMode.description')}
Expand All @@ -149,7 +167,7 @@ const SettingsPage = () => {
<div>
{t('setting.general.appVersion.description')}
<div className="spacing" />
<a href="https://github.com/2skydev/LADA/releases" target="_blank">
<a href="https://github.com/2skydev/LADA/releases" target="_blank" rel="noreferrer">
{t('setting.general.appVersion.releaseList')}
</a>{' '}
/{' '}
Expand Down

0 comments on commit 0a62332

Please sign in to comment.