Skip to content

Commit

Permalink
Merge pull request #35 from sandlbn/amigaampiconify
Browse files Browse the repository at this point in the history
Add Iconify AmigaAMP on start to automatically minimize AmigaAMP
  • Loading branch information
sandlbn authored Dec 10, 2024
2 parents 6ee274a + 0828d52 commit 1609d1f
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 15 deletions.
1 change: 1 addition & 0 deletions assets/amigaguide/tunefinder.english.guide
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ API Settings window contains:
- Autostart Program: Path to AmigaAMP executable for streaming playback
Click the 'Browse' button to select AmigaAMP executable location.
Example: "SYS:Media/AmigaAMP/AmigaAMP"
- Enable "Iconify AmigaAMP" to automatically minimize AmigaAMP

The autostart setting allows TuneFinder to launch AmigaAMP automatically when
needed for streaming. When set, AmigaAMP will be started if it's not already
Expand Down
6 changes: 5 additions & 1 deletion assets/aminet/TuneFinder.README
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Short: Search and play online radio stations
Author: [email protected] (Marcin Spoczynski)
Uploader: [email protected] (Marcin Spoczynski)
Type: comm/misc
Version: 1.3
Version: 1.3a
Architecture: m68k-amigaos >= 3.0
Distribution: Aminet
Replaces: comm/misc/TuneFinder.lha
Expand Down Expand Up @@ -133,4 +133,8 @@ TuneFinder 1.3 (08.12.2024)
- Renamed Save buttons to 'All' and 'One' for better fit
- Bug fixes and UI improvements

TuneFinder 1.3a (09.12.2024)

- Added Iconify AmigaAMP on start to automatically minimize AmigaAMP

Special thanks to Flype, Thomas, Ponki1986, Samir, Alexander, Paluch and many others for their help testing TuneFinder!
2 changes: 1 addition & 1 deletion assets/install/Install_TuneFinder
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

(welcome
"Welcome to the TuneFinder installation program.\n\n"
"This will install TuneFinder version 1.3 beta on your system."
"This will install TuneFinder version 1.3a on your system."
)

