Skip to content

Commit

Permalink
refactor(api)!: Rename primitives mod to core (#8273)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianLars committed Nov 20, 2023
1 parent 618b0d0 commit c2ad4d2
Show file tree
Hide file tree
Showing 34 changed files with 45 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changes/api-primitives-core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tauri-apps/api': 'patch:breaking'
---

Changed former `tauri` module from `primitives` to `core`.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/api/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { onMount } from 'svelte'
import { writable } from 'svelte/store'
import { invoke } from '@tauri-apps/api/primitives'
import { invoke } from '@tauri-apps/api/core'
import Welcome from './views/Welcome.svelte'
import Communication from './views/Communication.svelte'
Expand Down
2 changes: 1 addition & 1 deletion examples/api/src/views/Communication.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { listen, emit } from '@tauri-apps/api/event'
import { invoke } from '@tauri-apps/api/primitives'
import { invoke } from '@tauri-apps/api/core'
import { onMount, onDestroy } from 'svelte'
export let onMessage
Expand Down
2 changes: 1 addition & 1 deletion examples/api/src/views/Welcome.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { invoke } from '@tauri-apps/api/primitives'
import { invoke } from '@tauri-apps/api/core'
import { getName, getVersion, getTauriVersion } from '@tauri-apps/api/app'
let version = '1.0.0'
Expand Down
2 changes: 1 addition & 1 deletion examples/commands/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1>Tauri Commands</h1>
function runCommand(commandName, args, optional) {
const id = optional ? '#response-optional' : '#response'
const result = document.querySelector(id)
window.__TAURI__.primitives
window.__TAURI__.core
.invoke(commandName, args)
.then((response) => {
const val =
Expand Down
2 changes: 1 addition & 1 deletion examples/isolation/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h1>Hello, Tauri!</h1>
const ping = document.querySelector("#ping")
const pong = document.querySelector('#pong')
ping.addEventListener("click", () => {
window.__TAURI__.primitives.invoke("ping")
window.__TAURI__.core.invoke("ping")
.then(() => {
pong.innerText = `ok: ${Date.now()}`
})
Expand Down
2 changes: 1 addition & 1 deletion examples/parent-window/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

const responseContainer = document.getElementById('response')
function runCommand(commandName, args, optional) {
window.__TAURI__.primitives
window.__TAURI__.core
.invoke(commandName, args)
.then((response) => {
responseContainer.innerText += `Ok(${response})\n\n`
Expand Down
2 changes: 1 addition & 1 deletion examples/splashscreen/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h1>This is the main window!</h1>
document.addEventListener('DOMContentLoaded', () => {
// we delay here just so we can see the splashscreen for a while
setTimeout(() => {
window.__TAURI__.primitives.invoke('close_splashscreen')
window.__TAURI__.core.invoke('close_splashscreen')
}, 2000)
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion examples/streaming/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<source type="video/mp4" />
</video>
<script>
const { invoke, convertFileSrc } = window.__TAURI__.primitives
const { invoke, convertFileSrc } = window.__TAURI__.core
const video = document.getElementById('video_source')
const source = document.createElement('source')
invoke('video_uri').then(([scheme, path]) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/web/src/api/desktop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

import { invoke } from '@tauri-apps/api/primitives'
import { invoke } from '@tauri-apps/api/core'

export const NAME = 'Tauri'

Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

import { invoke } from './primitives'
import { invoke } from './core'

/**
* Application metadata and related APIs.
Expand Down
4 changes: 2 additions & 2 deletions tooling/api/src/primitives.ts → tooling/api/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ interface InvokeOptions {
* Sends a message to the backend.
* @example
* ```typescript
* import { invoke } from '@tauri-apps/api/primitives';
* import { invoke } from '@tauri-apps/api/core';
* await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
* ```
*
Expand Down Expand Up @@ -139,7 +139,7 @@ async function invoke<T>(
* @example
* ```typescript
* import { appDataDir, join } from '@tauri-apps/api/path';
* import { convertFileSrc } from '@tauri-apps/api/primitives';
* import { convertFileSrc } from '@tauri-apps/api/core';
* const appDataDirPath = await appDataDir();
* const filePath = await join(appDataDirPath, 'assets/video.mp4');
* const assetUrl = convertFileSrc(filePath);
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @module
*/

import { invoke, transformCallback } from './primitives'
import { invoke, transformCallback } from './core'

interface Event<T> {
/** Event name */
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/** @ignore */

import type { invoke, transformCallback, convertFileSrc } from './primitives'
import type { invoke, transformCallback, convertFileSrc } from './core'

/** @ignore */
declare global {
Expand Down
4 changes: 2 additions & 2 deletions tooling/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

import * as app from './app'
import * as event from './event'
import * as primitives from './primitives'
import * as core from './core'
import * as window from './window'
import * as path from './path'
import * as dpi from './dpi'
import * as tray from './tray'
import * as menu from './menu'

export { app, dpi, event, path, primitives, window, tray, menu }
export { app, dpi, event, path, core, window, tray, menu }
2 changes: 1 addition & 1 deletion tooling/api/src/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

import { invoke } from '../primitives'
import { invoke } from '../core'

/**
* A rust-backed resource.
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/menu/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT

import { Resource } from '../internal'
import { Channel, invoke } from '../primitives'
import { Channel, invoke } from '../core'
import { CheckMenuItemOptions } from './checkMenuItem'
import { IconMenuItemOptions } from './iconMenuItem'
import { MenuItemOptions } from './menuItem'
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/menu/checkMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT

import { MenuItemBase, newMenu } from './base'
import { invoke } from '../primitives'
import { invoke } from '../core'
import { type MenuItemOptions } from '../menu'

/** Options for creating a new check menu item. */
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/menu/iconMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { MenuItemBase, newMenu } from './base'
import { type MenuItemOptions } from '../menu'
import { invoke } from '../primitives'
import { invoke } from '../core'

/**
* A native Icon to be used for the menu item
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PredefinedMenuItem } from './predefinedMenuItem'
import { Submenu } from './submenu'
import { type LogicalPosition, PhysicalPosition } from '../dpi'
import { type Window } from '../window'
import { invoke } from '../primitives'
import { invoke } from '../core'
import { type ItemKind, MenuItemBase, newMenu } from './base'

function itemFromKind([rid, id, kind]: [number, string, ItemKind]):
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/menu/menuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT

import { MenuItemBase, newMenu } from './base'
import { invoke } from '../primitives'
import { invoke } from '../core'

/** Options for creating a new menu item. */
export interface MenuItemOptions {
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/menu/predefinedMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT

import { MenuItemBase, newMenu } from './base'
import { invoke } from '../primitives'
import { invoke } from '../core'

/** A metadata for the about predefined menu item. */
export interface AboutMetadata {
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/menu/submenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MenuItem, type MenuItemOptions } from './menuItem'
import { CheckMenuItem } from './checkMenuItem'
import { IconMenuItem } from './iconMenuItem'
import { PredefinedMenuItem } from './predefinedMenuItem'
import { invoke } from '../primitives'
import { invoke } from '../core'
import { type LogicalPosition, PhysicalPosition, type Window } from '../window'
import { type ItemKind, MenuItemBase, newMenu } from './base'
import { type MenuOptions } from './menu'
Expand Down
6 changes: 3 additions & 3 deletions tooling/api/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface IPCMessage {
* Testing setup using vitest:
* ```js
* import { mockIPC, clearMocks } from "@tauri-apps/api/mocks"
* import { invoke } from "@tauri-apps/api/primitives"
* import { invoke } from "@tauri-apps/api/core"
*
* afterEach(() => {
* clearMocks()
Expand All @@ -42,7 +42,7 @@ interface IPCMessage {
* The callback function can also return a Promise:
* ```js
* import { mockIPC, clearMocks } from "@tauri-apps/api/mocks"
* import { invoke } from "@tauri-apps/api/primitives"
* import { invoke } from "@tauri-apps/api/core"
*
* afterEach(() => {
* clearMocks()
Expand Down Expand Up @@ -141,7 +141,7 @@ export function mockWindows(
* @example
* ```js
* import { mockConvertFileSrc } from "@tauri-apps/api/mocks";
* import { convertFileSrc } from "@tauri-apps/api/primitives";
* import { convertFileSrc } from "@tauri-apps/api/core";
*
* mockConvertFileSrc("windows")
*
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @module
*/

import { invoke } from './primitives'
import { invoke } from './core'

/**
* @since 2.0.0
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import type { Menu, Submenu } from './menu'
import { Resource } from './internal'
import { Channel, invoke } from './primitives'
import { Channel, invoke } from './core'

/**
* Describes a tray event emitted when a tray icon is clicked
Expand Down
2 changes: 1 addition & 1 deletion tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from './dpi'
import type { Event, EventName, EventCallback, UnlistenFn } from './event'
import { TauriEvent, emit, listen, once } from './event'
import { invoke } from './primitives'
import { invoke } from './core'

/**
* Allows you to retrieve information about a given monitor.
Expand Down
2 changes: 1 addition & 1 deletion tooling/bench/tests/cpu_intensive/public/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const onMessage = (message) => {

if (message.data.status === 'done') {
// tell tauri that we are done
window.__TAURI__.primitives.invoke('app_completed_successfully')
window.__TAURI__.core.invoke('app_completed_successfully')
}

status.innerHTML = `${prefix} Found <code>${message.data.count}</code> prime numbers in <code>${message.data.time}ms</code>`
Expand Down
6 changes: 3 additions & 3 deletions tooling/bench/tests/files_transfer/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ <h1>Welcome to Tauri!</h1>

<script>
window.addEventListener('DOMContentLoaded', (event) => {
window.__TAURI__.primitives
window.__TAURI__.core
.invoke('read_file')
.then((_data) => {
// success
window.__TAURI__.primitives.invoke('app_should_close', {
window.__TAURI__.core.invoke('app_should_close', {
exitCode: 0
})
})
.catch((_error) => {
// error
window.__TAURI__.primitives.invoke('app_should_close', {
window.__TAURI__.core.invoke('app_should_close', {
exitCode: 1
})
})
Expand Down
2 changes: 1 addition & 1 deletion tooling/bench/tests/helloworld/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>Welcome to Tauri!</h1>

<script>
window.addEventListener('DOMContentLoaded', (event) =>
window.__TAURI__.primitives.invoke('app_loaded_successfully')
window.__TAURI__.core.invoke('app_loaded_successfully')
)
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions tooling/cli/src/migrate/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
process::Command,
};

const CORE_API_MODULES: &[&str] = &["dpi", "event", "path", "primitives", "window", "mocks"];
const CORE_API_MODULES: &[&str] = &["dpi", "event", "path", "core", "window", "mocks"];
const JS_EXTENSIONS: &[&str] = &["js", "jsx", "ts", "tsx", "mjs"];

pub fn migrate(app_dir: &Path, tauri_dir: &Path) -> Result<()> {
Expand All @@ -40,7 +40,7 @@ pub fn migrate(app_dir: &Path, tauri_dir: &Path) -> Result<()> {
let original = cap.get(0).unwrap().as_str();

if module == "tauri" {
let new = "@tauri-apps/api/primitives".to_string();
let new = "@tauri-apps/api/core".to_string();
log::info!("Replacing `{original}` with `{new}` on {}", path.display());
new
} else if CORE_API_MODULES.contains(&module) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { invoke } from "@tauri-apps/api/primitives"
import { invoke } from "@tauri-apps/api/core"
let name = "";
let greetMsg = ""
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/templates/plugin/webview-src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#if license_header}}
{{ license_header }}
{{/if}}
import { invoke } from '@tauri-apps/api/primitives'
import { invoke } from '@tauri-apps/api/core'

export async function execute() {
await invoke('plugin:{{ plugin_name }}|execute')
Expand Down

0 comments on commit c2ad4d2

Please sign in to comment.