Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #1395 Use tauri shell::open instead of open #1407

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"authorization_code": "Authorization Code",
"authorization_help": "Please paste the authorization code from your browser",
"without_code_authorize": "Please approve Fedistar in your browser, and after you approve it please authorize",
"authorization_url": "Normally, the browser will open automatically, but if it doesn't, please open the following URL in your browser and approve it.",
"authorize": "Authorize",
"loading": "Loading"
}
Expand Down
33 changes: 1 addition & 32 deletions src-tauri/Cargo.lock

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

1 change: 0 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ tokio = { version = "1.36", features = ["full"] }
futures = "0.3"
directories = "5.0"
megalodon = "0.13.2"
open = "5.1"
tracing = "0.1.40"
reqwest = { version = "0.11", features = ["json", "multipart", "stream"] }
scraper = "0.19"
Expand Down
23 changes: 12 additions & 11 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use megalodon::{self, oauth};
use rust_i18n::t;
use serde::Serialize;
use std::{env, fs::OpenOptions, path::PathBuf, str::FromStr, sync::Arc};
use tauri::{async_runtime::Mutex, AppHandle, Manager, State};
use tauri::{api::shell, async_runtime::Mutex, AppHandle, Manager, State};
mod database;
mod entities;
mod favicon;
Expand Down Expand Up @@ -88,16 +88,12 @@ async fn remove_server(

#[tauri::command]
async fn add_application(
app_handle: AppHandle,
_sqlite_pool: State<'_, sqlx::SqlitePool>,
url: &str,
) -> Result<oauth::AppData, String> {
let sns = megalodon::detector(url).await.map_err(|e| e.to_string())?;
let client = megalodon::generator(
sns,
url.clone().to_string(),
None,
Some(String::from("fedistar")),
);
let client = megalodon::generator(sns, url.to_string(), None, Some(String::from("fedistar")));

let options = megalodon::megalodon::AppInputOptions {
..Default::default()
Expand All @@ -107,8 +103,9 @@ async fn add_application(
.await
.map_err(|e| e.to_string())?;

let url = app_data.url.clone();
open::that(url.expect("URL is not found")).expect("Failed to open the URL");
let url = app_data.url.clone().expect("URL is not found");
tracing::info!("Opening the URL: {}", url);
shell::open(&app_handle.shell_scope(), url, None).expect("Failed to open the URL");
Ok(app_data)
}

Expand Down Expand Up @@ -644,8 +641,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.menu(menu::menu())
.on_menu_event(|event| match event.menu_item_id() {
"crash_reporting" => {
open::that("https://fedistar.net/help#crash_reporting")
.expect("Failed to open the URL");
shell::open(
&event.window().app_handle().shell_scope(),
"https://fedistar.net/help#crash_reporting",
None,
)
.expect("Failed to open the URL");
}
_ => {}
})
Expand Down
4 changes: 4 additions & 0 deletions src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,7 @@
}
}
}

.no-scrollbar::-webkit-scrollbar {
display: none;
}
35 changes: 35 additions & 0 deletions src/components/servers/New.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { OAuth } from 'megalodon'
import alert from '../utils/alert'
import { parseDomain } from 'src/utils/domainParser'
import { FormattedMessage, useIntl } from 'react-intl'
import { BsClipboard } from 'react-icons/bs'
import { Icon } from '@rsuite/icons'

type Props = {
open: boolean
Expand Down Expand Up @@ -89,6 +91,10 @@ const New: React.FC<Props> = props => {
props.onClose()
}

const copyText = (text: string) => {
navigator.clipboard.writeText(text)
}

return (
<Modal backdrop="static" keyboard={true} open={props.open} onClose={() => close()}>
<Modal.Header>
Expand Down Expand Up @@ -141,6 +147,35 @@ const New: React.FC<Props> = props => {
)}
{app !== undefined && (
<Form fluid formValue={{ code: code }} onChange={o => setCode(o.code)}>
<p>
<FormattedMessage id="servers.new.authorization_url" />
</p>
<div
style={{
backgroundColor: 'var(--rs-gray-800)',
width: '80%',
padding: '8px 0 8px 12px',
borderRadius: '4px',
margin: '8px 0',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center'
}}
>
<span
className="no-scrollbar"
style={{
width: '90%',
whiteSpace: 'nowrap',
overflowX: 'auto'
}}
>
{app.url}
</span>
<Button appearance="link" onClick={() => copyText(app.url)}>
<Icon as={BsClipboard} />
</Button>
</div>
{app.session_token ? (
<div style={{ margin: '1em 0' }}>
<FormattedMessage id="servers.new.without_code_authorize" />
Expand Down
Loading