blob: a4e5a0fe9da0c152e1c40d1739b45c5fa617da66 [file] [log] [blame]
Alexander Afanasyevfda42a82017-02-01 18:03:39 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2017, Regents of the University of California.
4 *
5 * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD
6 * authors and contributors.
7 *
8 * NFD Control Center is free software: you can redistribute it and/or modify it under the
9 * terms of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with NFD
17 * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "osx-auto-update-sparkle.hpp"
21
22#import <AppKit/AppKit.h>
23#import <Foundation/Foundation.h>
24#import <Sparkle/Sparkle.h>
25
26@interface UpdaterDelegate : NSObject<SUUpdaterDelegate> {
27 ndn::ncc::OsxAutoUpdateSparkle* this_;
28}
29
30- (void)setSelf:(ndn::ncc::OsxAutoUpdateSparkle*)ptr;
31
32- (BOOL)updater:(SUUpdater *)updater
33 shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update
34 untilInvoking:(NSInvocation *)invocation;
35
36@end
37
38@implementation UpdaterDelegate
39
40- (void)setSelf:(ndn::ncc::OsxAutoUpdateSparkle*)ptr
41{
42 this_ = ptr;
43}
44
45- (BOOL)updater:(SUUpdater *)updater
46 shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update
47 untilInvoking:(NSInvocation *)invocation
48{
49 NSTask *task = [[NSTask alloc] init];
50 task.launchPath = @"/usr/bin/killall";
51 task.arguments = @[@"ndn-autoconfig", @"nfd"];
52 [task launch];
53 return NO;
54}
55
56@end
57
58namespace ndn {
59namespace ncc {
60
61class OsxAutoUpdateSparkle::Impl
62{
63public:
64 SUUpdater* m_updater;
65 UpdaterDelegate* delegate;
66};
67
68OsxAutoUpdateSparkle::OsxAutoUpdateSparkle(const std::string& updateUrl)
69 : m_impl(make_unique<Impl>())
70{
71 m_impl->m_updater = [[SUUpdater sharedUpdater] retain];
72 NSURL* url = [NSURL URLWithString:[NSString stringWithUTF8String:updateUrl.data()]];
73 [m_impl->m_updater setFeedURL:url];
74 [m_impl->m_updater setAutomaticallyChecksForUpdates:YES];
75 [m_impl->m_updater setUpdateCheckInterval:86400];
76
77 m_impl->delegate = [[UpdaterDelegate alloc] init];
78 [m_impl->delegate setSelf:this];
79 [m_impl->m_updater setDelegate:m_impl->delegate];
80}
81
82OsxAutoUpdateSparkle::~OsxAutoUpdateSparkle()
83{
84 [m_impl->m_updater release];
85 // presummably SUUpdater handles garbage collection
86}
87
88void
89OsxAutoUpdateSparkle::checkForUpdates()
90{
91 //[m_impl->m_updater checkForUpdatesInBackground];
92 [m_impl->m_updater checkForUpdates:nil];
93}
94
95} // namespace ncc
96} // namespace ndn