Skip to content

Commit

Permalink
🐧 autostart for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
4silvertooth committed Feb 25, 2021
1 parent 5ed5af4 commit b977bb2
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion storage.tis
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,63 @@ $(#trayicon-weather) << event click {
root.WEATHER_IN_TRAY_ICON = !this.state.checked;
updateTrayIcon();
};

async function createDir(path){
await System.mkdir(path);
}

$(#autostart) << event click {
root.START_ON_LOGIN = this.state.checked;
switch(System.PLATFORM) {
case #Windows:
break;

case #OSX:
break;

case #Linux:
{
const autodir = System.path(#USER_HOME,".config/autostart");
if(!System.scanFiles(autodir)) {
createDir(autodir);
}
const path = System.path(#USER_HOME,".config/autostart/temps-lite.desktop");

//TODO: Check .state.checked value is opposite of button|checkbox here
//debug info: this.state.checked;
if(!this.state.checked) {
const appName = "temps-lite";
const appPath = URL.toPath(self.url("./scapp"));
const data = String.$([Desktop Entry]
Type=Application
Version=1.0
Name={appName}
Comment={appName} autostart script
Exec={appPath}
StartupNotify=false
Terminal=false
)
const stream = Stream.openFile(path,"uw");
if( !stream ) {
view.msgbox(#warning, "Cannot open file "+ path +" for writing. Settings will not be saved." );
return;
}
stream.printf("%s",data);
stream.close();
}
else {
System.unlink(path)
.then(
:: root.START_ON_LOGIN = false
)
.catch(function err(e){
throw String.$(Cant unlink/remove {path} );
});
}
}
break;
}

};

$(#city).value = root.LOCATION;
Expand All @@ -54,4 +109,4 @@ root.TIME_FORMAT === "24h"

$(#trayicon-weather).state.checked = root.WEATHER_IN_TRAY_ICON;
$(#autostart).state.checked = root.START_ON_LOGIN;
$(#lang).value = root.LANG;
$(#lang).value = root.LANG;

2 comments on commit b977bb2

@4silvertooth
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For mac it should be similar where the file name would be temps-lite.plist in path ~/Library/LaunchAgents/ with file format

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>{appName}</string>
  <key>ProgramArguments</key>
  <array>
    {appPath}
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

@4silvertooth
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming the scapp in the folder, if it's quark app the binary name should be changed.

Please sign in to comment.