Skip to content

Commit

Permalink
System tray + build
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsparrow committed Jan 25, 2024
1 parent 9da5900 commit e3934e3
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 23 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Build
on: push
jobs:
app:
name: Build Desktop App
runs-on: ubuntu-latest
container:
image: ivangabriele/tauri:debian-bullseye-18
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup dependencies
run: |
apt-get install python3-pip
pip3 install torch --index-url https://download.pytorch.org/whl/cpu
- name: Run
run: |
export LD_LIBRARY_PATH=/usr/local/lib/python3.9/dist-packages/torch/lib
npm run tauri -- build --verbose
working-directory: ./semdesk-app
36 changes: 36 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,22 @@
webkitgtk
librsvg
(python3.withPackages(ps: with ps; [ torch ]))
libayatana-appindicator
];
in
{
devShell = pkgs.mkShell {
buildInputs = packages;
nativeBuildInputs = with pkgs; [
pkg-config
];

shellHook =
''
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
export XDG_DATA_DIRS=${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS
export LIBTORCH_BYPASS_VERSION_CHECK=1
export LIBTORCH_USE_PYTORCH=1
'';
};
});
Expand Down
2 changes: 1 addition & 1 deletion semdesk-app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"
tauri-build = { version = "1.5", features = [] }

[dependencies]
tauri = { version = "1.5", features = ["shell-open"] }
tauri = { version = "1.5", features = [ "system-tray", "shell-open"] }
serde = { version = "1.0", features = ["derive"] }
semdesk-api = { path = "../../semdesk-api" }
serde_json = "1.0"
Expand Down
35 changes: 31 additions & 4 deletions semdesk-app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::thread;
use actix_web::rt::System;
use std::thread;

use semdesk_api::run_server;

use tauri::{CustomMenuItem, SystemTray, SystemTrayMenu, SystemTrayMenuItem, SystemTrayEvent};
use tauri::Manager;

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
Expand All @@ -14,16 +15,42 @@ fn greet(name: &str) -> String {
}

fn main() {
let quit = CustomMenuItem::new("quit".to_string(), "Quit");
let show_hide = CustomMenuItem::new("show_hide".to_string(), "Show/Hide");

let tray_menu = SystemTrayMenu::new()
.add_item(quit)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(show_hide);
let tray = SystemTray::new().with_menu(tray_menu);

tauri::Builder::default()
.system_tray(tray)
.on_system_tray_event(|app, event| match event {
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"quit" => {
std::process::exit(0);
}
"show_hide" => {
match app.get_window("main") {
Some(window) => match window.is_visible().unwrap() {
true => window.hide().unwrap(),
false => window.show().unwrap()
},
_ => ()
}
}
_ => {}
},
_ => {}
})
.setup(|app| {

let handle = app.handle();
let boxed_handle = Box::new(handle);

thread::spawn(move || {
System::new().block_on(run_server()).unwrap();
});
println!("Continuing");
Ok(())
})
.invoke_handler(tauri::generate_handler![greet])
Expand Down
10 changes: 7 additions & 3 deletions semdesk-app/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"distDir": "../dist"
},
"package": {
"productName": "semdesk-app",
"version": "0.0.0"
"productName": "semtex",
"version": "0.1.0"
},
"tauri": {
"allowlist": {
Expand All @@ -17,10 +17,14 @@
"open": true
}
},
"systemTray": {
"iconPath": "icons/32x32.png",
"iconAsTemplate": true
},
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.tauri.dev",
"identifier": "dev.scalar.semtex",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
Expand Down
11 changes: 5 additions & 6 deletions semdesk-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useState } from "react";
import { invoke } from "@tauri-apps/api/tauri";
import { ResultList } from "./ResultList";

function App() {
const [name, setName] = useState("");
const [data, setData] = useState<any[]>([]);

async function greet() {
async function search() {
const r = await fetch(`http://localhost:8080/search?query=${name}`, {
headers: { "Content-Type": "application/json" },
});
Expand All @@ -15,15 +14,15 @@ function App() {

return (
<>
<div className="sticky top-0 w-full bg-slate-300 p-4 z-0">
<div className="sticky top-0 w-full bg-slate-300 p-4 z-10">
<div className="flex items-center">
<h1 className="flex-1 text-3xl font-bold">semdesk</h1>
<h1 className="flex-1 text-3xl font-bold">semtex</h1>

<form
className="row"
onSubmit={(e) => {
e.preventDefault();
greet();
search();
}}
>
<div className="flex items-center gap-2">
Expand All @@ -48,7 +47,7 @@ function App() {
</div>
</div>

<div className="container mx-auto px-2 py-4">
<div className="container mx-auto px-2 py-4 z-0">
{data && <ResultList results={data} />}
</div>
</>
Expand Down
4 changes: 2 additions & 2 deletions semdesk-app/src/ResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ export function ResultList({ results }: Props) {
maximumFractionDigits: 1,
})}
</p>
<p className="mt-1 text-xs leading-5 text-gray-500">
{/* <p className="mt-1 text-xs leading-5 text-gray-500">
<time dateTime={result.lastSeenDateTime}>
{result.lastSeen}
</time>
</p>
</p> */}
</div>
</div>
</li>
Expand Down
10 changes: 5 additions & 5 deletions semdesk-webext/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "vite-web-extension",
"version": "1.0.0",
"displayName": "Vite Web Extension",
"author": "@samrum/vite-plugin-web-extension",
"description": "A @samrum/vite-plugin-web-extension web extension",
"name": "semtex",
"version": "0.1.0",
"displayName": "semtex browser extension",
"author": "Scalar Labs",
"description": "An offline semantic search tool",
"type": "module",
"scripts": {
"build": "tsc && vite build",
Expand Down
2 changes: 1 addition & 1 deletion semdesk-webext/src/entries/contentScript/primary/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isProbablyReaderable } from "@mozilla/readability";
import renderContent from "../renderContent";
import "./style.css";
import * as browser from "webextension-polyfill";
Expand All @@ -6,7 +7,6 @@ renderContent(
import.meta.PLUGIN_WEB_EXT_CHUNK_CSS_PATHS,
(_appRoot: HTMLElement) => {
if (isProbablyReaderable(document)) {
console.log("redaable");
browser.runtime.sendMessage({
type: "store",
content: {
Expand Down
2 changes: 1 addition & 1 deletion semdesk-webext/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const manifest = {
],
browser_specific_settings: {
gecko: {
id: "semdesk@scalar.dev"
id: "semtex@scalar.dev"
},
},
browser_action: {
Expand Down

0 comments on commit e3934e3

Please sign in to comment.