Skip to content

Commit

Permalink
style: add prettier (#34)
Browse files Browse the repository at this point in the history
* style: add prettier

style: add prettier ignore file

style: apply formatting

style: install and apply svelte prettier

* Add prettier to recommended extensions

* chore: add check and format scripts to package.json

* chore: update prettier scripts to avoid conflict with svelte-check
  • Loading branch information
benediktms authored Jan 12, 2023
1 parent d0f00a5 commit e7ee512
Show file tree
Hide file tree
Showing 27 changed files with 591 additions and 574 deletions.
6 changes: 5 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

github: [parthjadhav]
ko_fi: parthjadhav
custom: ["https://paypal.me/parthJadhav22", "https://www.buymeacoffee.com/Parthjadhav"]
custom:
[
'https://paypal.me/parthJadhav22',
'https://www.buymeacoffee.com/Parthjadhav',
]
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
src-tauri
dist
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"arrowParens": "avoid"
}
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"recommendations": [
"svelte.svelte-vscode",
"tauri-apps.tauri-vscode",
"rust-lang.rust-analyzer"
"rust-lang.rust-analyzer",
"esbenp.prettier-vscode"
]
}
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
- Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Verve is a lightweight and blazingly fast launcher for accessing and opening app
<img src="./docs/preferences.png" alt="drawing" width="620"/>

## 🚀 Features
<img src="https://user-images.githubusercontent.com/42001064/210351599-bc19bd5b-2872-4bed-80fc-b687508a6faa.png" alt="drawing" width="620"/>

<img src="https://user-images.githubusercontent.com/42001064/210351599-bc19bd5b-2872-4bed-80fc-b687508a6faa.png" alt="drawing" width="620"/>

## 📥 Downloading

Expand Down
3 changes: 1 addition & 2 deletions docs/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Download: [theme-blue.json](./themes/theme-blue/theme.json)

![Verve Dracula Theme](./themes/theme-green/theme-green.png)


Download: [theme-green.json](./themes/theme-green/theme.json)

### Create your own theme
Expand All @@ -26,4 +25,4 @@ You can create your own theme by editing the theme.json file. You can find the t

Save the file & Restart the app.

