Skip to content

Commit

Permalink
Initial support for syncthing arguments. See #154
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry Jacobs committed May 9, 2021
1 parent 8c813d1 commit c1387cb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ syncthing-macos is designed to run its own syncthing instance and automatically
local running instance, a remote instance is not supported. It is possible to run your own instance and point to it for advanced/development purposes. You
should only change the settings if you know what you are doing.

Setting extra syncthing commandline parameters is a hidden feature. You need to write these using the application defaults configuration.
The only current limitation the parameters cannot contain spaces!.
In the example below the audit log is enabled:

```
defaults write com.github.xor-gate.syncthing-macosx Arguments '--audit --auditfile=/Users/JohnDoe/staudit.log'
```

## Default IP address change

When the default IP address is changed from 127.0.0.1 to a routable one like e.g 192.168.1.102 the tray application
Expand Down
11 changes: 9 additions & 2 deletions syncthing/DaemonProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@ import Foundation
let RestartInterval = 10.0 // seconds
let MaxKeepLogLines = 200

@objc public protocol DaemonProcessDelegate: class {
@objc public protocol DaemonProcessDelegate: AnyObject {
func process(_: DaemonProcess, isRunning: Bool)
}

@objc public class DaemonProcess: NSObject {
private var path: String
private var arguments: [String]
private weak var delegate: DaemonProcessDelegate?
private var process: Process?
private var log = [String]()
private var queue = DispatchQueue(label: "DaemonProcess")
private var shouldTerminate = false

@objc init(path: String, delegate: DaemonProcessDelegate) {
@objc init(path: String, arguments: String, delegate: DaemonProcessDelegate) {
self.path = path
self.delegate = delegate
if !arguments.isEmpty {
self.arguments = arguments.components(separatedBy: " ")
} else {
self.arguments = []
}
}

@objc func launch() {
Expand Down Expand Up @@ -59,6 +65,7 @@ let MaxKeepLogLines = 200
let p = Process()
p.environment = environment
p.arguments = ["-no-browser", "-no-restart", "-logfile=default"]
p.arguments?.append(contentsOf: self.arguments)
p.launchPath = path
p.standardInput = Pipe() // isolate daemon from our stdin
p.standardOutput = pipeIntoLineBuffer()
Expand Down
4 changes: 2 additions & 2 deletions syncthing/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.16.1-1</string>
<string>1.16.1-2</string>
<key>CFBundleVersion</key>
<string>101600101</string>
<string>101600102</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
9 changes: 8 additions & 1 deletion syncthing/STApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ @interface STAppDelegate ()
@property (nonatomic, strong, readwrite) NSStatusItem *statusItem;
@property (nonatomic, strong, readwrite) XGSyncthing *syncthing;
@property (nonatomic, strong, readwrite) NSString *executable;
@property (nonatomic, strong, readwrite) NSString *arguments;
@property (nonatomic, strong, readwrite) DaemonProcess *process;
@property (nonatomic, strong, readwrite) STStatusMonitor *statusMonitor;
@property (weak) IBOutlet NSMenuItem *toggleAllDevicesItem;
Expand All @@ -31,7 +32,7 @@ - (void) applicationDidFinishLaunching:(NSNotification *)aNotification {

[self applicationLoadConfiguration];

_process = [[DaemonProcess alloc] initWithPath:_executable delegate:self];
_process = [[DaemonProcess alloc] initWithPath:_executable arguments: _arguments delegate:self];
[_process launch];

_statusMonitor = [[STStatusMonitor alloc] init];
Expand Down Expand Up @@ -75,6 +76,12 @@ - (void)applicationLoadConfiguration {
_syncthing.URI = [defaults stringForKey:@"URI"];
_syncthing.ApiKey = [defaults stringForKey:@"ApiKey"];

self.arguments = [defaults stringForKey:@"Arguments"];
if (!self.arguments) {
self.arguments = @"";
[defaults setObject:self.arguments forKey: @"Arguments"];
}

// If no values are set, read from XML and store in defaults
if (!_syncthing.URI.length && !_syncthing.ApiKey.length) {
BOOL success = [_syncthing loadConfigurationFromXML];
Expand Down

0 comments on commit c1387cb

Please sign in to comment.