Skip to content

Commit

Permalink
docs: comments English
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie committed Feb 14, 2025
1 parent ebce83a commit 34db4a0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
Binary file removed packages/.DS_Store
Binary file not shown.
Binary file removed packages/main/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions packages/main/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ dist
bin/Logs
release
types
.DS_Store
4 changes: 2 additions & 2 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const start = async (): Promise<void> => {
const mediago = container.get<ElectronApp>(TYPES.ElectronApp);
// let initialUrl: string = "";
// if (process.defaultApp) {
// // 在开发环境中,检查命令行参数
// // dev
// if (process.argv.length >= 2) {
// const urlArg = process.argv.find((arg) => arg.startsWith("mediago://"));
// if (urlArg) {
// initialUrl = urlArg;
// }
// }
// } else {
// // 在生产环境中,检查命令行参数
// // prod
// if (process.argv.length >= 2) {
// const urlArg = process.argv[1];
// if (urlArg.startsWith("mediago://")) {
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const electronApi = {
getVideoFolders(): Promise<string[]> {
return ipcRenderer.invoke("get-video-folders");
},
// ipc with main process to get url params
onUrlParams(callback: (url: string) => void): void {
ipcRenderer.on("url-params", (event, url) => {
callback(url);
Expand Down
18 changes: 9 additions & 9 deletions packages/main/src/windows/MainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { isWin } from "../helper/variables.ts";
@injectable()
export default class MainWindow extends Window {
url = isDev ? "http://localhost:8555/" : "mediago://index.html/";
private initialUrl: string | null = null; // 将 initialUrl 提升为成员变量
private initialUrl: string | null = null;
constructor(
@inject(TYPES.ElectronLogger)
private readonly logger: ElectronLogger,
Expand Down Expand Up @@ -83,15 +83,15 @@ export default class MainWindow extends Window {
this.window.on("resized", this.handleResize);
this.window.on("close", this.closeMainWindow);
// if (process.defaultApp) {
// // 在开发环境中,检查命令行参数
// // dev
// if (process.argv.length >= 2) {
// const urlArg = process.argv.find((arg) => arg.startsWith("mediago://"));
// if (urlArg) {
// this.initialUrl = urlArg;
// }
// }
// } else {
// // 在生产环境中,检查命令行参数
// // prod
// if (process.argv.length >= 2) {
// const urlArg = process.argv[1];
// if (urlArg.startsWith("mediago://")) {
Expand Down Expand Up @@ -178,11 +178,11 @@ export default class MainWindow extends Window {

this.window.webContents.send(channel, ...args);
if (!this.window) {
this.init(); // 如果窗口未初始化,先初始化窗口
this.init(); // If the window is closed, reinitialize the window
}

if (this.window) {
this.window.webContents.send(channel, ...args); // 确保窗口存在后再发送消息
this.window.webContents.send(channel, ...args); // Send message to renderer process
}
}

Expand All @@ -207,10 +207,10 @@ export default class MainWindow extends Window {
}
}

// 处理 URL 参数
// Handle URL in the form of mediago://
handleUrl(url: string) {
if (!this.window) {
this.init(); // 如果窗口未初始化,先初始化窗口
this.init();
}

if (this.window) {
Expand All @@ -220,10 +220,10 @@ export default class MainWindow extends Window {
this.window.focus();
}

this.send("url-params", url); // 发送 URL 参数
this.send("url-params", url); // Send the URL to the renderer process

if (url) {
this.window!.loadURL(url); // 加载 URL
this.window!.loadURL(url);
}
}
}
6 changes: 3 additions & 3 deletions packages/renderer/src/pages/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
}
}
}, [location.search]);

// mac ipc event get url params in macos schceme
useEffect(() => {
const handleUrlEvent = (url: string) => {
const searchParams = new URLSearchParams(url.split("?")[1]);
Expand All @@ -119,12 +121,10 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
}
};

// 注册监听器
window.electron.onUrlParams(handleUrlEvent);

// 清理监听器(组件卸载时)
return () => {
window.electron.onUrlParams(handleUrlEvent); // 确保移除监听器
window.electron.onUrlParams(handleUrlEvent);
};
}, []);

Expand Down

0 comments on commit 34db4a0

Please sign in to comment.