Create a Pull request to add your theme to the list.
Create a Pull request to add your theme to the list.
18 changes: 9 additions & 9 deletions docs/themes/theme-blue/theme.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"primary_bg_color": "rgba(20, 20, 80, 0.6)",
"secondary_bg_color": "rgba(84, 101, 115, 0.6)",
"primary_text_color": "#FFFFFF",
"secondary_text_color": "#878787",
"primary_accent_color": "#556CE5",
"secondary_accent_color": "#48A5FF",
"highlight_overlay": "rgba(255, 255, 255, 0.1)",
"dark_overlay": "rgba(0, 0, 0, 0.1)"
}
"primary_bg_color": "rgba(20, 20, 80, 0.6)",
"secondary_bg_color": "rgba(84, 101, 115, 0.6)",
"primary_text_color": "#FFFFFF",
"secondary_text_color": "#878787",
"primary_accent_color": "#556CE5",
"secondary_accent_color": "#48A5FF",
"highlight_overlay": "rgba(255, 255, 255, 0.1)",
"dark_overlay": "rgba(0, 0, 0, 0.1)"
}
18 changes: 9 additions & 9 deletions docs/themes/theme-default/theme.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"primary_bg_color": "rgba(20, 20, 30, 0.6)",
"secondary_bg_color": "rgba(84, 101, 115, 0.6)",
"primary_text_color": "#FFFFFF",
"secondary_text_color": "#878787",
"primary_accent_color": "#556CE5",
"secondary_accent_color": "#48A5FF",
"highlight_overlay": "rgba(255, 255, 255, 0.1)",
"dark_overlay": "rgba(0, 0, 0, 0.1)"
}
"primary_bg_color": "rgba(20, 20, 30, 0.6)",
"secondary_bg_color": "rgba(84, 101, 115, 0.6)",
"primary_text_color": "#FFFFFF",
"secondary_text_color": "#878787",
"primary_accent_color": "#556CE5",
"secondary_accent_color": "#48A5FF",
"highlight_overlay": "rgba(255, 255, 255, 0.1)",
"dark_overlay": "rgba(0, 0, 0, 0.1)"
}
18 changes: 9 additions & 9 deletions docs/themes/theme-green/theme.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"primary_bg_color": "rgba(20, 45, 30, 0.6)",
"secondary_bg_color": "rgba(84, 101, 115, 0.6)",
"primary_text_color": "#FFFFFF",
"secondary_text_color": "#878787",
"primary_accent_color": "#556CE5",
"secondary_accent_color": "#48A5FF",
"highlight_overlay": "rgba(255, 255, 255, 0.1)",
"dark_overlay": "rgba(0, 0, 0, 0.1)"
}
"primary_bg_color": "rgba(20, 45, 30, 0.6)",
"secondary_bg_color": "rgba(84, 101, 115, 0.6)",
"primary_text_color": "#FFFFFF",
"secondary_text_color": "#878787",
"primary_accent_color": "#556CE5",
"secondary_accent_color": "#48A5FF",
"highlight_overlay": "rgba(255, 255, 255, 0.1)",
"dark_overlay": "rgba(0, 0, 0, 0.1)"
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"tauri": "tauri",
"package-and-build-arm": "yarn tauri build --target aarch64-apple-darwin && rm -rf ./src-tauri/target/verve_aarch64.dmg && create-dmg --volname Verve --volicon './src-tauri/icons/icon.icns' --background './src/dmg-background.png' --window-pos 200 120 --window-size 653 380 --icon-size 115 --icon 'verve.app' 180 189 --hide-extension 'Verve.app' --app-drop-link 460 185 ./src-tauri/target/aarch64-apple-darwin/release/bundle/verve_aarch64.dmg ./src-tauri/target/aarch64-apple-darwin/release/bundle/macos/verve.app && mv ./src-tauri/target/aarch64-apple-darwin/release/bundle/verve_aarch64.dmg ./src-tauri/target/",
"package-and-build-x86_64": "yarn tauri build --target x86_64-apple-darwin && rm -rf ./src-tauri/target/verve_x86_64.dmg && create-dmg --volname Verve --volicon './src-tauri/icons/icon.icns' --background './src/dmg-background.png' --window-pos 200 120 --window-size 653 380 --icon-size 115 --icon 'verve.app' 180 189 --hide-extension 'Verve.app' --app-drop-link 460 185 ./src-tauri/target/x86_64-apple-darwin/release/bundle/verve_x86_64.dmg ./src-tauri/target/x86_64-apple-darwin/release/bundle/macos/verve.app && mv ./src-tauri/target/x86_64-apple-darwin/release/bundle/verve_x86_64.dmg ./src-tauri/target/",
"package-and-build": "yarn package-and-build-arm && yarn package-and-build-x86_64 && open ./src-tauri/target/"
"package-and-build": "yarn package-and-build-arm && yarn package-and-build-x86_64 && open ./src-tauri/target/",
"format:check": "prettier --check .",
"format:write": "prettier --write ."
},
"dependencies": {
"@tauri-apps/api": "^1.1.0",
Expand All @@ -22,6 +24,8 @@
"@tauri-apps/cli": "^1.1.0",
"@tsconfig/svelte": "^3.0.0",
"@types/node": "^18.7.10",
"prettier": "^2.8.2",
"prettier-plugin-svelte": "^2.9.0",
"svelte": "^3.49.0",
"svelte-check": "^2.8.0",
"svelte-preprocess": "^4.10.7",
Expand Down
69 changes: 36 additions & 33 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,82 @@
import "./style.css";
import './style.css';
// @ts-ignore
import App from "./routes/App/App.svelte";
import { appWindow } from "@tauri-apps/api/window";
import { register } from '@tauri-apps/api/globalShortcut'
import { appDataDir, join, resolveResource } from "@tauri-apps/api/path";
import { readTextFile } from "@tauri-apps/api/fs";
import { invoke } from "@tauri-apps/api/tauri";
import { preferences, paths } from "./cache";
import { listen } from '@tauri-apps/api/event'
import App from './routes/App/App.svelte';
import { appWindow } from '@tauri-apps/api/window';
import { register } from '@tauri-apps/api/globalShortcut';
import { appDataDir, join, resolveResource } from '@tauri-apps/api/path';
import { readTextFile } from '@tauri-apps/api/fs';
import { invoke } from '@tauri-apps/api/tauri';
import { preferences, paths } from './cache';
import { listen } from '@tauri-apps/api/event';

// Create the app
const app = new App({
target: document.getElementById("app"),
target: document.getElementById('app'),
});

const fetchPreferencesData = async () => {
const preferencesData = await readTextFile(await join(paths.get("appDataDirPath"), `preferences.json`)).then((data) => JSON.parse(data));
Object.keys(preferencesData).forEach((key) => {
const preferencesData = await readTextFile(
await join(paths.get('appDataDirPath'), `preferences.json`)
).then(data => JSON.parse(data));
Object.keys(preferencesData).forEach(key => {
preferences.set(key, preferencesData[key]);
});
}
};

const reloadTheme = async () => {
const theme = await readTextFile(await join(paths.get("appDataDirPath"), `theme.json`)).then((data) => JSON.parse(data));
const theme = await readTextFile(
await join(paths.get('appDataDirPath'), `theme.json`)
).then(data => JSON.parse(data));
// @ts-ignore
const style = document.styleSheets[0].cssRules[0].style;
style.setProperty("--primary-bg-color", theme.primary_bg_color);
style.setProperty("--secondary-bg-color", theme.secondary_bg_color);
style.setProperty("--primary-text-color", theme.primary_text_color);
style.setProperty("--secondary-text-color", theme.secondary_text_color);
style.setProperty("--primary-accent-color", theme.primary_accent_color);
style.setProperty("--secondary-accent-color", theme.secondary_accent_color);
}
style.setProperty('--primary-bg-color', theme.primary_bg_color);
style.setProperty('--secondary-bg-color', theme.secondary_bg_color);
style.setProperty('--primary-text-color', theme.primary_text_color);
style.setProperty('--secondary-text-color', theme.secondary_text_color);
style.setProperty('--primary-accent-color', theme.primary_accent_color);
style.setProperty('--secondary-accent-color', theme.secondary_accent_color);
};

(async () => {
// get and set values
paths.set("appDataDirPath", await appDataDir());
paths.set('appDataDirPath', await appDataDir());
await fetchPreferencesData();
await reloadTheme();

document.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
document.addEventListener('keydown', event => {
if (event.key === 'Escape') {
appWindow.hide();
}
});

// Listen for Menu Bar event to open preferences emitted from main.rs
await listen("PreferencesClicked", (data) => {
await listen('PreferencesClicked', data => {
app.$set({
appState: {
app: false,
settings: true
}
settings: true,
},
});
});


await invoke("launch_on_login", {
enable: preferences.get("launch_on_login"),
await invoke('launch_on_login', {
enable: preferences.get('launch_on_login'),
});

await listenForHotkey(preferences.get("shortcut"));
await listenForHotkey(preferences.get('shortcut'));
})();

export async function listenForHotkey(shortcut: string) {
await register(shortcut, async () => {
if (document.hasFocus()) {
await appWindow.hide()
await appWindow.hide();
} else {
await appWindow.show();
await appWindow.center();
await appWindow.setFocus();
document.getElementById('searchBarInput').focus();
}
})
});
}

export default app;
42 changes: 21 additions & 21 deletions src/routes/App/App.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import { appWindow, LogicalSize } from "@tauri-apps/api/window";
import SearchBar from "./lib/SearchBar.svelte";
import Footer from "./lib/Footer.svelte";
import SearchResult from "./lib/SearchResult.svelte";
import Settings from "../Settings/Settings.svelte";
import { invoke } from "@tauri-apps/api/tauri";
import { appWindow, LogicalSize } from '@tauri-apps/api/window';
import SearchBar from './lib/SearchBar.svelte';
import Footer from './lib/Footer.svelte';
import SearchResult from './lib/SearchResult.svelte';
import Settings from '../Settings/Settings.svelte';
import { invoke } from '@tauri-apps/api/tauri';
export let appState = {
app: true,
Expand All @@ -13,10 +13,10 @@
let results: string[] = [];
let executionTime: number = 0;
let resultType: number = 0;
let footerText: string = "verve.app";
let footerText: string = 'verve.app';
document.onkeyup = function (event) {
if (event.metaKey && event.key === ",") {
if (event.metaKey && event.key === ',') {
appState.app = false;
appState.settings = true;
}
Expand All @@ -29,49 +29,49 @@
};
const searchResultClicked = async (event: any) => {
await invoke("open_command", { path: event.target.id });
await invoke('open_command', { path: event.target.id });
const searchBarInput = document.getElementById(
"searchBarInput"
'searchBarInput'
) as HTMLInputElement;
results = [];
searchBarInput.value = "";
searchBarInput.value = '';
await appWindow.hide();
};
const search = async (searchPrompt: string) => {
footerText = "Loading...";
[results, executionTime, resultType] = await invoke("handle_input", {
footerText = 'Loading...';
[results, executionTime, resultType] = await invoke('handle_input', {
input: searchPrompt,
});
if (results.length === 0) {
footerText = "No results found";
footerText = 'No results found';
return;
}
if (resultType === 3) {
footerText = "Copy Answer ⏎";
footerText = 'Copy Answer ⏎';
return;
}
footerText = `~ ${Math.floor(executionTime * 1000)} ms`;
};
document.addEventListener("keydown", async (event: any) => {
document.addEventListener('keydown', async (event: any) => {
if (event.keyCode == 13) {
event.preventDefault();
if (event.target?.value?.startsWith("/")) {
if (event.target?.value?.startsWith('/')) {
search(event.target.value);
}
}
});
const handleInput = async (event: any) => {
if (event.target.value === "") {
if (event.target.value === '') {
results = [];
footerText = "verve.app";
footerText = 'verve.app';
return;
}
if (event.target.value.startsWith("/")) {
if (event.target.value.startsWith('/')) {
// this signifies a full drive search. Searches in /Users folder
footerText = "Press Enter to search";
footerText = 'Press Enter to search';
return;
}
search(event.target.value);
Expand Down
Loading

0 comments on commit e7ee512

Please sign in to comment.