US Tray Menu: Introduction

From The Uniform Server Wiki
Jump to navigation Jump to search

 

UniServer 5-Nano
US Tray Menu.

US Tray Menu

Introduction

WinBinder 4 tutorial concluded with a working generic tray-menu. With the exception of move-servers (disabled) Uniform Server is fully controllable.

This is a follow up tutorial covering menu integration. First there is a crucial decision to be made, either fully integrate and replace UniTray or offer it as a self-contained plugin.

Full integration

Full integration is the preferred option. Locate WinBinder module in current PHP extension folder. Replace UniTray with new menu and update architecture accordingly. Main advantage is reduction in size however server becomes dependent. A new release of PHP before servers are functional requires a recompiled WinBinder module.

Top

Partial integration

Partial integration is to replace UniTray with our generic menu and update architecture accordingly. Small architecture changes means UniTray cannot be reinstated. Further UniTray has been a stable component for a long time and its removable has the potential to alienate users.

Top

Self-contained plugin

A self-contained menu has none of the above disadvantages. However price paid is an increase in size this is reducible by deleting UniTry.

A self-contained plugin by its nature means no changes to the existing control architecture.

Top

Decision time

With full and partial integration we are talking about a new architecture and a new Uniform Server branch neither is desirable.

A self-contained menu plugin provides an opportunity to test and explore its capabilities. A user has a choice to either delete it and use UniTray or delete UniTray and use the new menu.

Remainder of this tutorial looks at the self-contained menu plugin option.

Top

General note

What’s important; you have full control over menu design and implementation. Nothing is written in stone hence change code and menu configuration file as required.

That said this tutorial concludes with a working example use as is or modify it to meet your own requirements.

The menu has a number of advantages, provides UTF-8 support allowing it to be translated into any language without recourse to using entities. Removes the need for a third party component thus providing full architecture control. Main advantage is the unification of Uniform Server’s control architecture all scripting is written in a common language PHP.

There are a few problems areas that require addressing these are covered first. This is followed by integration.

Killing a WinBinder windowed application.

XP-Home is the minimum OS for Uniform Server hence killing a process by name still requires utility pskill.

Problem 1

Killing a tray menu when minimised leaves an image artefact. This will disappear when either the task bar is refreshed or when mouse is moved over tray icon. UniTray also suffered from this issue however solution used for Unitay cannot be applied to our WinBinder tray menu.

Top

Solution

When an application is maximised (visible) killing it with pskill leaves no artefacts. Our tray menu is a single instance application implemented using this WinBinder function

bool wb_get_instance (string caption [, bool bringtofront])

The second parameter when set to true forces a minimised application to be maximised (visible) allowing it to be cleanly killed with pskill.

Top

Problem 2

I mentioned killing an application by name problem is what name to use.

Top

Solution

For a multi-server implementation UniTray uses an executable name UniTray1.exe the digit being incremented for each new instance of Uniform Server.

A similar technique is used for our new tray menu. You may be wondering what application to rename!

For testing this would be php.exe final menu uses php-win.exe

Make a copy and rename to UniTray1.exe

Note: For consistency following files have been renamed:

  • tray_menu.phpw to UniTray.phpw
  • tray_menu.ini to UniTray.ini

Test scripts:

File Z_run.bat

start UniTray1.exe -n  UniTray.phpw

File Z_kill_.bat

php.exe -n   Z_kill.phpw

File Z_kill.phpw

<?php

chdir(dirname(__FILE__));                          // Change wd to this files location
include "winbinder/winbinder.php";                 // Inlude winbinder

$ini_filename         = "UniTray.ini";             // Configuration file
$ini_array = parse_ini_file($ini_filename, true);  // Read config file into array


if(wb_get_instance($ini_array['title'], TRUE)){   // If an existing instance open it
  $cmd = 'pskill.exe UniTray1.exe  c';            // Create command c=kill command 
  exec($cmd,$dummy,$return);                      // run command to kill app 
}
?>

Top

Run tests

  • Start menu using Z_run.bat
  • Minimise menu
  • Run Z_kill_.bat

Script Z_kill.phpw obtains initial application title from configuration file.

The function wb_get_instance checks for a identical running instance.

There is and forces it to pop-up then killed by name using pskill.

Thus proving the concept.

Top

Serious side effect

Serious side effect

