Skip to content

Commit

Permalink
Merge pull request #6 from infeeeee/dev
Browse files Browse the repository at this point in the history
Added inno setup, padded time output
  • Loading branch information
infeeeee authored Jul 27, 2019
2 parents 7166c7d + 30c287e commit 98f845f
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 34 deletions.
6 changes: 1 addition & 5 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
<<<<<<< HEAD
SOFTWARE.
=======
SOFTWARE.
>>>>>>> 2ffa9275ad4ec845877c772c2b5097db51a797c7
SOFTWARE.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,29 @@ UI:

Integration:
- [x] Portable executable for all three platforms
- [ ] Installer for windows
- [x] Installer for windows
- [ ] Generate output for Rainmeter (Windows) (Just like [kimai-cmd](https://github.com/infeeeee/kimai-cmd))
- [x] Generate output for Argos/Kargos/Bitbar (Gnome, Kde, Mac). More info here: [kimai2-cmd-argos](https://github.com/infeeeee/kimai2-cmd-argos)

Requests for integrations with other softwares are welcomed! Just open an issue and show an example output, what you need.

## Installation

Download executable from [releases](https://github.com/infeeeee/kimai2-cmd/releases/latest). Standalone executable, no installation required.
Download from [releases](https://github.com/infeeeee/kimai2-cmd/releases/latest).

You have to create an API password for your username on your Kimai installation. In Kimai: User menu (Top right corner) -> User profile -> API
You have to create an API password for your username on your Kimai installation. In Kimai: User menu (Top right corner) -> User profile -> API.

### Notes on Windows

Add the path of the containing folder to the %PATH% environment variable so you can run it from command line/powershell system wide. I didn't find any reliable way to do this from command line, so follow this guide. It should work on win 7-10
Portable executable or installer available.

Installer automatically adds the install path to the %PATH% environment variable, so you can use it from command line/powershell system wide. Sign out and in if it's not working.

- Open start menu and type: SystemPropertiesAdvanced.exe
- Go to Advanced tab click Environment variables
- Select path on the top pane, click Edit
- On win 7,8 add the following to the end of the variable: `;c:\path\to\containing\folder`
- On win 10 click New and type `c:\path\to\containing\folder`
- Log off and on if not working
With the portable version you have to do this manually. Follow [this tutorial](https://stackoverflow.com/questions/44272416/how-to-add-a-folder-to-path-environment-variable-in-windows-10-with-screensho) or a similar one if you don't know how to do it.

### Notes on Linux/Mac

On the following terminal examples use the file name you downloaded.
Portable executable only. On the following terminal examples use the file name you downloaded.

Make the downloaded binary executable:
```
Expand Down Expand Up @@ -121,7 +120,7 @@ Integration settings are not asked during first run, you have to change them man

### Installation

requirements:
Prerequisites:
- node js 10+
- git

Expand All @@ -133,7 +132,7 @@ npm install

### Build

Requirements: globally installed [pkg](https://github.com/zeit/pkg):
Prerequisite: globally installed [pkg](https://github.com/zeit/pkg):

```
npm install pkg -g
Expand All @@ -145,7 +144,6 @@ Build for current platform and architecture
npm run build-current
```


Build x64 executables for linux, mac on linux or on mac

```
Expand All @@ -154,6 +152,12 @@ npm run build-nix

About building for other platforms see pkg's documentation, or open an issue and I can build it for you.

### Installer (Windows only)

Prerequisite: [Inno Setup](http://www.jrsoftware.org/isinfo.php)

- Create a windows build: `npm run build-current`
- Open `kimai2-innosetup.iss` in Inno Setup

### Usage

Expand Down
Binary file added assets/kimai-icon-192x192.ico
Binary file not shown.
Binary file added assets/kimai-icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 39 additions & 11 deletions kimai2-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function callKimaiApi(httpMethod, kimaiMethod, serversettings, options = false)
//default options to false:
const qs = options.qs || false
const reqbody = options.reqbody || false

if (program.verbose) {
console.log("calling kimai:", httpMethod, kimaiMethod, serversettings)
}
Expand Down Expand Up @@ -102,6 +102,7 @@ function callKimaiApi(httpMethod, kimaiMethod, serversettings, options = false)
* @param {object} settings The full settings object read from the ini
*/
function uiMainMenu(settings) {
console.log()
inquirer
.prompt([
{
Expand Down Expand Up @@ -406,34 +407,61 @@ function printList(settings, arr, endpoint) {

if (moment(element.end).isValid()) {
//finished measurements:
let dur = moment.duration(moment(element.end).diff(moment(element.begin)))
console.log(' Duration: ' + dur.hours() + ':' + dur.minutes())
console.log(' Duration: ' + formattedDuration(element.begin, element.end))
} else {
//active measurements:
let dur = moment.duration(moment().diff(moment(element.begin)))
console.log(' Duration: ' + dur.hours() + ':' + dur.minutes())
console.log(' Duration: ' + formattedDuration(element.begin))
}

} else if (program.id) {
console.log(element.id + ':', element.project.name, '|', element.activity.name)
} else if (program.argos) {
//Argos
if (endpoint == 'timesheets/recent') {
console.log('--' + element.project.name + ',', element.activity.name, '|', 'bash=' + settings.argos_bitbar.kimaipath + ' param1=restart param2=' + element.id + ' terminal=false refresh=true')
} else if (endpoint == 'timesheets/active') {
let dur = moment.duration(moment().diff(moment(element.begin)))
console.log(dur.hours() + ':' + dur.minutes(), element.project.name + ',', element.activity.name, '|', 'bash=' + settings.argos_bitbar.kimaipath + ' param1=stop param2=' + element.id + ' terminal=false refresh=true')
console.log(formattedDuration(element.begin), element.project.name + ',', element.activity.name, '|', 'bash=' + settings.argos_bitbar.kimaipath + ' param1=stop param2=' + element.id + ' terminal=false refresh=true')
}
} else if (program.argosbutton) {
let dur = moment.duration(moment().diff(moment(element.begin)))
console.log(dur.hours() + ':' + dur.minutes(), element.project.name + ',', element.activity.name, '| length=' + settings.argos_bitbar.buttonlength)
//Argosbutton
console.log(formattedDuration(element.begin), element.project.name + ',', element.activity.name, '| length=' + settings.argos_bitbar.buttonlength)
} else {
console.log(element.project.name, '|', element.activity.name)
console.log()
//Regular output
if (moment(element.end).isValid()) {
//finished measurements:
console.log(element.project.name, '|', element.activity.name)
} else {
//active measurements:
console.log(formattedDuration(element.begin), element.project.name, '|', element.activity.name)
}
}
}
}
}

/**
* Returns duration between the two moments or between beginning and now. padded to minimum two digits.
*
* @param {moment} begin beginning moment
* @param {moment} end optional, end moment
*/
function formattedDuration(begin, end) {
let momentDuration = moment.duration(moment(end).diff(moment(begin)))

let hrs = momentDuration.hours()
let mins = momentDuration.minutes()

if (hrs.toString().length == 1) {
hrs = "0" + hrs
}

if (mins.toString().length == 1) {
mins = "0" + mins
}

return hrs + ':' + mins
}


/**
* Interactive ui: select measurement from a list of measurements
Expand Down
100 changes: 100 additions & 0 deletions kimai2-innosetup.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{A10BF7B2-6641-4B06-9C68-268B649FCE57}
AppName=kimai2-cmd
AppVersion=0.2.4
AppPublisher=infeeeee
AppPublisherURL=https://github.com/infeeeee/kimai2-cmd
AppSupportURL=https://github.com/infeeeee/kimai2-cmd
AppUpdatesURL=https://github.com/infeeeee/kimai2-cmd
DefaultDirName={pf}\kimai2-cmd
DefaultGroupName=kimai2-cmd
AllowNoIcons=yes
LicenseFile={#SourcePath}\LICENSE
OutputDir={#SourcePath}\builds
OutputBaseFilename=kimai2-cmd-setup
SetupIconFile={#SourcePath}\assets\kimai-icon-192x192.ico
Compression=lzma
SolidCompression=yes
ArchitecturesInstallIn64BitMode=x64
ArchitecturesAllowed=x64

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "builds\kimai2-cmd.exe"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Source: "settings.ini.example"; DestDir: "{userappdata}\kimai2-cmd"; DestName: "settings.ini"; Flags: onlyifdoesntexist uninsneveruninstall recursesubdirs; AfterInstall: InitializeWizard

[Icons]
Name: "{group}\kimai2-cmd"; Filename: "{app}\kimai2-cmd.exe"
Name: "{group}\{cm:UninstallProgram,kimai2-cmd}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\kimai2-cmd"; Filename: "{app}\kimai2-cmd.exe"; Tasks: desktopicon

[Run]
Filename: "{app}\kimai2-cmd.exe"; Description: "{cm:LaunchProgram,kimai2-cmd}"; Flags: nowait postinstall skipifsilent

[INI]
Filename: "{userappdata}\kimai2-cmd\settings.ini"; Section: "serversettings"; Key: "kimaiurl"; String: "{code:GetKimaiUrl}"
Filename: "{userappdata}\kimai2-cmd\settings.ini"; Section: "serversettings"; Key: "username"; String: "{code:GetUserName}"
Filename: "{userappdata}\kimai2-cmd\settings.ini"; Section: "serversettings"; Key: "password"; String: "{code:GetPassword}"

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"; \
Check: NeedsAddPath(ExpandConstant('{app}'))

[Code]
var AuthPage: TInputQueryWizardPage;
procedure InitializeWizard;
begin
AuthPage := CreateInputQueryPage(wpInstalling,
'Kimai2 settings', 'Please enter your server url and account information',
'');
AuthPage.Add('Kimai2 url:', False);
AuthPage.Add('Username:', False);
AuthPage.Add('API password:', False);
end;
function AuthForm_NextButtonClick(Page: TWizardPage): Boolean;
begin
Result := True;
end;
function GetKimaiUrl(Param: String): string;
begin
result := AuthPage.Values[0];
end;
function GetUserName(Param: String): string;
begin
result := AuthPage.Values[1];
end;
function GetPassword(Param: String): string;
begin
result := AuthPage.Values[2];
end;
function NeedsAddPath(Param: string): boolean;
var
OrigPath: string;
begin
if not RegQueryStringValue(HKEY_LOCAL_MACHINE,
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
'Path', OrigPath)
then begin
Result := True;
exit;
end;
{ look for the path with leading and trailing semicolon }
{ Pos() returns 0 if not found }
Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
end;
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kimai2-cmd",
"version": "0.2.2",
"version": "0.2.3",
"description": "Command line client for Kimai2",
"main": "kimai2-cmd.js",
"bin": "kimai2-cmd.js",
Expand Down

0 comments on commit 98f845f

Please sign in to comment.