Unverified Commit 4b0ba186 authored by Fernando Rodrigues's avatar Fernando Rodrigues Committed by GitHub
Browse files

trilium-{desktop,server}: 0.97.2 -> 0.98.0 | refactor (#434791)

parents 8062f8a4 d636fc57
Loading
Loading
Loading
Loading
+0 −72
Original line number Diff line number Diff line
diff --git a/src/services/log.js b/src/services/log.js
index a141eae14..094b9381b 100644
--- a/src/services/log.js
+++ b/src/services/log.js
@@ -1,15 +1,7 @@
 "use strict";
 
-const fs = require('fs');
-const dataDir = require('./data_dir.js');
 const cls = require('./cls.js');
 
-if (!fs.existsSync(dataDir.LOG_DIR)) {
-    fs.mkdirSync(dataDir.LOG_DIR, 0o700);
-}
-
-let logFile = null;
-
 const SECOND = 1000;
 const MINUTE = 60 * SECOND;
 const HOUR = 60 * MINUTE;
@@ -17,38 +9,6 @@ const DAY = 24 * HOUR;
 
 const NEW_LINE = process.platform === "win32" ? '\r\n' : '\n';
 
-let todaysMidnight = null;
-
-initLogFile();
-
-function getTodaysMidnight() {
-    const now = new Date();
-
-    return new Date(now.getFullYear(), now.getMonth(), now.getDate());
-}
-
-function initLogFile() {
-    todaysMidnight = getTodaysMidnight();
-
-    const path = `${dataDir.LOG_DIR}/trilium-${formatDate()}.log`;
-
-    if (logFile) {
-        logFile.end();
-    }
-
-    logFile = fs.createWriteStream(path, {flags: 'a'});
-}
-
-function checkDate(millisSinceMidnight) {
-    if (millisSinceMidnight >= DAY) {
-        initLogFile();
-
-        millisSinceMidnight -= DAY;
-    }
-
-    return millisSinceMidnight;
-}
-
 function log(str) {
     const bundleNoteId = cls.get("bundleNoteId");
 
@@ -56,12 +16,6 @@ function log(str) {
         str = `[Script ${bundleNoteId}] ${str}`;
     }
 
-    let millisSinceMidnight = Date.now() - todaysMidnight.getTime();
-
-    millisSinceMidnight = checkDate(millisSinceMidnight);
-
-    logFile.write(`${formatTime(millisSinceMidnight)} ${str}${NEW_LINE}`);
-
     console.log(str);
 }
 
 No newline at end of file
+0 −21
Original line number Diff line number Diff line
{ lib, callPackage, ... }:

let
  metaCommon = with lib; {
    description = "Hierarchical note taking application with focus on building large personal knowledge bases";
    homepage = "https://github.com/zadam/trilium";
    license = licenses.agpl3Plus;
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    platforms = [ "x86_64-linux" ];
    maintainers = with maintainers; [
      fliegendewurst
      eliandoran
    ];
  };
in
{

  trilium-desktop = callPackage ./desktop.nix { metaCommon = metaCommon; };
  trilium-server = callPackage ./server.nix { metaCommon = metaCommon; };

}
+0 −113
Original line number Diff line number Diff line
{
  stdenv,
  lib,
  unzip,
  autoPatchelfHook,
  fetchurl,
  makeWrapper,
  alsa-lib,
  libgbm,
  nss,
  nspr,
  systemd,
  makeDesktopItem,
  copyDesktopItems,
  wrapGAppsHook3,
  metaCommon,
}:

let
  pname = "trilium-desktop";
  version = "0.63.6";

  linuxSource.url = "https://github.com/zadam/trilium/releases/download/v${version}/trilium-linux-x64-${version}.tar.xz";
  linuxSource.sha256 = "12kgq5x4f93hxz057zqhz0x1y0rxfxh90fv9fjjs3jrnk0by7f33";

  darwinSource.url = "https://github.com/zadam/trilium/releases/download/v${version}/trilium-mac-x64-${version}.zip";
  darwinSource.sha256 = "0ry512cn622av3nm8rnma2yvqc71rpzax639872ivvc5vm4rsc30";

  meta = metaCommon // {
    mainProgram = "trilium";
    platforms = [
      "x86_64-linux"
      "x86_64-darwin"
    ];
  };

  linux = stdenv.mkDerivation rec {
    inherit pname version meta;

    src = fetchurl linuxSource;

    # TODO: migrate off autoPatchelfHook and use nixpkgs' electron
    nativeBuildInputs = [
      autoPatchelfHook
      makeWrapper
      wrapGAppsHook3
      copyDesktopItems
    ];

    buildInputs = [
      alsa-lib
      libgbm
      nss
      nspr
      stdenv.cc.cc
      systemd
    ];

    desktopItems = [
      (makeDesktopItem {
        name = "Trilium";
        exec = "trilium";
        icon = "trilium";
        comment = meta.description;
        desktopName = "Trilium Notes";
        categories = [ "Office" ];
        startupWMClass = "trilium notes";
      })
    ];

    # Remove trilium-portable.sh, so trilium knows it is packaged making it stop auto generating a desktop item on launch
    postPatch = ''
      rm ./trilium-portable.sh
    '';

    installPhase = ''
      runHook preInstall
      mkdir -p $out/bin
      mkdir -p $out/share/trilium
      mkdir -p $out/share/icons/hicolor/128x128/apps

      cp -r ./* $out/share/trilium
      ln -s $out/share/trilium/trilium $out/bin/trilium

      ln -s $out/share/trilium/icon.png $out/share/icons/hicolor/128x128/apps/trilium.png
      runHook postInstall
    '';

    # LD_LIBRARY_PATH "shouldn't" be needed, remove when possible :)
    # Error: libstdc++.so.6: cannot open shared object file: No such file or directory
    preFixup = ''
      gappsWrapperArgs+=(--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs})
    '';

    dontStrip = true;

    passthru.updateScript = ./update.sh;
  };

  darwin = stdenv.mkDerivation {
    inherit pname version meta;

    src = fetchurl darwinSource;
    nativeBuildInputs = [ unzip ];

    installPhase = ''
      mkdir -p $out/Applications
      cp -r *.app $out/Applications
    '';
  };

in
if stdenv.hostPlatform.isDarwin then darwin else linux
+0 −65
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  autoPatchelfHook,
  fetchurl,
  nixosTests,
  metaCommon,
}:

let
  serverSource.url = "https://github.com/zadam/trilium/releases/download/v${version}/trilium-linux-x64-server-${version}.tar.xz";
  serverSource.sha256 = "0gwp6h6nvfzq7k1g3233h838nans45jkd5c3pzl6qdhhm19vcs27";
  version = "0.63.6";
in
stdenv.mkDerivation {
  pname = "trilium-server";
  inherit version;
  meta = metaCommon // {
    platforms = [ "x86_64-linux" ];
    mainProgram = "trilium-server";
  };

  src = fetchurl serverSource;

  nativeBuildInputs = [
    autoPatchelfHook
  ];

  buildInputs = [
    (lib.getLib stdenv.cc.cc)
  ];

  patches = [
    # patch logger to use console instead of rolling files
    ./0001-Use-console-logger-instead-of-rolling-files.patch
  ];

  installPhase = ''
    runHook preInstall
    mkdir -p $out/bin
    mkdir -p $out/share/trilium-server

    cp -r ./* $out/share/trilium-server
    runHook postInstall
  '';

  postFixup = ''
    cat > $out/bin/trilium-server <<EOF
    #!${stdenv.cc.shell}
    cd $out/share/trilium-server
    exec ./node/bin/node src/www
    EOF
    chmod a+x $out/bin/trilium-server

    # ERROR: noBrokenSymlinks: found 4 dangling symlinks, 0 reflexive symlinks and 0 unreadable symlinks
    unlink $out/share/trilium-server/node/bin/npx
    unlink $out/share/trilium-server/node/bin/npm
    unlink $out/share/trilium-server/node_modules/.bin/electron
    unlink $out/share/trilium-server/node_modules/.bin/electron-installer-debian
  '';

  passthru.tests = {
    trilium-server = nixosTests.trilium-server;
  };
}
+0 −23
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils curl jq
set -euo pipefail

cd $(dirname "${BASH_SOURCE[0]}")

setKV () {
    sed -i "s|$2 = \".*\"|$2 = \"${3:-}\"|" $1
}

version=$(curl -s --show-error "https://api.github.com/repos/zadam/trilium/releases/latest" | jq -r '.tag_name' | tail -c +2)

# Update desktop application
sha256_linux64=$(nix-prefetch-url --quiet https://github.com/zadam/trilium/releases/download/v${version}/trilium-linux-x64-${version}.tar.xz)
sha256_darwin64=$(nix-prefetch-url --quiet https://github.com/zadam/trilium/releases/download/v${version}/trilium-mac-x64-${version}.zip)
setKV ./desktop.nix version $version
setKV ./desktop.nix linuxSource.sha256 $sha256_linux64
setKV ./desktop.nix darwinSource.sha256 $sha256_darwin64

# Update server
sha256_linux64_server=$(nix-prefetch-url --quiet https://github.com/zadam/trilium/releases/download/v${version}/trilium-linux-x64-server-${version}.tar.xz)
setKV ./server.nix version $version
setKV ./server.nix serverSource.sha256 $sha256_linux64_server
Loading