Update to version 1.1

This commit is contained in:
Panagiotis Dimopoulos 2018-04-02 14:34:00 +03:00 committed by Carlos R. Mafra
parent 9c9d1a22b0
commit aba739e980
6 changed files with 203 additions and 59 deletions

View file

@ -1,3 +1,12 @@
2018-04-02 Panagiotis A. Dimopoulos <panosdim@gmail.com>
- Release 1.1
- Add a gear icon to show when checking for updates
- Right click initiate a check for updates
- Left click will open an xterm and start system update
- You can now define that check interval with -c or --check-interval
command line arguments
2018-03-29 Panagiotis A. Dimopoulos <panosdim@gmail.com> 2018-03-29 Panagiotis A. Dimopoulos <panosdim@gmail.com>
Initial Release 1.0 - Initial Release 1.0

View file

@ -1,7 +1,7 @@
CC=gcc CC=gcc
INSTALL=install INSTALL=install
PREFIX=/usr/local PREFIX=/usr/local
CFLAGS+=-Wall `pkg-config --cflags dockapp` CFLAGS+=-Wall -O3 `pkg-config --cflags dockapp`
LIBS=`pkg-config --libs dockapp` LIBS=`pkg-config --libs dockapp`
wmarchup: wmarchup.o wmarchup: wmarchup.o
@ -13,6 +13,7 @@ wmarchup.o: wmarchup.c
install: install:
$(INSTALL) -d $(DESTDIR)$(PREFIX)/bin $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin
$(INSTALL) wmarchup $(DESTDIR)$(PREFIX)/bin $(INSTALL) wmarchup $(DESTDIR)$(PREFIX)/bin
$(INSTALL) arch_update.sh $(DESTDIR)$(PREFIX)/bin
clean: clean:
rm -f wmarchup wmarchup.o rm -f wmarchup wmarchup.o

View file

@ -17,13 +17,19 @@ managers such as Window Maker, AfterStep, BlackBox, Fluxbox and Enlightenment.
This dockapp is quite simple. It contains an Arch Linux logo icon. When there is This dockapp is quite simple. It contains an Arch Linux logo icon. When there is
not package updates then the Arch Linux logo icon is greyed. When there are not package updates then the Arch Linux logo icon is greyed. When there are
package updates then the Arch Linux logo icon is blue. The program check for package updates then the Arch Linux logo icon is blue. The program check for
updates every 10 minutes. updates every 10 minutes by default. However you can specify the checking
interval by using the -c or --check-interval command line arguments. When the
program checks for updates it change its icon in a gear. If you right click the
Arch Linux logo icon then it immediately starts a check for updates. If you left
click the Arch Linux log the it opens an xterm window and start a system update.
*************** ***************
*** OPTIONS *** *** OPTIONS ***
*************** ***************
This program has no command line options. This program has the following command line options
-c <number> : Sets the checking time interval in minutes. Default is 10 minutes.
--check-interval <number> : Same as -c
********************* *********************
*** REQUIREMENTS *** *** REQUIREMENTS ***
@ -31,6 +37,7 @@ This program has no command line options.
This program needs libdockapp library files in order to compile. This program needs libdockapp library files in order to compile.
You can find libdockapp at http://www.dockapps.net/libdockapp You can find libdockapp at http://www.dockapps.net/libdockapp
Also you need to have xterm installed.
******************* *******************
*** COMPILATION *** *** COMPILATION ***

7
wmArchUp/arch_update.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash
statusfile=$(mktemp)
xterm -e sh -c 'sudo pacman -Syu; echo $? > '$statusfile
status=$(cat $statusfile)
rm $statusfile
exit $status

64
wmArchUp/loading.xpm Normal file
View file

