Преглед на файлове

【文档】更新文档

- 更新 README 文件,增加 PageOS 环境扩展链接,移除重复内容
- 删除 pageos-greet-extension.js 文件
- 重命名 Scrach 适配细则文件,增加页码信息
PJ568 преди 1 година
родител
ревизия
ef4c0aa7ed
променени са 6 файла, в които са добавени 6 реда и са изтрити 286 реда
  1. 1 1
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 2 6
      README.en.md
  4. 2 3
      README.md
  5. 0 0
      doc/Scrach 适配细则.已弃用.txt
  6. 0 275
      src/pageos-greet-extension.js

+ 1 - 1
Cargo.lock

@@ -600,7 +600,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
 
 
 [[package]]
 [[package]]
 name = "pageos-greet"
 name = "pageos-greet"
-version = "1.3.1"
+version = "1.3.2"
 dependencies = [
 dependencies = [
  "axum",
  "axum",
  "clap",
  "clap",

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 [package]
 name = "pageos-greet"
 name = "pageos-greet"
-version = "1.3.1"
+version = "1.3.2"
 authors = ["PJ568 <[email protected]>"]
 authors = ["PJ568 <[email protected]>"]
 edition = "2024"
 edition = "2024"
 license = "MPL-2.0"
 license = "MPL-2.0"

+ 2 - 6
README.en.md

@@ -52,7 +52,7 @@ _Ey bro, how do I adapt my page or Scratch to use the pageos-greet login manager
 
 
 Yes! Bro! You just need to do these two things:
 Yes! Bro! You just need to do these two things:
 
 
-1. **Mode Detection**: Determine whether currently in login state.
+1. **Mode Detection**: Determine whether currently in login state. Can use [PageOS environment extension](https://github.com/swaybien/pageos-extension/blob/master/src/pageos-env-extension.js).
    Check the domain and port at the very beginning of page initialization. If matched, initialize and enter the login page.
    Check the domain and port at the very beginning of page initialization. If matched, initialize and enter the login page.
    For example, if your OS specifies the login page at `127.0.0.1:12801`, the condition would be:
    For example, if your OS specifies the login page at `127.0.0.1:12801`, the condition would be:
 
 
@@ -71,14 +71,10 @@ Yes! Bro! You just need to do these two things:
 
 
    - [Example web page](doc/login.html)
    - [Example web page](doc/login.html)
    - [Adapter details](doc/design-adapter.md)
    - [Adapter details](doc/design-adapter.md)
-   - [Turbowarp 扩展](src/pageos-greet-extension.js)
-   - [Scrach 适配细则](doc/Scrach%20适配细则.txt)
-
-```
+   - [PageOS Turbowarp extensions](https://github.com/swaybien/pageos-extension)
 
 
 ## Project Info
 ## Project Info
 
 
 - License: MPL-2.0
 - License: MPL-2.0
 - Repository: https://github.com/swaybien/pageos-greet
 - Repository: https://github.com/swaybien/pageos-greet
 - Keywords: greetd, login, web-server, authentication
 - Keywords: greetd, login, web-server, authentication
-```

+ 2 - 3
README.md

@@ -49,7 +49,7 @@ _不是哥们,那我要怎么适配我的页面或 Scratch 以使用 pageos-gr
 
 
 是!哥们!您只需要做到以下两点:
 是!哥们!您只需要做到以下两点:
 
 
-1. 模式判断:判断当前是否处于登录状态;
+1. 模式判断:判断当前是否处于登录状态,可使用 [PageOS 环境扩展](https://github.com/swaybien/pageos-extension/blob/master/src/pageos-env-extension.js);
 
 
    在页面初始化最开始检查域名和端口号,如果匹配则初始化进入登录页面。
    在页面初始化最开始检查域名和端口号,如果匹配则初始化进入登录页面。
    假如您的操作系统规定登录页面在 127.0.0.1:12801,则判断条件为:
    假如您的操作系统规定登录页面在 127.0.0.1:12801,则判断条件为:
@@ -68,8 +68,7 @@ _不是哥们,那我要怎么适配我的页面或 Scratch 以使用 pageos-gr
    
    
    - [示例网页](doc/login.html)
    - [示例网页](doc/login.html)
    - [适配详解](doc/design-adapter.md)
    - [适配详解](doc/design-adapter.md)
-   - [Turbowarp 扩展](src/pageos-greet-extension.js)
-   - [Scrach 适配细则](doc/Scrach%20适配细则.txt)
+   - [PageOS Turbowarp extensions](https://github.com/swaybien/pageos-extension)
 
 
 ## 项目信息
 ## 项目信息
 
 

+ 0 - 0
doc/Scrach 适配细则.txt → doc/Scrach 适配细则.已弃用.txt


+ 0 - 275
src/pageos-greet-extension.js

@@ -1,275 +0,0 @@
-// 本扩展需要非沙盒环境运行:websocket
-// This extension requires disabling sandboxing: websocket
-class PageOSLoginExtension {
-  constructor() {
-    this.ws = null;
-    this.connected = false;
-    this.isLoading = false;
-    this.currentPrompt = "";
-    this.promptType = "info";
-    this.logs = [];
-    this.state = "disconnected";
-  }
-
-  getInfo() {
-    return {
-      id: "pageoslogin",
-      name: "PageOS 登录",
-      color1: "#3498db",
-      color2: "#2980b9",
-      blocks: [
-        {
-          opcode: "connect",
-          blockType: Scratch.BlockType.COMMAND,
-          text: "连接 [URL]",
-          arguments: {
-            URL: {
-              type: Scratch.ArgumentType.STRING,
-              defaultValue: "ws://127.0.0.1:12801/ws",
-            },
-          },
-        },
-        {
-          opcode: "onConnect",
-          blockType: Scratch.BlockType.HAT,
-          text: "当建立连接",
-          isEdgeActivated: false,
-        },
-        {
-          opcode: "isConnected",
-          blockType: Scratch.BlockType.BOOLEAN,
-          text: "已连接?",
-        },
-        {
-          opcode: "onMessage",
-          blockType: Scratch.BlockType.HAT,
-          text: "当收到信息",
-          isEdgeActivated: false,
-        },
-        {
-          opcode: "onError",
-          blockType: Scratch.BlockType.HAT,
-          text: "当发生连接错误",
-          isEdgeActivated: false,
-        },
-        {
-          opcode: "onClose",
-          blockType: Scratch.BlockType.HAT,
-          text: "当连接关闭",
-          isEdgeActivated: false,
-        },
-        {
-          opcode: "sendAuthRequest",
-          blockType: Scratch.BlockType.COMMAND,
-          text: "发送验证请求 用户名 [USERNAME]",
-          arguments: {
-            USERNAME: {
-              type: Scratch.ArgumentType.STRING,
-              defaultValue: "user",
-            },
-          },
-        },
-        {
-          opcode: "sendAuthResponse",
-          blockType: Scratch.BlockType.COMMAND,
-          text: "发送认证响应 信息 [RESPONSE]",
-          arguments: {
-            RESPONSE: {
-              type: Scratch.ArgumentType.STRING,
-              defaultValue: "",
-            },
-          },
-        },
-        {
-          opcode: "sendStartSession",
-          blockType: Scratch.BlockType.COMMAND,
-          text: "发送启动会话响应 环境变量 [ENV] 启动命令 [CMD]",
-          arguments: {
-            ENV: {
-              type: Scratch.ArgumentType.STRING,
-              defaultValue: "LANG=zh_CN.UTF-8",
-            },
-            CMD: {
-              type: Scratch.ArgumentType.STRING,
-              defaultValue: "%SESSION_COMMAND%",
-            },
-          },
-        },
-        {
-          opcode: "getSessionState",
-          blockType: Scratch.BlockType.REPORTER,
-          text: "获取会话状态",
-        },
-        {
-          opcode: "isLoading",
-          blockType: Scratch.BlockType.BOOLEAN,
-          text: "正在加载中?",
-        },
-        {
-          opcode: "getPrompt",
-          blockType: Scratch.BlockType.REPORTER,
-          text: "获取提示信息",
-        },
-        {
-          opcode: "getPromptType",
-          blockType: Scratch.BlockType.REPORTER,
-          text: "获取提示信息类型",
-        },
-        {
-          opcode: "getLogs",
-          blockType: Scratch.BlockType.REPORTER,
-          text: "获取日志信息",
-        },
-        {
-          opcode: "clearLogs",
-          blockType: Scratch.BlockType.COMMAND,
-          text: "清空日志",
-        },
-      ],
-    };
-  }
-
-  connect(args) {
-    const url = args.URL;
-    if (this.ws) {
-      this.ws.close();
-    }
-
-    this.isLoading = true;
-    this.logMessage(`正在连接到: ${url}`, "info");
-    this.state = "connecting";
-
-    this.ws = new WebSocket(url);
-
-    this.ws.onopen = () => {
-      this.connected = true;
-      this.isLoading = false;
-      this.state = "connected";
-      this.logMessage("连接已建立", "info");
-      Scratch.vm.runtime.startHats("pageoslogin_onConnect");
-    };
-
-    this.ws.onmessage = (event) => {
-      try {
-        const msg = JSON.parse(event.data);
-        this.logMessage(`收到消息: ${JSON.stringify(msg)}`, "info");
-
-        if (msg.type === "AUTH_MESSAGE") {
-          this.currentPrompt = msg.message;
-          this.promptType = msg.message_type.toLowerCase();
-        }
-
-        Scratch.vm.runtime.startHats("pageoslogin_onMessage");
-      } catch (e) {
-        this.logMessage(`消息解析错误: ${e}`, "error");
-      }
-    };
-
-    this.ws.onerror = (error) => {
-      this.isLoading = false;
-      this.logMessage(`连接错误: ${error}`, "error");
-      this.state = "error";
-      Scratch.vm.runtime.startHats("pageoslogin_onError");
-    };
-
-    this.ws.onclose = () => {
-      this.connected = false;
-      this.isLoading = false;
-      this.state = "disconnected";
-      this.logMessage("连接已关闭", "warn");
-      Scratch.vm.runtime.startHats("pageoslogin_onClose");
-    };
-  }
-
-  sendAuthRequest(args) {
-    if (!this.connected) return;
-
-    const username = args.USERNAME;
-    this.isLoading = true;
-    this.logMessage(`发送验证请求: ${username}`, "info");
-    this.state = "authenticating";
-
-    this.ws.send(
-      JSON.stringify({
-        type: "AUTH_REQUEST",
-        username: username,
-      })
-    );
-  }
-
-  sendAuthResponse(args) {
-    if (!this.connected) return;
-
-    const response = args.RESPONSE;
-    this.isLoading = true;
-    this.logMessage(`发送认证响应`, "info");
-
-    this.ws.send(
-      JSON.stringify({
-        type: "AUTH_RESPONSE",
-        response: response,
-      })
-    );
-  }
-
-  sendStartSession(args) {
-    if (!this.connected) return;
-
-    const env = args.ENV;
-    const cmd = args.CMD;
-    this.isLoading = true;
-    this.logMessage(`发送启动会话请求`, "info");
-    this.state = "starting_session";
-
-    // 将环境变量和命令字符串转换为数组
-    const envArray = env.split(",").map((item) => item.trim());
-    const cmdArray = cmd
-      .match(/[^\s"']+|"([^"]*)"|'([^']*)'/g)
-      .map((arg) => arg.replace(/^["']|["']$/g, ""));
-
-    this.ws.send(
-      JSON.stringify({
-        type: "START_SESSION",
-        env: envArray,
-        cmd: cmdArray,
-      })
-    );
-  }
-
-  isConnected() {
-    return this.connected;
-  }
-
-  isLoading() {
-    return this.isLoading;
-  }
-
-  getSessionState() {
-    return this.state;
-  }
-
-  getPrompt() {
-    return this.currentPrompt;
-  }
-
-  getPromptType() {
-    return this.promptType;
-  }
-
-  getLogs() {
-    return this.logs.map((log) => `${log.time}: ${log.message}`).join("\n");
-  }
-
-  clearLogs() {
-    this.logs = [];
-  }
-
-  logMessage(message, type = "info") {
-    const time = new Date().toLocaleTimeString();
-    this.logs.push({ time, message, type });
-    // 限制日志长度
-    if (this.logs.length > 100) this.logs.shift();
-  }
-}
-
-Scratch.extensions.register(new PageOSLoginExtension());