Using the above technique of renaming either of the php.exe files introduces an undesirable effect. Running any of the menu items a command window opens for either a short time or multi-command windows open and then close.

It makes no difference which php.exe file is used culprit is our current method of detaching and running an application.

WinBinder provides a function wb_exec() this detaches a process allowing it to be run independently of the current process. However we require some processes to be hidden hence for our current scenario a combination of techniques is required to resolve the above.

Top

Solution

When you hit a problem like this its best to isolate the problem and run a few test scripts. Of importance for future reference include both failures and success.

Test requires a two batch files and test script as follows:

z_test_1.bat

php.exe -n  z_test_1.phpw
pause

z_test_2.bat

echo test > z_test.txt
exit

z_test_1.phpw

###############################################################################
# Name: z_test_1.phpw
###############################################################################
*/

chdir(dirname(__FILE__)); // Change wd to this files location
include_once "winbinder/winbinder.php";

// wb_message_box (NULL, "Test bat ", "Test 1");       // Produces a command window pop-up
// wb_exec("z_test_2.bat");

// wb_message_box (NULL, "Test exe", "Test 2");        // Convert bat to exe no problems
// wb_exec("z_test_2.exe");

// wb_message_box (NULL, "Test bat hidden", "Test 3");  // Run using uniserv.exe
// wb_exec("uniserv.exe"," z_test_2.bat");

// wb_message_box (NULL, "Test Notepad", "Test 4");     // No problem
// wb_exec("Notepad.exe");

// wb_message_box (NULL, "Test PHP", "Test 5");          // failed command pop-up 
// wb_exec("php.exe", " -n unitray_info.php 1");

// wb_message_box (NULL, "Test PHP", "Test 6");          // no problems 
// wb_exec( "uniserv.exe",   "\"php.exe -n unitray_info.php 1\"");

 wb_message_box (NULL, "Start UniServer", "Test 7");      // no problem 
 wb_exec( "uniserv.exe",   "\"php.exe -n ../main/start_servers.php 7\"");

 wb_message_box (NULL, "Test PHP", "Test 8");             // no problems 
 wb_exec( "uniserv.exe",   "\"php.exe -n unitray_info.php 1\"");

 wb_message_box (NULL, "Stop UniServers", "Test 9");        // no problems 
 wb_exec( "uniserv.exe",   "\"php.exe -n ../main/stop_servers.php 7\"");
?>

You can run a test by un-commenting a pair of lines.

I have included results these show command window pop-ups are resolvable.

However it does mean the menu command processor will require changing.

Not a real problem since our generic menu was always going to be modified to meet Uniform Server specific requirements. In particular add additional features impossible using original UniTray menu.

Top

Clean up

Generic menu files were moved into folder tray_menu_2.

Common files were moved into their own appropriate folders.

  • winbinder Contains the four WinBinder files:
  • images Contains menu icons (1-9) and image menu icon strip
  • includes Contains all include files
  • test_scripts For reference contains all test files mentioned.

Top

Download and Install

A working menu can be downloaded from SourceForge.

Depending on the file format choose one of the following installation methods:

exe:

  • Download file us_tray_menu_1.0.0.exe from Sourceforge
  • Save to folder UniServer.
  • To extract double click on file us_tray_menu_1.0.0.exe
  • You will see a new file Start_UniTray_2.exe double click to start menu
  • A new folder UniServer\unicon\tray_menu_2 is created containing menu folders and files:

zip:

  • Download file us_tray_menu_1.0.0.zip from Sourceforge
  • Create a new folder us2_temp and copy us_tray_menu_1.0.0.zip to it.
  • Extract all files to this current folder.
  • Copy file us2_temp\us_tray_menu_1.0.0\Start_UniTray_2.exe to folder UniServer
  • Copy folder us2_temp\us_tray_menu_1.0.0\unicon\tray_menu_2 and all its content to folder UniServer\unicon
  • To start menu double click on file Start_UniTray_2.exe

Note:

Tray menu menu us_tray_menu_1.0.0 although fully functional is really a starting point. Effectively it’s a replacement for UniTray with the advantage of UTF-8 support.

Translation: Edit file UniServer\unicon\tray_menu_2\UniTray.ini change all item[] text as appropriate.

Top

Summary

The above highlighted several issues and provided solutions.

These need to be integrated into our generic menu.

Next page covers modification required to the command processor.

Top