@ -0,0 +1,64 @@
/* XPM */
static char *loading[] = {
/* columns rows colors chars-per-pixel */
"56 56 2 1 ",
" c #FF727D",
". c None",
/* pixels */
"........................................................",
"......................... .........................",
"........................ ........................",
"................. ...... ...... .................",
"................ ..... ..... ................",
".............. ..... ..... ..............",
"............ .... .... ............",
"............ .. .. ............",
"............. .............",
"............. .............",
".............. ..............",
".............. ..............",
"...... ..... ..... ......",
"...... .. .. ......",
"..... .....",
"..... .....",
".... ....",
"... ........ ...",
".... ............ ....",
"...... .............. ......",
"........ ................ ........",
"........ .................. ........",
"....... .................... .......",
"....... .................... .......",
".. ...................... ..",
". ...................... .",
". ...................... .",
". ...................... .",
". ...................... .",
". ...................... .",
". ...................... .",
".. ...................... ..",
"....... .................... .......",
"....... .................... .......",
"........ .................. ........",
"........ ................ ........",
"...... .............. ......",
".... ............ ....",
"... ........ ...",
".... ....",
"..... .....",
"..... .....",
"...... .. .. ......",
"...... ..... ..... ......",
".............. ..............",
".............. ..............",
"............. .............",
"............. .............",
"............ .. .. ............",
"............ .... .... ............",
".............. ..... ..... ..............",
"................ ..... ..... ................",
"................. ...... ...... .................",
"........................ ........................",
"......................... .........................",
"........................................................"
};

View file

