11/**
2- * A simple extension that downloads an image and then converts it to grey scale using `sharp` node.js lib via
3- * Phoenix Code node.js Extension. Extension can be activated using menu: `file->Download Image & Greyscale` .
4- * * /
2+ * Phoenix AI Control Extension
3+ * Verifies and displays the AI control configuration status for educational institutions .
4+ */
55
66/*global define, brackets, $ */
77
88// See detailed docs in https://docs.phcode.dev/api/creating-extensions
99// A good place to look for code examples for extensions: https://github.com/phcode-dev/phoenix/tree/main/src/extensions/default
1010
11-
1211define ( function ( require , exports , module ) {
1312 "use strict" ;
1413
@@ -18,82 +17,71 @@ define(function (require, exports, module) {
1817 Dialogs = brackets . getModule ( "widgets/Dialogs" ) ,
1918 CommandManager = brackets . getModule ( "command/CommandManager" ) ,
2019 Menus = brackets . getModule ( "command/Menus" ) ,
21- NodeConnector = brackets . getModule ( "NodeConnector" ) ;
22-
23- let nodeConnector ;
24-
25- async function fetchImage ( ) {
26- const imageUrl = "https://picsum.photos/536/354" ;
27- const response = await fetch ( imageUrl ) ;
20+ NodeConnector = brackets . getModule ( "NodeConnector" ) ,
21+ Mustache = brackets . getModule ( "thirdparty/mustache/mustache" ) ;
2822
29- if ( ! response . ok ) {
30- throw new Error (
31- `Failed to fetch image (status ${ response . status } )`
32- ) ;
33- }
23+ // HTML Templates
24+ const browserMessageTemplate = require ( "text!./html/browser-message.html" ) ,
25+ statusTemplate = require ( "text!./html/status-template.html" ) ,
26+ errorTemplate = require ( "text!./html/error-template.html" ) ;
3427
35- return response . arrayBuffer ( ) ;
36- }
28+ let nodeConnector ;
3729
3830 // Function to run when the menu item is clicked
39- async function handleHelloWorld ( ) {
40- if ( ! Phoenix . isNativeApp ) {
41- alert ( "Node Features only works in desktop apps." ) ;
42- return ;
43- }
44- let html = "<b>Image conversion failed</b>" ;
45- try {
46- alert ( "downloading image..." ) ;
47- // Fetch the image and get its array buffer
48- const imageArrayBuffer = await fetchImage ( ) ;
49-
50- // Call the nodeConnector to convert the image to grayscale
51- const { buffer, success } = await nodeConnector . execPeer (
52- "convertToGreyScale" ,
53- { imageName : "imageName" } ,
54- imageArrayBuffer
55- ) ;
31+ async function checkAIControlStatus ( ) {
32+ let html ;
5633
57- if ( ! success ) {
58- alert ( "Image conversion failed in Node." ) ;
59- return ;
34+ if ( ! Phoenix . isNativeApp ) {
35+ html = browserMessageTemplate ;
36+ } else {
37+ try {
38+ // Call the nodeConnector to get AI control status
39+ const status = await nodeConnector . execPeer ( "getAIControlStatus" ) ;
40+
41+ // Prepare view model for Mustache
42+ const viewModel = {
43+ statusColor : status . isEnabled ? "#4caf50" : "#f44336" , // Green if enabled, red if disabled
44+ statusIcon : status . isEnabled ? "✓" : "✗" ,
45+ statusText : status . isEnabled ? "Enabled" : "Disabled" ,
46+ status : status ,
47+ showConfigDetails : status . exists && status . isConfigured ,
48+ hasAllowedUsers : status . allowedUsers && status . allowedUsers . length > 0 ,
49+ allowedUsersList : status . allowedUsers ? status . allowedUsers . join ( ", " ) : ""
50+ } ;
51+
52+ // Render the template with Mustache
53+ html = Mustache . render ( statusTemplate , viewModel ) ;
54+
55+ } catch ( error ) {
56+ console . error ( "Error checking AI control status:" , error ) ;
57+
58+ // Render error template with Mustache
59+ html = Mustache . render ( errorTemplate , {
60+ errorMessage : error . message || "Unknown error"
61+ } ) ;
6062 }
61-
62- // Construct HTML with the grayscale image array buffer
63- // For example, you can use the buffer as a base64 data URL
64- html = `<img src="data:image/jpeg;base64,${ Buffer . from ( buffer ) . toString ( "base64" ) } ">` ;
65- } catch ( error ) {
66- console . error ( "Error:" , error ) ;
6763 }
68- Dialogs . showModalDialog ( DefaultDialogs . DIALOG_ID_INFO , "Image to greyscale with node.js" , html ) ;
64+
65+ Dialogs . showModalDialog ( DefaultDialogs . DIALOG_ID_INFO , "Phoenix AI Control Status" , html ) ;
6966 }
7067
71- // First, register a command - a UI-less object associating an id to a handler
72- var MY_COMMAND_ID = "helloworld.imageConvert" ; // package-style naming to avoid collisions
73- CommandManager . register ( "Download Image & Greyscale " , MY_COMMAND_ID , handleHelloWorld ) ;
68+ // Register command for AI Control Status check
69+ var AI_CONTROL_STATUS_ID = "phoenix.aiControlStatus" ;
70+ CommandManager . register ( "Check AI Control Status " , AI_CONTROL_STATUS_ID , checkAIControlStatus ) ;
7471
75- // Then create a menu item bound to the command
76- // The label of the menu item is the name we gave the command (see above)
72+ // Add menu item to File menu
7773 var menu = Menus . getMenu ( Menus . AppMenuBar . FILE_MENU ) ;
78- menu . addMenuItem ( MY_COMMAND_ID ) ;
79-
80- // We could also add a key binding at the same time:
81- //menu.addMenuItem(MY_COMMAND_ID, "Ctrl-Alt-W");
82- // (Note: "Ctrl" is automatically mapped to "Cmd" on Mac)
74+ menu . addMenuItem ( AI_CONTROL_STATUS_ID ) ;
8375
84- // Initialize extension once shell is finished initializing.
76+ // Initialize extension once shell is finished initializing
8577 AppInit . appReady ( function ( ) {
86- // nb: Please enable `Debug menu> Phoenix code diagnostic tools> enable detailed logs` to view all console logs.`
87- console . log ( "hello world" ) ;
78+ console . log ( "Phoenix AI Control extension initialized" ) ;
8879
8980 if ( Phoenix . isNativeApp ) {
9081 nodeConnector = NodeConnector . createNodeConnector (
9182 "github-phcode-dev-phoenix-code-ai-control" ,
9283 exports
9384 ) ;
94- // you can also execute nodejs code in dekstop builds
95- // below code will execute the function `echoTest` defined in `node/index.js`
96- nodeConnector . execPeer ( "echoTest" , "yo!" ) . then ( console . log ) ;
9785 }
9886 } ) ;
9987} ) ;
0 commit comments