Skip to content

Commit

Permalink
stop/restart panel/dock
Browse files Browse the repository at this point in the history
  • Loading branch information
darkoverlordofdata committed Nov 30, 2023
1 parent 8fcbca9 commit 25207ff
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 68 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cmake.configureOnOpen": true,
"editor.inlayHints.enabled": "off",
// "extensions.ignoreRecommendations": true,
// "cmake.buildDirectory": "${workspaceRoot}/${workspaceFolderBasename}.app",
"cmake.buildDirectory": "${workspaceRoot}/DailyBing.app"
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set ( APP_NAME "DailyBing" )
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON )

include ( CMakeToolsHelpers OPTIONAL )
list ( APPEND CMAKE_MODULE_PATH ~/.local/lib/cmake/GNUstep )
list ( APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/GNUstep )
find_package ( GNUstep REQUIRED )

link_directories ( ${GNUSTEP_LIBRARY_DIRS} )
Expand Down
Binary file modified DailyBing
Binary file not shown.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,17 @@ pkill dde-top-panel;pkill dde-dock;openapp DailyBing --lockscreen --pin 420420;d
sh /usr/GNUstep/Local/Applications/DailyBing.app/Resources/LockScreen


openapp DailyBing --lockscreen --pin 420420 --task dde-top-panel --task dde-dock
openapp DailyBing --lockscreen --pin 420420 --dde-top-panel --dde-dock

openapp DailyBing --lockscreen --pin 420420 --Menu --plank

cmake --build DailyBing.app
cmake --build DailyBing.app --target install



--dde-top-panel
--dde-dock
--Menu
--plank

74 changes: 74 additions & 0 deletions Resources/QtSingleApplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# @see https://copyprogramming.com/howto/qtsingleapplication-for-pyside-or-pyqt


import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtNetwork import *
from PyQt5.QtWidgets import (QApplication, QMainWindow, QTableView,
QWidget, QVBoxLayout, QLabel, QHeaderView)

class QtSingleApplication(QApplication):
messageReceived = pyqtSignal()
def __init__(self, id, *argv):
super(QtSingleApplication, self).__init__(*argv)
self._id = id
self._activationWindow = None
self._activateOnMessage = False
# Is there another instance running?
self._outSocket = QLocalSocket()
self._outSocket.connectToServer(self._id)
self._isRunning = self._outSocket.waitForConnected()
if self._isRunning:
# Yes, there is.
self._outStream = QTextStream(self._outSocket)
self._outStream.setCodec('UTF-8')
else:
# No, there isn't.
self._outSocket = None
self._outStream = None
self._inSocket = None
self._inStream = None
self._server = QLocalServer()
self._server.listen(self._id)
self._server.newConnection.connect(self._onNewConnection)
def isRunning(self):
return self._isRunning
def id(self):
return self._id
def activationWindow(self):
return self._activationWindow
def setActivationWindow(self, activationWindow, activateOnMessage = True):
self._activationWindow = activationWindow
self._activateOnMessage = activateOnMessage
def activateWindow(self):
if not self._activationWindow:
return
self._activationWindow.setWindowState(
self._activationWindow.windowState() & ~Qt.WindowMinimized)
self._activationWindow.raise_()
self._activationWindow.activateWindow()
def sendMessage(self, msg):
if not self._outStream:
return False
self._outStream << msg << '\n'
self._outStream.flush()
return self._outSocket.waitForBytesWritten()
def _onNewConnection(self):
if self._inSocket:
self._inSocket.readyRead.disconnect(self._onReadyRead)
self._inSocket = self._server.nextPendingConnection()
if not self._inSocket:
return
self._inStream = QTextStream(self._inSocket)
self._inStream.setCodec('UTF-8')
self._inSocket.readyRead.connect(self._onReadyRead)
if self._activateOnMessage:
self.activateWindow()
def _onReadyRead(self):
while True:
msg = self._inStream.readLine()
if not msg: break
self.messageReceived.emit(msg)


16 changes: 3 additions & 13 deletions Resources/catlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,19 +390,6 @@ def checkDownloadStatus(self, valid, dbus):


if __name__ == '__main__':
#
# bail if already running:
#
# Simple singleton:
# Ensure that only one instance of this application is running by trying to kill the other ones
# p = QProcess()
# p.setProgram("pkill")
# p.setArguments(["-f", os.path.abspath(__file__)])
# cmd = p.program() + " " + " ".join(p.arguments())
# print(cmd)
# p.start()
# p.waitForFinished()



