mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-05 12:40:40 +08:00
mac part WIP
This commit is contained in:
parent
16af97d63f
commit
c2bbc850c7
@ -14,6 +14,13 @@ set(SLIC3R_DOWNLOADER_SOURCES
|
||||
FromSlicer/Http.hpp
|
||||
)
|
||||
|
||||
if (APPLE)
|
||||
list(APPEND SLIC3R_GUI_SOURCES
|
||||
InstanceSendMac.cpp
|
||||
InstanceSendMac.hpp
|
||||
)
|
||||
endif ()
|
||||
|
||||
if(NOT WIN32)
|
||||
add_executable(PrusaSlicer_Downloader ${SLIC3R_DOWNLOADER_SOURCES})
|
||||
set_target_properties(PrusaSlicer_Downloader PROPERTIES OUTPUT_NAME "prusa-slicer-downloader")
|
||||
|
@ -228,15 +228,17 @@ bool send_message_downloader(const wxString& message)
|
||||
|
||||
#elif __APPLE__
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static bool send_message(const std::string& message_text, const std::string& version)
|
||||
{
|
||||
//std::string v(version);
|
||||
//std::replace(v.begin(), v.end(), '.', '-');
|
||||
//if (!instance_check_internal::get_lock(v))
|
||||
{
|
||||
send_message_mac(message_text, version);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@ -517,7 +519,7 @@ void OtherDownloaderMessageHandler::init(wxEvtHandler* callback_evt_handler)
|
||||
|
||||
|
||||
#if defined(__APPLE__)
|
||||
//this->register_for_messages(wxGetApp().get_instance_hash_string());
|
||||
this->register_for_messages(get_instance_hash());
|
||||
#endif //__APPLE__
|
||||
|
||||
#ifdef BACKGROUND_DOWNLOADER_MESSAGE_LISTENER
|
||||
@ -577,7 +579,7 @@ void OtherDownloaderMessageHandler::init_windows_properties(MainFrame* main_fram
|
||||
}
|
||||
void OtherInstanceMessageHandler::print_window_info(HWND hwnd)
|
||||
{
|
||||
std::wstring instance_hash = boost::nowide::widen(wxGetApp().get_instance_hash_string());
|
||||
std::wstring instance_hash = boost::nowide::widen(get_instance_hash());
|
||||
TCHAR wndText[1000];
|
||||
TCHAR className[1000];
|
||||
GetClassName(hwnd, className, 1000);
|
||||
@ -647,10 +649,11 @@ void OtherDownloaderMessageHandler::handle_message(const std::string& message)
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
//void OtherDownloaderMessageHandler::handle_message_other_closed()
|
||||
//{
|
||||
// instance_check_internal::get_lock(wxGetApp().get_instance_hash_string() + ".lock", data_dir() + "/cache/");
|
||||
//}
|
||||
void OtherDownloaderMessageHandler::handle_message_other_closed()
|
||||
{
|
||||
//get_instance_hash
|
||||
//instance_check_internal::get_lock(wxGetApp().get_instance_hash_string() + ".lock", data_dir() + "/cache/");
|
||||
}
|
||||
#endif //__APPLE__
|
||||
|
||||
#ifdef BACKGROUND_DOWNLOADER_MESSAGE_LISTENER
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
void handle_message(const std::string& message);
|
||||
#ifdef __APPLE__
|
||||
// Messege form other instance, that it deleted its lockfile - first instance to get it will create its own.
|
||||
//void handle_message_other_closed();
|
||||
void handle_message_other_closed();
|
||||
#endif //__APPLE__
|
||||
#ifdef _WIN32
|
||||
// static void init_windows_properties(MainFrame* main_frame, size_t instance_hash);
|
||||
@ -80,11 +80,11 @@ private:
|
||||
#endif //BACKGROUND_DOWNLOADER_MESSAGE_LISTENER
|
||||
|
||||
#if __APPLE__
|
||||
//implemented at InstanceCheckMac.mm
|
||||
//void register_for_messages(const std::string &version_hash);
|
||||
//void unregister_for_messages();
|
||||
// implemented at InstanceSendMac.mm
|
||||
void register_for_messages(const std::string &version_hash);
|
||||
void unregister_for_messages();
|
||||
// Opaque pointer to RemovableDriveManagerMM
|
||||
//void* m_impl_osx;
|
||||
void* m_impl_osx;
|
||||
public:
|
||||
//void bring_instance_forward();
|
||||
#endif //__APPLE__
|
||||
|
9
src/downloader/InstanceSendMac.h
Normal file
9
src/downloader/InstanceSendMac.h
Normal file
@ -0,0 +1,9 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface DownloaderMessageHandlerMac : NSObject
|
||||
|
||||
-(instancetype) init;
|
||||
-(void) add_observer:(NSString *)version;
|
||||
-(void) message_update:(NSNotification *)note;
|
||||
-(void) bring_forward;
|
||||
@end
|
83
src/downloader/InstanceSendMac.mm
Normal file
83
src/downloader/InstanceSendMac.mm
Normal file
@ -0,0 +1,83 @@
|
||||
#import "InstanceSend.hpp"
|
||||
#import "InstanceSendMac.h"
|
||||
#import "GUI_App.hpp"
|
||||
|
||||
@implementation DownloaderMessageHandlerMac
|
||||
|
||||
-(instancetype) init
|
||||
{
|
||||
self = [super init];
|
||||
return self;
|
||||
}
|
||||
-(void)add_observer:(NSString *)version_hash
|
||||
{
|
||||
//NSLog(@"adding observer");
|
||||
//NSString *nsver = @"OtherPrusaSlicerInstanceMessage" + version_hash;
|
||||
NSString *nsver = [NSString stringWithFormat: @"%@%@", @"OtherDownloaderInstanceMessage", version_hash];
|
||||
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(message_update:) name:nsver object:nil suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
|
||||
}
|
||||
|
||||
-(void)message_update:(NSNotification *)msg
|
||||
{
|
||||
[self bring_forward];
|
||||
//pass message
|
||||
//Slic3r::GUI::wxGetApp().other_instance_message_handler()->handle_message(std::string([msg.userInfo[@"data"] UTF8String]));\
|
||||
// send event instead?
|
||||
}
|
||||
|
||||
-(void) bring_forward
|
||||
{
|
||||
//demiaturize all windows
|
||||
for(NSWindow* win in [NSApp windows])
|
||||
{
|
||||
if([win isMiniaturized])
|
||||
{
|
||||
[win deminiaturize:self];
|
||||
}
|
||||
}
|
||||
//bring window to front
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace Downloader {
|
||||
|
||||
void send_message_mac(const std::string &msg, const std::string &version)
|
||||
{
|
||||
NSString *nsmsg = [NSString stringWithCString:msg.c_str() encoding:[NSString defaultCStringEncoding]];
|
||||
//NSString *nsver = @"OtherPrusaSlicerInstanceMessage" + [NSString stringWithCString:version.c_str() encoding:[NSString defaultCStringEncoding]];
|
||||
NSString *nsver = [NSString stringWithCString:version.c_str() encoding:[NSString defaultCStringEncoding]];
|
||||
NSString *notifname = [NSString stringWithFormat: @"%@%@", @"OtherDownloaderInstanceMessage", nsver];
|
||||
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:notifname object:nil userInfo:[NSDictionary dictionaryWithObject:nsmsg forKey:@"data"] deliverImmediately:YES];
|
||||
}
|
||||
|
||||
void OtherDownloaderMessageHandler::register_for_messages(const std::string &version_hash)
|
||||
{
|
||||
m_impl_osx = [[DownloaderMessageHandlerMac alloc] init];
|
||||
if(m_impl_osx) {
|
||||
NSString *nsver = [NSString stringWithCString:version_hash.c_str() encoding:[NSString defaultCStringEncoding]];
|
||||
[(id)m_impl_osx add_observer:nsver];
|
||||
}
|
||||
}
|
||||
|
||||
void OtherDownloaderMessageHandler::unregister_for_messages()
|
||||
{
|
||||
//NSLog(@"unreegistering other instance messages");
|
||||
if (m_impl_osx) {
|
||||
[(id)m_impl_osx release];
|
||||
m_impl_osx = nullptr;
|
||||
} else {
|
||||
NSLog(@"warning: unregister instance InstanceSend notifications not required");
|
||||
}
|
||||
}
|
||||
|
||||
void OtherDownloaderMessageHandler::bring_instance_forward()
|
||||
{
|
||||
if (m_impl_osx) {
|
||||
[(id)m_impl_osx bring_forward];
|
||||
}
|
||||
}
|
||||
}//namespace Downloader
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user