add support for ios dev build (#68)

This commit is contained in:
QP Hou
2024-12-30 00:37:01 -08:00
committed by GitHub
parent 75e872af51
commit abb1b7ae9c
26 changed files with 59 additions and 16 deletions
+5
View File
@@ -149,6 +149,11 @@ For Windows targets, “Build Tools for Visual Studio 2022” (or a higher editi
```bash
pnpm tauri dev
```
For ios:
```bash
pnpm tauri ios dev
```
### 5. Build for Production
@@ -55,11 +55,9 @@
"core:window:allow-start-dragging",
"core:window:allow-toggle-maximize",
"shell:default",
"updater:default",
"process:default",
"process:allow-exit",
"process:allow-restart",
"cli:default",
"oauth:allow-start",
"oauth:allow-cancel",
"opener:default"
@@ -0,0 +1,10 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "desktop-capability",
"windows": ["main"],
"platforms": ["linux", "macOS", "windows"],
"permissions": [
"updater:default",
"cli:default"
]
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

+22 -5
View File
@@ -74,7 +74,6 @@ async fn start_server(window: Window) -> Result<u16, String> {
pub fn run() {
let builder = tauri::Builder::default()
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_oauth::init())
.invoke_handler(tauri::generate_handler![start_server])
.plugin(tauri_plugin_shell::init())
@@ -84,6 +83,9 @@ pub fn run() {
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_fs::init());
#[cfg(desktop)]
let builder = builder.plugin(tauri_plugin_updater::Builder::new().build());
#[cfg(target_os = "macos")]
let builder = builder.plugin(tauri_traffic_light_positioner_plugin::init());
@@ -120,8 +122,19 @@ pub fn run() {
});
}
}
#[cfg(desktop)]
app.handle().plugin(tauri_plugin_cli::init())?;
{
app.handle().plugin(tauri_plugin_cli::init())?;
let app_handle = app.handle().clone();
app.listen("window-ready", move |_| {
app_handle.get_webview_window("main").unwrap()
.eval("window.__READEST_CLI_ACCESS = true; window.__READEST_UPDATER_ACCESS = true;")
.expect("Failed to set cli access config");
});
}
#[cfg(desktop)]
if cfg!(debug_assertions) {
app.handle().plugin(
@@ -130,7 +143,11 @@ pub fn run() {
.build(),
)?;
}
let win_builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default())
let win_builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default());
#[cfg(desktop)]
let win_builder = win_builder
.inner_size(800.0, 600.0)
.resizable(true)
.maximized(true);
@@ -141,7 +158,7 @@ pub fn run() {
.title_bar_style(TitleBarStyle::Overlay)
.title("");
#[cfg(not(target_os = "macos"))]
#[cfg(all(not(target_os = "macos"), desktop))]
let win_builder = win_builder
.decorations(false)
.transparent(true)
@@ -163,7 +180,7 @@ pub fn run() {
.run(
#[allow(unused_variables)]
|app_handle, event| {
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(target_os = "macos")]
if let tauri::RunEvent::Opened { urls } = event {
let files = urls
.into_iter()
+2 -2
View File
@@ -8,7 +8,7 @@ import { Book } from '@/types/book';
import { AppService } from '@/types/system';
import { navigateToReader } from '@/utils/nav';
import { parseOpenWithFiles } from '@/helpers/cli';
import { isTauriAppPlatform } from '@/services/environment';
import { isTauriAppPlatform, hasUpdater } from '@/services/environment';
import { checkForAppUpdates } from '@/helpers/updater';
import { FILE_ACCEPT_FORMATS, SUPPORTED_FILE_EXTS } from '@/services/constants';
@@ -46,7 +46,7 @@ const LibraryPage = () => {
useEffect(() => {
const doAppUpdates = async () => {
if (isTauriAppPlatform()) {
if (hasUpdater()) {
await checkForAppUpdates();
}
};
+2 -2
View File
@@ -2,7 +2,7 @@
import { useEffect } from 'react';
import { useTheme } from '@/hooks/useTheme';
import { isTauriAppPlatform } from '@/services/environment';
import { hasUpdater } from '@/services/environment';
import { checkForAppUpdates } from '@/helpers/updater';
import Reader from './components/Reader';
@@ -10,7 +10,7 @@ export default function Page() {
useTheme();
useEffect(() => {
const doAppUpdates = async () => {
if (isTauriAppPlatform()) {
if (hasUpdater()) {
await checkForAppUpdates();
}
};
@@ -1,5 +1,6 @@
import clsx from 'clsx';
import React, { useEffect, useRef } from 'react';
import { useEnv } from '@/context/EnvContext';
import { tauriHandleMinimize, tauriHandleToggleMaximize, tauriHandleClose } from '@/utils/window';
import { isTauriAppPlatform } from '@/services/environment';
@@ -44,6 +45,7 @@ const WindowButtons: React.FC<WindowButtonsProps> = ({
onClose,
}) => {
const parentRef = useRef<HTMLDivElement>(null);
const { appService } = useEnv();
const handleMouseDown = async (e: MouseEvent) => {
const target = e.target as HTMLElement;
@@ -110,7 +112,7 @@ const WindowButtons: React.FC<WindowButtonsProps> = ({
className,
)}
>
{showMinimize && (
{showMinimize && appService?.hasWindowBar && (
<WindowButton onClick={handleMinimize} ariaLabel='Minimize' id='titlebar-minimize'>
<svg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' viewBox='0 0 24 24'>
<path fill='currentColor' d='M20 14H4v-2h16' />
@@ -118,7 +120,7 @@ const WindowButtons: React.FC<WindowButtonsProps> = ({
</WindowButton>
)}
{showMaximize && (
{showMaximize && appService?.hasWindowBar && (
<WindowButton onClick={handleMaximize} ariaLabel='Maximize/Restore' id='titlebar-maximize'>
<svg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' viewBox='0 0 24 24'>
<path fill='currentColor' d='M4 4h16v16H4zm2 4v10h12V8z' />
@@ -126,7 +128,7 @@ const WindowButtons: React.FC<WindowButtonsProps> = ({
</WindowButton>
)}
{showClose && (
{showClose && (appService?.hasWindowBar || onClose) && (
<WindowButton onClick={handleClose} ariaLabel='Close' id='titlebar-close'>
<svg xmlns='http://www.w3.org/2000/svg' width='1em' height='1em' viewBox='0 0 24 24'>
<path
+2 -2
View File
@@ -1,4 +1,4 @@
import { isWebAppPlatform } from '@/services/environment';
import { isWebAppPlatform, hasCli } from '@/services/environment';
declare global {
interface Window {
@@ -36,7 +36,7 @@ export const parseOpenWithFiles = async () => {
if (isWebAppPlatform()) return [];
let files = parseWindowOpenWithFiles();
if (!files) {
if (!files && hasCli()) {
files = await parseCLIOpenWithFiles();
}
return files;
@@ -1,7 +1,16 @@
import { AppService } from '@/types/system';
declare global {
interface Window {
__READEST_CLI_ACCESS?: boolean;
__READEST_UPDATER_ACCESS?: boolean;
}
}
export const isTauriAppPlatform = () => process.env['NEXT_PUBLIC_APP_PLATFORM'] === 'tauri';
export const isWebAppPlatform = () => process.env['NEXT_PUBLIC_APP_PLATFORM'] === 'web';
export const hasUpdater = () => window.__READEST_UPDATER_ACCESS === true;
export const hasCli = () => window.__READEST_CLI_ACCESS === true;
export interface EnvConfigType {
getAppService: () => Promise<AppService>;
@@ -119,6 +119,7 @@ export class NativeAppService extends BaseAppService {
appPlatform = 'tauri' as AppPlatform;
isAppDataSandbox = isMobile;
hasTrafficLight = osType() === 'macos';
hasWindowBar = !(osType() === 'ios' || osType() === 'android');
override resolvePath(fp: string, base: BaseDir): { baseDir: number; base: BaseDir; fp: string } {
return resolvePath(fp, base);
+1
View File
@@ -23,6 +23,7 @@ export interface AppService {
fs: FileSystem;
appPlatform: AppPlatform;
hasTrafficLight: boolean;
hasWindowBar: boolean;
isAppDataSandbox: boolean;
selectFiles(name: string, extensions: string[]): Promise<string[]>;