-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
85 lines (68 loc) · 3.21 KB
/
main.js
File metadata and controls
85 lines (68 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Phoenix AI Control Extension
* Verifies and displays the AI control configuration status for educational institutions.
*/
/*global define, brackets, $ */
// See detailed docs in https://docs.phcode.dev/api/creating-extensions
// A good place to look for code examples for extensions: https://github.com/phcode-dev/phoenix/tree/main/src/extensions/default
define(function (require, exports, module) {
"use strict";
// Brackets modules
const AppInit = brackets.getModule("utils/AppInit"),
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
Dialogs = brackets.getModule("widgets/Dialogs"),
CommandManager = brackets.getModule("command/CommandManager"),
Menus = brackets.getModule("command/Menus"),
NodeConnector = brackets.getModule("NodeConnector"),
Mustache = brackets.getModule("thirdparty/mustache/mustache");
// HTML Templates
const browserMessageTemplate = require("text!./html/browser-message.html"),
statusTemplate = require("text!./html/status-template.html"),
errorTemplate = require("text!./html/error-template.html");
let nodeConnector;
// Function to run when the menu item is clicked
async function checkAIControlStatus() {
let html;
if (!Phoenix.isNativeApp) {
html = browserMessageTemplate;
} else {
try {
// Call the nodeConnector to get AI control status
const status = await nodeConnector.execPeer("getAIControlStatus");
// Prepare view model for Mustache
const viewModel = {
status: status,
showConfigDetails: status.exists && status.isConfigured,
hasAllowedUsers: status.allowedUsers && status.allowedUsers.length > 0,
allowedUsersList: status.allowedUsers ? status.allowedUsers.join(", ") : ""
};
// Render the template with Mustache
html = Mustache.render(statusTemplate, viewModel);
} catch (error) {
console.error("Error checking AI control status:", error);
// Render error template with Mustache
html = Mustache.render(errorTemplate, {
errorMessage: error.message || "Unknown error"
});
}
}
Dialogs.showModalDialog(DefaultDialogs.DIALOG_ID_INFO, "Phoenix Code AI Control Status", html);
}
// Register command for AI Control Status check
var AI_CONTROL_STATUS_ID = "phoenix.aiControlStatus";
CommandManager.register("AI Control Status", AI_CONTROL_STATUS_ID, checkAIControlStatus);
// Add menu item to View menu, below theme settings
var menu = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU);
menu.addMenuDivider();
menu.addMenuItem(AI_CONTROL_STATUS_ID);
// Initialize extension once shell is finished initializing
AppInit.appReady(function () {
console.log("Phoenix AI Control extension initialized");
if (Phoenix.isNativeApp) {
nodeConnector = NodeConnector.createNodeConnector(
"github-phcode-dev-phoenix-code-ai-control",
exports
);
}
});
});