@ -1,36 +1,34 @@
/* /* Also includes Xlib, Xresources, XPM, stdlib and stdio */
* Copyright (c) 2002 Alban G. Hertroys
*
* Basic example of libDockapp usage
*
* This dockapp will draw a rectangle with a
* bouncing ball in it.
*/
/* also includes Xlib, Xresources, XPM, stdlib and stdio */
#include <dockapp.h> #include <dockapp.h>
#include <stdio.h> #include <stdio.h>
/* include the pixmap to use */ /* Include the pixmap to use */
#include "archlinux.xpm" #include "archlinux.xpm"
#include "archlinux_bw.xpm" #include "archlinux_bw.xpm"
#include "loading.xpm"
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#define MAX 256 #define MAX 256
#define CHK_INTERVAL 600
#define WMARCHUP_VER "1.1"
#define VERSION "wmArchUp version " WMARCHUP_VER
/* /*
* Prototypes for local functions * Prototypes for local functions
*/ */
void destroy(void); void destroy(void);
int check_for_updates(); void check_for_updates();
void buttonrelease(int button, int state, int x, int y);
void update();
/* /*
* Global variables * Global variables
*/ */
Pixmap arch, arch_mask, arch_bw, arch_bw_mask; Pixmap arch, arch_mask, arch_bw, arch_bw_mask, checking, checking_mask;
unsigned short height, width; unsigned short height, width;
XEvent ev; unsigned int check_interval = CHK_INTERVAL;
int updates_available = FALSE;
/* /*
* M A I N * M A I N
@ -39,27 +37,43 @@ XEvent ev;
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
/* Set callbacks for events */
DACallbacks eventCallbacks = { DACallbacks eventCallbacks = {
destroy, /* destroy */ destroy, /* destroy */
NULL, /* buttonPress */ NULL, /* buttonPress */
NULL, /* buttonRelease */ &buttonrelease, /* buttonRelease */
NULL, /* motion (mouse) */ NULL, /* motion (mouse) */
NULL, /* mouse enters window */ NULL, /* mouse enters window */
NULL, /* mouse leaves window */ NULL, /* mouse leaves window */
NULL /* timeout */ check_for_updates /* timeout */
};
int interval = 0;
/* Set program options */
DAProgramOption options[] = {
{
"-c",
"--check-interval",
"Check interval in minutes. Default 10 minutes.",
DONatural,
False,
{&interval}
},
}; };
/* provide standard command-line options */ /* provide standard command-line options */
DAParseArguments( DAParseArguments(
argc, argv, /* Where the options come from */ argc, argv, /* Where the options come from */
NULL, 0, /* Our list with options - none as you can see */ options, 1, /* Our list with options */
"This is dockapp watch for available updates " "This is dockapp watch for available updates "
"in Arch Linux packages.\n", "in Arch Linux packages.\n",
"wmarchup version 1.0"); VERSION);
/* Tell libdockapp what version we expect it to be (a date from /* Set the check interval */
* NEWS should do). check_interval = interval ? (interval * 60) : CHK_INTERVAL;
*/
/* Check if correct libdockapp version exists in system */
DASetExpectedVersion(20050716); DASetExpectedVersion(20050716);
DAInitialize("", "WMArchUp", 56, 56, argc, argv); DAInitialize("", "WMArchUp", 56, 56, argc, argv);
@ -78,50 +92,80 @@ main(int argc, char **argv)
&height, &height,
&width); &width);
DASetShape(arch_bw_mask); DAMakePixmapFromData(
DASetPixmap(arch_bw); loading,
&checking,
&checking_mask,
&height,
&width);
/* Respond to destroy and timeout events (the ones not NULL in the /* Respond to destroy and timeout events (the ones not NULL in the
* eventCallbacks variable. * eventCallbacks variable.
*/ */
DASetCallbacks(&eventCallbacks); DASetCallbacks(&eventCallbacks);
DAShow(); /* Show the dockapp window. */ /* Set timeout in msec */
DASetTimeout(check_interval * 1000);
while (1) { /* Show the dockapp window. */
if (check_for_updates() == TRUE) { DAShow();
DASetShape(arch_mask);
DASetPixmap(arch);
} else {
DASetShape(arch_bw_mask);
DASetPixmap(arch_bw);
}
/* handle all pending X events */ /* Check for updates at the begining */
while (XPending(DADisplay)) { check_for_updates();
XNextEvent(DADisplay, &ev);
DAProcessEvent(&ev); /* Loop for events */
} DAEventLoop();
sleep(600);
}
/* not reached */ /* not reached */
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
int void
check_for_updates() { update()
{
if (updates_available == TRUE) {
XSelectInput(DAGetDisplay(NULL), DAGetWindow(), NoEventMask);
char *update_script = "./arch_update.sh";
int ret = system(update_script);
if (WEXITSTATUS(ret) == 0) {
updates_available = FALSE;
DASetShape(arch_bw_mask);
DASetPixmap(arch_bw);
}
XSelectInput(DAGetDisplay(NULL), DAGetWindow(),
ButtonPressMask | ButtonReleaseMask);
}
}
void
check_for_updates()
{
XSelectInput(DAGetDisplay(NULL), DAGetWindow(), NoEventMask);
FILE *fp; FILE *fp;
char res[MAX]; char res[MAX];
DASetShape(checking_mask);
DASetPixmap(checking);
/* Read output from command */ /* Read output from command */
fp = popen("checkupdates","r"); fp = popen("checkupdates", "r");
if( fgets (res, MAX, fp)!=NULL ) { if (fgets(res, MAX, fp) != NULL) {
fclose(fp); fclose(fp);
return TRUE; updates_available = TRUE;
DASetShape(arch_mask);
DASetPixmap(arch);
} else { } else {
return FALSE; updates_available = FALSE;
DASetShape(arch_bw_mask);
DASetPixmap(arch_bw);
} }
XSelectInput(DAGetDisplay(NULL), DAGetWindow(),
ButtonPressMask | ButtonReleaseMask);
} }
void void
@ -129,3 +173,15 @@ destroy(void)
{ {
return; return;
} }
/* A mouse button was pressed and released.
* See if it was button 1 left click or button 3 right click. */
void
buttonrelease(int button, int state, int x, int y)
{
if (button == 1) {
update();
} else if (button == 3) {
check_for_updates();
}
}