Skip to content

Commit

Permalink
Add autostart on login
Browse files Browse the repository at this point in the history
  • Loading branch information
Zensey committed Sep 14, 2021
1 parent a2bed38 commit 6b8aaf6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
39 changes: 34 additions & 5 deletions gobridge/gobridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import "C"

import (
"fmt"
"io/ioutil"
"log"
"os"

"github.com/mysteriumnetwork/myst-launcher/app"
"github.com/mysteriumnetwork/myst-launcher/model"
Expand All @@ -29,8 +31,35 @@ var (

func init() {
fmt.Println("gobridge init>")
ap = app.NewApp()
}

func copyFile(sourceFile, destinationFile string) {
input, err := ioutil.ReadFile(sourceFile)
if err != nil {
fmt.Println(err)
return
}

err = ioutil.WriteFile(destinationFile, input, 0644)
if err != nil {
fmt.Println("Error creating", destinationFile)
fmt.Println(err)
return
}
}

//export GoInit
func GoInit(res_path *C.char) {
cfg.ResourcePath = C.GoString(res_path)
fmt.Println("resPath >", cfg.ResourcePath)

fileName := "com.mysterium.launcher.plist"
copyFile(cfg.ResourcePath+"/"+fileName, os.Getenv("HOME")+"/Library/LaunchAgents/"+fileName)
}

//export GoStart
func GoStart() {
ap = app.NewApp()
mod = model.NewUIModel()
sendConfig()

Expand Down Expand Up @@ -96,11 +125,11 @@ func GoDialogueComplete() {

//export GoOnAppExit
func GoOnAppExit() {
fmt.Println("OnAppExit >")
fmt.Println("OnAppExit >")

ap.TriggerAction("stop")
// wait for SuperviseDockerNode to finish its work
ap.WaitGroup.Wait()
ap.TriggerAction("stop")
// wait for SuperviseDockerNode to finish its work
ap.WaitGroup.Wait()
}

//export GoSetStateAndConfig
Expand Down
2 changes: 2 additions & 0 deletions gobridge/gobridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
extern "C" {
#endif

extern void GoInit(char* res_path);
extern void GoStart();
extern void GoSetModalResult(int rc);
extern void GoDialogueComplete();
extern void GoOnAppExit();
Expand Down
4 changes: 4 additions & 0 deletions launcher.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
9A63DEE026E605A800594C0B /* MainWindowDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A63DEDE26E605A800594C0B /* MainWindowDelegate.m */; };
9A6FB69E26E8E82500069932 /* Label.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A6FB69D26E8E82500069932 /* Label.m */; };
9A6FB6A126E8EA4200069932 /* NSAttributedString.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A6FB6A026E8EA4200069932 /* NSAttributedString.m */; };
9A725ABE26F0CC6C00E0A64A /* com.mysterium.launcher.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9A725ABD26F0CC6C00E0A64A /* com.mysterium.launcher.plist */; };
9A93390526EF6856004D9F30 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 9AC8756F26C919D400A99070 /* Info.plist */; };
9AC8756B26C919D400A99070 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9AC8756A26C919D400A99070 /* Assets.xcassets */; };
9AC8756E26C919D400A99070 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9AC8756C26C919D400A99070 /* MainMenu.xib */; };
Expand Down Expand Up @@ -74,6 +75,7 @@
9A6FB69D26E8E82500069932 /* Label.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Label.m; sourceTree = "<group>"; };
9A6FB69F26E8EA1000069932 /* NSAttributedString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSAttributedString.h; sourceTree = "<group>"; };
9A6FB6A026E8EA4200069932 /* NSAttributedString.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSAttributedString.m; sourceTree = "<group>"; };
9A725ABD26F0CC6C00E0A64A /* com.mysterium.launcher.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = com.mysterium.launcher.plist; sourceTree = "<group>"; };
9AC8756426C919CB00A99070 /* Launcher.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Launcher.app; sourceTree = BUILT_PRODUCTS_DIR; };
9AC8756726C919CC00A99070 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
9AC8756826C919CC00A99070 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -163,6 +165,7 @@
9AC8756626C919CB00A99070 /* launcher */ = {
isa = PBXGroup;
children = (
9A725ABD26F0CC6C00E0A64A /* com.mysterium.launcher.plist */,
9AC8757026C919D400A99070 /* main.m */,
9A16EF8C26EA5EF20036447D /* utils.h */,
9A16EF8A26EA5EB00036447D /* utils.m */,
Expand Down Expand Up @@ -312,6 +315,7 @@
9A63DEDA26E5D86E00594C0B /* ModalWindow.xib in Resources */,
9A93390526EF6856004D9F30 /* Info.plist in Resources */,
9AC8756E26C919D400A99070 /* MainMenu.xib in Resources */,
9A725ABE26F0CC6C00E0A64A /* com.mysterium.launcher.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
9 changes: 8 additions & 1 deletion launcher/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#import "ModalWindowDelegate.h"
#import "../gobridge/gobridge.h"

#include <sys/stat.h>
#include <copyfile.h>

LauncherState *mod = nil;

@implementation AppDelegate
Expand All @@ -21,7 +24,11 @@ - (void) applicationWillTerminate:(NSNotification *)aNotification {
GoOnAppExit();
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
GoInit((char*)[resourcePath UTF8String]);
GoStart();

mod = [[LauncherState alloc] init];

if (!self.modalWindowDelegate) {
Expand Down
19 changes: 13 additions & 6 deletions launcher/com.mysterium.launcher.plist
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
com.mysterium.launcher.plist
launcher
Created by mac mini on 14/09/2021.
Copyright (c) 2021 mac mini. All rights reserved.
Created by @zensey on 14/09/2021.
Copyright © 2021 Mysterium Network. All rights reserved.
-->
<plist version="1.0">
<dict>

</dict>
<dict>
<key>Label</key>
<string>com.mysterium.launcher</string>
<key>ProgramArguments</key>
<array>
<string>open -g /Applications/Launcher.app</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

0 comments on commit 6b8aaf6

Please sign in to comment.