Skip to content

Commit f321ee6

Browse files
author
Star
committed
Merge branch 'feature/office-name-from-identity' into review/pr70-pr79-combined
2 parents 4c356dc + e281a19 commit f321ee6

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

backend/app.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
ASSET_ALLOWED_EXTS = {".png", ".webp", ".jpg", ".jpeg", ".gif", ".svg", ".avif"}
4747
ASSET_TEMPLATE_ZIP = os.path.join(ROOT_DIR, "assets-replace-template.zip")
4848
WORKSPACE_DIR = os.path.dirname(ROOT_DIR)
49+
OPENCLAW_WORKSPACE = os.environ.get("OPENCLAW_WORKSPACE") or os.path.join(os.path.expanduser("~"), ".openclaw", "workspace")
50+
IDENTITY_FILE = os.path.join(OPENCLAW_WORKSPACE, "IDENTITY.md")
4951
GEMINI_SCRIPT = os.path.join(WORKSPACE_DIR, "skills", "gemini-image-generate", "scripts", "gemini_image_generate.py")
5052
GEMINI_PYTHON = os.path.join(WORKSPACE_DIR, "skills", "gemini-image-generate", ".venv", "bin", "python")
5153
ROOM_REFERENCE_IMAGE = (
@@ -199,6 +201,22 @@ def load_state():
199201
return state
200202

201203

204+
def get_office_name_from_identity():
205+
"""Read office display name from OpenClaw workspace IDENTITY.md (Name field) -> 'XXX的办公室'."""
206+
if not os.path.isfile(IDENTITY_FILE):
207+
return None
208+
try:
209+
with open(IDENTITY_FILE, "r", encoding="utf-8") as f:
210+
content = f.read()
211+
m = re.search(r"-\s*\*\*Name:\*\*\s*(.+)", content)
212+
if m:
213+
name = m.group(1).strip().replace("\r", "").split("\n")[0].strip()
214+
return f"{name}的办公室" if name else None
215+
except Exception:
216+
pass
217+
return None
218+
219+
202220
def save_state(state: dict):
203221
"""Save state to file"""
204222
with open(STATE_FILE, "w", encoding="utf-8") as f:
@@ -1127,8 +1145,11 @@ def leave_agent():
11271145

11281146
@app.route("/status", methods=["GET"])
11291147
def get_status():
1130-
"""Get current main state (backward compatibility)"""
1148+
"""Get current main state (backward compatibility). Optionally include officeName from IDENTITY.md."""
11311149
state = load_state()
1150+
office_name = get_office_name_from_identity()
1151+
if office_name:
1152+
state["officeName"] = office_name
11321153
return jsonify(state)
11331154

11341155

frontend/electron-standalone.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,7 @@
18741874

18751875
function t(key) { return (I18N[uiLang] && I18N[uiLang][key]) || key; }
18761876
function getOfficePlaqueTitle() {
1877-
return officePlaqueCustomTitle || t('officeTitle');
1877+
return (window.officeNameFromServer || officePlaqueCustomTitle || t('officeTitle'));
18781878
}
18791879
function refreshOfficePlaqueTitle() {
18801880
const el = document.getElementById('office-plaque-text');
@@ -5474,6 +5474,10 @@
54745474
.then(response => response.json())
54755475
.then(data => {
54765476
try {
5477+
if (data.officeName) {
5478+
window.officeNameFromServer = data.officeName;
5479+
refreshOfficePlaqueTitle();
5480+
}
54775481
const nextState = normalizeState(data.state);
54785482
const stateInfo = STATES[nextState] || STATES.idle;
54795483
// If we're mid-transition, don't restart the path every poll

frontend/index.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,9 @@
14591459
if (memoTitle) memoTitle.textContent = t('memoTitle');
14601460
const guestTitle = document.getElementById('guest-agent-panel-title');
14611461
if (guestTitle) guestTitle.textContent = t('guestTitle');
1462+
const plaqueTitle = (typeof window.officeNameFromServer !== 'undefined' && window.officeNameFromServer) || t('officeTitle');
14621463
if (window.officePlaqueText && window.officePlaqueText.setText) {
1463-
window.officePlaqueText.setText(t('officeTitle'));
1464+
window.officePlaqueText.setText(plaqueTitle);
14641465
}
14651466

14661467
const coordsBtn = document.getElementById('coords-toggle');
@@ -4091,7 +4092,9 @@
40914092
fontWeight: '900',
40924093
fontStyle: 'bold',
40934094
stroke: '#000',
4094-
strokeThickness: 3
4095+
strokeThickness: 3,
4096+
wordWrap: { width: 400 },
4097+
align: 'center'
40954098
}).setOrigin(0.5);
40964099
// 牌匾两边加个小装饰(跟随牌匾居中)
40974100
game.add.text(plaqueX - 190, plaqueY, '⭐', { fontFamily: 'ArkPixel, monospace', fontSize: '20px' }).setOrigin(0.5);
@@ -4664,7 +4667,12 @@
46644667
.then(response => response.json())
46654668
.then(data => {
46664669
try {
4667-
4670+
if (data.officeName) {
4671+
window.officeNameFromServer = data.officeName;
4672+
if (window.officePlaqueText && window.officePlaqueText.setText) {
4673+
window.officePlaqueText.setText(data.officeName);
4674+
}
4675+
}
46684676
const nextState = normalizeState(data.state);
46694677
const stateInfo = STATES[nextState] || STATES.idle;
46704678
// If we're mid-transition, don't restart the path every poll

0 commit comments

Comments
 (0)