(set default-dest
Expand Down
3 changes: 3 additions & 0 deletions assets/translation/tunefinder.cd
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ Browse
MSG_SELECT_PROGRAM (36//)
Select program
;
MSG_ICONIFY_AMIGAAMP (37//)
Iconify AmigaAMP
;
; Status Messages with Parameters
MSG_FOUND_STATIONS (40//)
Found %d stations
Expand Down
4 changes: 3 additions & 1 deletion assets/translation/tunefinder_english.ct
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ Browse
MSG_SELECT_PROGRAM
Select program
;

MSG_ICONIFY_AMIGAAMP
Iconify AmigaAMP
;
MSG_FOUND_STATIONS
Found %d stations
;
Expand Down
1 change: 1 addition & 0 deletions include/amigaamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ BOOL NextTrackAmigaAMP(void);
BOOL PreviousTrackAmigaAMP(void);
BOOL SetVolumeAmigaAMP(LONG volume);
BOOL QuitAmigaAMP(void);
BOOL WaitAndIconifyAmigaAMP(void);

#endif /* AMIGAAMP_H */
2 changes: 1 addition & 1 deletion include/locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#define MSG_AUTOSTART 34 // "Autostart Program"
#define MSG_BROWSE 35 // "Browse"
#define MSG_SELECT_PROGRAM 36 // "Select program"

#define MSG_ICONIFY_AMIGAAMP 37 // Iconify amigaamp
// Status Messages with Parameters
#define MSG_FOUND_STATIONS 40 // "Found %d stations"
#define MSG_PLAYING_STATION 41 // "Playing: %s"
Expand Down
3 changes: 2 additions & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define ENV_COUNTRY "country"
#define ENV_CODEC "codec"
#define ENV_AUTOSTART "autostart"
#define ENV_ICONIFY_AMIGAAMP "iconify_amigaamp"
#define MAX_PATH_LEN 256

struct APISettings {
Expand All @@ -26,7 +27,7 @@ struct APISettings {
char autostart[MAX_PATH_LEN];
ULONG windowLeft;
ULONG windowTop;

BOOL iconifyAmigaAMP;
};

BOOL LoadSettings(struct APISettings *settings);
Expand Down
6 changes: 3 additions & 3 deletions include/version.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef VERSION_H
#define VERSION_H

#define VERS "TuneFinder 1.3"
#define VSTRING "TuneFinder 1.3 (12.08.2024)\r\n"
#define VERSTAG "\0$VER: TuneFinder 1.3 (12.08.2024)"
#define VERS "TuneFinder 1.3a"
#define VSTRING "TuneFinder 1.3a (12.09.2024)\r\n"
#define VERSTAG "\0$VER: TuneFinder 1.3a (12.09.2024)"
#define AUTHOR "Marcin Spoczynski"
#define TRANSLATION "-German: Thomas Blatt\n-Italian: Samir Hawamdeh\n-French: Eric 'Tarinz' LUCZYSZYN \nIcons: Thomas Blatt\n"
__attribute__((section(".text"))) UBYTE VString[] =
Expand Down
20 changes: 19 additions & 1 deletion src/amigaamp/amigaamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,22 @@ BOOL SetVolumeAmigaAMP(LONG volume) {

BOOL QuitAmigaAMP(void) {
return SendCommandToAmigaAMP("QUIT");
}
}

BOOL WaitAndIconifyAmigaAMP(void) {
BOOL success = FALSE;
int retries = 20; // Wait up to 2 seconds (20 * 100ms)

// Wait for AmigaAMP to start and open its ARexx port
while (retries > 0) {
if (IsAmigaAMPRunning()) {
// Try to iconify
success = SendCommandToAmigaAMP("ICONIFY");
break;
}
Delay(5); // Wait 100ms
retries--;
}

return success;
}
4 changes: 2 additions & 2 deletions src/locale/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ static const char *built_in_strings[] = {

// Options and Settings (30-35)
"API Host", "API Port", "HTTPS Only", "Hide Broken", "Autostart Program", "Browse",
"Select Program",
"Select Program", "Iconify AmigaAmp",
// Padding to align with IDs 39
NULL, NULL, NULL,
NULL, NULL,

// Status Messages with Parameters (40-46)
"Found %d stations", "Playing: %s", "Settings loaded.", "Settings saved.",
Expand Down
3 changes: 3 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ int main(int argc, char *argv[]) {
DEBUG("Launching autostart program: %s", currentSettings.autostart);
SystemTags(currentSettings.autostart, SYS_Input, NULL, SYS_Output, NULL,
SYS_Asynch, TRUE, TAG_DONE);
if (currentSettings.iconifyAmigaAMP) {
WaitAndIconifyAmigaAMP();
}
}

// Create message port for AppIcon
Expand Down
47 changes: 43 additions & 4 deletions src/settings/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ BOOL SaveSettings(const struct APISettings *settings) {
return FALSE;
}
Close(file);

// Save iconify setting
sprintf(filepath, TUNEFINDER_DIR ENV_ICONIFY_AMIGAAMP);
file = Open(filepath, MODE_NEWFILE);
if (file) {
char value = settings->iconifyAmigaAMP ? '1' : '0';
Write(file, &value, 1);
Close(file);
}
GetTFFormattedString(msg, sizeof(msg), MSG_SET_SAVED, settings->host, settings->port, settings->limit);
UpdateStatusMessage(msg);
return TRUE;
Expand Down Expand Up @@ -229,6 +236,19 @@ BOOL LoadSettings(struct APISettings *settings) {
settings->windowLeft = NO_POSITION;
settings->windowTop = NO_POSITION;
}

sprintf(filepath, TUNEFINDER_DIR ENV_ICONIFY_AMIGAAMP);
file = Open(filepath, MODE_OLDFILE);
if (file) {
char value;
if (Read(file, &value, 1) == 1) {
settings->iconifyAmigaAMP = (value == '1');
}
Close(file);
} else {
settings->iconifyAmigaAMP = FALSE; // Default to not iconifying
}

UpdateStatusMessage(GetTFString(MSG_SETTINGS_LOADED));

return (hostLoaded || portLoaded || limitLoaded || defaultProgram);
Expand All @@ -242,6 +262,7 @@ BOOL CreateSettingsWindow(struct APISettings *settings, struct Window *parent) {
struct Gadget *limitGad = NULL;
struct Gadget *autostartGad = NULL;
struct Gadget *browseGad = NULL;
struct Gadget *iconifyCheckBox = NULL;

struct NewGadget ng;
void *vi;
Expand Down Expand Up @@ -368,6 +389,22 @@ BOOL CreateSettingsWindow(struct APISettings *settings, struct Window *parent) {
// Move to next row
currentTop += rowHeight + rowSpacing;

// checkbox after autostart gadget
ng.ng_TopEdge += rowHeight + rowSpacing;
ng.ng_LeftEdge = leftMargin + labelWidth;
ng.ng_Width = controlWidth;
ng.ng_GadgetText = GetTFString(MSG_ICONIFY_AMIGAAMP);
ng.ng_Flags = PLACETEXT_LEFT;
ng.ng_GadgetID = 22;

iconifyCheckBox = CreateGadget(
CHECKBOX_KIND, autostartGad, &ng,
GTCB_Checked, settings->iconifyAmigaAMP,
TAG_DONE
);
// Move to next row
currentTop += rowHeight + rowSpacing;

// Move to button row
currentTop += rowHeight + rowSpacing * 2; // Extra spacing before buttons

Expand All @@ -379,7 +416,7 @@ BOOL CreateSettingsWindow(struct APISettings *settings, struct Window *parent) {
ng.ng_GadgetID = 4;
ng.ng_Flags = PLACETEXT_IN;

gad = CreateGadget(BUTTON_KIND, browseGad, &ng, TAG_DONE);
gad = CreateGadget(BUTTON_KIND, iconifyCheckBox, &ng, TAG_DONE);
if (!gad) {
DEBUG("Failed to create save button");
goto cleanup;
Expand Down Expand Up @@ -452,17 +489,18 @@ BOOL CreateSettingsWindow(struct APISettings *settings, struct Window *parent) {
STRPTR hostStr, portStr, limitStr, autoStartStr;
BOOL inputValid = TRUE;
char msg[MAX_STATUS_MSG_LEN];
LONG iconifyState = 0;

GT_GetGadgetAttrs(hostGad, window, NULL, GTST_String, &hostStr,
TAG_DONE);

GT_GetGadgetAttrs(portGad, window, NULL, GTST_String, &portStr,
TAG_DONE);

GT_GetGadgetAttrs(limitGad, window, NULL, GTST_String, &limitStr,
TAG_DONE);
GT_GetGadgetAttrs(autostartGad, window, NULL, GTST_String,
&autoStartStr, TAG_DONE);
GT_GetGadgetAttrs(iconifyCheckBox, window, NULL, GTCB_Checked,
&iconifyState, TAG_DONE);

if (autoStartStr) {
strncpy(settings->autostart, autoStartStr, MAX_PATH_LEN - 1);
Expand Down Expand Up @@ -498,6 +536,7 @@ BOOL CreateSettingsWindow(struct APISettings *settings, struct Window *parent) {
settings->host[MAX_HOST_LEN - 1] = '\0';
settings->port = (UWORD)tempPort;
settings->limit = tempLimit;
settings->iconifyAmigaAMP = iconifyState ? TRUE : FALSE;

if (SaveSettings(settings)) {
success = TRUE;
Expand Down

0 comments on commit 1609d1f

Please sign in to comment.