RSSNext / Follow

🧡 Follow your favorites in one inbox
https://follow.is
GNU General Public License v3.0
19.29k stars 794 forks source link

在 Electron 进行开发时,无法正常登录 #672

Closed zxhd863943427 closed 2 months ago

zxhd863943427 commented 2 months ago

Describe the bug

我打算使用 webview 改进一下客户端版本的全文获取功能,但是 electron 跳转到浏览器登录后,会打开另一个 electron 窗口,这个窗口会尝试打开workspace/Follow/dist/renderer/index.html而直接失败,而原有的electron窗口会直接卡在等待登录状态。

图片

Feed Info

无需feed

Reproduction Video

No response

App Type

Electron / App

Version

0.0.1alpha17

Operating System

Windows 10

Browser Info

No response

Validations

Contributions

linear[bot] commented 2 months ago

FOL-299 在 Electron 进行开发时,无法正常登录

zxhd863943427 commented 2 months ago

目前还不能支持非官方针对electron进行开发是吗?

Innei commented 2 months ago

请提供最小复现

zxhd863943427 commented 2 months ago

我只修改了.env,如下所示:

VITE_WEB_URL=http://localhost:5173
VITE_API_URL=https://api.follow.is
VITE_IMGPROXY_URL=https://thumbor.follow.is
VITE_SENTRY_DSN=
VITE_BUILD_TYPE=production
VITE_POSTHOG_KEY=

在window10上进行开发,运行了如下命令:

corepack enable
pnpm install
pnpm run dev
Innei commented 2 months ago

生产环境登录后打开的是 follow:// 的协议,但是开发环境是 follow-dev:// 所以这里要手动修改下

zxhd863943427 commented 2 months ago

目前使用的已经是follow-dev://协议的,我查找注册表,确定调用的是如下命令:

"D:\workspace\typescript-workspace\Follow\node_modules\electron\dist\electron.exe" "D:\workspace\typescript-workspace\Follow" "%1"

我写了个bat脚本来检验参数输入,脚本代码如下:

@echo off
echo The argument is: %1
pause

将注册表里follow-dev协议的调动改为:

"C:\Users\****\Desktop\print_arg.bat" "%1"

能正常输出如下内容:

The argument is: follow-dev://auth/?token=***

尝试手动调用如下指令:

&"D:\workspace\typescript-workspace\Follow\node_modules\electron\dist\electron.exe" "D:\workspace\typescript-workspace\Follow" 

发生同样的问题,打开一个新的electron窗口,并白屏。检查控制台,产生报错:

Not allowed to load local resource: file:///D:/workspace/typescript-workspace/Follow/dist/renderer/index.html

检查原本的electron窗口,发现一开始打开的是http://localhost:5173/,修改尝试,运行如下命令:

&"D:\workspace\typescript-workspace\Follow\node_modules\electron\dist\electron.exe" "http://localhost:5173/" 

能打开一个正常加载的窗口,但无法如下传入参数:

&"D:\workspace\typescript-workspace\Follow\node_modules\electron\dist\electron.exe" "http://localhost:5173/" "follow-dev://auth/?token=***"

会直接无法打开。

Soya-xy commented 2 months ago

目前使用的已经是follow-dev://协议的,我查找注册表,确定调用的是如下命令:

"D:\workspace\typescript-workspace\Follow\node_modules\electron\dist\electron.exe" "D:\workspace\typescript-workspace\Follow" "%1"

我写了个bat脚本来检验参数输入,脚本代码如下:

@echo off
echo The argument is: %1
pause

将注册表里follow-dev协议的调动改为:

"C:\Users\****\Desktop\print_arg.bat" "%1"

能正常输出如下内容:

The argument is: follow-dev://auth/?token=***

尝试手动调用如下指令:

&"D:\workspace\typescript-workspace\Follow\node_modules\electron\dist\electron.exe" "D:\workspace\typescript-workspace\Follow" 

发生同样的问题,打开一个新的electron窗口,并白屏。检查控制台,产生报错:

Not allowed to load local resource: file:///D:/workspace/typescript-workspace/Follow/dist/renderer/index.html

检查原本的electron窗口,发现一开始打开的是http://localhost:5173/,修改尝试,运行如下命令:

&"D:\workspace\typescript-workspace\Follow\node_modules\electron\dist\electron.exe" "http://localhost:5173/" 

能打开一个正常加载的窗口,但无法如下传入参数:

&"D:\workspace\typescript-workspace\Follow\node_modules\electron\dist\electron.exe" "http://localhost:5173/" "follow-dev://auth/?token=***"

会直接无法打开。

可以通过命令行执行(可能需要多执行几次) set ELECTRON_RENDERER_URL=http://localhost:5173 && start follow-dev://auth?token=xxx ,启动后如果还是提示需要登录的情况下,打开控制台删除cookies下authjs.session-token value 为空的一行 刷新即可

Innei commented 2 months ago

还得是我 soya 哥

zxhd863943427 commented 2 months ago
12:47:26.794 (main) > D:\workspace\typescript-workspace\Follow\dist\renderer\index.html {}
12:47:26.799 (main) > auto-updater feed config {
  channel: 'alpha',
  provider: 'custom',
  repo: 'follow',
  owner: 'RSSNext',
  releaseType: 'prerelease'
}
Skip checkForUpdates because application is not packed and dev update config is not forced
(node:11760) electron: Failed to load URL: file:///D:/workspace/typescript-workspace/Follow/dist/renderer/index.html with error: ERR_FILE_NOT_FOUND
(Use `electron --trace-warnings ...` to show where the warning was created)
[11760:1004/124735.950:ERROR:CONSOLE(1)] "Request Autofill.enable failed. {"code":-32601,"message":"'Autofill.enable' wasn't found"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1)
[11760:1004/124735.951:ERROR:CONSOLE(1)] "Request Autofill.setAddresses failed. {"code":-32601,"message":"'Autofill.setAddresses' wasn't found"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1)
Skip checkForUpdates because application is not packed and dev update config is not forced
Skip checkForUpdates because application is not packed and dev update config is not forced
(node:11760) electron: Failed to load URL: file:///D:/workspace/typescript-workspace/Follow/dist/renderer/index.html with error: ERR_FILE_NOT_FOUND

一样的报错,electron 貌似直接无视了 ELECTRON_RENDERER_URL 环境变量。

不过我发现直接运行

& "D:\workspace\typescript-workspace\Follow\node_modules\electron\dist\electron.exe" "http://localhost:5173/" 

进行登录不会跳转到外部浏览器,但是这样操作就不会被当成 electron 端了。

最后的解决方案是:我登录了一次 follow,然后手动复制了 authjs.session-token 的 cookies 过来,这样刷新后就进入登录状态了。也算能用吧……