usage = """Usage:
Expand All @@ -424,6 +411,9 @@ def checkDownloadStatus(self, valid, dbus):
valid = False

app = QApplication(sys.argv)
# app = QtSingleApplication('6ca8b889-1e95-4f8e-9d55-f18624c9d188', sys.argv)
# if app.isRunning():
# sys.exit(0)


try:
Expand Down
17 changes: 16 additions & 1 deletion Source/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,24 @@
@property (strong, nonatomic) NSString *defaultAt;
@property (strong, nonatomic) NSString *defaultFont;
@property (strong, nonatomic) NSWindow *window;
@property (assign, nonatomic) BOOL plank;
@property (assign, nonatomic) BOOL menu;
@property (assign, nonatomic) BOOL dde_dock;
@property (assign, nonatomic) BOOL dde_top_panel;


// - (instancetype)initWithPin:(NSString*)pin at:(NSString*)at font:(NSString*)font;
- (instancetype)initWithFlags:(BOOL)help version:(BOOL)version schedule:(BOOL)schedule lockscreen:(BOOL)lockscreen pin:(NSString*)pin at:(NSString*)at font:(NSString*)font ;
- (instancetype)initWithFlags:(BOOL)help
version:(BOOL)version
schedule:(BOOL)schedule
lockscreen:(BOOL)lockscreen
pin:(NSString*)pin
at:(NSString*)at
font:(NSString*)font
plank:(BOOL)plank
menu:(BOOL)menu
dde_dock:(BOOL)dde_dock
dde_top_panel:(BOOL)dde_top_panel;

- (void)applicationDidFinishLaunching:(NSNotification *) not;
- (void)applicationWillTerminate:(NSNotification *) not;
Expand Down
45 changes: 39 additions & 6 deletions Source/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ @implementation AppDelegate
@synthesize defaultPin = _defaultPin;
@synthesize defaultAt = _defaultAt;
@synthesize defaultFont = _defaultFont;
@synthesize plank = _plank;
@synthesize menu = _menu;
@synthesize dde_dock = _dde_dock;
@synthesize dde_top_panel = _dde_top_panel;


- (instancetype) init
Expand All @@ -32,7 +36,17 @@ - (instancetype) init
}


- (instancetype)initWithFlags:(BOOL)help version:(BOOL)version schedule:(BOOL)schedule lockscreen:(BOOL)lockscreen pin:(NSString*)pin at:(NSString*)at font:(NSString*)font
- (instancetype)initWithFlags:(BOOL)help
version:(BOOL)version
schedule:(BOOL)schedule
lockscreen:(BOOL)lockscreen
pin:(NSString*)pin
at:(NSString*)at
font:(NSString*)font
plank:(BOOL)plank
menu:(BOOL)menu
dde_dock:(BOOL)dde_dock
dde_top_panel:(BOOL)dde_top_panel;
{
self = [self init];

Expand All @@ -45,6 +59,11 @@ - (instancetype)initWithFlags:(BOOL)help version:(BOOL)version schedule:(BOOL)sc
_at = [at isEqualToString:@""]? _defaultAt : at;
_font = [font isEqualToString:@""]? _defaultFont : font;

_plank = plank;
_menu = menu;
_dde_dock = dde_dock;
_dde_top_panel = dde_top_panel;

return self;
}

Expand All @@ -63,6 +82,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
*/
if (_help) {
printf("Usage: openapp DailyBing [OPTION ...]\n");
printf("-1, --plank\n");
printf("-2, --Menu\n");
printf("-3, --dde-dock\n");
printf("-4, --dde-top-panel\n");
printf("-h, --help display this help message\n");
printf("-v, --version display version\n");
printf("-s, --schedule schedule download\n");
Expand All @@ -84,11 +107,21 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
*/
} else if (_lockscreen) {

if ([[[[NSProcessInfo processInfo] environment] objectForKey:@"DESKTOP_SESSION"] isEqualToString:@"dde-x11"])
{
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/pkill" arguments:[NSArray arrayWithObjects:@"dde-top-panel", nil]];
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/pkill" arguments:[NSArray arrayWithObjects:@"dde-dock", nil]];
}
// if ([[[[NSProcessInfo processInfo] environment] objectForKey:@"DESKTOP_SESSION"] isEqualToString:@"dde-x11"])
// {
if (_plank)
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/pkill" arguments:[NSArray arrayWithObjects:@"plank", nil]];

if (_menu)
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/pkill" arguments:[NSArray arrayWithObjects:@"Menu", nil]];

if (_dde_dock)
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/pkill" arguments:[NSArray arrayWithObjects:@"dde-dock", nil]];

if (_dde_top_panel)
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/pkill" arguments:[NSArray arrayWithObjects:@"dde-top-panel", nil]];

// }

_window = [[LockWindow alloc] initWithParent:self];
[_window setDelegate:self];
Expand Down
4 changes: 2 additions & 2 deletions Source/Interactive/ImagePanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ - (void)onSelectImage
if ([[NSFileManager defaultManager] fileExistsAtPath: @"/usr/local/bin/launch"]) {

// helloSystem
NSLog(@"/usr/local/bin/launch Filer --set-wallpaper %@", [NSString stringWithFormat:@"%@", wallpaperPicture]);
NSLog(@"/usr/local/bin/launch /System/Filer.app/Filer --set-wallpaper %@", [NSString stringWithFormat:@"%@", wallpaperPicture]);
[NSTask launchedTaskWithLaunchPath:@"/usr/local/bin/launch"
arguments:@[
@"/usr/local/bin/launch",
@"Filer",
@"/System/Filer.app/Filer",
@"--set-wallpaper",
[NSString stringWithFormat:@"%@", wallpaperPicture]
]];
Expand Down
15 changes: 10 additions & 5 deletions Source/Interactive/ImageWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ - (instancetype)initWithParent: (AppDelegate*) app
[super initWithContentRect:NSMakeRect(0, 0, 1920, 140) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO];
[self setTitle:@"Bing Picture Of the Day"];

if ([NSWindow instancesRespondToSelector:@selector(setIsVisible:)]) {
// Latest version on Linux has fixed this
#if OBJC_RUNTIME==21
[self setIsVisible:YES];
} else {
// Latest version on FreeBSD doesn't have the fix yet...
#else
[self orderFrontRegardless];
}
#endif
// if ([NSWindow instancesRespondToSelector:@selector(setIsVisible:)]) {
// // Latest version on Linux has fixed this
// [self setIsVisible:YES];
// } else {
// // Latest version on FreeBSD doesn't have the fix yet...
// [self orderFrontRegardless];
// }
return self;
}

Expand Down
21 changes: 15 additions & 6 deletions Source/LockScreen/LockWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ - (instancetype)initWithParent: (AppDelegate*) app
[self becomeMainWindow];
[self becomeKeyWindow];
[self orderFrontRegardless];
[self setLevel:NSScreenSaverWindowLevel - 1];
[self setLevel:NSScreenSaverWindowLevel];
[self setAutodisplay:YES];
[self makeFirstResponder:self];
[self setExcludedFromWindowsMenu:YES];
Expand Down Expand Up @@ -443,11 +443,20 @@ - (void)keyDown:(NSEvent *)theEvent
[_passcode setStringValue:_input];
if ([_input isEqualToString:_pin]) {

if ([[[[NSProcessInfo processInfo] environment] objectForKey:@"DESKTOP_SESSION"] isEqualToString:@"dde-x11"])
{
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/dde-top-panel" arguments:@[]];
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/dde-dock" arguments:@[]];
}
// if ([[[[NSProcessInfo processInfo] environment] objectForKey:@"DESKTOP_SESSION"] isEqualToString:@"dde-x11"])
// {
if (_app.plank)
[NSTask launchedTaskWithLaunchPath:@"/usr/local/bin/plank" arguments:@[]];

if (_app.menu)
[NSTask launchedTaskWithLaunchPath:@"/System/Menu.app/Menu" arguments:@[]];

if (_app.dde_top_panel)
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/dde-top-panel" arguments:@[]];

if (_app.dde_dock)
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/dde-dock" arguments:@[]];
// }

_timer = [NSTimer scheduledTimerWithTimeInterval:0.25f
target:self
Expand Down
37 changes: 34 additions & 3 deletions Source/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
* Decode process arguments
*/
static const struct option longopts[] = {
{"plank", no_argument, NULL, '1'},
{"Menu", no_argument, NULL, '2'},
{"dde-dock", no_argument, NULL, '3'},
{"dde-top-panel", no_argument, NULL, '4'},
{"help", no_argument, NULL, 'h'},
{"lockscreen", no_argument, NULL, 'l'},
{"schedule", no_argument, NULL, 's'},
{"version", no_argument, NULL, 'v'},
{"at", required_argument, NULL, 'a'},
{"pin", required_argument, NULL, 'p'},
{"font", required_argument, NULL, 'f'},
{"taask", required_argument, NULL, 't'}
{0,0,0,0}
};


Expand All @@ -34,6 +38,10 @@ int main(int argc, char *argv[])
[NSApplication sharedApplication];

int longindex = -1, opt;
BOOL task_plank = NO;
BOOL task_Menu = NO;
BOOL task_dde_dock = NO;
BOOL task_dde_top_panel = NO;
BOOL help = NO;
BOOL version = NO;
BOOL schedule = NO;
Expand All @@ -53,6 +61,20 @@ int main(int argc, char *argv[])
while ((opt = getopt_long(argc, argv, "hlsva:p:f:", longopts, &longindex))
!= -1) {
switch (opt) {

case '1': // plank
task_plank = YES;
break;
case '2': // Menu
task_Menu = YES;
break;
case '3': // dde-dock
task_dde_dock = YES;
break;
case '4': // dde-top-panel
task_dde_top_panel = YES;
break;

case 'h': // --help
help = YES;
break;
Expand All @@ -66,7 +88,6 @@ int main(int argc, char *argv[])
version = YES;
break;


case 'a': // --at
at = [NSString stringWithCString:optarg];
break;
Expand All @@ -84,7 +105,17 @@ int main(int argc, char *argv[])
}


AppDelegate *controller = [[AppDelegate alloc]initWithFlags:help version:version schedule:schedule lockscreen:lockscreen pin:pin at:at font:font];
AppDelegate *controller = [[AppDelegate alloc]initWithFlags:help
version:version
schedule:schedule
lockscreen:lockscreen
pin:pin
at:at
font:font
plank:task_plank
menu:task_Menu
dde_dock:task_dde_dock
dde_top_panel:task_dde_top_panel];
[[NSApplication sharedApplication] setDelegate: controller];

NSApplicationMain(argc, (const char **)argv);
Expand Down
Loading

0 comments on commit 25207ff

Please sign in to comment.