Skip to content

Commit

Permalink
feat(renderer): add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfan0 committed Sep 26, 2024
1 parent 5003752 commit 1c5563c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const FFMPEG_PROGRESS_INFO = 'FFMPEG_PROGRESS_INFO'
export const DOWNLOAD_DEP_PROGRESS_INFO = 'DOWNLOAD_DEP_PROGRESS_INFO'

export const SHOW_NOTIFICATION = 'SHOW_NOTIFICATION'
export const OPEN_LOGS_DIR = 'OPEN_LOGS_DIR'
export const SHOW_UPDATE_DIALOG = 'SHOW_UPDATE_DIALOG'

export const MINIMIZE_WINDOW = 'MINIMIZE_WINDOW'
Expand Down
7 changes: 6 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app, shell, BrowserWindow, ipcMain, dialog, Notification } from 'electron'
import { join } from 'path'
import { join, resolve } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'

import { lt } from 'semver'
Expand All @@ -14,6 +14,7 @@ import {
MAXIMIZE_RESTORE_WINDOW,
MINIMIZE_WINDOW,
NAV_BY_DEFAULT_BROWSER,
OPEN_LOGS_DIR,
RECORD_DUMMY_PROCESS,
RETRY_DOWNLOAD_DEP,
SELECT_DIR,
Expand Down Expand Up @@ -270,6 +271,10 @@ app.whenReady().then(async () => {
showNotification(title, body)
})

ipcMain.handle(OPEN_LOGS_DIR, () => {
shell.openPath(resolve(app.getPath('userData'), 'logs'))
})

ipcMain.handle(MINIMIZE_WINDOW, () => {
win?.minimize()
})
Expand Down
1 change: 1 addition & 0 deletions src/preload/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare global {
api: {
isDarwin: boolean
selectDir: () => Promise<{ canceled: boolean; filePaths: string[] }>
openLogsDir: () => void
getLiveUrls: (info: {
roomUrl: string
proxy?: string
Expand Down
2 changes: 2 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
MAXIMIZE_RESTORE_WINDOW,
MINIMIZE_WINDOW,
NAV_BY_DEFAULT_BROWSER,
OPEN_LOGS_DIR,
RETRY_DOWNLOAD_DEP,
SELECT_DIR,
SHOW_NOTIFICATION,
Expand All @@ -22,6 +23,7 @@ import {
const api = {
isDarwin: process.platform === 'darwin',
selectDir: () => ipcRenderer.invoke(SELECT_DIR),
openLogsDir: () => ipcRenderer.invoke(OPEN_LOGS_DIR),
getLiveUrls: (info: { roomUrl: string; proxy?: string; cookie?: string }) =>
ipcRenderer.invoke('GET_LIVE_URLS', info),
navByDefaultBrowser: (url: string) => ipcRenderer.invoke(NAV_BY_DEFAULT_BROWSER, url),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { useEffect } from 'react'
const formSchema = z.object({
directory: z.string(),
lang: z.string(),
xizhiKey: z.optional(z.string())
xizhiKey: z.optional(z.string()),
logsDir: z.optional(z.string())
})

interface StreamConfigSheetProps {
Expand Down Expand Up @@ -49,6 +50,10 @@ export default function DefaultSettingSheet(props: StreamConfigSheetProps) {
form.setValue('directory', filePaths[0])
}

const handleOpenLogsDir = () => {
window.api.openLogsDir()
}

const handleSetSheetOpen = async (status: boolean, trigger = false) => {
const formValues = form.getValues() as IDefaultDefaultSettingsConfig
if (trigger) {
Expand Down Expand Up @@ -127,6 +132,28 @@ export default function DefaultSettingSheet(props: StreamConfigSheetProps) {
</FormItem>
)}
/>
<FormField
control={form.control}
name="logsDir"
render={({ field }) => (
<FormItem>
<FormLabel>{t('default_settings.logs_dir')}</FormLabel>
<FormControl>
<div className="flex gap-2">
<Input
placeholder={t('default_settings.logs_dir_placeholder')}
{...field}
disabled
/>
<Button variant="outline" type="button" onClick={handleOpenLogsDir}>
{t('stream_config.open')}
</Button>
</div>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</form>
</Form>
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/src/locales/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default {
directory: 'Storage Directory',
directory_placeholder: 'Please select a storage directory',
xizhi_key: 'Xizhi API Key (For WeChat Push)',
xizhi_key_placeholder: 'Please enter the Xizhi API Key'
xizhi_key_placeholder: 'Please enter the Xizhi API Key',
logs_dir: 'Logs Directory',
logs_dir_placeholder: 'Open Logs Directory'
},
stream_config: {
confirm: 'Confirm',
Expand Down Expand Up @@ -45,6 +47,7 @@ export default {
directory: 'Storage Directory',
directory_placeholder: 'Please select a storage directory',
select: 'Select',
open: 'Open',
title_can_not_be_empty: 'Title cannot be empty',
title_already_exists: 'Title already exists',
room_url_can_not_be_empty: 'Stream URL cannot be empty',
Expand Down Expand Up @@ -143,7 +146,9 @@ export default {
directory: '存储目录',
directory_placeholder: '请选择存储目录',
xizhi_key: '息知API Key(用于微信推送)',
xizhi_key_placeholder: '请输入息知API Key'
xizhi_key_placeholder: '请输入息知API Key',
logs_dir: '日志目录',
logs_dir_placeholder: '打开日志目录'
},
stream_config: {
confirm: '确认',
Expand Down Expand Up @@ -171,6 +176,7 @@ export default {
directory: '存储目录',
directory_placeholder: '请选择存储目录',
select: '选择',
open: '打开',
title_can_not_be_empty: '标题不能为空',
title_already_exists: '标题已存在',
room_url_can_not_be_empty: '直播间地址不能为空',
Expand Down

0 comments on commit 1c5563c

Please sign in to comment.